Aligned and unaligned memory accesses?

前端 未结 6 1664
长情又很酷
长情又很酷 2020-12-13 20:33

What is the difference between aligned and unaligned memory access?

I work on an TMS320C64x DSP, and I want to use the intrinsic functions (C functions for assembly

6条回答
  •  难免孤独
    2020-12-13 20:43

    Many processors have alignment restrictions on memory access. Unaligned access either generates an exception interrupt (e.g. ARM), or is just slower (e.g. x86).

    _mem2 is probably implemented as fetching two bytes and using shift and or bitwise operations to make a 16-bit ushort out of them.

    _amem2 probably just reads the 16-bit ushort from the specified ptr.

    I don't know TMS320C64x specifically but I'd guess it requires 16-bit alignment for 16-bit memory accesses. So you can use _mem2 always but with performance penalty, and _amem2 when you can guarantee that ptr is an even address.

提交回复
热议问题