https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117016
Bug ID: 117016
Summary: Alignment requirements of std::simd too large
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: pieter.p.dev at outlook dot com
Target Milestone: ---
The value of std::experimental::memory_alignment appears to be too large for
fixed-size vectors that are larger than the native vector length.
For example, on both x86 AVX512 and ARM NEON, the alignment requirement for a
12-element double vector reported by libstdc++ is 128 bytes, even though there
are no instructions that require such a huge alignment (the maximum is 512
bits/64 bytes for AVX512).
https://godbolt.org/z/45hEWG14b
#include <experimental/simd>
namespace stdx = std::experimental;
using simd12 = stdx::simd<double, stdx::simd_abi::fixed_size<12>>;
static_assert(stdx::memory_alignment_v<simd12> <= 64);
// static assertion failed: the comparison reduces to '(128 <= 64)'
Looking at bits/simd.h, it appears that the alignment for fixed_size_simd<T, N>
is computed simply as bit_ceil(sizeof(T) * N), which is very conservative.
Having different alignment requirements for large SIMD vectors makes allocating
buffers that are reused with different vector lengths quite tricky.