This is not branchless.
It's if-less. But the ternary operator (?:) is a branching instruction.
It's if-less. But the ternary operator (?:) is a branching instruction.
f(x) ? y : 0
can also be written as (int)(bool)f(x) * yIf the constants had been less convenient numbers, like 42, the compiler could have instead used a conditional move instruction -- more general-purpose, but I believe slightly larger and often ever-so-slightly slower.