float to int conversion (and msvc inline assembly)
How do I get float to int convertion faster than regular typecasting? I wrote a function with an inline assembler routine, that looks like this:
uint32 fistp(float * f)
{
uint32 * tmp;
__asm
{
mov eax, f
fld [eax]
fistp [ebx]
mov tmp, eax
}
return *tmp;
}
but it turned out to be slower than int i = (float)f.
It feels like this could be done faster, but I just don''t have enough knowledge of how the FPU works and how MSVC deals with inline asm, so any links on that topic would be great.
thanks.
//pl
If only I knew ASM. That would be cool for both of us.
Dennis
Dennis
visit my site, please:members.nbci.com/dennis428/default.htm
there is a slight problem with your function:
uint32 *tmp;
does not allocate any memory to store the unsigned integer. secondly fistp does not return unsigned integers.
try this:
int32 __fistp(float f)
{
int32 iresult;
__asm {
fld f
fistp iresult;
}
return (iresult);
}
this still won''t be faster than:
float f;
int i = (int)f;
because of the function call and stack pushes and pops. you can try __inline though which should speed up the process by eliminating the function call.
uint32 *tmp;
does not allocate any memory to store the unsigned integer. secondly fistp does not return unsigned integers.
try this:
int32 __fistp(float f)
{
int32 iresult;
__asm {
fld f
fistp iresult;
}
return (iresult);
}
this still won''t be faster than:
float f;
int i = (int)f;
because of the function call and stack pushes and pops. you can try __inline though which should speed up the process by eliminating the function call.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
try your function as
int32 __declspec(naked) __fistp(float f)
{
__asm
{
fld eax;
fistp eax;
ret
}
}
i dont know if it works so, i cant boot vc++ currently i dont have the time, but i try it when i can
we wanna play, not watch the pictures
int32 __declspec(naked) __fistp(float f)
{
__asm
{
fld eax;
fistp eax;
ret
}
}
i dont know if it works so, i cant boot vc++ currently i dont have the time, but i try it when i can
we wanna play, not watch the pictures
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement