2 years ago
#71978
Andreas Loanjoe
Is it possible to do an aligned alllocation in a constexpr context?
I have some code that requires a vector to be SIMD aligned and I'm using an aligned allocator from a library as an allocator to implement that, but this allocator has no constexpr support. Would it be possible to use constexpr new and delete to make an aligned allocator? I don't actually have to perform SIMD operations in the constexpr context, but I would like to be able to constexpr construct the types to run a couple of static assert tests without having duplicate code.
Let's say the compile time test looks like something like this:
constexpr std::vector<float, AlignedAllocator<float>> vector = { 0.f, 1.f, 2.f };
static_assert(vector.size() == 3);
But the runtime code uses the same vector type to perform SIMD operations requiring the actual alignment of the allocator. The allocator could be non-standard conforming because I am using something else than an actual vector in the actual code, but the idea stays the same that memory should be aligned for runtime use. The main requirement I'm trying to address is that I would like to have the same container type at runtime as the one being used in the constant evaluated context (where no SIMD operations are performed).
c++
simd
constexpr
memory-alignment
0 Answers
Your Answer