Could someone clarify why using NOT
operator twice like in the following example:
setBits += !!(n & mask); // if some bits match between n and mask, setBits = 1, else setBits = 0
Which basically works in C language, and also work after I had rewritten it this way:
setBits += if (n & mask) != 0 {1} else {0};
Does not work as intended in Rust? As of now, it returns the value of n & mask, while I want to force twice NOT at the bytecode level and avoid branching (cmp
instructions).
NB: I just checked the assembly code and apparently the Rust compiler optimize it away...
However !!value
is not equivalent to value
Any way to force NOT x2
and avoid CMP
instruction?