Skip to content

Commit 8b7a6f0

Browse files
committed
bswap.h: add support for built-in bswap functions
Newer compiler versions, like GCC 10 and Clang 12, have built-in functions for bswap32 and bswap64. This comes in handy, for example, when targeting CLANGARM64 on Windows, which would not be supported without this logic. Signed-off-by: Dennis Ameling <dennis@dennisameling.com>
1 parent 0355083 commit 8b7a6f0

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_bswap32) && __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)