views:

811

answers:

2

I am writing some code and trying to speed it up using SIMD intrinsics SSE2/3. My code is of such nature that I need to load some data into an XMM register and act on it many times. When I'm looking at the assembler code generated, it seems that GCC keeps flushing the data back to the memory, in order to reload something else in XMM0 and XMM1. I am compiling for x86-64 so I have 15 registers. Why is GCC using only two and what can I do to ask it to use more? Is there any way that I can "pin" some value in a register? I added the "register" keyword to my variable definition, but the generated assembly code is identical.

+1  A: 

Yes, you can. Explicit Reg Vars talks about the syntax you need to pin a variable to a specific register.

Chris Jester-Young
I tried >>register __m128i v0 asm ("xmm7");<< but the compiler does not like it >>error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘asm’<<.
florin
Did you #include <xmmintrin.h>?
Chris Jester-Young
+1  A: 

If you're getting to the point where you're specifying individual registers for each intrinsic, you might as well just write the assembly directory, especially given gcc's nasty habit of pessimizing intrinsics unnecessarily in many cases.

Dark Shikari