<HTML>
<HEAD>
<TITLE>Re: [vtk-developers] vtkMath inline choices...</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>The patch looks OK to me, but I defer final judgment to those at Kitware that have to support it. &nbsp;To this end, I have posted the commit to gerrit for review. &nbsp;The URL is<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><a href="http://review.source.kitware.com/760">http://review.source.kitware.com/760</a><BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
Could we get a volunteer from Kitware to take a look at the changes?<BR>
<BR>
-Ken<BR>
<BR>
<BR>
On 1/21/11 2:28 PM, &quot;Sean McBride&quot; &lt;<a href="sean@rogue-research.com">sean@rogue-research.com</a>&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Kenneth,<BR>
<BR>
I know it's been months, but I've finally learned enough git to pursue<BR>
this....<BR>
<BR>
<BR>
On Wed, 15 Sep 2010 09:24:14 -0600, Moreland, Kenneth said:<BR>
<BR>
&gt;I can speak to why IsNan is not inlined. &nbsp;The IsNan (and similar non-<BR>
&gt;finite tests) rely on some non-portable functionality. &nbsp;Depending on<BR>
&gt;whether the isnan function is provided, IEEE-754 numbers are used, or if<BR>
&gt;operations on NaNs are trapped, different implementations are provided.<BR>
&gt;Over time this can get even more complicated as we encounter computers<BR>
&gt;and compilers that treat NaNs differently. &nbsp;Quite simply, I did not want<BR>
&gt;to expose all of this complexity in the header file.<BR>
<BR>
vtkMath::IsNan() is currently implemented like so:<BR>
<BR>
int vtkMath::IsNan(double x)<BR>
{<BR>
#ifdef VTK_HAS_ISNAN<BR>
&nbsp;&nbsp;return (isnan(x) ? 1 : 0);<BR>
#else<BR>
&nbsp;&nbsp;return !((x &lt;= 0.0) || (x &gt;= 0.0));<BR>
#endif<BR>
}<BR>
<BR>
I don't see any IEEE-754 assumptions/non-portable code there.... but<BR>
then I noticed isnan() itself is conditionally redefined. &nbsp;Evil. :)<BR>
<BR>
&gt;If you plan to go through the trouble of moving that to the header file,<BR>
&gt;you should do performance tests to make sure that there is a clear<BR>
&gt;advantage to inlining the function. &nbsp;I've been surprised in the past to<BR>
&gt;find an inline function did not really perform any better than a<BR>
&gt;function call. &nbsp;The fact of the matter is that function calls are cheap<BR>
&gt;operations nowadays.<BR>
<BR>
For me, in Release, vtkMath::IsNan() becomes:<BR>
<BR>
+0x0 &nbsp;&nbsp;&nbsp;pushq &nbsp;&nbsp;%rbp<BR>
+0x1 &nbsp;&nbsp;&nbsp;movq &nbsp;&nbsp;&nbsp;%rsp, %rbp<BR>
+0x4 &nbsp;&nbsp;&nbsp;xorl &nbsp;&nbsp;&nbsp;%eax, %eax<BR>
+0x6 &nbsp;&nbsp;&nbsp;ucomisd %xmm0, %xmm0<BR>
+0xa &nbsp;&nbsp;&nbsp;setpb &nbsp;&nbsp;%al<BR>
+0xd &nbsp;&nbsp;&nbsp;leave &nbsp;<BR>
+0xe &nbsp;&nbsp;&nbsp;ret &nbsp;&nbsp;&nbsp;<BR>
+0xf &nbsp;&nbsp;&nbsp;nop &nbsp;&nbsp;&nbsp;<BR>
<BR>
Profiling (by sampling) a slow spot in my app, I spend a full 5% of my<BR>
time in it (it's number #2). &nbsp;That's a lot of samples for a 7<BR>
instruction function. &nbsp;And of the samples that occur within it, 75% of<BR>
them are the initial 'pushq' or the 'ret'. &nbsp;I do believe inlining would<BR>
help here.<BR>
<BR>
What do you think of the attached patch? &nbsp;I inline IsNan only if<BR>
VTK_HAS_ISNAN is true, so the yucky stuff is still hidden in the .c. &nbsp;I<BR>
had to #include &quot;vtkMathConfigure.h&quot; in vtkMath.h, which would mean that<BR>
vtkMathConfigure.h would have to be 'installed' also. &nbsp;I don't know how<BR>
to do that.<BR>
<BR>
Cheers,<BR>
<BR>
--<BR>
____________________________________________________________<BR>
Sean McBride, B. Eng &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="sean@rogue-research.com">sean@rogue-research.com</a><BR>
Rogue Research &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.rogue-research.com<BR>
Mac Software Developer &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Montr&eacute;al, Qu&eacute;bec, Canada<BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'><BR>
&nbsp;&nbsp;&nbsp;**** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kenneth Moreland<BR>
&nbsp;&nbsp;&nbsp;&nbsp;*** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sandia National Laboratories<BR>
*********** &nbsp;<BR>
*** *** *** &nbsp;email: <a href="kmorel@sandia.gov">kmorel@sandia.gov</a><BR>
** &nbsp;*** &nbsp;** &nbsp;phone: (505) 844-8919<BR>
&nbsp;&nbsp;&nbsp;&nbsp;*** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;web: &nbsp;&nbsp;<a href="http://www.cs.unm.edu/~kmorel">http://www.cs.unm.edu/~kmorel</a><BR>
</SPAN></FONT></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT>
</BODY>
</HTML>