qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 4/8] target/ppc: Evaluate TARGET_BIG_ENDIAN at compile time
Date: Thu, 17 Apr 2025 15:10:00 +0200	[thread overview]
Message-ID: <20250417131004.47205-5-philmd@linaro.org> (raw)
In-Reply-To: <20250417131004.47205-1-philmd@linaro.org>

Rather than evaluating TARGET_BIG_ENDIAN at preprocessing
time via #ifdef'ry, do it in C at compile time

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/ppc/cpu_init.c   | 12 ++++++------
 target/ppc/mem_helper.c |  6 +-----
 target/ppc/translate.c  |  6 +-----
 3 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 077991ed535..bbab411a07c 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7262,14 +7262,14 @@ static void ppc_cpu_reset_hold(Object *obj, ResetType type)
 #if defined(TARGET_PPC64)
     msr |= (target_ulong)1 << MSR_TM; /* Transactional memory */
 #endif
-#if !TARGET_BIG_ENDIAN
-    msr |= (target_ulong)1 << MSR_LE; /* Little-endian user mode */
-    if (!((env->msr_mask >> MSR_LE) & 1)) {
-        fprintf(stderr, "Selected CPU does not support little-endian.\n");
-        exit(1);
+    if (!TARGET_BIG_ENDIAN) {
+        msr |= (target_ulong)1 << MSR_LE; /* Little-endian user mode */
+        if (!((env->msr_mask >> MSR_LE) & 1)) {
+            fprintf(stderr, "Selected CPU does not support little-endian.\n");
+            exit(1);
+        }
     }
 #endif
-#endif
 
 #if defined(TARGET_PPC64)
     if (mmu_is_64bit(env->mmu_model)) {
diff --git a/target/ppc/mem_helper.c b/target/ppc/mem_helper.c
index d7e8d678f4b..cc3ed29a35b 100644
--- a/target/ppc/mem_helper.c
+++ b/target/ppc/mem_helper.c
@@ -32,11 +32,7 @@
 
 static inline bool needs_byteswap(const CPUPPCState *env)
 {
-#if TARGET_BIG_ENDIAN
-  return FIELD_EX64(env->msr, MSR, LE);
-#else
-  return !FIELD_EX64(env->msr, MSR, LE);
-#endif
+  return TARGET_BIG_ENDIAN ^ FIELD_EX64(env->msr, MSR, LE);
 }
 
 /*****************************************************************************/
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 399107d319a..828b850b40e 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -213,11 +213,7 @@ struct DisasContext {
 /* Return true iff byteswap is needed in a scalar memop */
 static inline bool need_byteswap(const DisasContext *ctx)
 {
-#if TARGET_BIG_ENDIAN
-     return ctx->le_mode;
-#else
-     return !ctx->le_mode;
-#endif
+     return TARGET_BIG_ENDIAN ^ ctx->le_mode;
 }
 
 /* True when active word size < size of target_long.  */
-- 
2.47.1



  parent reply	other threads:[~2025-04-17 13:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-17 13:09 [PATCH 0/8] misc: Prefer evaluating TARGET_BIG_ENDIAN in C Philippe Mathieu-Daudé
2025-04-17 13:09 ` [PATCH 1/8] linux-user/elfload: Use target_needs_bswap() Philippe Mathieu-Daudé
2025-04-18 17:44   ` Richard Henderson
2025-04-17 13:09 ` [PATCH 2/8] accel/kvm: " Philippe Mathieu-Daudé
2025-04-18 17:47   ` Richard Henderson
2025-04-17 13:09 ` [PATCH 3/8] target/mips: Check CPU endianness at runtime using env_is_bigendian() Philippe Mathieu-Daudé
2025-04-18 17:53   ` Richard Henderson
2025-04-17 13:10 ` Philippe Mathieu-Daudé [this message]
2025-04-17 19:26   ` [PATCH 4/8] target/ppc: Evaluate TARGET_BIG_ENDIAN at compile time Pierrick Bouvier
2025-04-18 17:56   ` Richard Henderson
2025-04-17 13:10 ` [PATCH 5/8] target/xtensa: " Philippe Mathieu-Daudé
2025-04-18 17:56   ` Richard Henderson
2025-04-17 13:10 ` [PATCH 6/8] hw/mips: " Philippe Mathieu-Daudé
2025-04-18 17:57   ` Richard Henderson
2025-04-17 13:10 ` [PATCH 7/8] hw/microblaze: " Philippe Mathieu-Daudé
2025-04-18 17:58   ` Richard Henderson
2025-04-17 13:10 ` [PATCH 8/8] gdbstub/helpers: " Philippe Mathieu-Daudé
2025-04-17 16:18   ` Alex Bennée
2025-04-18 18:01   ` Richard Henderson
2025-04-25 15:17 ` [PATCH 0/8] misc: Prefer evaluating TARGET_BIG_ENDIAN in C 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=20250417131004.47205-5-philmd@linaro.org \
    --to=philmd@linaro.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 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).