type_with_alignment question

I am using boost::aligned_storage<> and I would like it to be aligned on 32 byte boundary (the reason being that sizeof(my type) is 32 bytes and I want it to be aligned on x86 cash line size so that it is cashed most effectively). I am working now under VC7.1 and it seems like the maximum alignment I can get with the compiler is 8 which is the alignment of the largest built-in type which is long double (or a pointer to member/function). But type_with_alignment.hpp seems to have special support for gcc in the form of: namespace align { struct __attribute__((__aligned__(2))) a2 {}; struct __attribute__((__aligned__(4))) a4 {}; struct __attribute__((__aligned__(8))) a8 {}; struct __attribute__((__aligned__(16))) a16 {}; struct __attribute__((__aligned__(32))) a32 {}; } template<> class type_with_alignment<1> { public: typedef char type; }; template<> class type_with_alignment<2> { public: typedef align::a2 type; }; template<> class type_with_alignment<4> { public: typedef align::a4 type; }; template<> class type_with_alignment<8> { public: typedef align::a8 type; }; template<> class type_with_alignment<16> { public: typedef align::a16 type; }; template<> class type_with_alignment<32> { public: typedef align::a32 type; }; Are MSVSs going to be supported as they have similar extension __declspec(align(x))? -- Maxim Yegorushkin

Maxim Yegorushkin <e-maxim@yandex.ru> wrote:
I am using boost::aligned_storage<> and I would like it to be aligned on 32 byte boundary (the reason being that sizeof(my type) is 32 bytes and I want it to be aligned on x86 cash line size so that it is cashed most effectively). I am working now under VC7.1 and it seems like the maximum alignment I can get with the compiler is 8 which is the alignment of the largest built-in type which is long double (or a pointer to member/function). But type_with_alignment.hpp seems to have special support for gcc in the form of:
namespace align { struct __attribute__((__aligned__(2))) a2 {}; struct __attribute__((__aligned__(4))) a4 {}; struct __attribute__((__aligned__(8))) a8 {}; struct __attribute__((__aligned__(16))) a16 {}; struct __attribute__((__aligned__(32))) a32 {}; }
template<> class type_with_alignment<1> { public: typedef char type; }; template<> class type_with_alignment<2> { public: typedef align::a2 type; }; template<> class type_with_alignment<4> { public: typedef align::a4 type; }; template<> class type_with_alignment<8> { public: typedef align::a8 type; }; template<> class type_with_alignment<16> { public: typedef align::a16 type; }; template<> class type_with_alignment<32> { public: typedef align::a32 type; };
Are MSVSs going to be supported as they have similar extension __declspec(align(x))?
I've just found out that the following code won't compile on MSVC7.1: struct some { struct __declspec(align(32)) align {}; align a; }; void f(some s); // error C2719: 's': formal parameter with __declspec(align('32')) won't be aligned int main() { some s; f(s); } Was that the reason for not adding __declspec(align(x)) support for MSVC? I also found that Intel C++ 8 compiles the code without a complain, though it's unclear what effect __declspec(align(x)) has on the compiler. -- Maxim Yegorushkin

On Aug 8, 2004, at 3:21 AM, Maxim Yegorushkin wrote:
I've just found out that the following code won't compile on MSVC7.1:
struct some { struct __declspec(align(32)) align {}; align a; };
void f(some s); // error C2719: 's': formal parameter with __declspec(align('32')) won't be aligned
int main() { some s; f(s); }
Was that the reason for not adding __declspec(align(x)) support for MSVC?
It wasn't added because nobody has added it. If it works, we can add support for it. Would you like to come up with a patch? Doug
participants (2)
-
Doug Gregor
-
Maxim Yegorushkin