-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

José Fonseca wrote:
> Attached is a patch that generalizes the ALIGN16/8_XXX macros in
> p_compiler.h to work on MSVC and handle alignments beyond 8 and 16
> bytes.
> 
> There is more than one way to have cross-platform alignment macros --
> all quite ugly.
> 
> The major complication here is that GCC and MSVC syntax for type/vars
> attributes differs. MSVC's attributes are before types/vars
> declarations. GCC's attributes are in general after the types/vars
> declarations, although it is possible to put var attributes before too.
> For more detail read:
> - http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Attribute-Syntax.html
> - http://msdn.microsoft.com/en-us/library/83ythb65.aspx
> 
> The approach I chose in the attached patch was to define the alignment
> macros to contain the whole declaration as an argument, e.g.:

I encountered this problem when I was working with the vector math
library in Bullet.  I've since stopped using that library (the SSE
routines we completely untested and very buggy), but my recollection is
that GCC will take the attribute either before or after.

I created a macro ALIGN16 and s/__declspec\(align\(16\)\)/ALIGN16/g.
This code worked with both GCC and, IIRC, Visual Studio 2005.

#ifdef __GNUC__
# define ALIGN16 __attribute__((aligned(16)))
#else
# define ALIGN16 __declspec(align(16))
#endif

...

inline const Matrix3 Matrix3::scale(const Vector3 &scaleVec)
{
    __m128 zero = _mm_setzero_ps();
    ALIGN16 unsigned int select_x[4] = {0xffffffff, 0, 0, 0};
    ALIGN16 unsigned int select_y[4] = {0, 0xffffffff, 0, 0};
    ALIGN16 unsigned int select_z[4] = {0, 0, 0xffffffff, 0};

    return Matrix3(
        Vector3( vec_sel( zero, scaleVec.get128(), select_x ) ),
        Vector3( vec_sel( zero, scaleVec.get128(), select_y ) ),
        Vector3( vec_sel( zero, scaleVec.get128(), select_z ) )
    );
}


It seems like you ought to be able to define a similar PIPE_ALIGN(x),
and just prefix that on declarations.

I agree that both of the proposed options are really ugly.

> 
>   PIPE_ALIGN_TYPE(16, 
>   struct {
>     float rgba[4];
>   });
> 
>   PIPE_ALIGN_VAR(16, float rgba[4]);
> 
> Another alternative would be to define pre-/post-fix macros, where
> alignment would have to be passed twice:
> 
>   PIPE_ALIGN_TYPE_BEGIN(16) 
>   struct {
>     float rgba[4];
>   }
>   PIPE_ALIGN_TYPE_END(16);
> 
>   PIPE_ALIGN_VAR_BEGIN(16)
>   float rgba[4]
>   PIPE_ALIGN_VAR_END(16);
> 
> Or provide a mixture or union of all the above macros.
> 
> I honestly don't care either way -- they all look ugly to me --, as long
> it works with all compilers I'm happy to go either way.
> 
> With this patch it is possible to build and run llvmpipe on windows with
> MSVC.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktLedEACgkQX1gOwKyEAw/26ACgksMn2zkjhOAnY6DwNjLr/SLe
t6oAoIGXRZM1uESvbcsPjjtNxkfa95QK
=gCmN
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to