H.J. Lu wrote: > You can use __BIGGEST_ALIGNMENT__ for that purpose.
Yes, _for that purpose_ it works perfectly. However, I would also like be able to align fields to cache line size. I have a set of C++ template cache geometry descriptors which provide a constant by the name of line_size: namespace cache { template <std::size_t N_level> class geometry; // --------------- template <> class geometry<1> : private nonconstructible { // Superclass typedef nonconstructible super; public: static const std::size_t capacity = 32 * 1024; static const std::size_t associativity = 8; static const std::size_t line_size = 64; }; // --------------- template <> class geometry<2> : private nonconstructible { // Superclass typedef nonconstructible super; public: static const std::size_t capacity = 3 * 1024 * 1024; static const std::size_t associativity = 12; static const std::size_t line_size = 64; }; } I would like to declare a level 1 data cache line size-aligned variable x: int x __attribute__((__aligned__(cache::geometry<1>::line_size))); which is not possible now. BTW, since GCC has -mtune=native, it would be great to have a compiler-provided cache info in the form of a bunch of target-dependent preprocessor definitions, e.g. for Core2: __GCC_DCACHE_LEVELS 2 __GCC_ICACHE_LEVELS 2 __GCC_DCACHE_LINE_SIZE1 64 __GCC_DCACHE_LINE_SIZE2 64 __GCC_DCACHE_ASSOCIATIVITY1 8 __GCC_DCACHE_ASSOCIATIVITY2 12 etc. It would help in a lot of cases, e.g. lock-free algorithms, false sharing avoidance, alignment calculations in custom allocators etc. Best regards, Piotr Wyderski