I am working on a Rust box that changes the rounding mode (+ inf, -inf, nearest or truncate).
Functions that change the rounding mode are recorded using the built-in assembly:
fn upward() { let cw: u32 = 0; unsafe { asm!("stmxcsr $0; mov $0, %eax; or $$0x4000, %eax; mov %eax, $0; ldmxcsr $0;" : "=*m"(&cw) : "*m"(&cw) : "{eax}" ); } }
When I compile the code in debug mode, it works as intended, I get 0.3333333333337 one-third when rounded to positive infinity, but when I compile in free mode, I get the same result no matter what rounding mode I set. I assume this behavior is related to the optimizations that the LLVM server does.
If I knew which LLVM passes are responsible for this optimization, I can disable them, because at the moment I do not see another workaround.
source share