x = some_bool ? a : b;
x = (some_bool & a) | (~some_bool & b);
C arguably picked the wrong semantics here. Hardware picks up the slack, however, with the setcc instructions on x86, csinc on AArch64, etc.
const True = -1
const False = 0
const ternary = (condition, left, right) => \
(condition & left) | (~condition & right)
ternary(True, 0, 1) // 0
ternary(False, 0, 1) // 1
I assume someone once upon a time thought it was a nice thing for ~x to be equal to !x.
"Cranelift is designed to be a code generator for WebAssembly, but it is general enough to be useful elsewhere too. The initial planned uses that affected its design are:
WebAssembly compiler for the SpiderMonkey engine in Firefox.
Debug build backend for the Rust compiler."
If it is to generate code with the same optimization quality and hardware support as LLVM, not really.
There are still cases where LLVM is playing catch up with GCC.
I also would like to see a pure Rust compiler toolchain, but sometimes pragmatism wins.