All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Kamil Rytarowski" <kamil@netbsd.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH v2 2/8] qemu/bswap: Replace bswapXX() by compiler __builtin_bswap()
Date: Mon, 28 Sep 2020 15:19:28 +0200	[thread overview]
Message-ID: <20200928131934.739451-3-philmd@redhat.com> (raw)
In-Reply-To: <20200928131934.739451-1-philmd@redhat.com>

Use the compiler built-in function to byte swap values,
as the compiler is clever and will fold constants.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/qemu/bswap.h | 33 +++++++--------------------------
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index 8b01c38040c..41131d3d76e 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -27,32 +27,13 @@ static inline uint64_t bswap64(uint64_t x)
 {
     return bswap_64(x);
 }
-# else
-static inline uint16_t bswap16(uint16_t x)
-{
-    return (((x & 0x00ff) << 8) |
-            ((x & 0xff00) >> 8));
-}
-
-static inline uint32_t bswap32(uint32_t x)
-{
-    return (((x & 0x000000ffU) << 24) |
-            ((x & 0x0000ff00U) <<  8) |
-            ((x & 0x00ff0000U) >>  8) |
-            ((x & 0xff000000U) >> 24));
-}
-
-static inline uint64_t bswap64(uint64_t x)
-{
-    return (((x & 0x00000000000000ffULL) << 56) |
-            ((x & 0x000000000000ff00ULL) << 40) |
-            ((x & 0x0000000000ff0000ULL) << 24) |
-            ((x & 0x00000000ff000000ULL) <<  8) |
-            ((x & 0x000000ff00000000ULL) >>  8) |
-            ((x & 0x0000ff0000000000ULL) >> 24) |
-            ((x & 0x00ff000000000000ULL) >> 40) |
-            ((x & 0xff00000000000000ULL) >> 56));
-}
+#else
+#undef  bswap16
+#define bswap16(_x) __builtin_bswap16(_x)
+#undef  bswap32
+#define bswap32(_x) __builtin_bswap32(_x)
+#undef  bswap64
+#define bswap64(_x) __builtin_bswap64(_x)
 #endif /* ! CONFIG_MACHINE_BSWAP_H */
 
 static inline void bswap16s(uint16_t *s)
-- 
2.26.2



  parent reply	other threads:[~2020-09-28 13:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28 13:19 [PATCH v2 0/8] qemu/bswap: Use compiler __builtin_bswap() Philippe Mathieu-Daudé
2020-09-28 13:19 ` [PATCH v2 1/8] qemu/bswap: Remove unused qemu_bswap_len() Philippe Mathieu-Daudé
2020-09-28 13:19 ` Philippe Mathieu-Daudé [this message]
2020-09-28 13:19 ` [PATCH v2 3/8] qemu/bswap: Replace bswapXXs() by compiler __builtin_bswap() Philippe Mathieu-Daudé
2020-09-28 17:29   ` Thomas Huth
2020-09-28 13:19 ` [PATCH v2 4/8] qemu/bswap: Remove <byteswap.h> dependency Philippe Mathieu-Daudé
2020-09-28 13:19 ` [PATCH v2 5/8] qemu/bswap: Use compiler __builtin_bswap() on Haiku Philippe Mathieu-Daudé
2020-09-28 14:09   ` David CARLIER
2020-09-28 14:13     ` Daniel P. Berrangé
2020-09-28 14:18       ` Philippe Mathieu-Daudé
2020-10-19 11:00         ` Philippe Mathieu-Daudé
2020-09-28 15:00       ` David CARLIER
2020-09-28 17:29   ` Thomas Huth
2020-09-28 13:19 ` [PATCH v2 6/8] qemu/bswap: Use compiler __builtin_bswap() on FreeBSD Philippe Mathieu-Daudé
2020-09-28 17:32   ` Thomas Huth
2020-09-28 17:57     ` Philippe Mathieu-Daudé
2020-09-28 17:58       ` Philippe Mathieu-Daudé
2020-09-28 21:16   ` Ed Maste
2020-09-28 13:19 ` [PATCH v2 7/8] qemu/bswap: Use compiler __builtin_bswap() on NetBSD Philippe Mathieu-Daudé
2020-09-28 21:51   ` Kamil Rytarowski
2020-09-29  8:58     ` Peter Maydell
2020-09-29 14:06       ` Kamil Rytarowski
2020-09-28 13:19 ` [RFC PATCH v2 8/8] tests/vm: Add Haiku test based on their vagrant images Philippe Mathieu-Daudé

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=20200928131934.739451-3-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=fam@euphon.net \
    --cc=kamil@netbsd.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.