On Thu, Nov 21, 2013 at 02:25:30PM -0800, Jarno Rajahalme wrote:
> Count leading zeroes using builtins if available.
>
> Signed-off-by: Jarno Rajahalme <[email protected]>
Could we rename raw_clz() to raw_clz64()? clz is a function that
doesn't make sense without a defined length.
> +static inline int
> +raw_clz(uint64_t n)
> +{
> + /* With GCC 4.7 on 32-bit x86, if a 32-bit integer is passed as 'n',
> using
> + * a plain __builtin_ctzll() here always generates an out-of-line
> function
> + * call. The test below helps it to emit a single 'bsf' instruction. */
> + return (__builtin_constant_p(n <= UINT32_MAX) && n <= UINT32_MAX
> + ? __builtin_clz(n) + 32
> + : __builtin_clzll(n));
In my tests the above trick isn't necessary for clz. Just writing
__builtin_clzll() generates good code. (But the comment would need an
update anyway: s/ctz/clz/ and s/bsf/bsr/.)
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev