On Tue, Jan 7, 2020 at 7:58 AM Christophe Lyon
<christophe.l...@linaro.org> wrote:
>
> Hi,
>
> I've received a support request where GCC generates strd/ldrd which
> require aligned memory addresses, while the user code actually
> provides sub-aligned pointers.
>
> The sample code is derived from CMSIS:
> #define __SIMD32_TYPE int
> #define __SIMD32(addr) (*(__SIMD32_TYPE **) & (addr))
>
> void foo(short *pDst, int in1, int in2) {
>    *__SIMD32(pDst)++ = in1;
>    *__SIMD32(pDst)++ = in2;
> }
>
> compiled with arm-none-eabi-gcc -mcpu=cortex-m7 CMSIS.c -S -O2
> generates:
> foo:
>         strd    r1, r2, [r0]
>         bx      lr
>
> Using -mno-unaligned-access of course makes no change, since the code
> is lying to the compiler by casting short* to int*.
>
> However, LLVM has -arm-assume-misaligned-load-store which disables
> generation of ldrd/strd in such cases:
> https://reviews.llvm.org/D17015?id=48020
>
> Would some equivalent be acceptable in GCC? I have a small patch that
> seems to work.

Violating C standard option, -fno-strict-alignment.  GCC uses the
alignment of int across many places, more than target specific parts.
It seems like you just want to disable one part of the assumition but
not the rest.  This seems broken and very fragile.

What they want is the following:
#define int __attribute__((aligned(1) )) int

Which might not work for unsigned int or short int.

Thanks,
Andrew Pinski

>
> Thanks,
>
> Christophe

Reply via email to