开发者

fesetround with MSVC x64

开发者 https://www.devze.com 2023-01-02 04:32 出处:网络
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:

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

精彩评论

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