Web lists-archives.org

Re: [PATCH] asm-generic/bitops/fls64.h




On Tue, 13 May 2008 16:29:04 +0400, "Nickolay Vinogradov"
<nickolay@xxxxxxxxx> said:
> Alexander van Heukelum &#1087;&#1080;&#1096;&#1077;&#1090;:
> 
> > Hi Nickolay,
> > 
> > The change is ok, I guess, but the cast should be a no-op (fls
> > takes an int, which is always 32 bit in linux). What is the problem
> > you are seeing? Does fls64() return a wrong value in some cases? If
> > so, what cpu? Which values?
> > 
> > Why would this be a bug on big endian systems only? There is no
> > pointer magic involved, so the compiler should take care of the
> > casts in a correct way.
> > 
> > Maybe you see a compiler warning? Which compiler version?
> > 
> > (also note that current (development) kernels now have separate
> > versions for 32-bit and 64-bit environments.)
> 
> Because fls() is a macro for asm-arm:
> 
> #define fls(x) \
>          ( __builtin_constant_p(x) ? constant_fls(x) : \
>          ({ int __r; asm("clz\t%0, %1" : "=r"(__r) : "r"(x) : "cc"); 
> 32-__r; }) )
> 
> We can fix it right here:
> 
> diff --git a/include/asm-arm/bitops.h b/include/asm-arm/bitops.h
> index 5c60bfc..ce3fb6f 100644
> --- a/include/asm-arm/bitops.h
> +++ b/include/asm-arm/bitops.h
> @@ -279,7 +279,7 @@ static inline int constant_fls(int x)
> 
>   #define fls(x) \
>          ( __builtin_constant_p(x) ? constant_fls(x) : \
> -         ({ int __r; asm("clz\t%0, %1" : "=r"(__r) : "r"(x) : "cc"); 
> 32-__r; }) )
> +         ({ int __r; asm("clz\t%0, %1" : "=r"(__r) : "r"((__u32)x) : 
> "cc"); 32-__r; }) )
>   #define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
>   #define __ffs(x) (ffs(x) - 1)
>   #define ffz(x) __ffs( ~(x) )

Hmm, indeed.

Maybe: ({ int __r, __x = (x); asm("clz\t%0, %1" : "=r"(__r) : "r"(__x) :
"cc"); 32-__r; }) ?

This is a 32-bit machine, right? Doesn't the compiler complain about
feeding a long long into a 32-bit register?

Greetings,
    Alexander
-- 
  Alexander van Heukelum
  heukelum@xxxxxxxxxxx

-- 
http://www.fastmail.fm - I mean, what is it about a decent email service?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/