We are currently using two different algorithms for constant-time comparison of Words:
- the one in
CtChoice (e.g. from_word_lt()), using arithmetic on Word
- the one in
Limb's implementations of subtle traits, using arithmetic on WideWord
The latter seems to be faster than the former (from the limb.rs benchmarks). We should use just one version of the algorithms both for performance reasons, and for simplicity. Probably should be implemented in CtChoice, and the Limb's impls should call it and convert CtChoice to Choice.
Also there is a third way to do it, by using the built-in overflowing_sub() method instead of sbb. Seems to be producing branch-free assembly, according to Godbolt - how safe is it?
We are currently using two different algorithms for constant-time comparison of
Words:CtChoice(e.g.from_word_lt()), using arithmetic onWordLimb's implementations ofsubtletraits, using arithmetic onWideWordThe latter seems to be faster than the former (from the
limb.rsbenchmarks). We should use just one version of the algorithms both for performance reasons, and for simplicity. Probably should be implemented inCtChoice, and theLimb's impls should call it and convertCtChoicetoChoice.Also there is a third way to do it, by using the built-in
overflowing_sub()method instead ofsbb. Seems to be producing branch-free assembly, according to Godbolt - how safe is it?