The portable way of accessing bits in the FP representation is to write into a union, which writes into memory. At least, that's what glibc does. But the code below looks wildly overcomplicated, as well as slow. I'm wondering whether there is an x86 instruction to copy 64 accessible bits of an FP register into an integer register so that the bits can be manipulated? This wouldn't be portable, but the idea is to have an inline function, and each port has to implement a standard c开发者_开发知识库lean (and fast) routine.
In this case I'm looking at isnan, which is implemented as:
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
int __isnan(double x)
{
int32_t hx,lx;
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
hx |= (u_int32_t)(lx|(-lx))>>31;
hx = 0x7ff00000 - hx;
return (int)(((u_int32_t)hx)>>31);
}
There is no x86 instruction to copy a FP register into an integer register or vice versa. You can probably get what you want by using SSE instrinsics instead, since an SSE register can contain both integer and floating point values.
精彩评论