Skip to main content

consttime_cmove

Function consttime_cmove 

Source
pub fn consttime_cmove(bits: impl FnMut() -> u64) -> f64
Expand description

Modified port of uniformbinary64_consttime: like fast, but the zero-m event is branchless, with the flag computed as m != 0.

This is a small variant of mine: it relies on the compiler turning the comparison into a conditional-move–style instruction (setne, cset) rather than a branch. Taylor prefers the bit-smearing variant (consttime) because, for security reasons, it guarantees at the source level that no test can be inserted by the compiler, whereas here the absence of a branch is at the optimizer’s discretion.

Always consumes three 64-bit words.