[LLVMdev] Is LLVM’s floating point operations IEEE 754 compliant on x86?

Chen Li meloli87 at gmail.com
Fri May 30 12:34:46 PDT 2014


Hi llvmdev,

I would like to know some implementation details of LLVM’s floating point operations on x86. Is it IEEE 754 compliant by default?

On x86, the precision of floating point operations could be very different due to different implementations. For example, FPU (x87) instructions allows better precision by calculating 80-bit intermediate results, while SSE2 instructions only have single and double precision. FMA (fused multiply-add) is another example of reducing two roundings to a single rounding compared with normal multiply-add. 

>From LLVM language reference manual, I saw there are several floating point types defined, e.g., x86_fp80 to use 80-bit x87 register, and double of 64-bit. Does this imply that x87 is only supported when an explicit x86_fp80 is declared or it is also supported in intermediate results of 64-bit double floating point operations? Anything to do with the fast-math flag?

I have also found a old note on LLVM’s floating point operations back to 2004 (http://nondot.org/sabre/LLVMNotes/FloatingPointChanges.txt) and I am not sure if it is still valid today. In the note, it is said LLVM’s x86 floating point implementation is not IEEE 754 compliant by default because of performance considerations. However, nowadays, some of those concerns might not be true any longer. From what I’ve read, especially on x86-64, some SSE2 instructions are more efficient than FPU instructions, and therefore, having IEEE compliant operations is not expensive as it used to be. And the proposed add_strict (operations to support IEEE compliant) in the note seems not pushed in the mainstream. 

Based on what I found so far, I think LLVM’s default setting is to only allow fmuladd as fused floating point operations (defined by FPOpFusion in TargetOptions.h), but I am not sure how x87 is used. Dose anyone know some details of those?

Also, what does LLVM do with compile time optimizations on floating point? For example, constant folding on (1.5 + 2.5 + 3.5), does it use the same precision on the intermediate result or it only does one rounding at the end?

Thanks in advance!

best,
chen 
 



More information about the llvm-dev mailing list