Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_BITOPS_H |
| 2 | #define __ASM_SH_BITOPS_H |
| 3 | |
| 4 | #ifdef __KERNEL__ |
Jiri Slaby | 0624517 | 2007-10-18 23:40:26 -0700 | [diff] [blame] | 5 | |
| 6 | #ifndef _LINUX_BITOPS_H |
| 7 | #error only <linux/bitops.h> can be included directly |
| 8 | #endif |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <asm/system.h> |
| 11 | /* For __swab32 */ |
| 12 | #include <asm/byteorder.h> |
| 13 | |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 14 | #ifdef CONFIG_GUSA_RB |
| 15 | #include <asm/bitops-grb.h> |
Paul Mundt | 0d5bbe0 | 2008-11-25 21:22:02 +0900 | [diff] [blame] | 16 | #elif defined(CONFIG_CPU_SH2A) |
| 17 | #include <asm-generic/bitops/atomic.h> |
| 18 | #include <asm/bitops-op32.h> |
Paul Mundt | 742fd1b | 2008-08-07 17:36:12 +0900 | [diff] [blame] | 19 | #elif defined(CONFIG_CPU_SH4A) |
| 20 | #include <asm/bitops-llsc.h> |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 21 | #else |
Paul Mundt | 16b529d | 2008-11-20 15:25:22 +0900 | [diff] [blame] | 22 | #include <asm-generic/bitops/atomic.h> |
| 23 | #include <asm-generic/bitops/non-atomic.h> |
Stuart Menefy | 1efe4ce | 2007-11-30 16:12:36 +0900 | [diff] [blame] | 24 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* |
| 27 | * clear_bit() doesn't provide any barrier for the compiler. |
| 28 | */ |
Paul Mundt | 1c8db71 | 2009-10-18 15:36:02 +0900 | [diff] [blame] | 29 | #define smp_mb__before_clear_bit() smp_mb() |
| 30 | #define smp_mb__after_clear_bit() smp_mb() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Paul Mundt | 63e2c80 | 2007-11-11 17:28:18 +0900 | [diff] [blame] | 32 | #ifdef CONFIG_SUPERH32 |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame] | 33 | static inline unsigned long ffz(unsigned long word) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | unsigned long result; |
| 36 | |
| 37 | __asm__("1:\n\t" |
| 38 | "shlr %1\n\t" |
| 39 | "bt/s 1b\n\t" |
| 40 | " add #1, %0" |
| 41 | : "=r" (result), "=r" (word) |
| 42 | : "0" (~0L), "1" (word) |
| 43 | : "t"); |
| 44 | return result; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * __ffs - find first bit in word. |
| 49 | * @word: The word to search |
| 50 | * |
| 51 | * Undefined if no bit exists, so code should check against 0 first. |
| 52 | */ |
Paul Mundt | e4c2cfe | 2006-09-27 12:31:01 +0900 | [diff] [blame] | 53 | static inline unsigned long __ffs(unsigned long word) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | unsigned long result; |
| 56 | |
| 57 | __asm__("1:\n\t" |
| 58 | "shlr %1\n\t" |
| 59 | "bf/s 1b\n\t" |
| 60 | " add #1, %0" |
| 61 | : "=r" (result), "=r" (word) |
| 62 | : "0" (~0L), "1" (word) |
| 63 | : "t"); |
| 64 | return result; |
| 65 | } |
Paul Mundt | 63e2c80 | 2007-11-11 17:28:18 +0900 | [diff] [blame] | 66 | #else |
| 67 | static inline unsigned long ffz(unsigned long word) |
| 68 | { |
| 69 | unsigned long result, __d2, __d3; |
| 70 | |
| 71 | __asm__("gettr tr0, %2\n\t" |
| 72 | "pta $+32, tr0\n\t" |
| 73 | "andi %1, 1, %3\n\t" |
| 74 | "beq %3, r63, tr0\n\t" |
| 75 | "pta $+4, tr0\n" |
| 76 | "0:\n\t" |
| 77 | "shlri.l %1, 1, %1\n\t" |
| 78 | "addi %0, 1, %0\n\t" |
| 79 | "andi %1, 1, %3\n\t" |
| 80 | "beqi %3, 1, tr0\n" |
| 81 | "1:\n\t" |
| 82 | "ptabs %2, tr0\n\t" |
| 83 | : "=r" (result), "=r" (word), "=r" (__d2), "=r" (__d3) |
| 84 | : "0" (0L), "1" (word)); |
| 85 | |
| 86 | return result; |
| 87 | } |
| 88 | |
| 89 | #include <asm-generic/bitops/__ffs.h> |
| 90 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Akinobu Mita | e2268c7 | 2006-03-26 01:39:35 -0800 | [diff] [blame] | 92 | #include <asm-generic/bitops/find.h> |
| 93 | #include <asm-generic/bitops/ffs.h> |
| 94 | #include <asm-generic/bitops/hweight.h> |
Nick Piggin | 2633357 | 2007-10-18 03:06:39 -0700 | [diff] [blame] | 95 | #include <asm-generic/bitops/lock.h> |
Akinobu Mita | e2268c7 | 2006-03-26 01:39:35 -0800 | [diff] [blame] | 96 | #include <asm-generic/bitops/sched.h> |
| 97 | #include <asm-generic/bitops/ext2-non-atomic.h> |
| 98 | #include <asm-generic/bitops/ext2-atomic.h> |
| 99 | #include <asm-generic/bitops/minix.h> |
| 100 | #include <asm-generic/bitops/fls.h> |
Alexander van Heukelum | 56a6b1e | 2008-03-15 18:31:49 +0100 | [diff] [blame] | 101 | #include <asm-generic/bitops/__fls.h> |
Akinobu Mita | e2268c7 | 2006-03-26 01:39:35 -0800 | [diff] [blame] | 102 | #include <asm-generic/bitops/fls64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | #endif /* __KERNEL__ */ |
| 105 | |
| 106 | #endif /* __ASM_SH_BITOPS_H */ |