Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Question on performance



> Date: Sat, 09 Oct 2010 11:06:18 +0200
> From: Arnold Neumaier <Arnold.Neumaier@xxxxxxxxxxxx>
> To: 1788 <stds-1788@xxxxxxxxxxxxxxxxx>
> Subject: Question on performance
> 
> I have a question about performance on current 754-conforming hardware:
> 
> 
> Suppose I write code consisting only of 754 floating-point operations
> and calls to simple customized additional functions such as
>      nan2zero(x), which returns 0 if isnan(x), and x otherwise.
> 
> 
> Will the code generated by a standard, good compiler run --
> 
> (i) essentially as efficient as without these function calls?
> 
> (ii) essentially as efficient as if it contained explicit case
> distinctions?
> 
> (iii) intermediate but still efficient?
> 
> (iv) intermediate but still inefficient?
> 
> 
> In case of (ii) or (iv), could a special purpose compiler do 
> significantly better?
> 
> 
> 
> Arnold Neumaier

	That will work well.  Not as efficient as not doing it,
	of course, but more efficient than you think.  Modern
	compilers are pretty routinely inlining that sort of
	thing so it should go better than even a simple user
	function call.  In fact, to aid it along, rather than
	writing it as a function call you might consider just
	using a #define.  Something like:

#define nan2zero(x) ((isnan(x))?0.0:x)

	Then there is no function call in the first place.

	Good luck.  - Dan