0

I plan using SSE instructions applied to elements of int16_t array. Is there a way to force 16 byte alignment with new operator or uique_ptr semantics?

int16_t *array=new int16_t[N];

Is the only possibility is to use posix_memalign? I assume that using

int16_t *array __attribute__ ((aligned (16)));

will align the pointer itself only.

  • 2
    See: [SSE, intrinsics, and alignment](http://stackoverflow.com/questions/12502071/sse-intrinsics-and-alignment). – Paul R Mar 02 '16 at 08:14
  • 2
    @PeterCordes: I don't think that works for `new`, which typically calls `malloc` and returns memory with whatever the platform's alignment requirement is (often 16 bytes, but can be just 8). See the linked question in my comment above. – Paul R Mar 02 '16 at 08:16
  • 2
    @PaulR: thanks, it looks like you're right. I was misremembering, probably confusing it with the static / local alignment case where the union with `__m128i` trick does work. And Wojciech: yes `posix_memalign` is a good choice, because it returns a pointer that is guaranteed to be freeable with `free()`. Pointers from `_mm_malloc` are not guaranteed to work with `free()`. You'd better check on `operator delete`, too, if you want to have that work for sure. – Peter Cordes Mar 02 '16 at 08:29

0 Answers0