I want to be able to set or clear (multiple) bits of a
i = b ? (i | mask) : (i & ~mask)
Exploiting the fact that
-1u is the value with all bits set:
i = (i & ~mask) | (mask & -b);
i ^= (i ^ -b) & mask;
The second approach reduces the number of operations and code size. The first approach may still be faster on a superscalar architecture because some operations can be executed in parallel.