Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.

gcc x87

leo1981816
Beginner
205 Views
i have a problem, code like this:
int _float2int(float f)
{
int i;

__asm fld f
__asm fistp i

return i;
}
how to rewrite with gcc
0 Kudos
1 Reply
Dale_S_Intel
Employee
205 Views
I assume you're asking about how to generally use gcc style asm?
For details try googling "gcc inline asm".
If you've got MS style asm already, you could just use "icc -use-msasm" to avoid rewriting everything in gcc style. This should work as long as you don't mix the two (some system headers may contain gcc style inline asm)
I assume you're using inline asm to convert floats to ints for performance
reasons. In that case you may want to try using SSE instructions instead
of x87, which you could do with intrinsics such as _mm_cvtps_epi32(), thus avoiding inline asm entirely.
Finally, if you're still determined to use gcc stylex87 assembly, you could try something like this:
__asm__("flds %1;
fistpl %0;": "=m" (i) : "m" (f));
I believe in gnu style asm you need to specify the sizes as a suffix to the instruction name, hence "flds" and "fistpl".
Dale
Reply