-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update q_math.c Q_rsqrt 10x #6
base: master
Are you sure you want to change the base?
Conversation
Removing unnecessary variables increases speed 10x from 1000 ns to 100 ns.
Have you benchmarked this with optimizations turned on? Doubtful it will make a difference in the end. |
Yes, I did a performance test, that's because the code in assembly is smaller, it also reduces the times in which it saves in memory and calls the memory again to do the other calculations, that makes it 10 times faster |
I did the tests in the online tools. I compared original vs new.
OnlineGDB:
New:
OnlineGDB:
I don't see much difference using |
In theory you can save the saving of 'y' in memory outside the game and place the return directly in the last function, that saves a step, and yes it is true some compilers already include optimization. |
I see, but it doesn't change anything with float Q_rsqrt( float number )
{
long i;
float x2;
x2 = number * 0.5F;
i = 0x5f3759df - ( * ( long * ) &number >> 1 );
return * ( float * ) &i * ( 1.5F - ( x2 * (* ( float * ) &i) * (* ( float * ) &i) ) );
} Even with the very reduced version: float Q_rsqrt( float number )
{
float x2 = number * 0.5f;
long i = 0x5f3759df - ( *( long* )&number >> 1 );
number = *( float* )&i;
return ( number * ( 1.5f - ( x2 * number * number ) ) );
} Nothing changes. The result is the same. |
Removing unnecessary variables increases speed 10x from 1000 ns to 100 ns.