X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=include%2Fasm-frv%2Fbitops.h;h=e29de7131b79dcca7250aad73b3d603fb1f53458;hb=f07234b66af1d1a204b9ddabdbdb312e8f1fb35e;hp=1f70d47148bdb702e55126a0e854731d565ee9cd;hpb=cf134483b2cd657039b305777215c531a1009947;p=safe%2Fjmp%2Flinux-2.6 diff --git a/include/asm-frv/bitops.h b/include/asm-frv/bitops.h index 1f70d47..e29de71 100644 --- a/include/asm-frv/bitops.h +++ b/include/asm-frv/bitops.h @@ -21,6 +21,10 @@ #ifdef __KERNEL__ +#ifndef _LINUX_BITOPS_H +#error only can be included directly +#endif + #include /* @@ -256,8 +260,53 @@ int __ffs(unsigned long x) return 31 - bit; } +/* + * special slimline version of fls() for calculating ilog2_u32() + * - note: no protection against n == 0 + */ +#define ARCH_HAS_ILOG2_U32 +static inline __attribute__((const)) +int __ilog2_u32(u32 n) +{ + int bit; + asm("scan %1,gr0,%0" : "=r"(bit) : "r"(n)); + return 31 - bit; +} + +/* + * special slimline version of fls64() for calculating ilog2_u64() + * - note: no protection against n == 0 + */ +#define ARCH_HAS_ILOG2_U64 +static inline __attribute__((const)) +int __ilog2_u64(u64 n) +{ + union { + u64 ll; + struct { u32 h, l; }; + } _; + int bit, x, y; + + _.ll = n; + + asm(" subcc %3,gr0,gr0,icc0 \n" + " ckeq icc0,cc4 \n" + " cscan.p %3,gr0,%0 ,cc4,0 \n" + " setlos #63,%1 \n" + " cscan.p %4,gr0,%0 ,cc4,1 \n" + " setlos #31,%2 \n" + " csub.p %1,%0,%0 ,cc4,0 \n" + " csub %2,%0,%0 ,cc4,1 \n" + : "=&r"(bit), "=r"(x), "=r"(y) + : "0r"(_.h), "r"(_.l) + : "icc0", "cc4" + ); + return bit; +} + #include #include +#include #include