On Mon, 2010-01-11 at 11:19 -0800, Ian Romanick wrote: > -----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.
I noticed GCC allows prefixed attributes for var declarations, but I was unsure if there were any caveats since all references I could google suggested postfixing. But if worked well for you then we could do that instead -- it does looks a bit closer to "normal C". This won't work for types though, since according the gcc docs the type attribute must be immediately after "struct" keyword, or after the closing '}'. Jose ------------------------------------------------------------------------------ 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