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