[C++-sig] Exposing 128-bit aligned datatype

Niall Douglas s_sourceforge at nedprod.com
Mon Feb 20 22:34:49 CET 2012


Aligning to 128 bits is surely __attribute__((__aligned__(16)))?

You also can inherit from an aligned base class even if that base 
class contains no items and the alignment passes down just fine.

BTW alignment isn't reliable as soon as something leaves static 
storage e.g. goes through a parameterisation via being given to a 
function. This is extremely hard to control in C++03 metaprogramming. 
C++11 makes this much easier as you have rvalues.

Also, MSVC is less reliable than GCC with alignment. Use with extreme 
caution! Generally I have found that the unaligned SSE load ops are 
sufficiently quick during the occasional misalignment that there's no 
point being overexact - if misaligned (test via if(addr & 15)), just 
unaligned load instead of aligned load before executing.

Niall


On 20 Feb 2012 at 10:13, VáclavSmilauer wrote:

> I am exposing a struct which is 128-bit aligned to python; it is always
> constructed dynamically in c++ code, hence there is no trouble that the
> alignment is correct. I was getting errors on compilation and had to add this
> bit to my code:
> 
> namespace boost {
> 	namespace align { struct __attribute__((__aligned__(128))) a128 {};}
> 	template<> class type_with_alignment<128> { public: typedef align::a128 type; };
> };
> 
> The wrapper works correctly. For some reason
> boost/type_traits/type_with_alignment.hpp only defines alignment > 32 only for
> MSVC or Intel compilers. I am not sure where to ask for fix, can someone forward
> this to the right place?
> 
> The aligned type is cl_double16, compiling with gcc.
> 
> Cheers, Vaclav
> 
> 
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig


-- 
Technology & Consulting Services - ned Productions Limited.
http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Company no: 
472909.





More information about the Cplusplus-sig mailing list