Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Fast approximate of transcendental operations

$
0
0

Hi,

You might know the "Carmack" trick to have a fast and crude approximation of 1/sqrt(x). It is

float Q_rsqrt( float number )
{
	long i;
	float x2, y;
	const float threehalfs = 1.5F;

	x2 = number * 0.5F;
	y  = number;
	i  = * ( long * ) &y;
	i  = 0x5f3759df - ( i >> 1 );
	y  = * ( float * ) &i;
	y  = y * ( threehalfs - ( x2 * y * y ) );

	return y;
}

It takes an integer and see it as a raw sequence of bit. It then shifts to the right all the bits that in the process divide the exposant by 2. Then there are some more elaborate explanation on why the 0x5f3759df which one could find on wikipedia. It is about 10 times faster than a regular pow(x, -0.5) but has a low accuracy (only the first 2 digits are correct).

I've heard that x86-64 has a rsqrt operation that does this kind of trick. Is there a documented way on how to call such a function? Is there any other transcendental function which is also available as fast (and low accuracy) version?

I need it in one of my ordinary differential equation solver where x^(1/3), x^(1/5), ... needs to be computed to choose the best order at run time depending upon the timestep. When the ODE does not have any transcendental function, it becomes the bottleneck and I need to speed it up. I might adapt the "Carmack" trick but I was wondering if there was already one implemented in x86-64 ?


Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>