Skip to content

Loop unrolling

A circuit cannot loop at run time the way a program does. __unroll repeats its body at compile time, producing one copy of the logic per iteration. The bounds must be constants.

masked_xor.flux
__fpga void maskedXor(bits<8> data, bits<8> mask, bits<8>& result) {
__unroll(int i = 0; i < 8; ++i) {
result[i] = data[i] ^ mask[i];
}
}

This is eight XOR gates side by side.

An ordinary for loop is an error.