From 2d9c780a47cae218af7edbf68023cf068166d94a Mon Sep 17 00:00:00 2001 From: David Howells Date: Mon, 25 Sep 2006 23:32:08 -0700 Subject: [PATCH] --- yaml --- r: 35647 b: refs/heads/master c: a8ad27d03f17e6154c61e81d4a7028c56ca6390d h: refs/heads/master i: 35645: 00da0d4b8de0f93f2ed0313481435fbb2568ceb2 35643: 4e737bcd4a52387264a44c141c5e250aa4f58568 35639: ba0248cfce96165e6d944b28a77361b6f7d05090 35631: a9d7b0d2751bea20468ed6ac83f5f1e05be87e6c 35615: f300574f30f374787ad2dbb39d4f1968ccb9b3de 35583: f5b7725a8b4d523f83c3f4939f62431c97ad7f33 v: v3 --- [refs] | 2 +- trunk/include/asm-frv/bitops.h | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 499ec34f3f73..6e27bd7e66b6 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 92fc707208bb2e601c24b5ab65db37bcb361b658 +refs/heads/master: a8ad27d03f17e6154c61e81d4a7028c56ca6390d diff --git a/trunk/include/asm-frv/bitops.h b/trunk/include/asm-frv/bitops.h index 97fb746f76c7..591eecc1f8cd 100644 --- a/trunk/include/asm-frv/bitops.h +++ b/trunk/include/asm-frv/bitops.h @@ -186,7 +186,47 @@ static inline int __test_bit(int nr, const volatile void * addr) bit; \ }) -#include +/** + * fls64 - find last bit set in a 64-bit value + * @n: the value to search + * + * This is defined the same way as ffs: + * - return 64..1 to indicate bit 63..0 most significant bit set + * - return 0 to indicate no bits set + */ +static inline __attribute__((const)) +int fls64(u64 n) +{ + union { + u64 ll; + struct { u32 h, l; }; + } _; + int bit, x, y; + + _.ll = n; + + asm(" subcc.p %3,gr0,gr0,icc0 \n" + " subcc %4,gr0,gr0,icc1 \n" + " ckne icc0,cc4 \n" + " ckne icc1,cc5 \n" + " norcr cc4,cc5,cc6 \n" + " csub.p %0,%0,%0 ,cc6,1 \n" + " orcr cc5,cc4,cc4 \n" + " andcr cc4,cc5,cc4 \n" + " cscan.p %3,gr0,%0 ,cc4,0 \n" + " setlos #64,%1 \n" + " cscan.p %4,gr0,%0 ,cc4,1 \n" + " setlos #32,%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", "icc1", "cc4", "cc5", "cc6" + ); + return bit; + +} + #include #include