From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
To: git@vger.kernel.org
Subject: [PATCH] bswap.h: Move the overwriting of the ntohl*/ htonl* macros.
Date: Fri, 6 Jun 2025 18:57:18 +0200 [thread overview]
Message-ID: <20250606165718.HOiC2U4X@breakpoint.cc> (raw)
The top of that file contains optimized bswap32/64 only for a few little
endian machines. Since the commit cited below there is one for every
architecture supporting the __builtin_bswap* directives.
Later in the file, the ntohl* macros are replaced with the bswap* macros
should they be provided. Since they are now provided even on big endian
machines they replace the nop with a swap.
Move the ntohl*/ htonl* replacement once it is determined that it is a
little architecture where the swap is performed.
Fixes: 6547d1c9cbafa ("bswap.h: add support for built-in bswap functions")
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
This builds on top of v2.50.0-rc1 on s390x and -rc0 and x86-64. The
testsuite passes.
compat/bswap.h | 37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/compat/bswap.h b/compat/bswap.h
index 9e0f98e00b93a..5789d12c2c356 100644
--- a/compat/bswap.h
+++ b/compat/bswap.h
@@ -95,24 +95,6 @@ static inline uint64_t git_bswap64(uint64_t x)
#endif
-#if defined(bswap32)
-
-#undef ntohl
-#undef htonl
-#define ntohl(x) bswap32(x)
-#define htonl(x) bswap32(x)
-
-#endif
-
-#if defined(bswap64)
-
-#undef ntohll
-#undef htonll
-#define ntohll(x) bswap64(x)
-#define htonll(x) bswap64(x)
-
-#else
-
#undef ntohll
#undef htonll
@@ -151,10 +133,23 @@ static inline uint64_t git_bswap64(uint64_t x)
# define ntohll(n) (n)
# define htonll(n) (n)
#else
-# define ntohll(n) default_bswap64(n)
-# define htonll(n) default_bswap64(n)
-#endif
+# if defined(bswap32)
+# undef ntohl
+# undef htonl
+# define ntohl(x) bswap32(x)
+# define htonl(x) bswap32(x)
+# endif
+
+# if defined(bswap64)
+# undef ntohll
+# undef htonll
+# define ntohll(x) bswap64(x)
+# define htonll(x) bswap64(x)
+# else
+# define ntohll(n) default_bswap64(n)
+# define htonll(n) default_bswap64(n)
+# endif
#endif
static inline uint16_t get_be16(const void *ptr)
--
2.49.0
next reply other threads:[~2025-06-06 16:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-06 16:57 Sebastian Andrzej Siewior [this message]
2025-06-06 21:05 ` [PATCH] bswap.h: Move the overwriting of the ntohl*/ htonl* macros Junio C Hamano
2025-06-06 22:04 ` Sebastian Andrzej Siewior
2025-06-06 22:36 ` Junio C Hamano
2025-06-07 21:02 ` Junio C Hamano
2025-06-09 21:57 ` Sebastian Andrzej Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250606165718.HOiC2U4X@breakpoint.cc \
--to=sebastian@breakpoint.cc \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).