5 * include/asm-s390/bitops.h
8 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
11 * Derived from "include/asm-i386/bitops.h"
12 * Copyright (C) 1992, Linus Torvalds
18 #include <linux/compiler.h>
21 * 32 bit bitops format:
22 * bit 0 is the LSB of *addr; bit 31 is the MSB of *addr;
23 * bit 32 is the LSB of *(addr+4). That combined with the
24 * big endian byte order on S390 give the following bit
26 * 1f 1e 1d 1c 1b 1a 19 18 17 16 15 14 13 12 11 10 \
27 * 0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
28 * after that follows the next long with bit numbers
29 * 3f 3e 3d 3c 3b 3a 39 38 37 36 35 34 33 32 31 30
30 * 2f 2e 2d 2c 2b 2a 29 28 27 26 25 24 23 22 21 20
31 * The reason for this bit ordering is the fact that
32 * in the architecture independent code bits operations
33 * of the form "flags |= (1 << bitnr)" are used INTERMIXED
34 * with operation of the form "set_bit(bitnr, flags)".
36 * 64 bit bitops format:
37 * bit 0 is the LSB of *addr; bit 63 is the MSB of *addr;
38 * bit 64 is the LSB of *(addr+8). That combined with the
39 * big endian byte order on S390 give the following bit
41 * 3f 3e 3d 3c 3b 3a 39 38 37 36 35 34 33 32 31 30
42 * 2f 2e 2d 2c 2b 2a 29 28 27 26 25 24 23 22 21 20
43 * 1f 1e 1d 1c 1b 1a 19 18 17 16 15 14 13 12 11 10
44 * 0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
45 * after that follows the next long with bit numbers
46 * 7f 7e 7d 7c 7b 7a 79 78 77 76 75 74 73 72 71 70
47 * 6f 6e 6d 6c 6b 6a 69 68 67 66 65 64 63 62 61 60
48 * 5f 5e 5d 5c 5b 5a 59 58 57 56 55 54 53 52 51 50
49 * 4f 4e 4d 4c 4b 4a 49 48 47 46 45 44 43 42 41 40
50 * The reason for this bit ordering is the fact that
51 * in the architecture independent code bits operations
52 * of the form "flags |= (1 << bitnr)" are used INTERMIXED
53 * with operation of the form "set_bit(bitnr, flags)".
56 /* bitmap tables from arch/S390/kernel/bitmap.S */
57 extern const char _oi_bitmap[];
58 extern const char _ni_bitmap[];
59 extern const char _zb_findmap[];
60 extern const char _sb_findmap[];
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) \
71 __asm__ __volatile__(" l %0,0(%4)\n" \
73 __op_string " %1,%3\n" \
76 : "=&d" (__old), "=&d" (__new), \
77 "=m" (*(unsigned long *) __addr) \
78 : "d" (__val), "a" (__addr), \
79 "m" (*(unsigned long *) __addr) : "cc" );
83 #define __BITOPS_ALIGN 7
84 #define __BITOPS_WORDSIZE 64
85 #define __BITOPS_OR "ogr"
86 #define __BITOPS_AND "ngr"
87 #define __BITOPS_XOR "xgr"
89 #define __BITOPS_LOOP(__old, __new, __addr, __val, __op_string) \
90 __asm__ __volatile__(" lg %0,0(%4)\n" \
92 __op_string " %1,%3\n" \
93 " csg %0,%1,0(%4)\n" \
95 : "=&d" (__old), "=&d" (__new), \
96 "=m" (*(unsigned long *) __addr) \
97 : "d" (__val), "a" (__addr), \
98 "m" (*(unsigned long *) __addr) : "cc" );
100 #endif /* __s390x__ */
102 #define __BITOPS_WORDS(bits) (((bits)+__BITOPS_WORDSIZE-1)/__BITOPS_WORDSIZE)
103 #define __BITOPS_BARRIER() __asm__ __volatile__ ( "" : : : "memory" )
107 * SMP safe set_bit routine based on compare and swap (CS)
109 static inline void set_bit_cs(unsigned long nr, volatile unsigned long *ptr)
111 unsigned long addr, old, new, mask;
113 addr = (unsigned long) ptr;
114 /* calculate address for CS */
115 addr += (nr ^ (nr & (__BITOPS_WORDSIZE - 1))) >> 3;
117 mask = 1UL << (nr & (__BITOPS_WORDSIZE - 1));
118 /* Do the atomic update. */
119 __BITOPS_LOOP(old, new, addr, mask, __BITOPS_OR);
123 * SMP safe clear_bit routine based on compare and swap (CS)
125 static inline void clear_bit_cs(unsigned long nr, volatile unsigned long *ptr)
127 unsigned long addr, old, new, mask;
129 addr = (unsigned long) ptr;
130 /* calculate address for CS */
131 addr += (nr ^ (nr & (__BITOPS_WORDSIZE - 1))) >> 3;
133 mask = ~(1UL << (nr & (__BITOPS_WORDSIZE - 1)));
134 /* Do the atomic update. */
135 __BITOPS_LOOP(old, new, addr, mask, __BITOPS_AND);
139 * SMP safe change_bit routine based on compare and swap (CS)
141 static inline void change_bit_cs(unsigned long nr, volatile unsigned long *ptr)
143 unsigned long addr, old, new, mask;
145 addr = (unsigned long) ptr;
146 /* calculate address for CS */
147 addr += (nr ^ (nr & (__BITOPS_WORDSIZE - 1))) >> 3;
149 mask = 1UL << (nr & (__BITOPS_WORDSIZE - 1));
150 /* Do the atomic update. */
151 __BITOPS_LOOP(old, new, addr, mask, __BITOPS_XOR);
155 * SMP safe test_and_set_bit routine based on compare and swap (CS)
158 test_and_set_bit_cs(unsigned long nr, volatile unsigned long *ptr)
160 unsigned long addr, old, new, mask;
162 addr = (unsigned long) ptr;
163 /* calculate address for CS */
164 addr += (nr ^ (nr & (__BITOPS_WORDSIZE - 1))) >> 3;
165 /* make OR/test mask */
166 mask = 1UL << (nr & (__BITOPS_WORDSIZE - 1));
167 /* Do the atomic update. */
168 __BITOPS_LOOP(old, new, addr, mask, __BITOPS_OR);
170 return (old & mask) != 0;
174 * SMP safe test_and_clear_bit routine based on compare and swap (CS)
177 test_and_clear_bit_cs(unsigned long nr, volatile unsigned long *ptr)
179 unsigned long addr, old, new, mask;
181 addr = (unsigned long) ptr;
182 /* calculate address for CS */
183 addr += (nr ^ (nr & (__BITOPS_WORDSIZE - 1))) >> 3;
184 /* make AND/test mask */
185 mask = ~(1UL << (nr & (__BITOPS_WORDSIZE - 1)));
186 /* Do the atomic update. */
187 __BITOPS_LOOP(old, new, addr, mask, __BITOPS_AND);
189 return (old ^ new) != 0;
193 * SMP safe test_and_change_bit routine based on compare and swap (CS)
196 test_and_change_bit_cs(unsigned long nr, volatile unsigned long *ptr)
198 unsigned long addr, old, new, mask;
200 addr = (unsigned long) ptr;
201 /* calculate address for CS */
202 addr += (nr ^ (nr & (__BITOPS_WORDSIZE - 1))) >> 3;
203 /* make XOR/test mask */
204 mask = 1UL << (nr & (__BITOPS_WORDSIZE - 1));
205 /* Do the atomic update. */
206 __BITOPS_LOOP(old, new, addr, mask, __BITOPS_XOR);
208 return (old & mask) != 0;
210 #endif /* CONFIG_SMP */
213 * fast, non-SMP set_bit routine
215 static inline void __set_bit(unsigned long nr, volatile unsigned long *ptr)
219 addr = (unsigned long) ptr + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
220 asm volatile("oc 0(1,%1),0(%2)"
221 : "=m" (*(char *) addr)
222 : "a" (addr), "a" (_oi_bitmap + (nr & 7)),
223 "m" (*(char *) addr) : "cc" );
227 __constant_set_bit(const unsigned long nr, volatile unsigned long *ptr)
231 addr = ((unsigned long) ptr) + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
234 asm volatile ("oi 0(%1),0x01" : "=m" (*(char *) addr)
235 : "a" (addr), "m" (*(char *) addr) : "cc" );
238 asm volatile ("oi 0(%1),0x02" : "=m" (*(char *) addr)
239 : "a" (addr), "m" (*(char *) addr) : "cc" );
242 asm volatile ("oi 0(%1),0x04" : "=m" (*(char *) addr)
243 : "a" (addr), "m" (*(char *) addr) : "cc" );
246 asm volatile ("oi 0(%1),0x08" : "=m" (*(char *) addr)
247 : "a" (addr), "m" (*(char *) addr) : "cc" );
250 asm volatile ("oi 0(%1),0x10" : "=m" (*(char *) addr)
251 : "a" (addr), "m" (*(char *) addr) : "cc" );
254 asm volatile ("oi 0(%1),0x20" : "=m" (*(char *) addr)
255 : "a" (addr), "m" (*(char *) addr) : "cc" );
258 asm volatile ("oi 0(%1),0x40" : "=m" (*(char *) addr)
259 : "a" (addr), "m" (*(char *) addr) : "cc" );
262 asm volatile ("oi 0(%1),0x80" : "=m" (*(char *) addr)
263 : "a" (addr), "m" (*(char *) addr) : "cc" );
268 #define set_bit_simple(nr,addr) \
269 (__builtin_constant_p((nr)) ? \
270 __constant_set_bit((nr),(addr)) : \
271 __set_bit((nr),(addr)) )
274 * fast, non-SMP clear_bit routine
277 __clear_bit(unsigned long nr, volatile unsigned long *ptr)
281 addr = (unsigned long) ptr + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
282 asm volatile("nc 0(1,%1),0(%2)"
283 : "=m" (*(char *) addr)
284 : "a" (addr), "a" (_ni_bitmap + (nr & 7)),
285 "m" (*(char *) addr) : "cc" );
289 __constant_clear_bit(const unsigned long nr, volatile unsigned long *ptr)
293 addr = ((unsigned long) ptr) + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
296 asm volatile ("ni 0(%1),0xFE" : "=m" (*(char *) addr)
297 : "a" (addr), "m" (*(char *) addr) : "cc" );
300 asm volatile ("ni 0(%1),0xFD": "=m" (*(char *) addr)
301 : "a" (addr), "m" (*(char *) addr) : "cc" );
304 asm volatile ("ni 0(%1),0xFB" : "=m" (*(char *) addr)
305 : "a" (addr), "m" (*(char *) addr) : "cc" );
308 asm volatile ("ni 0(%1),0xF7" : "=m" (*(char *) addr)
309 : "a" (addr), "m" (*(char *) addr) : "cc" );
312 asm volatile ("ni 0(%1),0xEF" : "=m" (*(char *) addr)
313 : "a" (addr), "m" (*(char *) addr) : "cc" );
316 asm volatile ("ni 0(%1),0xDF" : "=m" (*(char *) addr)
317 : "a" (addr), "m" (*(char *) addr) : "cc" );
320 asm volatile ("ni 0(%1),0xBF" : "=m" (*(char *) addr)
321 : "a" (addr), "m" (*(char *) addr) : "cc" );
324 asm volatile ("ni 0(%1),0x7F" : "=m" (*(char *) addr)
325 : "a" (addr), "m" (*(char *) addr) : "cc" );
330 #define clear_bit_simple(nr,addr) \
331 (__builtin_constant_p((nr)) ? \
332 __constant_clear_bit((nr),(addr)) : \
333 __clear_bit((nr),(addr)) )
336 * fast, non-SMP change_bit routine
338 static inline void __change_bit(unsigned long nr, volatile unsigned long *ptr)
342 addr = (unsigned long) ptr + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
343 asm volatile("xc 0(1,%1),0(%2)"
344 : "=m" (*(char *) addr)
345 : "a" (addr), "a" (_oi_bitmap + (nr & 7)),
346 "m" (*(char *) addr) : "cc" );
350 __constant_change_bit(const unsigned long nr, volatile unsigned long *ptr)
354 addr = ((unsigned long) ptr) + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
357 asm volatile ("xi 0(%1),0x01" : "=m" (*(char *) addr)
358 : "a" (addr), "m" (*(char *) addr) : "cc" );
361 asm volatile ("xi 0(%1),0x02" : "=m" (*(char *) addr)
362 : "a" (addr), "m" (*(char *) addr) : "cc" );
365 asm volatile ("xi 0(%1),0x04" : "=m" (*(char *) addr)
366 : "a" (addr), "m" (*(char *) addr) : "cc" );
369 asm volatile ("xi 0(%1),0x08" : "=m" (*(char *) addr)
370 : "a" (addr), "m" (*(char *) addr) : "cc" );
373 asm volatile ("xi 0(%1),0x10" : "=m" (*(char *) addr)
374 : "a" (addr), "m" (*(char *) addr) : "cc" );
377 asm volatile ("xi 0(%1),0x20" : "=m" (*(char *) addr)
378 : "a" (addr), "m" (*(char *) addr) : "cc" );
381 asm volatile ("xi 0(%1),0x40" : "=m" (*(char *) addr)
382 : "a" (addr), "m" (*(char *) addr) : "cc" );
385 asm volatile ("xi 0(%1),0x80" : "=m" (*(char *) addr)
386 : "a" (addr), "m" (*(char *) addr) : "cc" );
391 #define change_bit_simple(nr,addr) \
392 (__builtin_constant_p((nr)) ? \
393 __constant_change_bit((nr),(addr)) : \
394 __change_bit((nr),(addr)) )
397 * fast, non-SMP test_and_set_bit routine
400 test_and_set_bit_simple(unsigned long nr, volatile unsigned long *ptr)
405 addr = (unsigned long) ptr + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
406 ch = *(unsigned char *) addr;
407 asm volatile("oc 0(1,%1),0(%2)"
408 : "=m" (*(char *) addr)
409 : "a" (addr), "a" (_oi_bitmap + (nr & 7)),
410 "m" (*(char *) addr) : "cc", "memory" );
411 return (ch >> (nr & 7)) & 1;
413 #define __test_and_set_bit(X,Y) test_and_set_bit_simple(X,Y)
416 * fast, non-SMP test_and_clear_bit routine
419 test_and_clear_bit_simple(unsigned long nr, volatile unsigned long *ptr)
424 addr = (unsigned long) ptr + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
425 ch = *(unsigned char *) addr;
426 asm volatile("nc 0(1,%1),0(%2)"
427 : "=m" (*(char *) addr)
428 : "a" (addr), "a" (_ni_bitmap + (nr & 7)),
429 "m" (*(char *) addr) : "cc", "memory" );
430 return (ch >> (nr & 7)) & 1;
432 #define __test_and_clear_bit(X,Y) test_and_clear_bit_simple(X,Y)
435 * fast, non-SMP test_and_change_bit routine
438 test_and_change_bit_simple(unsigned long nr, volatile unsigned long *ptr)
443 addr = (unsigned long) ptr + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
444 ch = *(unsigned char *) addr;
445 asm volatile("xc 0(1,%1),0(%2)"
446 : "=m" (*(char *) addr)
447 : "a" (addr), "a" (_oi_bitmap + (nr & 7)),
448 "m" (*(char *) addr) : "cc", "memory" );
449 return (ch >> (nr & 7)) & 1;
451 #define __test_and_change_bit(X,Y) test_and_change_bit_simple(X,Y)
454 #define set_bit set_bit_cs
455 #define clear_bit clear_bit_cs
456 #define change_bit change_bit_cs
457 #define test_and_set_bit test_and_set_bit_cs
458 #define test_and_clear_bit test_and_clear_bit_cs
459 #define test_and_change_bit test_and_change_bit_cs
461 #define set_bit set_bit_simple
462 #define clear_bit clear_bit_simple
463 #define change_bit change_bit_simple
464 #define test_and_set_bit test_and_set_bit_simple
465 #define test_and_clear_bit test_and_clear_bit_simple
466 #define test_and_change_bit test_and_change_bit_simple
471 * This routine doesn't need to be atomic.
474 static inline int __test_bit(unsigned long nr, const volatile unsigned long *ptr)
479 addr = (unsigned long) ptr + ((nr ^ (__BITOPS_WORDSIZE - 8)) >> 3);
480 ch = *(volatile unsigned char *) addr;
481 return (ch >> (nr & 7)) & 1;
485 __constant_test_bit(unsigned long nr, const volatile unsigned long *addr) {
486 return (((volatile char *) addr)
487 [(nr^(__BITOPS_WORDSIZE-8))>>3] & (1<<(nr&7))) != 0;
490 #define test_bit(nr,addr) \
491 (__builtin_constant_p((nr)) ? \
492 __constant_test_bit((nr),(addr)) : \
493 __test_bit((nr),(addr)) )
496 * ffz = Find First Zero in word. Undefined if no zero exists,
497 * so code should check against ~0UL first..
499 static inline unsigned long ffz(unsigned long word)
501 unsigned long bit = 0;
504 if (likely((word & 0xffffffff) == 0xffffffff)) {
509 if (likely((word & 0xffff) == 0xffff)) {
513 if (likely((word & 0xff) == 0xff)) {
517 return bit + _zb_findmap[word & 0xff];
521 * __ffs = find first bit in word. Undefined if no bit exists,
522 * so code should check against 0UL first..
524 static inline unsigned long __ffs (unsigned long word)
526 unsigned long bit = 0;
529 if (likely((word & 0xffffffff) == 0)) {
534 if (likely((word & 0xffff) == 0)) {
538 if (likely((word & 0xff) == 0)) {
542 return bit + _sb_findmap[word & 0xff];
546 * Find-bit routines..
552 find_first_zero_bit(const unsigned long * addr, unsigned long size)
554 typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
555 unsigned long cmp, count;
560 __asm__(" lhi %1,-1\n"
586 : "=&a" (res), "=&d" (cmp), "=&a" (count)
587 : "a" (size), "a" (addr), "a" (&_zb_findmap),
588 "m" (*(addrtype *) addr) : "cc" );
589 return (res < size) ? res : size;
593 find_first_bit(const unsigned long * addr, unsigned long size)
595 typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
596 unsigned long cmp, count;
601 __asm__(" slr %1,%1\n"
627 : "=&a" (res), "=&d" (cmp), "=&a" (count)
628 : "a" (size), "a" (addr), "a" (&_sb_findmap),
629 "m" (*(addrtype *) addr) : "cc" );
630 return (res < size) ? res : size;
633 #else /* __s390x__ */
635 static inline unsigned long
636 find_first_zero_bit(const unsigned long * addr, unsigned long size)
638 typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
639 unsigned long res, cmp, count;
643 __asm__(" lghi %1,-1\n"
648 "0: cg %1,0(%0,%4)\n"
654 "1: lg %2,0(%0,%4)\n"
665 "3: tmll %2,0x00ff\n"
673 : "=&a" (res), "=&d" (cmp), "=&a" (count)
674 : "a" (size), "a" (addr), "a" (&_zb_findmap),
675 "m" (*(addrtype *) addr) : "cc" );
676 return (res < size) ? res : size;
679 static inline unsigned long
680 find_first_bit(const unsigned long * addr, unsigned long size)
682 typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
683 unsigned long res, cmp, count;
687 __asm__(" slgr %1,%1\n"
692 "0: cg %1,0(%0,%4)\n"
698 "1: lg %2,0(%0,%4)\n"
709 "3: tmll %2,0x00ff\n"
717 : "=&a" (res), "=&d" (cmp), "=&a" (count)
718 : "a" (size), "a" (addr), "a" (&_sb_findmap),
719 "m" (*(addrtype *) addr) : "cc" );
720 return (res < size) ? res : size;
723 #endif /* __s390x__ */
726 find_next_zero_bit (const unsigned long * addr, unsigned long size,
727 unsigned long offset)
729 const unsigned long *p;
730 unsigned long bit, set;
734 bit = offset & (__BITOPS_WORDSIZE - 1);
737 p = addr + offset / __BITOPS_WORDSIZE;
740 * s390 version of ffz returns __BITOPS_WORDSIZE
741 * if no zero bit is present in the word.
743 set = ffz(*p >> bit) + bit;
745 return size + offset;
746 if (set < __BITOPS_WORDSIZE)
748 offset += __BITOPS_WORDSIZE;
749 size -= __BITOPS_WORDSIZE;
752 return offset + find_first_zero_bit(p, size);
756 find_next_bit (const unsigned long * addr, unsigned long size,
757 unsigned long offset)
759 const unsigned long *p;
760 unsigned long bit, set;
764 bit = offset & (__BITOPS_WORDSIZE - 1);
767 p = addr + offset / __BITOPS_WORDSIZE;
770 * s390 version of __ffs returns __BITOPS_WORDSIZE
771 * if no one bit is present in the word.
773 set = __ffs(*p & (~0UL << bit));
775 return size + offset;
776 if (set < __BITOPS_WORDSIZE)
778 offset += __BITOPS_WORDSIZE;
779 size -= __BITOPS_WORDSIZE;
782 return offset + find_first_bit(p, size);
786 * Every architecture must define this function. It's the fastest
787 * way of searching a 140-bit bitmap where the first 100 bits are
788 * unlikely to be set. It's guaranteed that at least one of the 140
791 static inline int sched_find_first_bit(unsigned long *b)
793 return find_first_bit(b, 140);
796 #include <asm-generic/bitops/ffs.h>
798 #include <asm-generic/bitops/fls.h>
799 #include <asm-generic/bitops/fls64.h>
801 #include <asm-generic/bitops/hweight.h>
804 * ATTENTION: intel byte ordering convention for ext2 and minix !!
805 * bit 0 is the LSB of addr; bit 31 is the MSB of addr;
806 * bit 32 is the LSB of (addr+4).
807 * That combined with the little endian byte order of Intel gives the
808 * following bit order in memory:
809 * 07 06 05 04 03 02 01 00 15 14 13 12 11 10 09 08 \
810 * 23 22 21 20 19 18 17 16 31 30 29 28 27 26 25 24
813 #define ext2_set_bit(nr, addr) \
814 __test_and_set_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
815 #define ext2_set_bit_atomic(lock, nr, addr) \
816 test_and_set_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
817 #define ext2_clear_bit(nr, addr) \
818 __test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
819 #define ext2_clear_bit_atomic(lock, nr, addr) \
820 test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
821 #define ext2_test_bit(nr, addr) \
822 test_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
827 ext2_find_first_zero_bit(void *vaddr, unsigned int size)
829 typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
830 unsigned long cmp, count;
835 __asm__(" lhi %1,-1\n"
840 "0: cl %1,0(%0,%4)\n"
862 : "=&a" (res), "=&d" (cmp), "=&a" (count)
863 : "a" (size), "a" (vaddr), "a" (&_zb_findmap),
864 "m" (*(addrtype *) vaddr) : "cc" );
865 return (res < size) ? res : size;
868 #else /* __s390x__ */
870 static inline unsigned long
871 ext2_find_first_zero_bit(void *vaddr, unsigned long size)
873 typedef struct { long _[__BITOPS_WORDS(size)]; } addrtype;
874 unsigned long res, cmp, count;
878 __asm__(" lghi %1,-1\n"
883 "0: clg %1,0(%0,%4)\n"
889 "1: cl %1,0(%0,%4)\n"
900 "3: tmll %2,0xff00\n"
908 : "=&a" (res), "=&d" (cmp), "=&a" (count)
909 : "a" (size), "a" (vaddr), "a" (&_zb_findmap),
910 "m" (*(addrtype *) vaddr) : "cc" );
911 return (res < size) ? res : size;
914 #endif /* __s390x__ */
917 ext2_find_next_zero_bit(void *vaddr, unsigned long size, unsigned long offset)
919 unsigned long *addr = vaddr, *p;
920 unsigned long word, bit, set;
924 bit = offset & (__BITOPS_WORDSIZE - 1);
927 p = addr + offset / __BITOPS_WORDSIZE;
934 : "=&a" (word) : "a" (p), "m" (*p) : "cc" );
936 asm(" lrvg %0,%1" : "=a" (word) : "m" (*p) );
939 * s390 version of ffz returns __BITOPS_WORDSIZE
940 * if no zero bit is present in the word.
942 set = ffz(word >> bit) + bit;
944 return size + offset;
945 if (set < __BITOPS_WORDSIZE)
947 offset += __BITOPS_WORDSIZE;
948 size -= __BITOPS_WORDSIZE;
951 return offset + ext2_find_first_zero_bit(p, size);
954 #include <asm-generic/bitops/minix.h>
956 #endif /* __KERNEL__ */
958 #endif /* _S390_BITOPS_H */