[PATCH 16/16] util/bitmap: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check

Philippe Mathieu-Daudé posted 16 patches 1 month ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@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>, Stefano Garzarella <sgarzare@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Jason Wang <jasowang@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Paolo Bonzini <pbonzini@redhat.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
[PATCH 16/16] util/bitmap: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check
Posted by Philippe Mathieu-Daudé 1 month ago
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>
---
 util/bitmap.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/util/bitmap.c b/util/bitmap.c
index 8d12e90a5a4..2346159116e 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -421,19 +421,14 @@ static void bitmap_to_from_le(unsigned long *dst,
 {
     long len = BITS_TO_LONGS(nbits);
 
-#if HOST_BIG_ENDIAN
-    long index;
-
-    for (index = 0; index < len; index++) {
-# if HOST_LONG_BITS == 64
-        dst[index] = bswap64(src[index]);
-# else
-        dst[index] = bswap32(src[index]);
-# endif
+    if (HOST_BIG_ENDIAN) {
+        for (long index = 0; index < len; index++) {
+            dst[index] = (HOST_LONG_BITS == 64) ? bswap64(src[index])
+                                                : bswap32(src[index]);
+        }
+    } else {
+        memcpy(dst, src, len * sizeof(unsigned long));
     }
-#else
-    memcpy(dst, src, len * sizeof(unsigned long));
-#endif
 }
 
 void bitmap_from_le(unsigned long *dst, const unsigned long *src,
-- 
2.51.0