[Spice-commits] common/quic.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 5 13:58:21 UTC 2018


 common/quic.c |    7 +++++++
 1 file changed, 7 insertions(+)

New commits:
commit 1dcdefa8b3a69a8bd008aba276c180f28f7ceca3
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun May 13 00:36:01 2018 +0100

    quic: Use __builtin_clz if available
    
    Different processors has specific instructions to count leading
    zero bits. This includes: x86. x64, arm, ppc.
    For portability reason the behaviour of __builtin_clz is not
    defined if the value is zero so test for it.
    Currently the function is not called with the value or 0.
    This increase performance decoding of about 4-5% on a x64 machine
    (code size decreases a little too, but about 0.1%).
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/quic.c b/common/quic.c
index c0ef5e8..90aac85 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -280,6 +280,12 @@ static const BYTE lzeroes[256] = {
 /* count leading zeroes */
 static unsigned int cnt_l_zeroes(const unsigned int bits)
 {
+    if (spice_extra_checks) {
+        spice_assert(bits != 0);
+    }
+#if defined(__GNUC__) && __GNUC__ >= 4
+    return __builtin_clz(bits);
+#else
     if (bits & 0xff800000) {
         return lzeroes[bits >> 24];
     } else if (bits & 0xffff8000) {
@@ -289,6 +295,7 @@ static unsigned int cnt_l_zeroes(const unsigned int bits)
     } else {
         return 24 + lzeroes[bits & 0x000000ff];
     }
+#endif
 }
 
 #define QUIC_FAMILY_8BPC


More information about the Spice-commits mailing list