Remove <swab.h> and swabXX() functions

GCC generates correct code for __builtin_bswapXX() on all architectures,
including ArmV4. It seems that whatever bug caused this to not work back
in commit 879ea7fce8 ("endian: Replace explicit byte swapping with
compiler builtin") has been fixed now. We can eliminate the swabXX()
functions and simplify the code.

All instances that had been calling these functions directly should have
been using real endianness conversions anyway.

Change-Id: I19713fd009aa5c0e01c4a42e0cf012364d6bed60
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/90438
Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Frans Hendriks <fhendriks@eltan.com>
This commit is contained in:
Julius Werner 2025-12-09 11:34:18 -08:00 committed by Yu-Ping Wu
commit 8f34fdfab3
9 changed files with 17 additions and 76 deletions

View file

@ -5,8 +5,8 @@
/*
* This header should not be included directly. Including source must define
* prerequisites like uintXX_t types, the byteswap functions swabXX(),
* __BIG_ENDIAN or __LITTLE_ENDIAN and I/O accessors readXX()/writeXX().
* prerequisites like uintXX_t types, __BIG_ENDIAN or __LITTLE_ENDIAN and
* I/O accessors readXX()/writeXX().
*/
/* Endian functions from glibc 2.9 / BSD "endian.h" */
@ -15,13 +15,13 @@
#define htobe16(in) (in)
#define htobe32(in) (in)
#define htobe64(in) (in)
#define htole16(in) ((uint16_t)swab16(in))
#define htole32(in) ((uint32_t)swab32(in))
#define htole64(in) ((uint64_t)swab64(in))
#define htole16(in) ((uint16_t)__builtin_bswap16(in))
#define htole32(in) ((uint32_t)__builtin_bswap32(in))
#define htole64(in) ((uint64_t)__builtin_bswap64(in))
#elif defined(__LITTLE_ENDIAN)
#define htobe16(in) ((uint16_t)swab16(in))
#define htobe32(in) ((uint32_t)swab32(in))
#define htobe64(in) ((uint64_t)swab64(in))
#define htobe16(in) ((uint16_t)__builtin_bswap16(in))
#define htobe32(in) ((uint32_t)__builtin_bswap32(in))
#define htobe64(in) ((uint64_t)__builtin_bswap64(in))
#define htole16(in) (in)
#define htole32(in) (in)
#define htole64(in) (in)