qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org,
	qemu-s390x@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Helge Deller" <deller@gmx.de>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [PATCH 07/16] hw/display: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check
Date: Fri, 10 Oct 2025 15:42:16 +0200	[thread overview]
Message-ID: <20251010134226.72221-8-philmd@linaro.org> (raw)
In-Reply-To: <20251010134226.72221-1-philmd@linaro.org>

Replace compile-time #ifdef with a runtime check to ensure all code
paths are built and tested. This reduces build-time configuration
complexity and improves maintainability.

No functional change intended.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/virtio/virtio-gpu-bswap.h |  6 +++---
 hw/display/artist.c                  | 12 ++++++------
 hw/display/vga.c                     | 20 ++++++++------------
 hw/display/virtio-gpu-gl.c           |  8 ++++----
 hw/display/virtio-gpu-rutabaga.c     |  8 ++++----
 5 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virtio-gpu-bswap.h
index dd1975e2d40..279734231e2 100644
--- a/include/hw/virtio/virtio-gpu-bswap.h
+++ b/include/hw/virtio/virtio-gpu-bswap.h
@@ -29,7 +29,9 @@ virtio_gpu_ctrl_hdr_bswap(struct virtio_gpu_ctrl_hdr *hdr)
 static inline void
 virtio_gpu_bswap_32(void *ptr, size_t size)
 {
-#if HOST_BIG_ENDIAN
+    if (!HOST_BIG_ENDIAN) {
+        return;
+    }
 
     size_t i;
     struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *) ptr;
@@ -41,8 +43,6 @@ virtio_gpu_bswap_32(void *ptr, size_t size)
         le32_to_cpus((uint32_t *)(ptr + i));
         i = i + sizeof(uint32_t);
     }
-
-#endif
 }
 
 static inline void
diff --git a/hw/display/artist.c b/hw/display/artist.c
index 3c884c92437..8d73f2d894d 100644
--- a/hw/display/artist.c
+++ b/hw/display/artist.c
@@ -738,9 +738,9 @@ static void combine_write_reg(hwaddr addr, uint64_t val, int size, void *out)
      * FIXME: is there a qemu helper for this?
      */
 
-#if !HOST_BIG_ENDIAN
-    addr ^= 3;
-#endif
+    if (!HOST_BIG_ENDIAN) {
+        addr ^= 3;
+    }
 
     switch (size) {
     case 1:
@@ -1132,9 +1132,9 @@ static uint64_t combine_read_reg(hwaddr addr, int size, void *in)
      * FIXME: is there a qemu helper for this?
      */
 
-#if !HOST_BIG_ENDIAN
-    addr ^= 3;
-#endif
+    if (!HOST_BIG_ENDIAN) {
+        addr ^= 3;
+    }
 
     switch (size) {
     case 1:
diff --git a/hw/display/vga.c b/hw/display/vga.c
index 90b89cf4044..01b1cfa98d3 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -1307,13 +1307,13 @@ static void vga_draw_text(VGACommonState *s, int full_update)
                 if (cx > cx_max)
                     cx_max = cx;
                 *ch_attr_ptr = ch_attr;
-#if HOST_BIG_ENDIAN
-                ch = ch_attr >> 8;
-                cattr = ch_attr & 0xff;
-#else
-                ch = ch_attr & 0xff;
-                cattr = ch_attr >> 8;
-#endif
+                if (HOST_BIG_ENDIAN) {
+                    ch = ch_attr >> 8;
+                    cattr = ch_attr & 0xff;
+                } else {
+                    ch = ch_attr & 0xff;
+                    cattr = ch_attr >> 8;
+                }
                 font_ptr = font_base[(cattr >> 3) & 1];
                 font_ptr += 32 * 4 * ch;
                 bgcol = palette[cattr >> 4];
@@ -1489,11 +1489,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
     vga_draw_line_func *vga_draw_line = NULL;
     bool allocate_surface, force_shadow = false;
     pixman_format_code_t format;
-#if HOST_BIG_ENDIAN
-    bool byteswap = !s->big_endian_fb;
-#else
-    bool byteswap = s->big_endian_fb;
-#endif
+    bool byteswap = s->big_endian_fb ^ HOST_BIG_ENDIAN;
 
     full_update |= update_basic_params(s);
 
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index c06a078fb36..c29152a3c7a 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -123,10 +123,10 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
     ERRP_GUARD();
     VirtIOGPU *g = VIRTIO_GPU(qdev);
 
-#if HOST_BIG_ENDIAN
-    error_setg(errp, "virgl is not supported on bigendian platforms");
-    return;
-#endif
+    if (HOST_BIG_ENDIAN) {
+        error_setg(errp, "virgl is not supported on bigendian platforms");
+        return;
+    }
 
     if (!object_resolve_path_type("", TYPE_VIRTIO_GPU_GL, NULL)) {
         error_setg(errp, "at most one %s device is permitted", TYPE_VIRTIO_GPU_GL);
diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutabaga.c
index ed5ae52acbe..f82a84b53aa 100644
--- a/hw/display/virtio-gpu-rutabaga.c
+++ b/hw/display/virtio-gpu-rutabaga.c
@@ -1074,10 +1074,10 @@ static void virtio_gpu_rutabaga_realize(DeviceState *qdev, Error **errp)
     VirtIOGPUBase *bdev = VIRTIO_GPU_BASE(qdev);
     VirtIOGPU *gpudev = VIRTIO_GPU(qdev);
 
-#if HOST_BIG_ENDIAN
-    error_setg(errp, "rutabaga is not supported on bigendian platforms");
-    return;
-#endif
+    if (HOST_BIG_ENDIAN) {
+        error_setg(errp, "rutabaga is not supported on bigendian platforms");
+        return;
+    }
 
     if (!virtio_gpu_rutabaga_init(gpudev, errp)) {
         return;
-- 
2.51.0



  parent reply	other threads:[~2025-10-10 13:48 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10 13:42 [PATCH 00/16] overall: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 01/16] linux-user/arm: Checkpatch style cleanups Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 02/16] linux-user/arm: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 03/16] ui: " Philippe Mathieu-Daudé
2025-10-13 11:57   ` Marc-André Lureau
2025-10-10 13:42 ` [PATCH 04/16] net: " Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 05/16] disas: " Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 06/16] hw/core/loader: " Philippe Mathieu-Daudé
2025-10-14  5:18   ` Alistair Francis
2025-10-10 13:42 ` Philippe Mathieu-Daudé [this message]
2025-10-14  4:52   ` [PATCH 07/16] hw/display: " Akihiko Odaki
2025-10-10 13:42 ` [PATCH 08/16] hw/virtio: " Philippe Mathieu-Daudé
2025-10-10 19:23   ` Farhan Ali
2025-10-11  8:04     ` Lei Yang
2025-10-10 13:42 ` [PATCH 09/16] target/alpha: " Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 10/16] target/arm: " Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 11/16] target/mips: " Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 12/16] target/ppc: " Philippe Mathieu-Daudé
2025-10-14  6:48   ` Harsh Prateek Bora
2025-10-14  7:13     ` Harsh Prateek Bora
2025-10-10 13:42 ` [PATCH 13/16] target/riscv: " Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 14/16] target/s390x: " Philippe Mathieu-Daudé
2025-10-10 13:56   ` David Hildenbrand
2025-10-10 13:42 ` [PATCH 15/16] target/sparc: " Philippe Mathieu-Daudé
2025-10-10 13:42 ` [PATCH 16/16] util/bitmap: " Philippe Mathieu-Daudé
2025-10-10 13:51 ` [PATCH 00/16] overall: " Paolo Bonzini
2025-10-10 14:37   ` 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=20251010134226.72221-8-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=deller@gmx.de \
    --cc=dmitry.osipenko@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=mst@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@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).