blob: fc8e652cf173f23e92395e344fb1e2d306791830 [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>
Peter Zijlstra603228b2014-03-13 19:00:35 +010012#include <asm/barrier.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090014#ifdef CONFIG_GUSA_RB
15#include <asm/bitops-grb.h>
Paul Mundt0d5bbe02008-11-25 21:22:02 +090016#elif defined(CONFIG_CPU_SH2A)
17#include <asm-generic/bitops/atomic.h>
18#include <asm/bitops-op32.h>
Paul Mundt742fd1b2008-08-07 17:36:12 +090019#elif defined(CONFIG_CPU_SH4A)
20#include <asm/bitops-llsc.h>
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090021#else
Paul Mundt16b529d2008-11-20 15:25:22 +090022#include <asm-generic/bitops/atomic.h>
23#include <asm-generic/bitops/non-atomic.h>
Stuart Menefy1efe4ce2007-11-30 16:12:36 +090024#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Paul Mundt63e2c802007-11-11 17:28:18 +090026#ifdef CONFIG_SUPERH32
Paul Mundte4c2cfe2006-09-27 12:31:01 +090027static inline unsigned long ffz(unsigned long word)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
29 unsigned long result;
30
31 __asm__("1:\n\t"
32 "shlr %1\n\t"
33 "bt/s 1b\n\t"
34 " add #1, %0"
35 : "=r" (result), "=r" (word)
36 : "0" (~0L), "1" (word)
37 : "t");
38 return result;
39}
40
41/**
42 * __ffs - find first bit in word.
43 * @word: The word to search
44 *
45 * Undefined if no bit exists, so code should check against 0 first.
46 */
Paul Mundte4c2cfe2006-09-27 12:31:01 +090047static inline unsigned long __ffs(unsigned long word)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
49 unsigned long result;
50
51 __asm__("1:\n\t"
52 "shlr %1\n\t"
53 "bf/s 1b\n\t"
54 " add #1, %0"
55 : "=r" (result), "=r" (word)
56 : "0" (~0L), "1" (word)
57 : "t");
58 return result;
59}
Paul Mundt63e2c802007-11-11 17:28:18 +090060#else
61static inline unsigned long ffz(unsigned long word)
62{
63 unsigned long result, __d2, __d3;
64
65 __asm__("gettr tr0, %2\n\t"
66 "pta $+32, tr0\n\t"
67 "andi %1, 1, %3\n\t"
68 "beq %3, r63, tr0\n\t"
69 "pta $+4, tr0\n"
70 "0:\n\t"
71 "shlri.l %1, 1, %1\n\t"
72 "addi %0, 1, %0\n\t"
73 "andi %1, 1, %3\n\t"
74 "beqi %3, 1, tr0\n"
75 "1:\n\t"
76 "ptabs %2, tr0\n\t"
77 : "=r" (result), "=r" (word), "=r" (__d2), "=r" (__d3)
78 : "0" (0L), "1" (word));
79
80 return result;
81}
82
83#include <asm-generic/bitops/__ffs.h>
84#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Akinobu Mitae2268c72006-03-26 01:39:35 -080086#include <asm-generic/bitops/find.h>
87#include <asm-generic/bitops/ffs.h>
88#include <asm-generic/bitops/hweight.h>
Nick Piggin26333572007-10-18 03:06:39 -070089#include <asm-generic/bitops/lock.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -080090#include <asm-generic/bitops/sched.h>
Akinobu Mita861b5ae2011-03-23 16:42:02 -070091#include <asm-generic/bitops/le.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -080092#include <asm-generic/bitops/ext2-atomic.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -080093#include <asm-generic/bitops/fls.h>
Alexander van Heukelum56a6b1e2008-03-15 18:31:49 +010094#include <asm-generic/bitops/__fls.h>
Akinobu Mitae2268c72006-03-26 01:39:35 -080095#include <asm-generic/bitops/fls64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97#endif /* __KERNEL__ */
98
99#endif /* __ASM_SH_BITOPS_H */