Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / include / asm-cris / arch-v32 / bitops.h
blob147689d6b624bc806ccfe5e2603506ac7672b00a
1 #ifndef _ASM_CRIS_ARCH_BITOPS_H
2 #define _ASM_CRIS_ARCH_BITOPS_H
4 /*
5 * Helper functions for the core of the ff[sz] functions. They compute the
6 * number of leading zeroes of a bits-in-byte, byte-in-word and
7 * word-in-dword-swapped number. They differ in that the first function also
8 * inverts all bits in the input.
9 */
11 static inline unsigned long
12 cris_swapnwbrlz(unsigned long w)
14 unsigned long res;
16 __asm__ __volatile__ ("swapnwbr %0\n\t"
17 "lz %0,%0"
18 : "=r" (res) : "0" (w));
20 return res;
23 static inline unsigned long
24 cris_swapwbrlz(unsigned long w)
26 unsigned long res;
28 __asm__ __volatile__ ("swapwbr %0\n\t"
29 "lz %0,%0"
30 : "=r" (res) : "0" (w));
32 return res;
36 * Find First Zero in word. Undefined if no zero exist, so the caller should
37 * check against ~0 first.
39 static inline unsigned long
40 ffz(unsigned long w)
42 return cris_swapnwbrlz(w);
46 * Find First Set bit in word. Undefined if no 1 exist, so the caller
47 * should check against 0 first.
49 static inline unsigned long
50 __ffs(unsigned long w)
52 return cris_swapnwbrlz(~w);
56 * Find First Bit that is set.
58 static inline unsigned long
59 kernel_ffs(unsigned long w)
61 return w ? cris_swapwbrlz (w) + 1 : 0;
64 #endif /* _ASM_CRIS_ARCH_BITOPS_H */