blob: ea8706d94f08d31f04ec75ae21958369dae9866c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_BITOPS_H
2#define __ASM_SH_BITOPS_H
3
4#ifdef __KERNEL__
Jiri Slaby06245172007-10-18 23:40:26 -07005
6#ifndef _LINUX_BITOPS_H
7#error only <linux/bitops.h> can be included directly
8#endif
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010/* For __swab32 */
11#include <asm/byteorder.h>
12
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090013#ifdef CONFIG_GUSA_RB
14#include <asm/bitops-grb.h>
Paul Mundt0d5bbe02008-11-25 21:22:02 +090015#elif defined(CONFIG_CPU_SH2A)
16#include <asm-generic/bitops/atomic.h>
17#include <asm/bitops-op32.h>
Paul Mundt742fd1b2008-08-07 17:36:12 +090018#elif defined(CONFIG_CPU_SH4A)
19#include <asm/bitops-llsc.h>
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090020#else
Paul Mundt16b529d2008-11-20 15:25:22 +090021#include <asm-generic/bitops/atomic.h>
22#include <asm-generic/bitops/non-atomic.h>
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090023#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/*
26 * clear_bit() doesn't provide any barrier for the compiler.
27 */
Paul Mundt1c8db712009-10-18 15:36:02 +090028#define smp_mb__before_clear_bit() smp_mb()
29#define smp_mb__after_clear_bit() smp_mb()
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Paul Mundt63e2c802007-11-11 17:28:18 +090031#ifdef CONFIG_SUPERH32
Paul Mundte4c2cfe2006-09-27 12:31:01 +090032static inline unsigned long ffz(unsigned long word)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 unsigned long result;
35
36 __asm__("1:\n\t"
37 "shlr %1\n\t"
38 "bt/s 1b\n\t"
39 " add #1, %0"
40 : "=r" (result), "=r" (word)
41 : "0" (~0L), "1" (word)
42 : "t");
43 return result;
44}
45
46/**
47 * __ffs - find first bit in word.
48 * @word: The word to search
49 *
50 * Undefined if no bit exists, so code should check against 0 first.
51 */
Paul Mundte4c2cfe2006-09-27 12:31:01 +090052static inline unsigned long __ffs(unsigned long word)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 unsigned long result;
55
56 __asm__("1:\n\t"
57 "shlr %1\n\t"
58 "bf/s 1b\n\t"
59 " add #1, %0"
60 : "=r" (result), "=r" (word)
61 : "0" (~0L), "1" (word)
62 : "t");
63 return result;
64}
Paul Mundt63e2c802007-11-11 17:28:18 +090065#else
66static inline unsigned long ffz(unsigned long word)
67{
68 unsigned long result, __d2, __d3;
69
70 __asm__("gettr tr0, %2\n\t"
71 "pta $+32, tr0\n\t"
72 "andi %1, 1, %3\n\t"
73 "beq %3, r63, tr0\n\t"
74 "pta $+4, tr0\n"
75 "0:\n\t"
76 "shlri.l %1, 1, %1\n\t"
77 "addi %0, 1, %0\n\t"
78 "andi %1, 1, %3\n\t"
79 "beqi %3, 1, tr0\n"
80 "1:\n\t"
81 "ptabs %2, tr0\n\t"
82 : "=r" (result), "=r" (word), "=r" (__d2), "=r" (__d3)
83 : "0" (0L), "1" (word));
84
85 return result;
86}
87
88#include <asm-generic/bitops/__ffs.h>
89#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Akinobu Mitae2268c72006-03-26 01:39:35 -080091#include <asm-generic/bitops/find.h>
92#include <asm-generic/bitops/ffs.h>
93#include <asm-generic/bitops/hweight.h>
Nick Piggin26333572007-10-18 03:06:39 -070094#include <asm-generic/bitops/lock.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -080095#include <asm-generic/bitops/sched.h>
Akinobu Mita861b5ae2011-03-23 16:42:02 -070096#include <asm-generic/bitops/le.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -080097#include <asm-generic/bitops/ext2-atomic.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -080098#include <asm-generic/bitops/fls.h>
Alexander van Heukelum56a6b1e2008-03-15 18:31:49 +010099#include <asm-generic/bitops/__fls.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -0800100#include <asm-generic/bitops/fls64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102#endif /* __KERNEL__ */
103
104#endif /* __ASM_SH_BITOPS_H */