mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-14 18:02:22 -07:00
d72db2698b
Recent LLVM is getting smart to the point where the optimizer can change a traditional constant-time conditional swap into a pointer swap. Ensure that this does not happen by force-disabling optimization. Additionally, disable inlining the relevant routines such that manual inspection in optimized builds is still reasonably easy to do.
27 lines
640 B
Odin
27 lines
640 B
Odin
package fiat
|
|
|
|
// This package provides various helpers and types common to all of the
|
|
// fiat-crypto derived backends.
|
|
|
|
// This code only works on a two's complement system.
|
|
#assert((-1 & 3) == 3)
|
|
|
|
u1 :: distinct u8
|
|
i1 :: distinct i8
|
|
|
|
@(optimization_mode="none")
|
|
cmovznz_u64 :: proc "contextless" (arg1: u1, arg2, arg3: u64) -> (out1: u64) {
|
|
x1 := (u64(arg1) * 0xffffffffffffffff)
|
|
x2 := ((x1 & arg3) | ((~x1) & arg2))
|
|
out1 = x2
|
|
return
|
|
}
|
|
|
|
@(optimization_mode="none")
|
|
cmovznz_u32 :: proc "contextless" (arg1: u1, arg2, arg3: u32) -> (out1: u32) {
|
|
x1 := (u32(arg1) * 0xffffffff)
|
|
x2 := ((x1 & arg3) | ((~x1) & arg2))
|
|
out1 = x2
|
|
return
|
|
}
|