__attribute__((aligned(16))) on ix86

Ryan T. Sammartino ryants@home.com
Tue Jun 19 11:29:00 GMT 2001


Here's all my info upfront:


GCC version:

Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)

Kernel info:

Linux 2.4.5-6mdksmp #1 SMP Mon Jun 18 10:19:22 PDT 2001 i686 unknown


I'm trying to compile the following test app:

---cut here---
#include <iostream>

class vector
{
public:
    float x;
    float y;
    float z;
    float w;

    vector(float _x, float _y, float _z, float _w)
            : x(_x), y(_y), z(_z), w(_w)
        {}
    vector()
        {}
    
    vector operator+(const vector &v1)
        {
            vector ret __attribute__((aligned(16)));
            
            asm("movl   %1,         %%esi   \n" 
                "movl   %2,         %%edi   \n" 
                "movaps (%%esi),    %%xmm0  \n"
                "addps  (%%edi),    %%xmm0  \n"
                "movaps %%xmm0,     %0      \n" 
                : "=g" (ret) : "r" (this), "r" (&v1));
            
            return ret;
        }
} __attribute__((aligned(16)));

int main(int argc, char *argv[])
{
    vector v1(3.0f, 4.0f, 5.0f, 1.0f);
    vector v2(7.0f, 1.0f, 9.0f, 1.0f);

    vector ans = v1 + v2;
    
    cout << ans.x << " " << ans.y << " " << ans.z << " " << ans.w << endl;
}
---cut here---


I compile it with:

g++ -o sse sse.cpp -Wall -g


However, no matter what I try, v1, v2, and ret are *not* aligned
properly, and so it crashes on the movaps instruction.

I can get them aligned properly if I declare three dummy ints:


    int i,j,k;
    vector v1(...)


but that is not a very good solution.


So how do I tell g++ to align stuff to 16 byte boundaries?


(Note: Searching GNATS and this mailing list archive didn't turn up any
similar problems)




-- 
Ryan T. Sammartino
http://members.home.net/ryants/
Ignorance is never out of style.  It was in fashion yesterday, it is the
rage today, and it will set the pace tomorrow.
		-- Franklin K. Dane



More information about the Gcc-help mailing list