<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><br>
</p>
<div class="moz-cite-prefix">On 03/16/2017 12:43 PM, Evandro Menezes
wrote:<br>
</div>
<blockquote
cite="mid:895e1e2f-ee5d-25b2-119b-aef9bc4090b8@samsung.com"
type="cite">
<div class="moz-text-flowed" style="font-family: -moz-fixed;
font-size: 12px;" lang="x-unicode">Hal,
<br>
<br>
Would it be feasible for clang to generate crtfastmath.o on the
fly at link time, by using LLVM to emit the object file?
<br>
</div>
</blockquote>
<br>
We could. We could also just inject the necessary IR into each
module as a linkonce_odr initialization function. I'm not sure it is
worthwhile; we depend on compiler-rt for a lot of optional features.<br>
<br>
-Hal<br>
<br>
<blockquote
cite="mid:895e1e2f-ee5d-25b2-119b-aef9bc4090b8@samsung.com"
type="cite">
<div class="moz-text-flowed" style="font-family: -moz-fixed;
font-size: 12px;" lang="x-unicode">
<br>
Thank you,
<br>
<br>
<div class="moz-txt-sig"><span class="moz-txt-tag">-- <br>
</span>Evandro Menezes
<br>
<br>
On 03/16/2017 12:40 PM, Hal Finkel wrote:
<br>
<blockquote type="cite" style="color: #000000;">
<br>
On 03/16/2017 11:35 AM, Evandro Menezes wrote:
<br>
<blockquote type="cite" style="color: #000000;">Hi, Hal.
<br>
<br>
For the benefit of all, on foil 14 in this presentation by
Intel, <a moz-do-not-send="true"
class="moz-txt-link-freetext"
href="https://is.gd/7Ptgwx">https://is.gd/7Ptgwx</a>,
the issues of underflow and denormals in IEEE754 are
explained.
<br>
<br>
Here's what I found out in GCC:
<br>
<br>
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.
<br>
<br>
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).
<br>
<br>
Sun's SPARC compiler also flushes underflows and denormals
to zero when the option {-fast,-fnonstd,-fns} is
specified. The reason given (v. <a
moz-do-not-send="true" class="moz-txt-link-freetext"
href="https://is.gd/6jxW97">https://is.gd/6jxW97</a>) is
also performance degradation.
<br>
<br>
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}.
<br>
</blockquote>
<br>
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.
<br>
<br>
-Hal
<br>
<br>
<blockquote type="cite" style="color: #000000;"> 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.
<br>
<br>
Thank you,
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</div>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>