开发者

fesetround with MSVC x64

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;
  _m开发者_如何学运维xcsr |= (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 use MASM? Any advice is appreciated. Thank you.


The VC++ runtime library does provide equivalents, e.g. _control87, _controlfp, __control87_2 so you should be able to provide an implementation without resorting to assembler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜