git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/6] bswap.h: add support for built-in bswap functions

From
DGDennis Ameling via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 23, 2025, 08:01 UTC
Message-ID
<b89f39cbac6abb23ce1f6a987dc864181af2f395.1745395308.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1904.v2.git.1745395308.gitgitgadget@gmail.com>
From: Dennis Ameling <dennis@dennisameling.com>

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>
---
 compat/bswap.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/compat/bswap.h b/compat/bswap.h
index b34054f2bd7..9e0f98e00b9 100644
--- a/compat/bswap.h
+++ b/compat/bswap.h
@@ -35,7 +35,19 @@ static inline uint64_t default_bswap64(uint64_t val)
 #undef bswap32
 #undef bswap64
 
-#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+/**
+ * __has_builtin is available since Clang 10 and GCC 10.
+ * Below is a fallback for older compilers.
+ */
+#ifndef __has_builtin
+	#define __has_builtin(x) 0
+#endif
+
+#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
+#define bswap32(x) __builtin_bswap32((x))
+#define bswap64(x) __builtin_bswap64((x))
+
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
 
 #define bswap32 git_bswap32
 static inline uint32_t git_bswap32(uint32_t x)
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Dennis Ameling via GitGitGadget
Message 14 of 20 in “Support Windows/ARM64”
  1. 0/6 Support Windows/ARM64Johannes Schindelin via GitGitGadget, Apr 21, 2025
  2. 1/6 bswap.h: add support for built-in bswap functionsDennis Ameling via GitGitGadget, Apr 21, 2025
  3. 2/6 config.mak.uname: add support for clangarm64Dennis Ameling via GitGitGadget, Apr 21, 2025
  4. 3/6 mingw: do not use nedmalloc on Windows/ARM64Johannes Schindelin via GitGitGadget, Apr 21, 2025
  5. Patrick SteinhardtApr 22, 2025
  6. Dropping nedmalloc support? was Re: [PATCH 3/6] mingw: do not use nedmalloc on Windows/ARM64Johannes Schindelin, Apr 22, 2025
  7. 4/6 msvc: do handle builds on Windows/ARM64Johannes Schindelin via GitGitGadget, Apr 21, 2025
  8. 6/6 max_tree_depth: lower it for clangarm64 on WindowsJohannes Schindelin via GitGitGadget, Apr 21, 2025
  9. Patrick SteinhardtApr 22, 2025
  10. Johannes SchindelinApr 22, 2025
  11. 5/6 mingw(arm64): do move the `/etc/git*` locationJohannes Schindelin via GitGitGadget, Apr 21, 2025
  12. Junio C HamanoApr 21, 2025
  13. 0/6 Support Windows/ARM64Johannes Schindelin via GitGitGadget, Apr 23, 2025
  14. 1/6 bswap.h: add support for built-in bswap functionsDennis Ameling via GitGitGadget, Apr 23, 2025
  15. 2/6 config.mak.uname: add support for clangarm64Dennis Ameling via GitGitGadget, Apr 23, 2025
  16. 3/6 mingw: do not use nedmalloc on Windows/ARM64Johannes Schindelin via GitGitGadget, Apr 23, 2025
  17. Junio C HamanoApr 23, 2025
  18. 4/6 msvc: do handle builds on Windows/ARM64Johannes Schindelin via GitGitGadget, Apr 23, 2025
  19. 5/6 mingw(arm64): do move the `/etc/git*` locationJohannes Schindelin via GitGitGadget, Apr 23, 2025
  20. 6/6 max_tree_depth: lower it for clangarm64 on WindowsJohannes Schindelin via GitGitGadget, Apr 23, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.