Negative_3
n00b
- Joined
- Apr 14, 2008
- Messages
- 45
Hi. I have a problem. I am writing a C program in Visual Studio 2005 Pro and when I comment out a printf() statement, the whole program crashes. It doesn't make any sense to me, but hopefully some one here knows what the problem is.
Here is a simple program with some SSE instructions.
That prefetcht0 just puts f3 in the top level of CPU cache (which is where it would already be as f3 was just initialized). Then the program moves the four floating point numbers in f1 into SSE register xmm0. It moves f2 into SSE register xmm1. Then it adds the four floats in xmm0 with the corresponding floats in xmm1 and stores the results in xmm1. Then it square roots each of the 4 floats in xmm1 and stores the results in xmm1. Then it writes those results from xmm1 into f3. Then it displays the results as expected:
Now lets comment out a printf() statement:
And lets see what happens:
Wow, how does removing a printf() statement make the program crash?
I tried debugging it and I get this mess:
I hit the break button and it takes me here:
The problem is the movaps instruction??
How could removing a printf() statement cause that to fail?
Here is the source code in a non picture format:
Here is a simple program with some SSE instructions.
That prefetcht0 just puts f3 in the top level of CPU cache (which is where it would already be as f3 was just initialized). Then the program moves the four floating point numbers in f1 into SSE register xmm0. It moves f2 into SSE register xmm1. Then it adds the four floats in xmm0 with the corresponding floats in xmm1 and stores the results in xmm1. Then it square roots each of the 4 floats in xmm1 and stores the results in xmm1. Then it writes those results from xmm1 into f3. Then it displays the results as expected:
Now lets comment out a printf() statement:
And lets see what happens:
Wow, how does removing a printf() statement make the program crash?
I tried debugging it and I get this mess:
I hit the break button and it takes me here:
The problem is the movaps instruction??
How could removing a printf() statement cause that to fail?
Here is the source code in a non picture format:
Code:
#include <stdio.h>
void main(void)
{
int i;
float f1[4]={1,2,3,4},f2[4]={3,7,13,21},f3[4]={0,0,0,0};
__asm
{
prefetchT0 f3
movaps xmm0,f1
movaps xmm1,f2
addps xmm1,xmm0
sqrtps xmm1,xmm1
movaps f3,xmm1
}
for(i=0;i<4;i++)
{
printf("%f, ",f3[i]);
}
printf("\n\n");
}