]> git.ipfire.org Git - thirdparty/kernel/linux.git/blob - arch/cris/include/arch-v32/arch/bitops.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[thirdparty/kernel/linux.git] / arch / cris / include / arch-v32 / arch / bitops.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_CRIS_ARCH_BITOPS_H
3 #define _ASM_CRIS_ARCH_BITOPS_H
4
5 /*
6 * Helper functions for the core of the ff[sz] functions. They compute the
7 * number of leading zeroes of a bits-in-byte, byte-in-word and
8 * word-in-dword-swapped number. They differ in that the first function also
9 * inverts all bits in the input.
10 */
11
12 static inline unsigned long
13 cris_swapnwbrlz(unsigned long w)
14 {
15 unsigned long res;
16
17 __asm__ __volatile__ ("swapnwbr %0\n\t"
18 "lz %0,%0"
19 : "=r" (res) : "0" (w));
20
21 return res;
22 }
23
24 static inline unsigned long
25 cris_swapwbrlz(unsigned long w)
26 {
27 unsigned long res;
28
29 __asm__ __volatile__ ("swapwbr %0\n\t"
30 "lz %0,%0"
31 : "=r" (res) : "0" (w));
32
33 return res;
34 }
35
36 /*
37 * Find First Zero in word. Undefined if no zero exist, so the caller should
38 * check against ~0 first.
39 */
40 static inline unsigned long
41 ffz(unsigned long w)
42 {
43 return cris_swapnwbrlz(w);
44 }
45
46 /*
47 * Find First Set bit in word. Undefined if no 1 exist, so the caller
48 * should check against 0 first.
49 */
50 static inline unsigned long
51 __ffs(unsigned long w)
52 {
53 return cris_swapnwbrlz(~w);
54 }
55
56 /*
57 * Find First Bit that is set.
58 */
59 static inline unsigned long
60 kernel_ffs(unsigned long w)
61 {
62 return w ? cris_swapwbrlz (w) + 1 : 0;
63 }
64
65 #endif /* _ASM_CRIS_ARCH_BITOPS_H */