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

Re: Architectures where unaligned access is (not) OK?



On Fri, Nov 21, 2014 at 02:40:01PM +0000, Wookey wrote:
> Whilst that is nice and correct I'm not sure the meaning is clear to a
> software engineer, which is: Don't do unaligned access on arm64. It's
> always inefficient, sometimes extremely inefficient, and sometimes
> won't work at all.

That's an exaggeration.

libav/ffmpeg for example has:

  fast_unaligned_if_any="aarch64 ppc x86"
  armv[6-8]*) enable fast_clz fast_unaligned ;;

So the developers consider unaligned accesses a faster option than
aligned on armv6+. Feel free to benchmark with and without the flag :)

I can understand CPU/cache designers pain in implementing unaligned access,
but reality is that ARMv7+ supports unaligned accesses quite well and this
sometimes allows software engineers sometimes to write more clean and
maintainable code. 

This doesn't mean that unaligned accesses make always sense. There is plenty
of unaligned accesses that could be converted to more clean code that does
aligned accesses... 
 
> arm64 simply doesn't permit unaligned access in the core. Some types
> of access are wrapped (in hardware) so that 2 access will get done and
> you are returned the relevant pieces of the result, but this doesn't
> apply to all access types and is obviously slower/energy
> inefficent. 

If your data is split over aligment boundaries, you will need multiple
memory accesses anyways. 

Riku


Reply to: