2 * Copyright 1995, Russell King.
3 * Various bits and pieces copyrights include:
4 * Linus Torvalds (test_bit).
6 * Copyright (C) 2011 Andes Technology Corporation
7 * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
9 * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
11 * Please note that the code in this file should never be included
12 * from user space. Many of these are not implemented in assembler
13 * since they would be too costly. Also, they require priviledged
14 * instructions (which are not available from user mode) to ensure
15 * that they are atomic.
18 #ifndef __ASM_NDS_BITOPS_H
19 #define __ASM_NDS_BITOPS_H
23 #include <asm/system.h>
25 #define smp_mb__before_clear_bit() do { } while (0)
26 #define smp_mb__after_clear_bit() do { } while (0)
29 * Function prototypes to keep gcc -Wall happy.
31 extern void set_bit(int nr, void *addr);
33 static inline void __set_bit(int nr, void *addr)
39 mask = 1 << (nr & 0x1f);
43 extern void clear_bit(int nr, void *addr);
45 static inline void __clear_bit(int nr, void *addr)
52 mask = 1 << (nr & 0x1f);
53 local_irq_save(flags);
55 local_irq_restore(flags);
58 extern void change_bit(int nr, void *addr);
60 static inline void __change_bit(int nr, void *addr)
63 unsigned long *ADDR = (unsigned long *)addr;
66 mask = 1 << (nr & 31);
70 extern int test_and_set_bit(int nr, void *addr);
72 static inline int __test_and_set_bit(int nr, void *addr)
75 unsigned int *a = (unsigned int *)addr;
78 mask = 1 << (nr & 0x1f);
79 retval = (mask & *a) != 0;
84 extern int test_and_clear_bit(int nr, void *addr);
86 static inline int __test_and_clear_bit(int nr, void *addr)
89 unsigned int *a = (unsigned int *)addr;
92 mask = 1 << (nr & 0x1f);
93 retval = (mask & *a) != 0;
98 extern int test_and_change_bit(int nr, void *addr);
100 static inline int __test_and_change_bit(int nr, void *addr)
103 unsigned int *a = (unsigned int *)addr;
106 mask = 1 << (nr & 0x1f);
107 retval = (mask & *a) != 0;
112 extern int find_first_zero_bit(void *addr, unsigned size);
113 extern int find_next_zero_bit(void *addr, int size, int offset);
116 * This routine doesn't need to be atomic.
118 static inline int test_bit(int nr, const void *addr)
120 return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7));
124 * ffz = Find First Zero in word. Undefined if no zero exists,
125 * so code should check against ~0UL first..
127 static inline unsigned long ffz(unsigned long word)
133 if (word & 0x0000ffff) {
134 k -= 16; word <<= 16;
136 if (word & 0x00ff0000) {
139 if (word & 0x0f000000) {
142 if (word & 0x30000000) {
145 if (word & 0x40000000)
152 * ffs: find first bit set. This is defined the same way as
153 * the libc and compiler builtin ffs routines, therefore
154 * differs in spirit from the above ffz (man ffs).
158 * redefined in include/linux/bitops.h
159 * #define ffs(x) generic_ffs(x)
163 * hweightN: returns the hamming weight (i.e. the number
164 * of bits set) of a N-bit word
167 #define hweight32(x) generic_hweight32(x)
168 #define hweight16(x) generic_hweight16(x)
169 #define hweight8(x) generic_hweight8(x)
171 #define ext2_set_bit test_and_set_bit
172 #define ext2_clear_bit test_and_clear_bit
173 #define ext2_test_bit test_bit
174 #define ext2_find_first_zero_bit find_first_zero_bit
175 #define ext2_find_next_zero_bit find_next_zero_bit
177 /* Bitmap functions for the minix filesystem. */
178 #define minix_test_and_set_bit(nr, addr) test_and_set_bit(nr, addr)
179 #define minix_set_bit(nr, addr) set_bit(nr, addr)
180 #define minix_test_and_clear_bit(nr, addr) test_and_clear_bit(nr, addr)
181 #define minix_test_bit(nr, addr) test_bit(nr, addr)
182 #define minix_find_first_zero_bit(addr, size) find_first_zero_bit(addr, size)
184 #endif /* __KERNEL__ */
186 #endif /* __ASM_NDS_BITOPS_H */