On 10/29/2012 10:44 AM, Måns Rullgård wrote: > Justin Ruggles <justin.rugg...@gmail.com> writes: > >> +#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4) >> +#ifndef ff_ctz >> +#define ff_ctz(v) (__builtin_ctz(v)) > > Note that __builtin_ctz is undefined for an input of zero. Also, no > need for the parens. > >> +#endif >> +#endif >> + >> +#ifndef ff_ctz >> +#define ff_ctz ff_ctz_c >> +static av_always_inline av_const int ff_ctz_c(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; >> +} >> +#endif > > Is it intentional for ff_ctz(0) to return 31?
Yes. See the part of the patch that has: +/** + * Trailing zero bit count. + * + * @param v input value. If v is 0, the result is undefined. + * @return the number of trailing 0-bits + */ +int av_ctz(int v); So it doesn't matter what it returns for 0. -Justin _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel