Skip to content

Make floating-point abs IEEE 754 compliant

I think conformance to the floating-point standard is a good thing to have (cf. #9276).

IEEE 754 specifies abs operation to clear the sign bit, even if the value is NaN.

The current status is

  • NCG backend
    • x86: Lowers to bit manipulation (by 12ccf767), which is IEEE compliant
    • PPC: Lowers to FABS instruction (by 068af016), which is IEEE compliant
    • AArch64: Lowers to FABS instruction (by #20275 (closed) and !6421 (closed)), which is IEEE compliant
    • SPARC NCG was recently removed so we don't need to care :)
  • LLVM backend: Lowers to llvm.fabs.(f32|f64) (by 12ccf767), which is equivalent to C fabs(f) and should be IEEE compliant
  • unregisterised via-C backend: currently does not use fabs(f) and not IEEE compliant

So a change to via-C backend will make abs IEEE compliant.

Proposal

Change via-C backend to use fabs(f) (which is IEEE compliant if Annex F is supported) and declare abs to be IEEE compliant.

This implies that future NCGs would need to lower fabs(Float|Double)# primop to some native FABS instruction.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information