<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.apple-tab-span
{mso-style-name:apple-tab-span;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:70.85pt 70.85pt 56.7pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Wouldn’t it be better to use the target’s implementation (if there is one) instead of generically using one option for constant folding? Otherwise
target behavior and constant folded behavior would differ, which should be avoided if possible IMO.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Johannes S. Mueller-Roemer, MSc<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Wiss. Mitarbeiter - Interactive Engineering Technologies (IET)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Fraunhofer-Institut für Graphische Datenverarbeitung IGD<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Fraunhoferstr. 5 | 64283 Darmstadt | Germany<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Tel +49 6151 155-606 | Fax +49 6151 155-139<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">johannes.mueller-roemer@igd.fraunhofer.de | www.igd.fraunhofer.de<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Stephen Canon<br>
<b>Sent:</b> Thursday, August 14, 2014 18:03<br>
<b>To:</b> Matt Arsenault<br>
<b>Cc:</b> llvm-commits; LLVM Developers Mailing List<br>
<b>Subject:</b> Re: [LLVMdev] [PATCH][RFC]: Add fmin/fmax intrinsics<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">… actually, now that I’m able double-check this, I’m quite surprised to find that we didn’t define fmax(+0,–0) in IEEE–754, which says [paraphrased]:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span class="apple-tab-span"> </span><b>minNum</b>(x,y) is x if x < y, y if y < x, and the number if one is a number and the other is NaN. Otherwise, it is either x or y (this means results might differ among implementations).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">So I think your proposed semantics are perfectly reasonable.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">– Steve<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Aug 14, 2014, at 10:55 AM, Steve Canon <<a href="mailto:scanon@apple.com">scanon@apple.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I have no position on whether or not these should be added, but if they are they should match the IEEE 754 semantics, which fully specify all of these details.<br>
<br>
(Signaling NaNs could still be left unspecified as they're optional in IEEE-754).<br>
<br>
- Steve<br>
<br>
Sent from my iPhone<br>
<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">On Aug 13, 2014, at 7:38 PM, Matt Arsenault <<a href="mailto:arsenm2@gmail.com">arsenm2@gmail.com</a>> wrote:<br>
<br>
Hi,<br>
<br>
I’d like to re-propose adding intrinsics for fmin / fmax. These can be used to implement the equivalent libm functions as defined in C99 and OpenCL, which R600 and AArch64 at least have instructions with the same semantics. This is not equivalent to a simple
fcmp + select due to its handling of NaNs. <br>
<br>
This has been proposed before, but never delivered (<a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/057128.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/057128.html</a>)<br>
<br>
To summarize:<br>
1. If either operand is a NaN, returns the other operand<br>
2. If both operands are NaN, returns NaN<br>
3. If the operands are equal, returns a value that will compare equal to both arguments<br>
4. In the normal case, returns the smaller / larger operand<br>
5. Ignore what to do for signaling NaNs, since that’s what the rest of LLVM does currently anyway<br>
<br>
- Handling of fmin/fmax (+/- 0.0, +/- 0.0)<br>
Point 3 is worded as such because this doesn’t seem particularly well specified by any standard I’ve looked at. The most explicit mention of this I’ve found is a footnote in C99 that “Ideally, fmax would be sensitive to the sign of zero, for example fmax(-0.0,
0.0) would return +0; however, implementation in software might be impractical.” It doesn’t really state what the expected behavior is. glibc and OS X’s libc disagree on the (+0, -0) and (-0, +0) cases. To resolve this, the semantics of the intrinsic will
be that either will be OK as long as the result compares equal.<br>
<br>
For the purposes of constant folding, I’ve tried to follow the literal wording which was most explicit for the expected result from OpenCL (<a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/fmin.html">http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/fmin.html</a>)
and taking the comparison +/-0.0 < +/-0.0 will fail.<br>
<br>
This means the constant folded results will be:<br>
fmin(0.0, 0.0) = 0.0<br>
fmin(0.0, -0.0) = 0.0<br>
fmin(-0.0, 0.0) = -0.0<br>
fmin(-0.0, -0.0) = -0.0<br>
<br>
Other options would be to always use +0.0, or to be sensitive to the sign and claim -0.0 is less than 0.0.<br>
<br>
<0001-Add-fmin-fmax-intrinsics.patch><br>
<0002-Add-basic-fmin-fmax-instcombines.patch><br>
<0003-Fold-fmin-fmax-with-infinities.patch><br>
<0004-Move-fmin-fmax-constant-folding-logic-into-APFloat.patch><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>