Have a short test code for SSE2 instruction.
#include <windows.h>
#include <emmintrin.h>
int _tmain(int argc, _TCHAR* argv[])
{
const __m128d data1= {0, 0};
const __m128d data2= {1, 1};
_asm
{
movapd xmm0, data1
movapd xmm1, data2
cvtpd2pi mm0, xmm1
cvtpi2pd xmm0, mm0
}
double i=0;
i=i+1; //Debug and look at value of i !!!
return 1;
}
Compile and run it, it seems everything fine, but when I debug into the
code, in the line i=i+1;
you will find the value of i showing as " -1.#IND000000000000"
The problem is caused by " cvtpd2pi mm0, xmm1", if you comment these two
lines, nothing wrong with i. It seems to me instruction cvtpd2pi ruin the
stack.
Help, please!
Niki Estner - 16 Nov 2004 11:06 GMT
> Have a short test code for SSE2 instruction.
>
[quoted text clipped - 28 lines]
> lines, nothing wrong with i. It seems to me instruction cvtpd2pi ruin the
> stack.
AFAIK This is not a compiler issue: MMX, SSE and SSE2 use the FPU stack to
store their data registers: After using one of these, you'll need an "emms"
instruction to reset the FPU registers.
The problem was that intel didn't want to add new registers to it's pentium
processor, as all OSs which use task switching (i.e. all) rely on the
current register set, so they decided to use the FPU stack. To prevent FPU
operations on a damaged stack, the FPU is set to some kind of special state.
Try:
_asm
{
movapd xmm0, data1
movapd xmm1, data2
cvtpd2pi mm0, xmm1
cvtpi2pd xmm0, mm0
emms
}
double i=0;
i=i+1; //Debug and look at value of i !!!
Works fine on my PC.
Niki
Deng - 16 Nov 2004 18:23 GMT
Thanks a loooooot, Niki!
Now I see what happened
> > Have a short test code for SSE2 instruction.
> >
[quoted text clipped - 56 lines]
>
> Niki