[Spice-devel] [PATCH spice-common] quic: Use __builtin_clz if available

Christophe Fergeau cfergeau at redhat.com
Tue Jun 5 13:18:29 UTC 2018


ok,
Acked-by: Christophe Fergeau <cfergeau at redhat.com>

On Tue, Jun 05, 2018 at 11:54:46AM +0100, Frediano Ziglio wrote:
> 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>
> ---
>  common/quic.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/common/quic.c b/common/quic.c
> index e31f789..8af826e 100644
> --- a/common/quic.c
> +++ b/common/quic.c
> @@ -281,6 +281,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) {
> @@ -290,6 +296,7 @@ static unsigned int cnt_l_zeroes(const unsigned int bits)
>      } else {
>          return 24 + lzeroes[bits & 0x000000ff];
>      }
> +#endif
>  }
>  
>  #define QUIC_FAMILY_8BPC
> -- 
> 2.17.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180605/67e79a8e/attachment.sig>


More information about the Spice-devel mailing list