unageek / inari

A Rust implementation of interval arithmetic (IEEE 1788)
MIT License
32 stars 2 forks source link

[question] Protected against LLVM reordreing bug? #60

Closed Chris00 closed 2 years ago

Chris00 commented 2 years ago

I saw that LLVM can reorder rounding-mode-sensitive float operations outside rounding mode changes in SSE so I was wondering whether Inari is affected by this. While I am at it, I would like to make sure that I understood well the code (my ASM is very limited) and that there is no rounding that can adversely affect the result when stored from extended precision into memory. (I want to use your library for computer assisted proofs and I'd like to be reassured that it is 100% reliable. 😀)

unageek commented 2 years ago

The add_ru function, for example, does the following:

  1. Save the current value of the MXCSR register to the stack.
  2. Set the value of the MXCSR register to 24448 or 0x5F80, which tells FP operations to round the result toward +∞, while suppressing any FP exceptions.
  3. Perform FP addition.
  4. Restore the saved value of the MXCSR register.

The above operations are embedded in a single inline asm, which is immune to optimizations.