Re: x86/64 alignment, optimization, -Wcast-align

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 25, 2016 at 5:58 PM, Balázs Oroszi <orobalage@xxxxxxxxx> wrote:
> In case anyone was wondering, I did the following workaround:
>
> typedef uint32_t uint32_u_t __attribute__((aligned(1))) ;
>
> Effectively this creates a new type uint32_u_t, which has a lowered
> alignment, so GCC won't go vectorizing with aligned vmovdqa and the
> like, crashing if original alignment (in this case 4 bytes) was not
> met.
> I use this type whenever it is uncertain if an array is aligned or
> not, and works perfectly.

Usually, you go the other way: you either (1) align to 16 for stack
based allocations, or (2) allocate on the heap, which has 16-byte
alignment. It allows you the benefit of vectorization and AVX.

You also have to avoid the unaligned data accesses and type punning.
The undefined behavior sanitizers are usually very good about finding
them at runtime. Just compile with -fsanitize=undefined, and then run
your test suite.

Jeff




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux