Justin Ruggles <justin.rugg...@gmail.com> writes:

> +static av_always_inline av_const int ff_ctz_c(unsigned int v)
> +{
> +    int c;
> +
> +    if (v & 0x1)
> +        return 0;
> +
> +    c = 1;
> +    if (!(v & 0xffff)) {
> +        v >>= 16;
> +        c += 16;
> +    }
> +    if (!(v & 0xff)) {
> +        v >>= 8;
> +        c += 8;
> +    }
> +    if (!(v & 0xf)) {
> +        v >>= 4;
> +        c += 4;
> +    }
> +    if (!(v & 0x3)) {
> +        v >>= 2;
> +        c += 2;
> +    }
> +    c -= v & 0x1;
> +
> +    return c;
> +}

This doesn't work for an input of zero.  Is that intentional?

Furthermore, on CPUs with no CTZ intruction, but with CLZ, av_log2(v & -v)
is faster.  GCC has been seen to use this trick in the __builtin_ctz()
function though I don't know if it always does it.

-- 
Måns Rullgård
m...@mansr.com
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to