Problems using Vector Extensions

Thomas Unterthiner thomas_unterthiner@web.de
Mon Sep 10 21:59:00 GMT 2007


Brian Dessent wrote:
> So, first, it should be easy enough to verify that we are in fact
> talking about a fault due to alignment -- check the value of the
> operands of the faulting SSE opcode.
>   
At the moment when

movaps (%eax),%xmm1

gets executed (and segfaults), %eax has a value of  0x3f4f98. So as far 
as my understanding goes (once again, I'm not big at doing such 
low-level stuff, so bear with me if I'm wrong on this),  this really is 
an aligment-issue.
> Then determine where the object gets allocated and how.  If it's a
> global variable and it has a ctor then it is probably being constructed
> before main() when the list of global ctors is run.  That could also
> explain why removing seemingly unrelated object files causes a change in
> behavior, since that would change the order of global ctors even if it's
> otherwise dead code. 
The code gets called AFTER main (The call stack in the debugger confirms 
this).

>  In this case you might play around with adding
> __attribute__((aligned(16))) to the declarations.
>   
I'm not sure where to put this, so right now I've put this after the 
union{} declaration of Vector3D as well as at the end of the 
Vector3D-declaration. Currently the declaration looks like this:

class Vector3D
{
    private:
            typedef float v4sf __attribute__ (( vector_size(4 * 
sizeof(float)) ));
            typedef int v4si __attribute__ (( vector_size(4 * 
sizeof(int)) ));
            union
            {
                v4sf vec;
                float v[4];
            } __attribute__((aligned(16)));
            Vector3D(const v4sf& v);

} __attribute__ ((aligned (16)));


As far as I understood it, this should guarantee correct alignment, but 
%eax remains missaligned.

On a side note, I stumpled upon this message while searching the web: 
http://lists.xiph.org/pipermail/speex-dev/2007-August/006031.html

Looks like they're having problems similar to mine, even though none of 
their proposed solutions (using the align-attribute, switching  the 
relative positions of the variables within the union{} or using the 
force_align_arg_pointer-attribute) seems to work for me (I'm using a 
custom-build GCC, whereas I assume they are using the "official" GCC 
4.2.1 from mingw, so my config-flags for GCC are problably different, 
maybe that has something to do with it).

At this point I'm really a bit lost. Could this be a bug in GCC (or at 
least MinGW)?


Thomas






More information about the Gcc-help mailing list