Messages in this thread | | | Date | Thu, 22 Oct 2020 11:37:39 -0500 | From | Segher Boessenkool <> | Subject | Re: [PATCH] powerpc/bitops: Fix possible undefined behaviour with fls() and fls64() |
| |
On Thu, Oct 22, 2020 at 02:05:46PM +0000, Christophe Leroy wrote: > fls() and fls64() are using __builtin_ctz() and _builtin_ctzll(). > On powerpc, those builtins trivially use ctlzw and ctlzd power > instructions. > > Allthough those instructions provide the expected result with > input argument 0, __builtin_ctz() and __builtin_ctzll() are > documented as undefined for value 0.
> When the input of fls(x) is a constant, just check x for nullity and > return either 0 or __builtin_clz(x). Otherwise, use cntlzw instruction > directly.
That looks good :-)
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>
Segher
| |