11 #ifndef _S390_BITOPS_H
12 #define _S390_BITOPS_H
14 #ifndef _LINUX_BITOPS_H
15 #error only <linux/bitops.h> can be included directly
18 #include <linux/compiler.h>
64 #define __BITOPS_ALIGN 3
65 #define __BITOPS_WORDSIZE 32
66 #define __BITOPS_OR "or"
67 #define __BITOPS_AND "nr"
68 #define __BITOPS_XOR "xr"
70 #define __BITOPS_LOOP(__old, __new, __addr, __val, __op_string) \
74 __op_string " %1,%3\n" \
77 : "=&d" (__old), "=&d" (__new), \
78 "=Q" (*(unsigned long *) __addr) \
79 : "d" (__val), "Q" (*(unsigned long *) __addr) \
84 #define __BITOPS_ALIGN 7
85 #define __BITOPS_WORDSIZE 64
86 #define __BITOPS_OR "ogr"
87 #define __BITOPS_AND "ngr"
88 #define __BITOPS_XOR "xgr"
90 #define __BITOPS_LOOP(__old, __new, __addr, __val, __op_string) \
94 __op_string " %1,%3\n" \
97 : "=&d" (__old), "=&d" (__new), \
98 "=Q" (*(unsigned long *) __addr) \
99 : "d" (__val), "Q" (*(unsigned long *) __addr) \
104 #define __BITOPS_WORDS(bits) (((bits)+__BITOPS_WORDSIZE-1)/__BITOPS_WORDSIZE)
105 #define __BITOPS_BARRIER() asm volatile("" : : : "memory")
111 static inline void set_bit_cs(
unsigned long nr,
volatile unsigned long *
ptr)
115 addr = (
unsigned long) ptr;
127 static inline void clear_bit_cs(
unsigned long nr,
volatile unsigned long *
ptr)
131 addr = (
unsigned long) ptr;
143 static inline void change_bit_cs(
unsigned long nr,
volatile unsigned long *
ptr)
147 addr = (
unsigned long) ptr;
160 test_and_set_bit_cs(
unsigned long nr,
volatile unsigned long *
ptr)
164 addr = (
unsigned long) ptr;
172 return (old &
mask) != 0;
179 test_and_clear_bit_cs(
unsigned long nr,
volatile unsigned long *
ptr)
183 addr = (
unsigned long) ptr;
191 return (old ^
new) != 0;
198 test_and_change_bit_cs(
unsigned long nr,
volatile unsigned long *
ptr)
202 addr = (
unsigned long) ptr;
210 return (old &
mask) != 0;
217 static inline void __set_bit(
unsigned long nr,
volatile unsigned long *
ptr)
224 :
"=Q" (*(
char *) addr) :
"Q" (
_oi_bitmap[nr & 7]) :
"cc" );
228 __constant_set_bit(
const unsigned long nr,
volatile unsigned long *ptr)
233 *(
unsigned char *) addr |= 1 << (nr & 7);
236 #define set_bit_simple(nr,addr) \
237 (__builtin_constant_p((nr)) ? \
238 __constant_set_bit((nr),(addr)) : \
239 __set_bit((nr),(addr)) )
245 __clear_bit(
unsigned long nr,
volatile unsigned long *ptr)
252 :
"=Q" (*(
char *) addr) :
"Q" (
_ni_bitmap[nr & 7]) :
"cc" );
256 __constant_clear_bit(
const unsigned long nr,
volatile unsigned long *ptr)
261 *(
unsigned char *) addr &= ~(1 << (nr & 7));
264 #define clear_bit_simple(nr,addr) \
265 (__builtin_constant_p((nr)) ? \
266 __constant_clear_bit((nr),(addr)) : \
267 __clear_bit((nr),(addr)) )
272 static inline void __change_bit(
unsigned long nr,
volatile unsigned long *ptr)
279 :
"=Q" (*(
char *) addr) :
"Q" (
_oi_bitmap[nr & 7]) :
"cc" );
283 __constant_change_bit(
const unsigned long nr,
volatile unsigned long *ptr)
288 *(
unsigned char *) addr ^= 1 << (nr & 7);
291 #define change_bit_simple(nr,addr) \
292 (__builtin_constant_p((nr)) ? \
293 __constant_change_bit((nr),(addr)) : \
294 __change_bit((nr),(addr)) )
300 test_and_set_bit_simple(
unsigned long nr,
volatile unsigned long *ptr)
306 ch = *(
unsigned char *) addr;
309 :
"=Q" (*(
char *) addr) :
"Q" (
_oi_bitmap[nr & 7])
311 return (ch >> (nr & 7)) & 1;
313 #define __test_and_set_bit(X,Y) test_and_set_bit_simple(X,Y)
319 test_and_clear_bit_simple(
unsigned long nr,
volatile unsigned long *ptr)
325 ch = *(
unsigned char *) addr;
328 :
"=Q" (*(
char *) addr) :
"Q" (
_ni_bitmap[nr & 7])
330 return (ch >> (nr & 7)) & 1;
332 #define __test_and_clear_bit(X,Y) test_and_clear_bit_simple(X,Y)
338 test_and_change_bit_simple(
unsigned long nr,
volatile unsigned long *ptr)
344 ch = *(
unsigned char *) addr;
347 :
"=Q" (*(
char *) addr) :
"Q" (
_oi_bitmap[nr & 7])
349 return (ch >> (nr & 7)) & 1;
351 #define __test_and_change_bit(X,Y) test_and_change_bit_simple(X,Y)
354 #define set_bit set_bit_cs
355 #define clear_bit clear_bit_cs
356 #define change_bit change_bit_cs
357 #define test_and_set_bit test_and_set_bit_cs
358 #define test_and_clear_bit test_and_clear_bit_cs
359 #define test_and_change_bit test_and_change_bit_cs
361 #define set_bit set_bit_simple
362 #define clear_bit clear_bit_simple
363 #define change_bit change_bit_simple
364 #define test_and_set_bit test_and_set_bit_simple
365 #define test_and_clear_bit test_and_clear_bit_simple
366 #define test_and_change_bit test_and_change_bit_simple
374 static inline int __test_bit(
unsigned long nr,
const volatile unsigned long *ptr)
380 ch = *(
volatile unsigned char *) addr;
381 return (ch >> (nr & 7)) & 1;
385 __constant_test_bit(
unsigned long nr,
const volatile unsigned long *addr) {
386 return (((
volatile char *) addr)
390 #define test_bit(nr,addr) \
391 (__builtin_constant_p((nr)) ? \
392 __constant_test_bit((nr),(addr)) : \
393 __test_bit((nr),(addr)) )
404 static inline unsigned long __ffz_word_loop(
const unsigned long *addr,
408 unsigned long bytes = 0;
424 "0: cg %2,0(%0,%3)\n"
430 :
"+&a" (
bytes),
"+&d" (size)
431 :
"d" (-1
UL),
"a" (addr),
"m" (*(addrtype *) addr)
441 static inline unsigned long __ffs_word_loop(
const unsigned long *addr,
445 unsigned long bytes = 0;
461 "0: cg %2,0(%0,%3)\n"
467 :
"+&a" (
bytes),
"+&a" (size)
468 :
"d" (0
UL),
"a" (addr),
"m" (*(addrtype *) addr)
478 static inline unsigned long __ffz_word(
unsigned long nr,
unsigned long word)
481 if ((word & 0xffffffff) == 0xffffffff) {
486 if ((word & 0xffff) == 0xffff) {
490 if ((word & 0xff) == 0xff) {
502 static inline unsigned long __ffs_word(
unsigned long nr,
unsigned long word)
505 if ((word & 0xffffffff) == 0) {
510 if ((word & 0xffff) == 0) {
514 if ((word & 0xff) == 0) {
527 static inline unsigned long __load_ulong_be(
const unsigned long *
p,
530 p = (
unsigned long *)((
unsigned long) p +
offset);
539 static inline unsigned long __load_ulong_le(
const unsigned long *p,
540 unsigned long offset)
544 p = (
unsigned long *)((
unsigned long) p +
offset);
548 " icm %0,2,%O1+1(%R1)\n"
549 " icm %0,4,%O1+2(%R1)\n"
550 " icm %0,8,%O1+3(%R1)"
551 :
"=&d" (
word) :
"Q" (*p) :
"cc");
555 :
"=d" (
word) :
"m" (*p) );
570 static inline unsigned long ffz(
unsigned long word)
572 return __ffz_word(0, word);
581 static inline unsigned long __ffs (
unsigned long word)
583 return __ffs_word(0, word);
594 static inline int ffs(
int x)
598 return __ffs_word(1, x);
616 bytes = __ffz_word_loop(addr, size);
617 bits = __ffz_word(bytes*8, __load_ulong_be(addr, bytes));
618 return (bits < size) ? bits :
size;
620 #define find_first_zero_bit find_first_zero_bit
630 static inline unsigned long find_first_bit(
const unsigned long * addr,
637 bytes = __ffs_word_loop(addr, size);
638 bits = __ffs_word(bytes*8, __load_ulong_be(addr, bytes));
639 return (bits < size) ? bits :
size;
641 #define find_first_bit find_first_bit
651 unsigned long offset)
653 const unsigned long *
p;
654 unsigned long bit,
set;
667 set = __ffz_word(bit, *p >> bit);
678 #define find_next_zero_bit find_next_zero_bit
688 unsigned long offset)
690 const unsigned long *
p;
691 unsigned long bit,
set;
704 set = __ffs_word(0, *p & (~0
UL << bit));
715 #define find_next_bit find_next_bit
723 static inline int sched_find_first_bit(
unsigned long *
b)
751 bytes = __ffz_word_loop(vaddr, size);
752 bits = __ffz_word(bytes*8, __load_ulong_le(vaddr, bytes));
753 return (bits < size) ? bits :
size;
755 #define find_first_zero_bit_le find_first_zero_bit_le
758 unsigned long offset)
760 unsigned long *addr =
vaddr, *
p;
761 unsigned long bit,
set;
774 set = __ffz_word(bit, __load_ulong_le(p, 0) >> bit);
785 #define find_next_zero_bit_le find_next_zero_bit_le
793 bytes = __ffs_word_loop(vaddr, size);
794 bits = __ffs_word(bytes*8, __load_ulong_le(vaddr, bytes));
795 return (bits < size) ? bits :
size;
797 #define find_first_bit_le find_first_bit_le
800 unsigned long offset)
802 unsigned long *addr =
vaddr, *
p;
803 unsigned long bit,
set;
816 set = __ffs_word(0, __load_ulong_le(p, 0) & (~0
UL << bit));
827 #define find_next_bit_le find_next_bit_le