c++sdkvivadocortex-a

Declare an array so that the address is aligned on 16 byte boundaries


I have an uint8 array and I need to pass the pointer of this array to a DMA, which transfers 16 bytes at once. So, the requirement is that the array address is 16 byte aligned, like 32'hxxxxxx00 - the last two address numbers to be 0. I declare a global array as follows:

u8 R00_PRO_ADDR[0x64000]    __attribute__ ((aligned(16)));// 16 bytes address aligned

however, at the runtime, I see that the address of the array is 32'hxxxxxxx0. I also tried to do (aligned(128)) but get the same result.

This is specific to Vivado SDK Cortex A53


Solution

  • Declare an array so that the address is aligned on 16 byte boundaries

    You can use the standard keyword alignas. No need to use a language extension:

    alignas(16) u8 R00_PRO_ADDR[0x64000];
    

    So, the requirement is that the array address is 16 byte aligned, like 32'hxxxxxx00 - the last two address numbers to be 0.

    Your requirements are mixed. If you need this, then the address needs to be aligned on a 256 byte boundary:

    alignas(256) u8 R00_PRO_ADDR[0x64000];
    

    Note that a language implementation might not necessarily support arbitrarily strict alignments. If it doesn't, it should tell you so.