-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial cmov
crate
#741
Initial cmov
crate
#741
Conversation
Implements safe wrappers for the `cmovz` and `cmovnz` instructions which work on `x86` and `x86_64`, implemented using inline assembly. Using inline assembly allows us to provide a sort of black box which LLVM will not interfere with, which is otherwise problematic when using anything besides ASM. It's otherwise not possible to correctly emit CMOV instructions on x86 platforms with LLVM because the `x86-cmov-conversion` pass which will potentially rewrite them as branches. For more details, see: https://dsprenkels.com/cmov-conversion.html
Adds a fallback implementation based on bitwise arithmetic, which allows the crate to work on any target architecture. Unfortunately, this implementation cannot guarantee constant-time operation in the same way as dedicated instructions are able to.
Went ahead and added a portable fallback implementation for non-x86/x86_64 platforms in 5dfbdca with optimizations in 876653d which uses bitwise arithmetic but can't otherwise specifically guarantee constant-time operation. I think it's nice to have from an ergonomics perspective, even if we can't make guarantees. We could potentially add some tests that automatically inspect the generated assembly and make sure the generated instructions fall within a particular allow list. That'd provide a degree of due diligence that the resulting implementation is constant time, if not a guarantee. |
Implements safe wrappers for the
cmovz
andcmovnz
instructions which work onx86
andx86_64
, implemented using inline assembly.Using inline assembly allows us to provide a sort of black box which LLVM will not interfere with, which is otherwise problematic when using anything besides ASM.
It's otherwise not possible to correctly emit CMOV instructions on x86 platforms with LLVM because the
x86-cmov-conversion
pass which will potentially rewrite them as branches.For more details, see:
https://dsprenkels.com/cmov-conversion.html