Skip to content

Commit 3e9d79f

Browse files
committed
bswap.h: use built-in bswap32 and bswap64 when available
Clang 12 and GCC 10 added support for built-in bswap32 and bswap64. As bswap.h doesn't support ARM64/aarch64 when using GCC/Clang, this is a good opportunity to start using those built-ins. In the future, we might want to remove the custom git_bswap32 and git_bswap64 altogether and leave that up to the compiler to handle. Signed-off-by: Dennis Ameling <dennis@dennisameling.com>
1 parent 5536206 commit 3e9d79f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compat/bswap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ static inline uint64_t git_bswap64(uint64_t x)
7474
}
7575
#endif
7676

77+
/* available since Clang 12 and GCC 10, i.a. needed for ARM64/aarch64 on Windows */
78+
#elif defined(__has_builtin) && __has_builtin(__builtin_bswap64)
79+
80+
#define bswap32(x) __builtin_bswap32((x))
81+
#define bswap64(x) __builtin_bswap64((x))
82+
7783
#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64))
7884

7985
#include <stdlib.h>

0 commit comments

Comments
 (0)