Aligning addresses at 16-byte boundaries in c++

Aligning addresses at 16-byte boundaries in c++

Hello,
On page 8-2 of the MKL for Linux User's Guide, there is some tips for better performance with memory alignment. I tried the tip for C using malloc in my c++ code but get the following error:

test.cpp(36): error: expression must be a pointer to a complete object type a[i*SIZE+j]= static_cast(i+j);

Is there some c++ correct way to make this memory allocation and alignment (e.g., using new)?
Thanks!

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

new() supports 16-byte alignment on the 64-bit operating system/library combinationss supported by MKL. Regrettably ugly or non-portable methods are needed on 32-bit OS. Usually recommended are the _mm_malloc() or aligned_malloc() functions specific to your compiler. I'm downloading the current MKL in hopes of figuring out where you got your example. Until I see it, I'm skeptical that you got it from MKL docs.

Thanks for the note back. The page number (8-2) and code that I referenced is in a recent user's guide (on-line here: http://www.osc.edu/hpc/manuals/INTEL08082007/mkl/9.1/doc/userguide.pdf)

I am using a 64-bit OS with MKL supported processor, etc. So in this case, does new() automatically do the 16-byte alignment? Or do I need to do something else? I haven't had any luck with google searches on this topic (other than the malloc functions you note above).

Thanks again for your help!

http://www.x86-64.org/documentation/abi.pdf
refers to
http://www.codesourcery.com/cxx-abi/abi.html
but all I find there is that new[] must return "natural alignment."
In
another place in this reference, there is a bunch of legalese about new[] alignment which
seems as if it could boil down to 8 bytes, if sizeof(size_t) is 8
It
wouldn't hurt to check a number of examples to verify that it is
16-byte alignment. Both x86-64 and ia64 linux do depend in many cases
on 16-byte alignment for important optimizations.
Also, there are last year's C++ standardization proposals on alignment:
www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2140.pdf

The
example you refer to outlines too sketchily what _mm_malloc() and
_mm_free() do in a 32-bit compiler library. I didn't find it in the
current .pdf which comes with MKL.

I've asked some experts for verification that 64-bit new[] must produce 16-byte
alignments (at least, as one reference said, for objects of 16 bytes or
more), but the answer doesn't appear to be documented clearly.

Leave a Comment

Please sign in to add a comment. Not a member? Join today