This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC ARM: aligned access
- From: Peng Fan <van dot freenix at gmail dot com>
- To: Julian Brown <julian at codesourcery dot com>
- Cc: Matt Thomas <matt at 3am-software dot com>, Joel Sherrill <joel dot sherrill at OARcorp dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 03 Sep 2014 08:49:50 +0800
- Subject: Re: GCC ARM: aligned access
- Authentication-results: sourceware.org; auth=none
- References: <540320F5 dot 9030501 at gmail dot com> <1cf062bd-289a-4375-ab2b-e34419d22bd3 at email dot android dot com> <7567D3C5-285C-480B-B547-84387E2C4994 at 3am-software dot com> <5403C877 dot 1070807 at gmail dot com> <20140902142513 dot 32531bd4 at octopus>
On 09/02/2014 09:25 PM, Julian Brown wrote:
> On Mon, 1 Sep 2014 09:14:31 +0800
> Peng Fan <van.freenix@gmail.com> wrote:
>
>> On 09/01/2014 08:09 AM, Matt Thomas wrote:
>>>
>>> On Aug 31, 2014, at 11:32 AM, Joel Sherrill
>>> <joel.sherrill@OARcorp.com> wrote:
>>>> I think this is totally expected. You were passed a u8 pointer
>>>> which is aligned for that type (no restrictions likely). You cast
>>>> it to a type with stricter alignment requirements. The code is
>>>> just flawed. Some CPUs handle unaligned accesses but not your ARM.
>>>
>> armv7 and armv6 arch except armv6-m support unaligned access. a u8
>> pointer is casted to u32 pointer, should gcc take the align problem
>> into consideration to avoid possible errors? because
>> -mno-unaligned-access.
>
> Using -munaligned-access (or its inverse) isn't enough to make GCC
> generate code that can perform arbitrary unaligned accesses, because
> several instructions (e.g. VFP loads/stores or load/store multiple
> instructions IIRC) must still act on naturally-aligned data even when
> the hardware flag to enable unaligned accesses is on, and those
> instructions will still be generated by GCC when they are considered
> safe, i.e. when not doing explicitly-unaligned accesses in packed
> structures or similar.
>
> It would be *possible* to add an option to the backend to allow
> arbitrary alignment for any access, I think, but it's not at all clear
> that it's a good idea, and would certainly negatively affect
> performance.
>
> (If you need unaligned accesses, you can use e.g. memcpy, and that will
> probably generate good inline code.)
Thanks for the reply. I've tried memcpy and all is fine.
Regards,
Peng.
>
> Julian
>