The generic codecs currently read and write potentially unaligned memory ranges using raw pointer casts. This will break on platforms that require strict alignment for memory loads/stores. Examples:
memcpy(3) is defined by the C99 standard, so is portable. The arguments to memcpy are all known at compile time, so on platforms that allow nonaligned memory access, a good compiler will optimize the memcpy to a single mov instruction. On platforms without nonaligned memory loads/stores, the function generates bytewise access, which is the best we can do in those circumstances.
This will also allow us to remove the HAVE_FAST_UNALIGNED_ACCESS macro, which currently guards an unaligned memory store.
The generic codecs currently read and write potentially unaligned memory ranges using raw pointer casts. This will break on platforms that require strict alignment for memory loads/stores. Examples:
Replace such casts with calls to
memcpy(3)
:memcpy(3)
is defined by the C99 standard, so is portable. The arguments tomemcpy
are all known at compile time, so on platforms that allow nonaligned memory access, a good compiler will optimize thememcpy
to a singlemov
instruction. On platforms without nonaligned memory loads/stores, the function generates bytewise access, which is the best we can do in those circumstances.This will also allow us to remove the
HAVE_FAST_UNALIGNED_ACCESS
macro, which currently guards an unaligned memory store.