[PATCH xserver 1/3] Rewrite the byte swapping macros.
Eric Anholt
eric at anholt.net
Fri Apr 21 22:41:10 UTC 2017
Keith Packard <keithp at keithp.com> writes:
> [ Unknown signature status ]
> Eric Anholt <eric at anholt.net> writes:
>
>> #define swapll(x) do { \
>> + uint64_t temp; \
>> if (sizeof(*(x)) != 8) \
>> wrong_size(); \
>> - swap_uint64((uint64_t *)(x)); \
>> + memcpy(&temp, x, 8); \
>> + temp = bswap_64(temp); \
>> + memcpy(x, &temp, 8); \
>> } while (0)
>
>> #define swapl(x) do { \
>> + uint32_t temp; \
>> if (sizeof(*(x)) != 4) \
>> wrong_size(); \
>> - if (__builtin_constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \
>> - *(x) = lswapl(*(x)); \
>> - else \
>> - swap_uint32((uint32_t *)(x)); \
>> + memcpy(&temp, x, 4); \
>> + temp = bswap_32(temp); \
>> + memcpy(x, &temp, 4); \
>> } while (0)
>
>> #define swaps(x) do { \
>> + uint16_t temp; \
>> if (sizeof(*(x)) != 2) \
>> wrong_size(); \
>> - if (__builtin_constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \
>> - *(x) = lswaps(*(x)); \
>> - else \
>> - swap_uint16((uint16_t *)(x)); \
>> + memcpy(&temp, x, 2); \
>> + temp = bswap_16(temp); \
>> + memcpy(x, &temp, 2); \
>> } while (0)
>
> Any particular reason to think that x might be unaligned (and hence need
> the memcpys? Yeah, I know they're probably 'free' when things are
> aligned.
>
> The rest of this is
>
> Reviewed-by: Keith Packard <keithp at keithp.com>
The reason to think so is that the previous code had this weird stuff to
explicitly handle unaligned. I rip out the unaligned support in patch
3, because I think it's not needed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://lists.x.org/archives/xorg-devel/attachments/20170421/5d23111f/attachment-0001.sig>
More information about the xorg-devel
mailing list