[cfe-dev] -fdenormal-fp-math
Evandro Menezes via cfe-dev
cfe-dev at lists.llvm.org
Thu Mar 16 10:43:56 PDT 2017
Hal,
Would it be feasible for clang to generate crtfastmath.o on the fly at
link time, by using LLVM to emit the object file?
Thank you,
--
Evandro Menezes
On 03/16/2017 12:40 PM, Hal Finkel wrote:
>
> On 03/16/2017 11:35 AM, Evandro Menezes wrote:
>> Hi, Hal.
>>
>> For the benefit of all, on foil 14 in this presentation by Intel,
>> https://is.gd/7Ptgwx, the issues of underflow and denormals in
>> IEEE754 are explained.
>>
>> Here's what I found out in GCC:
>>
>> On {aarch64,alpha,arm,i386,ia64,mips,sparc}, when
>> {-Ofast,-ffast-math,-funsafe-math-optimizations} is specified, the
>> file crtfastmath.o is added to the link line.
>>
>> crtfastmath.c contains a static function with the attribute
>> "constructor" that sets the appropriate flag in a control register to
>> round denormals to zero. Some targets set other bits too (like Alpha
>> and i386, also to round underflows to zero, and MIPS, also to disable
>> exceptions).
>>
>> Sun's SPARC compiler also flushes underflows and denormals to zero
>> when the option {-fast,-fnonstd,-fns} is specified. The reason given
>> (v. https://is.gd/6jxW97) is also performance degradation.
>>
>> Since clang has a specific flag to guide the behavior of denormals,
>> -fdenormal-fp-math, it could be used to make sure that the FPU is set
>> to the same specified behavior: {ieee,preserve-sign,positive-zero}.
>
> I don't know if we can use ctrfastmath.o for this, independent of
> -ffast-math, essentially because we have no control over what else it
> might do, but I can certainly see shipping (e.g. as part of
> compiler-rt) some similar files that specifically deal with denormals.
>
> -Hal
>
>> Again, specific targets might decide to imply a value other than
>> "ieee" for -fdenormal-fp-math when -funsafe-math-optimizations is
>> specified, either explicitly or implicitly.
>>
>> Thank you,
>>
>
More information about the cfe-dev
mailing list