[PATCH 01/72] qemu/host-utils: Use __builtin_bitreverseN

Richard Henderson posted 72 patches 4 years, 9 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Richard Henderson <richard.henderson@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Eduardo Habkost <ehabkost@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Laurent Vivier <laurent@vivier.eu>, Aurelien Jarno <aurelien@aurel32.net>, Paolo Bonzini <pbonzini@redhat.com>
There is a newer version of this series
[PATCH 01/72] qemu/host-utils: Use __builtin_bitreverseN
Posted by Richard Henderson 4 years, 9 months ago
Clang has added some builtins for these operations;
use them if available.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/qemu/host-utils.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index cdca2991d8..f1e52851e0 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -272,6 +272,9 @@ static inline int ctpop64(uint64_t val)
  */
 static inline uint8_t revbit8(uint8_t x)
 {
+#if __has_builtin(__builtin_bitreverse8)
+    return __builtin_bitreverse8(x);
+#else
     /* Assign the correct nibble position.  */
     x = ((x & 0xf0) >> 4)
       | ((x & 0x0f) << 4);
@@ -281,6 +284,7 @@ static inline uint8_t revbit8(uint8_t x)
       | ((x & 0x22) << 1)
       | ((x & 0x11) << 3);
     return x;
+#endif
 }
 
 /**
@@ -289,6 +293,9 @@ static inline uint8_t revbit8(uint8_t x)
  */
 static inline uint16_t revbit16(uint16_t x)
 {
+#if __has_builtin(__builtin_bitreverse16)
+    return __builtin_bitreverse16(x);
+#else
     /* Assign the correct byte position.  */
     x = bswap16(x);
     /* Assign the correct nibble position.  */
@@ -300,6 +307,7 @@ static inline uint16_t revbit16(uint16_t x)
       | ((x & 0x2222) << 1)
       | ((x & 0x1111) << 3);
     return x;
+#endif
 }
 
 /**
@@ -308,6 +316,9 @@ static inline uint16_t revbit16(uint16_t x)
  */
 static inline uint32_t revbit32(uint32_t x)
 {
+#if __has_builtin(__builtin_bitreverse32)
+    return __builtin_bitreverse32(x);
+#else
     /* Assign the correct byte position.  */
     x = bswap32(x);
     /* Assign the correct nibble position.  */
@@ -319,6 +330,7 @@ static inline uint32_t revbit32(uint32_t x)
       | ((x & 0x22222222u) << 1)
       | ((x & 0x11111111u) << 3);
     return x;
+#endif
 }
 
 /**
@@ -327,6 +339,9 @@ static inline uint32_t revbit32(uint32_t x)
  */
 static inline uint64_t revbit64(uint64_t x)
 {
+#if __has_builtin(__builtin_bitreverse64)
+    return __builtin_bitreverse64(x);
+#else
     /* Assign the correct byte position.  */
     x = bswap64(x);
     /* Assign the correct nibble position.  */
@@ -338,6 +353,7 @@ static inline uint64_t revbit64(uint64_t x)
       | ((x & 0x2222222222222222ull) << 1)
       | ((x & 0x1111111111111111ull) << 3);
     return x;
+#endif
 }
 
 /* Host type specific sizes of these routines.  */
-- 
2.25.1


Re: [PATCH 01/72] qemu/host-utils: Use __builtin_bitreverseN
Posted by David Hildenbrand 4 years, 9 months ago
On 08.05.21 03:46, Richard Henderson wrote:
> Clang has added some builtins for these operations;
> use them if available.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   include/qemu/host-utils.h | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
> index cdca2991d8..f1e52851e0 100644
> --- a/include/qemu/host-utils.h
> +++ b/include/qemu/host-utils.h
> @@ -272,6 +272,9 @@ static inline int ctpop64(uint64_t val)
>    */
>   static inline uint8_t revbit8(uint8_t x)
>   {
> +#if __has_builtin(__builtin_bitreverse8)
> +    return __builtin_bitreverse8(x);
> +#else
>       /* Assign the correct nibble position.  */
>       x = ((x & 0xf0) >> 4)
>         | ((x & 0x0f) << 4);
> @@ -281,6 +284,7 @@ static inline uint8_t revbit8(uint8_t x)
>         | ((x & 0x22) << 1)
>         | ((x & 0x11) << 3);
>       return x;
> +#endif
>   }
>   
>   /**
> @@ -289,6 +293,9 @@ static inline uint8_t revbit8(uint8_t x)
>    */
>   static inline uint16_t revbit16(uint16_t x)
>   {
> +#if __has_builtin(__builtin_bitreverse16)
> +    return __builtin_bitreverse16(x);
> +#else
>       /* Assign the correct byte position.  */
>       x = bswap16(x);
>       /* Assign the correct nibble position.  */
> @@ -300,6 +307,7 @@ static inline uint16_t revbit16(uint16_t x)
>         | ((x & 0x2222) << 1)
>         | ((x & 0x1111) << 3);
>       return x;
> +#endif
>   }
>   
>   /**
> @@ -308,6 +316,9 @@ static inline uint16_t revbit16(uint16_t x)
>    */
>   static inline uint32_t revbit32(uint32_t x)
>   {
> +#if __has_builtin(__builtin_bitreverse32)
> +    return __builtin_bitreverse32(x);
> +#else
>       /* Assign the correct byte position.  */
>       x = bswap32(x);
>       /* Assign the correct nibble position.  */
> @@ -319,6 +330,7 @@ static inline uint32_t revbit32(uint32_t x)
>         | ((x & 0x22222222u) << 1)
>         | ((x & 0x11111111u) << 3);
>       return x;
> +#endif
>   }
>   
>   /**
> @@ -327,6 +339,9 @@ static inline uint32_t revbit32(uint32_t x)
>    */
>   static inline uint64_t revbit64(uint64_t x)
>   {
> +#if __has_builtin(__builtin_bitreverse64)
> +    return __builtin_bitreverse64(x);
> +#else
>       /* Assign the correct byte position.  */
>       x = bswap64(x);
>       /* Assign the correct nibble position.  */
> @@ -338,6 +353,7 @@ static inline uint64_t revbit64(uint64_t x)
>         | ((x & 0x2222222222222222ull) << 1)
>         | ((x & 0x1111111111111111ull) << 3);
>       return x;
> +#endif
>   }
>   
>   /* Host type specific sizes of these routines.  */
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


Re: [PATCH 01/72] qemu/host-utils: Use __builtin_bitreverseN
Posted by Alex Bennée 4 years, 9 months ago
Richard Henderson <richard.henderson@linaro.org> writes:

> Clang has added some builtins for these operations;
> use them if available.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée