1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Port on Texas Instruments TMS320C6x architecture
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2004, 2009, 2010 Texas Instruments Incorporated
6*4882a593Smuzhiyun * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun #ifndef _ASM_C6X_BITOPS_H
9*4882a593Smuzhiyun #define _ASM_C6X_BITOPS_H
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #ifdef __KERNEL__
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/bitops.h>
14*4882a593Smuzhiyun #include <asm/byteorder.h>
15*4882a593Smuzhiyun #include <asm/barrier.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun * We are lucky, DSP is perfect for bitops: do it in 3 cycles
19*4882a593Smuzhiyun */
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun /**
22*4882a593Smuzhiyun * __ffs - find first bit in word.
23*4882a593Smuzhiyun * @word: The word to search
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * Undefined if no bit exists, so code should check against 0 first.
26*4882a593Smuzhiyun * Note __ffs(0) = undef, __ffs(1) = 0, __ffs(0x80000000) = 31.
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun */
__ffs(unsigned long x)29*4882a593Smuzhiyun static inline unsigned long __ffs(unsigned long x)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun asm (" bitr .M1 %0,%0\n"
32*4882a593Smuzhiyun " nop\n"
33*4882a593Smuzhiyun " lmbd .L1 1,%0,%0\n"
34*4882a593Smuzhiyun : "+a"(x));
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun return x;
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun * ffz - find first zero in word.
41*4882a593Smuzhiyun * @word: The word to search
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * Undefined if no zero exists, so code should check against ~0UL first.
44*4882a593Smuzhiyun */
45*4882a593Smuzhiyun #define ffz(x) __ffs(~(x))
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /**
48*4882a593Smuzhiyun * fls - find last (most-significant) bit set
49*4882a593Smuzhiyun * @x: the word to search
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * This is defined the same way as ffs.
52*4882a593Smuzhiyun * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
53*4882a593Smuzhiyun */
fls(unsigned int x)54*4882a593Smuzhiyun static inline int fls(unsigned int x)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun if (!x)
57*4882a593Smuzhiyun return 0;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun asm (" lmbd .L1 1,%0,%0\n" : "+a"(x));
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun return 32 - x;
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /**
65*4882a593Smuzhiyun * ffs - find first bit set
66*4882a593Smuzhiyun * @x: the word to search
67*4882a593Smuzhiyun *
68*4882a593Smuzhiyun * This is defined the same way as
69*4882a593Smuzhiyun * the libc and compiler builtin ffs routines, therefore
70*4882a593Smuzhiyun * differs in spirit from the above ffz (man ffs).
71*4882a593Smuzhiyun * Note ffs(0) = 0, ffs(1) = 1, ffs(0x80000000) = 32.
72*4882a593Smuzhiyun */
ffs(int x)73*4882a593Smuzhiyun static inline int ffs(int x)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun if (!x)
76*4882a593Smuzhiyun return 0;
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun return __ffs(x) + 1;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun #include <asm-generic/bitops/__fls.h>
82*4882a593Smuzhiyun #include <asm-generic/bitops/fls64.h>
83*4882a593Smuzhiyun #include <asm-generic/bitops/find.h>
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun #include <asm-generic/bitops/sched.h>
86*4882a593Smuzhiyun #include <asm-generic/bitops/hweight.h>
87*4882a593Smuzhiyun #include <asm-generic/bitops/lock.h>
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun #include <asm-generic/bitops/atomic.h>
90*4882a593Smuzhiyun #include <asm-generic/bitops/non-atomic.h>
91*4882a593Smuzhiyun #include <asm-generic/bitops/le.h>
92*4882a593Smuzhiyun #include <asm-generic/bitops/ext2-atomic.h>
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun #endif /* __KERNEL__ */
95*4882a593Smuzhiyun #endif /* _ASM_C6X_BITOPS_H */
96