fesetround with MSVC x64
- by mr grumpy
I'm porting some code to Windows (sigh) and need to use fesetround. MSVC doesn't support C99, so for x86 I copied an implementation from MinGW and hacked it about:
//__asm__ volatile ("fnstcw %0;": "=m" (_cw));
__asm { fnstcw _cw }
_cw &= ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO);
_cw |= mode;
//__asm__ volatile ("fldcw %0;" : : "m" (_cw));
__asm { fldcw _cw }
if (has_sse) {
unsigned int _mxcsr;
//__asm__ volatile ("stmxcsr %0" : "=m" (_mxcsr));
__asm { stmxcsr _mxcsr }
_mxcsr &= ~ 0x6000;
_mxcsr |= (mode << __MXCSR_ROUND_FLAG_SHIFT);
//__asm__ volatile ("ldmxcsr %0" : : "m" (_mxcsr));
__asm { ldmxcsr _mxcsr }
}
The commented lines are the originals for gcc; uncommented for msvc. This appears to work.
However the x64 cl.exe doesn't support inline asm, so I'm stuck. Is there some code out there I can "borrow" for this? (I've spent hours with Google). Or will I have to go on a 2 week detour to learn some assembly and figure out how to get/use MASM? Any advice is appreciated. Thank you.