[PATCH 07/12] Simplify HOST_LONG_BITS

marcandre.lureau@redhat.com posted 12 patches 3 years, 6 months ago
There is a newer version of this series
[PATCH 07/12] Simplify HOST_LONG_BITS
Posted by marcandre.lureau@redhat.com 3 years, 6 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Simplify the macro, not depending on headers defines, but compiler
predefined __SIZEOF__POINTER__ only.

Available since gcc 4.3 and clang 2.8.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qemu/osdep.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 74473867f3f6..cea7303c78a4 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -261,13 +261,7 @@ G_NORETURN extern void QEMU_ERROR("code path is reachable")
 #endif
 
 /* HOST_LONG_BITS is the size of a native pointer in bits. */
-#if UINTPTR_MAX == UINT32_MAX
-# define HOST_LONG_BITS 32
-#elif UINTPTR_MAX == UINT64_MAX
-# define HOST_LONG_BITS 64
-#else
-# error Unknown pointer size
-#endif
+#define HOST_LONG_BITS (__SIZEOF_POINTER__ * 8)
 
 /* Mac OSX has a <stdint.h> bug that incorrectly defines SIZE_MAX with
  * the wrong type. Our replacement isn't usable in preprocessor
-- 
2.35.1.273.ge6ebfd0e8cbb


Re: [PATCH 07/12] Simplify HOST_LONG_BITS
Posted by Richard Henderson 3 years, 6 months ago
On 2/24/22 08:36, marcandre.lureau@redhat.com wrote:
> -#if UINTPTR_MAX == UINT32_MAX
> -# define HOST_LONG_BITS 32
> -#elif UINTPTR_MAX == UINT64_MAX
> -# define HOST_LONG_BITS 64
> -#else
> -# error Unknown pointer size
> -#endif
> +#define HOST_LONG_BITS (__SIZEOF_POINTER__ * 8)

I guess.  I'll note that there are 128-bit pointers on the horizon, but that UINTPTR_MAX 
would not necessarily change to match __SIZEOF_POINTER__ [1].

Acked-by: Richard Henderson <richard.henderson@linaro.org>


r~


[1] https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-947.pdf