Original Post
Use the code below to save a (very small) amount of time:
float sqrtf(float X)
{
__asm fld X
__asm fsqrt
}
Explanation:
Floating point values aren''t stored in x86 registers like integer values. Floating point vars like float or double are just left in the first floating point stack register (called st oder st(0)) so the calling function can easily use them.
If you write
float sqrts(float X)
{
__asm fld X
__asm fsqrt
__asm fstp X
return X;
}
your C/C++ compiler will compile it to:
fld dword ptr [ebp+04]
fsqrt
fstp dword ptr [ebp+04]
fld dword ptr [ebp+04]
ret
As you can see, the return command for a floating point value is just a fld call to load it into the first floating point stack register.
So if you just leave the sqrt in the register you get:
fld dword ptr [ebp+04]
fsqrt
ret
If you need more informations about registers email me (bjurke@gmx.de).