1
2#ifndef __ASM_SH_BITOPS_OP32_H
3#define __ASM_SH_BITOPS_OP32_H
4
5
6
7
8
9
10#if defined(__BIG_ENDIAN)
11#define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
12#define BYTE_NUMBER(nr) ((nr ^ BITOP_LE_SWIZZLE) / BITS_PER_BYTE)
13#define BYTE_OFFSET(nr) ((nr ^ BITOP_LE_SWIZZLE) % BITS_PER_BYTE)
14#else
15#define BYTE_NUMBER(nr) ((nr) / BITS_PER_BYTE)
16#define BYTE_OFFSET(nr) ((nr) % BITS_PER_BYTE)
17#endif
18
19static inline void __set_bit(int nr, volatile unsigned long *addr)
20{
21 if (__builtin_constant_p(nr)) {
22 __asm__ __volatile__ (
23 "bset.b %1, @(%O2,%0) ! __set_bit\n\t"
24 : "+r" (addr)
25 : "i" (BYTE_OFFSET(nr)), "i" (BYTE_NUMBER(nr))
26 : "t", "memory"
27 );
28 } else {
29 unsigned long mask = BIT_MASK(nr);
30 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
31
32 *p |= mask;
33 }
34}
35
36static inline void __clear_bit(int nr, volatile unsigned long *addr)
37{
38 if (__builtin_constant_p(nr)) {
39 __asm__ __volatile__ (
40 "bclr.b %1, @(%O2,%0) ! __clear_bit\n\t"
41 : "+r" (addr)
42 : "i" (BYTE_OFFSET(nr)),
43 "i" (BYTE_NUMBER(nr))
44 : "t", "memory"
45 );
46 } else {
47 unsigned long mask = BIT_MASK(nr);
48 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
49
50 *p &= ~mask;
51 }
52}
53
54
55
56
57
58
59
60
61
62
63static inline void __change_bit(int nr, volatile unsigned long *addr)
64{
65 if (__builtin_constant_p(nr)) {
66 __asm__ __volatile__ (
67 "bxor.b %1, @(%O2,%0) ! __change_bit\n\t"
68 : "+r" (addr)
69 : "i" (BYTE_OFFSET(nr)),
70 "i" (BYTE_NUMBER(nr))
71 : "t", "memory"
72 );
73 } else {
74 unsigned long mask = BIT_MASK(nr);
75 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
76
77 *p ^= mask;
78 }
79}
80
81
82
83
84
85
86
87
88
89
90static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
91{
92 unsigned long mask = BIT_MASK(nr);
93 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
94 unsigned long old = *p;
95
96 *p = old | mask;
97 return (old & mask) != 0;
98}
99
100
101
102
103
104
105
106
107
108
109static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
110{
111 unsigned long mask = BIT_MASK(nr);
112 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
113 unsigned long old = *p;
114
115 *p = old & ~mask;
116 return (old & mask) != 0;
117}
118
119
120static inline int __test_and_change_bit(int nr,
121 volatile unsigned long *addr)
122{
123 unsigned long mask = BIT_MASK(nr);
124 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
125 unsigned long old = *p;
126
127 *p = old ^ mask;
128 return (old & mask) != 0;
129}
130
131
132
133
134
135
136static inline int test_bit(int nr, const volatile unsigned long *addr)
137{
138 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
139}
140
141#endif
142