https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97445

--- Comment #40 from Christophe Leroy <christophe.leroy at csgroup dot eu> ---
(In reply to Jakub Jelinek from comment #39)
> (In reply to Christophe Leroy from comment #38)
> > But on powerpc that's already the case and it doesn't solve the issue.
> > 
> > static inline int fls(unsigned int x)
> > {
> >     return 32 - __builtin_clz(x);
> > }
> > 
> > static inline int fls64(__u64 x)
> > {
> >     return 64 - __builtin_clzll(x);
> > }
> 
> That is clearly a kernel bug (__builtin_clz* is documented undefined for 0,
> while fls* wants to be well defined there), and shouldn't change anything,
> because
> in the if (__builtin_constant_p (size))
> case get_order doesn't use fls*, but ilog2.  And it is ilog2 that should be
> changed.

What's the bug ?

int f(int x)
{
  return __builtin_clz(x);
}

Compiles into

<f>:
  cntlzw r3, r3
  blr


Powerpc 32 bits documentation says:

cntlzw : Count Leading Zeros Word

A count of the number of consecutive zero bits starting at bit 0 of rS is
placed into rA. This number ranges from 0 to 32, inclusive.

I can't see a problem when x == 0

Reply via email to