Hi,I've ran several experiments to see if we can use alignof/alignas in Chromium/Blink:https://codereview.chromium.org/1497963002/Unfortunately, VS2013 doesn't support these, so apparently we can't use them yet.MSDN says VS2015 will have those, though:So I propose to ban these for now, with a note to revisit when VS2015 arrives.
As an aside, alignas(N) for N > 64 causes an error on GCC (see patch set 1 of the CL above). According to aligned_memory_unittest.cc, higher N tends to cause problems in other toolchains, too. See the triple nested #ifs in the file:*sad face*I wonder if we could ban the use of ALIGNAS(N) macro for N > 64, because higher N isn't very useful itself and we currently don't use such a high value actually. The macro is useful for N = 8 or N = 16 to get better performance by aligned read, but I can't think of cases where N >= 32 is needed for this use case. If we need something page-aligned (N = 4096), we should probably make use of other means (mmap etc.).
On Tue, Dec 8, 2015 at 7:26 AM, Yuta Kitamura <yu...@chromium.org> wrote:Hi,I've ran several experiments to see if we can use alignof/alignas in Chromium/Blink:https://codereview.chromium.org/1497963002/Unfortunately, VS2013 doesn't support these, so apparently we can't use them yet.MSDN says VS2015 will have those, though:So I propose to ban these for now, with a note to revisit when VS2015 arrives.Unfortunate, but that sounds fine since the macros just work with __alignof / __declspec(align((#)).
As an aside, alignas(N) for N > 64 causes an error on GCC (see patch set 1 of the CL above). According to aligned_memory_unittest.cc, higher N tends to cause problems in other toolchains, too. See the triple nested #ifs in the file:*sad face*I wonder if we could ban the use of ALIGNAS(N) macro for N > 64, because higher N isn't very useful itself and we currently don't use such a high value actually. The macro is useful for N = 8 or N = 16 to get better performance by aligned read, but I can't think of cases where N >= 32 is needed for this use case. If we need something page-aligned (N = 4096), we should probably make use of other means (mmap etc.).It's useful to avoid destructive interference on some HW Chrome likely doesn't care about. Some packages (such as TBB) are / were pessimistic at some point in time and chose 128 bytes as cacheline size because IIRC one Intel chip chose that value at some point in time. I'm hoping that these numbers can eventually be provided by the compiler (http://wg21.link/p0154r0) but that won't help before at least C++17.The unit test has issues with stack alignment, which is still useful (sometimes even cross-thread) but not as widely has heap alignment IMO.It may be worth limiting until toolchains are fixed.
On Tue, Dec 8, 2015 at 7:26 AM, Yuta Kitamura <yu...@chromium.org> wrote:Hi,I've ran several experiments to see if we can use alignof/alignas in Chromium/Blink:https://codereview.chromium.org/1497963002/Unfortunately, VS2013 doesn't support these, so apparently we can't use them yet.MSDN says VS2015 will have those, though:So I propose to ban these for now, with a note to revisit when VS2015 arrives.Unfortunate, but that sounds fine since the macros just work with __alignof / __declspec(align((#)).
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABdywOd%2Bkr3YbAbhzDJ99aM5g9HdHaKdi54r%3DcHu6nMkHygNpA%40mail.gmail.com.
I wrote https://codereview.chromium.org/2670873002/ which removes the macros from //base/compiler_specific.h. I found a few issues while doing this:1. GCC on ARM doesn't like alignas(N) if N > 64. There doesn't seem to be any non-test code affected by this, and it throws a compile error if it doesn't like the alignment. However, this seems strictly better than relying on runtime checks to detect unsupported configurations (see aligned_memory_unittest.cc [1]).2. GCC/Clang are somewhat picky about mixing __attribute__(...) with alignas().struct alignas(16) __attribute__((packed)) Foo { ... }; // Not OKstruct __attribute__((packed)) alignas(16) Foo { ... }; // OK in clangstruct alignas(16) Foo { ... } __attribute__((packed)); // OK in clang and gcc3. GCC on ARM doesn't permit __attribute__((visibility(...))) after a definition:struct alignas(16) Foo { ... } __attribute__((visibility("default"))); // OK in clang, not OK in gccwhich means it's impossible to export a struct/class while specifying alignment.For (2), there's a workaround. For (3), there's no workaround, but it seems like structs/classes that require alignment are generally POD objects. Thus, there's generally no need to export them anyway. Usage should be relatively rare, so I don't expect these issues to occur much in practice.Given this, does moving alignof/alignas to the allowed language features seem reasonable?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAF3XrKp-W-9w7H5G-kbwN%2BZj8wxuVa0%3D8n1kObSK8_gXZr0%2BZw%40mail.gmail.com.
3. GCC on ARM doesn't permit __attribute__((visibility(...))) after a definition:struct alignas(16) Foo { ... } __attribute__((visibility("default"))); // OK in clang, not OK in gccwhich means it's impossible to export a struct/class while specifying alignment.
On Mon, Feb 6, 2017 at 11:50 AM, Daniel Cheng <dch...@chromium.org> wrote:I wrote https://codereview.chromium.org/2670873002/ which removes the macros from //base/compiler_specific.h. I found a few issues while doing this:1. GCC on ARM doesn't like alignas(N) if N > 64. There doesn't seem to be any non-test code affected by this, and it throws a compile error if it doesn't like the alignment. However, this seems strictly better than relying on runtime checks to detect unsupported configurations (see aligned_memory_unittest.cc [1]).2. GCC/Clang are somewhat picky about mixing __attribute__(...) with alignas().struct alignas(16) __attribute__((packed)) Foo { ... }; // Not OKstruct __attribute__((packed)) alignas(16) Foo { ... }; // OK in clangstruct alignas(16) Foo { ... } __attribute__((packed)); // OK in clang and gcc3. GCC on ARM doesn't permit __attribute__((visibility(...))) after a definition:struct alignas(16) Foo { ... } __attribute__((visibility("default"))); // OK in clang, not OK in gccwhich means it's impossible to export a struct/class while specifying alignment.For (2), there's a workaround. For (3), there's no workaround, but it seems like structs/classes that require alignment are generally POD objects. Thus, there's generally no need to export them anyway. Usage should be relatively rare, so I don't expect these issues to occur much in practice.Given this, does moving alignof/alignas to the allowed language features seem reasonable?Not occuring much seems bad still if it will occur at all, given there's no workaround. These cases will have to redesign things to make the aligned thing POD or keep/invent something like AlignedMemory around for them. There doesn't seem to be a good motivation to allow these if we have to also keep AlignedMemory, unless we're implementing AlignedMemory with them when possible, and allowing them only there. Unless you think it is good and reasonable that cases that run into problems here are refactored to not require export and aligned on the same type?
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAB%3D4xhrWzAcThwMu7ho%3Dm0SNvSNNeoi6o5%3DAK%2BK93Cz-iNEQww%40mail.gmail.com.
The visibility attribute is something specific to ELF anyway. For MSVC, __declspec(dllexport) is what's used. Does MSVC allow 'struct alignas(n) __declspec(...) Foo { ... };' ?
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAB%3D4xhruWmC74Lhr8_OZH%2BtOcJWTnbmtT6g%2Bma7AOjh2bgphHQ%40mail.gmail.com.
I wrote https://codereview.chromium.org/2670873002/ which removes the macros from //base/compiler_specific.h. I found a few issues while doing this:1. GCC on ARM doesn't like alignas(N) if N > 64. There doesn't seem to be any non-test code affected by this, and it throws a compile error if it doesn't like the alignment. However, this seems strictly better than relying on runtime checks to detect unsupported configurations (see aligned_memory_unittest.cc [1]).
2. GCC/Clang are somewhat picky about mixing __attribute__(...) with alignas().struct alignas(16) __attribute__((packed)) Foo { ... }; // Not OKstruct __attribute__((packed)) alignas(16) Foo { ... }; // OK in clangstruct alignas(16) Foo { ... } __attribute__((packed)); // OK in clang and gcc3. GCC on ARM doesn't permit __attribute__((visibility(...))) after a definition:struct alignas(16) Foo { ... } __attribute__((visibility("default"))); // OK in clang, not OK in gccwhich means it's impossible to export a struct/class while specifying alignment.For (2), there's a workaround. For (3), there's no workaround, but it seems like structs/classes that require alignment are generally POD objects. Thus, there's generally no need to export them anyway. Usage should be relatively rare, so I don't expect these issues to occur much in practice.Given this, does moving alignof/alignas to the allowed language features seem reasonable?
Sorry for being late to the party. Let me give some comments based on what I remember about my last experiments...On Tue, Feb 7, 2017 at 1:50 AM, Daniel Cheng <dch...@chromium.org> wrote:I wrote https://codereview.chromium.org/2670873002/ which removes the macros from //base/compiler_specific.h. I found a few issues while doing this:1. GCC on ARM doesn't like alignas(N) if N > 64. There doesn't seem to be any non-test code affected by this, and it throws a compile error if it doesn't like the alignment. However, this seems strictly better than relying on runtime checks to detect unsupported configurations (see aligned_memory_unittest.cc [1]).Yeah that's true. However, practically there's no real use case for such a big alignment. The main focus of alignas is to align data to follow the processor's requirements; 16 bytes alignments are usually sufficient for this purpose. (I imagine it's harder for compilers to implement large alignments, like for stack or data sections)If you need to align something to page boundary, it's probably better to rely on other mechanisms.
2. GCC/Clang are somewhat picky about mixing __attribute__(...) with alignas().struct alignas(16) __attribute__((packed)) Foo { ... }; // Not OKstruct __attribute__((packed)) alignas(16) Foo { ... }; // OK in clangstruct alignas(16) Foo { ... } __attribute__((packed)); // OK in clang and gcc
3. GCC on ARM doesn't permit __attribute__((visibility(...))) after a definition:struct alignas(16) Foo { ... } __attribute__((visibility("default"))); // OK in clang, not OK in gccwhich means it's impossible to export a struct/class while specifying alignment.For (2), there's a workaround. For (3), there's no workaround, but it seems like structs/classes that require alignment are generally POD objects. Thus, there's generally no need to export them anyway. Usage should be relatively rare, so I don't expect these issues to occur much in practice.Given this, does moving alignof/alignas to the allowed language features seem reasonable?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAFJcur9Gn71KKjXNn_FmK2N_gidw1ge4uKYXStcVHwjUKb7u2A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CACuR13e1XOixKq3S7wfKq77UzkvxTLPT7i0-Xcd6r-tobF_24Q%40mail.gmail.com.