I am writing a C program that should do quick math. I use the built-in SSE build instructions to get some SIMD action (using double precision floating point numbers). I am compiling GCC on Linux.
I am in a situation where I need to iterate over some data, and I use a constant coefficient in my calculations. I would like to keep this factor in a safe register during the loop, so I don't need to reload it every time.
To clarify the code:
struct vect2 { fltpt x; fltpt y; }__attribute__((aligned(16))); typedef struct vect2 vect2_t; void function() { for( int i = 0, i<N; i++ ){ asm( "Some calculations;" "on an element of;" "a data set.;" "The value in xmm1;" "is needed;" ); } }
I tried to do something with the keyword "register". But if I'm not mistaken, it looks like I can save a pointer to this structure (in general case). This will need to be postponed every iteration, wasting precious time.
register vect2_t hVect asm("xmm1") = {h, h}; register vect2_t *hVect2 asm("rax"); *hVect2 = (vect2_t){h,h};
I do not just want to assume that GCC will not change the case of xmm1, it is too many of the "demons flying from one nose" :-). Therefore, I hope that there is a right way to do this.
c assembly gcc inline-assembly sse
Roaldfre
source share