Re: [PATCH v5 2/2] x86/asm/bitops: __ffs,ffz: use __builtin_ctzl to evaluate constant expressions
From: Borislav Petkov
Date: Tue Aug 23 2022 - 15:13:05 EST
On Tue, Aug 23, 2022 at 10:12:17AM -0700, Nick Desaulniers wrote:
> Callers of these need to guard against zero input, as the pre-existing
> comment notes:
>
> >> Undefined if no bit exists, so code should check against 0 first.
This is just silly.
And then there's
* ffs(value) returns 0 if value is 0 or the position of the first
* set bit if value is nonzero. The first (least significant) bit
* is at position 1.
*/
static __always_inline int ffs(int x)
Can we unify the two and move the guard against 0 inside the function
or, like ffs() does, have it return 0 if value is 0?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette