inline asm with sse problem
wojtekb82_23
wojtekb82_23@o2.pl
Thu Feb 7 00:43:00 GMT 2008
Hi,
I have the code [appendix 1] that I compile using [appendix 2] on system [appendix 3].
I get a Segmentation fault at line:
0x080487ca <main+138>: movups (%esi),%xmm0
0x080487cd <main+141>: addps (%ebx),%xmm0 <- THIS ONE
0x080487d0 <main+144>: movups %xmm0,(%ebx)
What am I doing wrong?
Thanks in advance for any replies.
Kind regards,
WB.
BTW: if I compile the code with -O0 i get strange results in the generated executable:
0x08048896 <main+288>: mov 0xffffffe8(%ebp),%eax
0x08048899 <main+291>: movups (%eax),%xmm0
0x0804889c <main+294>: addps (%eax),%xmm0
0x0804889f <main+297>: movups %xmm0,(%eax)
0x080488a2 <main+300>: mov %eax,0xffffffe4(%ebp)
291 and 294 is (%eax) ???
-----------------------------------------------------------------
Appendix [1] :
#include <iostream>
using namespace std;
int main() {
float* dst = new float[4];
float* src = new float[4];
for(int i = 0; i<4; i++)
{
dst[i] = 0;
src[i] = 1;
}
cout << dst[0] << " " << dst[1] << " " << dst[2] << " " << dst[3] << endl;
asm ("movups 0(%[src]), %%xmm0\n\t"
"addps 0(%[dst]), %%xmm0\n\t"
"movups %%xmm0, 0(%[dst])\n\t"
: [dst] "=r" (dst)
: [src] "r" (src)
: "xmm0");
cout << dst[0] << " " << dst[1] << " " << dst[2] << " " << dst[3] << endl;
return 0;
}
-----------------------------------------------------------------
Appendix [2] :
Building file: ../src/main.cpp
Invoking: GCC C++ Compiler
g++ -O3 -msse -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/main.d" -MT"src/main.d" -o"src/main.o" "../src/main.cpp"
Finished building: ../src/main.cpp
Building target: testy
Invoking: GCC C++ Linker
g++ -o"testy" ./src/main.o
Finished building target: testy
-----------------------------------------------------------------
Appendix [3] :
wojtek@zbUbuntu:~/workspace/testy/Debug$ uname -a
Linux zbUbuntu 2.6.20-16-generic #2 SMP Fri Feb 1 02:59:08 UTC 2008 i686 GNU/Linux
wojtek@zbUbuntu:~/workspace/testy/Debug$ gcc --version
gcc (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
More information about the Gcc-help
mailing list