bitops: introduce little-endian bitops for most architectures
[linux-2.6/kvm.git] / arch / blackfin / include / asm / bitops.h
blobfe257cfec978366bd83dc8da31ff46299fdba6f5
1 /*
2 * Copyright 2004-2009 Analog Devices Inc.
4 * Licensed under the GPL-2 or later.
5 */
7 #ifndef _BLACKFIN_BITOPS_H
8 #define _BLACKFIN_BITOPS_H
10 #include <linux/compiler.h>
12 #include <asm-generic/bitops/__ffs.h>
13 #include <asm-generic/bitops/ffz.h>
14 #include <asm-generic/bitops/fls.h>
15 #include <asm-generic/bitops/__fls.h>
16 #include <asm-generic/bitops/fls64.h>
17 #include <asm-generic/bitops/find.h>
19 #ifndef _LINUX_BITOPS_H
20 #error only <linux/bitops.h> can be included directly
21 #endif
23 #include <asm-generic/bitops/sched.h>
24 #include <asm-generic/bitops/ffs.h>
25 #include <asm-generic/bitops/const_hweight.h>
26 #include <asm-generic/bitops/lock.h>
28 #include <asm-generic/bitops/le.h>
29 #include <asm-generic/bitops/ext2-non-atomic.h>
30 #include <asm-generic/bitops/ext2-atomic.h>
31 #include <asm-generic/bitops/minix.h>
33 #ifndef CONFIG_SMP
34 #include <linux/irqflags.h>
37 * clear_bit may not imply a memory barrier
39 #ifndef smp_mb__before_clear_bit
40 #define smp_mb__before_clear_bit() smp_mb()
41 #define smp_mb__after_clear_bit() smp_mb()
42 #endif
43 #include <asm-generic/bitops/atomic.h>
44 #include <asm-generic/bitops/non-atomic.h>
45 #else
47 #include <asm/byteorder.h> /* swab32 */
48 #include <linux/linkage.h>
50 asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
52 asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
54 asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
56 asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
58 asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
60 asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
62 asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
64 static inline void set_bit(int nr, volatile unsigned long *addr)
66 volatile unsigned long *a = addr + (nr >> 5);
67 __raw_bit_set_asm(a, nr & 0x1f);
70 static inline void clear_bit(int nr, volatile unsigned long *addr)
72 volatile unsigned long *a = addr + (nr >> 5);
73 __raw_bit_clear_asm(a, nr & 0x1f);
76 static inline void change_bit(int nr, volatile unsigned long *addr)
78 volatile unsigned long *a = addr + (nr >> 5);
79 __raw_bit_toggle_asm(a, nr & 0x1f);
82 static inline int test_bit(int nr, const volatile unsigned long *addr)
84 volatile const unsigned long *a = addr + (nr >> 5);
85 return __raw_bit_test_asm(a, nr & 0x1f) != 0;
88 static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
90 volatile unsigned long *a = addr + (nr >> 5);
91 return __raw_bit_test_set_asm(a, nr & 0x1f);
94 static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
96 volatile unsigned long *a = addr + (nr >> 5);
97 return __raw_bit_test_clear_asm(a, nr & 0x1f);
100 static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
102 volatile unsigned long *a = addr + (nr >> 5);
103 return __raw_bit_test_toggle_asm(a, nr & 0x1f);
107 * clear_bit() doesn't provide any barrier for the compiler.
109 #define smp_mb__before_clear_bit() barrier()
110 #define smp_mb__after_clear_bit() barrier()
112 #define test_bit __skip_test_bit
113 #include <asm-generic/bitops/non-atomic.h>
114 #undef test_bit
116 #endif /* CONFIG_SMP */
119 * hweightN: returns the hamming weight (i.e. the number
120 * of bits set) of a N-bit word
123 static inline unsigned int __arch_hweight32(unsigned int w)
125 unsigned int res;
127 __asm__ ("%0.l = ONES %1;"
128 "%0 = %0.l (Z);"
129 : "=d" (res) : "d" (w));
130 return res;
133 static inline unsigned int __arch_hweight64(__u64 w)
135 return __arch_hweight32((unsigned int)(w >> 32)) +
136 __arch_hweight32((unsigned int)w);
139 static inline unsigned int __arch_hweight16(unsigned int w)
141 return __arch_hweight32(w & 0xffff);
144 static inline unsigned int __arch_hweight8(unsigned int w)
146 return __arch_hweight32(w & 0xff);
149 #endif /* _BLACKFIN_BITOPS_H */