bool
values are mostly used in comparisons, and using the int
type uses the integer ALU for these comparisons. It is very fast, as it's in the CPU's normal pipeline. If you were to use the float
type, then it would have to use the floating-point unit, which would take more cycles.
Also, if you wanted to support using your bool
type in mathematical expressions, i.e.:
x = (4 * !!bool1) + (2 * !bool1);
so as to avoid unnecessary branching, your use of the integer ALU would also be faster than using the floating point unit.
The above code is equivalent to the following branching code:
if (bool1) {
x = 4;
} else {
x = 2;
}