FPU Exceptions

FPU Exceptions

Hello

I want floating-point exceptions to raise if operation result was not-a-number or infinity. To make this happen I use 'fldcw' instruction with '0x360' argument and it works fine on FPU-unit instructions.

Would exceptions raise if compiler has generated SSE-unit instructions to perform floating point operations (instead of FPU-unit instructions)?

Kirill Prazdnikov

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

SSE/SSE2 opcodes use another control word than the legacy x87 CW for exceptions, rounding mode and such. Provided that there isn't a higher level call that set both x87 + SSE CW consistently (I'm not sure if such a call is available) you will have to set both CW independently. For the SSE/SSE2 code, have a look at the "_mm_setcsr" and "_mm_getcsr" intrinsics.

The code snippet below should do more or less what you want, clear all exceptions flags and mask all exceptions but INVALID and OVERFLOW. Have a look at the doc. to be real sure...

#include

void Func()
{
_mm_setcsr( _MM_MASK_MASK & ~ (_MM_MASK_OVERFLOW|_MM_MASK_INVALID) );

// your code...
}

Melden Sie sich an, um einen Kommentar zu hinterlassen.