Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright IBM Corp. 1999,2013
4 *
5 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
6 *
7 * The description below was taken in large parts from the powerpc
8 * bitops header file:
9 * Within a word, bits are numbered LSB first. Lot's of places make
10 * this assumption by directly testing bits with (val & (1<<nr)).
11 * This can cause confusion for large (> 1 word) bitmaps on a
12 * big-endian system because, unlike little endian, the number of each
13 * bit depends on the word size.
14 *
15 * The bitop functions are defined to work on unsigned longs, so the bits
16 * end up numbered:
17 * |63..............0|127............64|191...........128|255...........192|
18 *
19 * We also have special functions which work with an MSB0 encoding.
20 * The bits are numbered:
21 * |0..............63|64............127|128...........191|192...........255|
22 *
23 * The main difference is that bit 0-63 in the bit number field needs to be
24 * reversed compared to the LSB0 encoded bit fields. This can be achieved by
25 * XOR with 0x3f.
26 *
27 */
28
29#ifndef _S390_BITOPS_H
30#define _S390_BITOPS_H
31
32#ifndef _LINUX_BITOPS_H
33#error only <linux/bitops.h> can be included directly
34#endif
35
36#include <linux/typecheck.h>
37#include <linux/compiler.h>
38#include <linux/types.h>
39#include <asm/atomic_ops.h>
40#include <asm/barrier.h>
41
42#define __BITOPS_WORDS(bits) (((bits) + BITS_PER_LONG - 1) / BITS_PER_LONG)
43
44static inline unsigned long *
45__bitops_word(unsigned long nr, const volatile unsigned long *ptr)
46{
47 unsigned long addr;
48
49 addr = (unsigned long)ptr + ((nr ^ (nr & (BITS_PER_LONG - 1))) >> 3);
50 return (unsigned long *)addr;
51}
52
53static inline unsigned long __bitops_mask(unsigned long nr)
54{
55 return 1UL << (nr & (BITS_PER_LONG - 1));
56}
57
58static __always_inline void arch_set_bit(unsigned long nr, volatile unsigned long *ptr)
59{
60 unsigned long *addr = __bitops_word(nr, ptr);
61 unsigned long mask = __bitops_mask(nr);
62
63 __atomic64_or(mask, (long *)addr);
64}
65
66static __always_inline void arch_clear_bit(unsigned long nr, volatile unsigned long *ptr)
67{
68 unsigned long *addr = __bitops_word(nr, ptr);
69 unsigned long mask = __bitops_mask(nr);
70
71 __atomic64_and(~mask, (long *)addr);
72}
73
74static __always_inline void arch_change_bit(unsigned long nr,
75 volatile unsigned long *ptr)
76{
77 unsigned long *addr = __bitops_word(nr, ptr);
78 unsigned long mask = __bitops_mask(nr);
79
80 __atomic64_xor(mask, (long *)addr);
81}
82
83static inline bool arch_test_and_set_bit(unsigned long nr,
84 volatile unsigned long *ptr)
85{
86 unsigned long *addr = __bitops_word(nr, ptr);
87 unsigned long mask = __bitops_mask(nr);
88 unsigned long old;
89
90 old = __atomic64_or_barrier(mask, (long *)addr);
91 return old & mask;
92}
93
94static inline bool arch_test_and_clear_bit(unsigned long nr,
95 volatile unsigned long *ptr)
96{
97 unsigned long *addr = __bitops_word(nr, ptr);
98 unsigned long mask = __bitops_mask(nr);
99 unsigned long old;
100
101 old = __atomic64_and_barrier(~mask, (long *)addr);
102 return old & mask;
103}
104
105static inline bool arch_test_and_change_bit(unsigned long nr,
106 volatile unsigned long *ptr)
107{
108 unsigned long *addr = __bitops_word(nr, ptr);
109 unsigned long mask = __bitops_mask(nr);
110 unsigned long old;
111
112 old = __atomic64_xor_barrier(mask, (long *)addr);
113 return old & mask;
114}
115
116static __always_inline void
117arch___set_bit(unsigned long nr, volatile unsigned long *addr)
118{
119 unsigned long *p = __bitops_word(nr, addr);
120 unsigned long mask = __bitops_mask(nr);
121
122 *p |= mask;
123}
124
125static __always_inline void
126arch___clear_bit(unsigned long nr, volatile unsigned long *addr)
127{
128 unsigned long *p = __bitops_word(nr, addr);
129 unsigned long mask = __bitops_mask(nr);
130
131 *p &= ~mask;
132}
133
134static __always_inline void
135arch___change_bit(unsigned long nr, volatile unsigned long *addr)
136{
137 unsigned long *p = __bitops_word(nr, addr);
138 unsigned long mask = __bitops_mask(nr);
139
140 *p ^= mask;
141}
142
143static __always_inline bool
144arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
145{
146 unsigned long *p = __bitops_word(nr, addr);
147 unsigned long mask = __bitops_mask(nr);
148 unsigned long old;
149
150 old = *p;
151 *p |= mask;
152 return old & mask;
153}
154
155static __always_inline bool
156arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
157{
158 unsigned long *p = __bitops_word(nr, addr);
159 unsigned long mask = __bitops_mask(nr);
160 unsigned long old;
161
162 old = *p;
163 *p &= ~mask;
164 return old & mask;
165}
166
167static __always_inline bool
168arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
169{
170 unsigned long *p = __bitops_word(nr, addr);
171 unsigned long mask = __bitops_mask(nr);
172 unsigned long old;
173
174 old = *p;
175 *p ^= mask;
176 return old & mask;
177}
178
179#define arch_test_bit generic_test_bit
180#define arch_test_bit_acquire generic_test_bit_acquire
181
182static inline bool arch_test_and_set_bit_lock(unsigned long nr,
183 volatile unsigned long *ptr)
184{
185 if (arch_test_bit(nr, ptr))
186 return true;
187 return arch_test_and_set_bit(nr, ptr);
188}
189
190static inline void arch_clear_bit_unlock(unsigned long nr,
191 volatile unsigned long *ptr)
192{
193 smp_mb__before_atomic();
194 arch_clear_bit(nr, ptr);
195}
196
197static inline void arch___clear_bit_unlock(unsigned long nr,
198 volatile unsigned long *ptr)
199{
200 smp_mb();
201 arch___clear_bit(nr, ptr);
202}
203
204#include <asm-generic/bitops/instrumented-atomic.h>
205#include <asm-generic/bitops/instrumented-non-atomic.h>
206#include <asm-generic/bitops/instrumented-lock.h>
207
208/*
209 * Functions which use MSB0 bit numbering.
210 * The bits are numbered:
211 * |0..............63|64............127|128...........191|192...........255|
212 */
213unsigned long find_first_bit_inv(const unsigned long *addr, unsigned long size);
214unsigned long find_next_bit_inv(const unsigned long *addr, unsigned long size,
215 unsigned long offset);
216
217#define for_each_set_bit_inv(bit, addr, size) \
218 for ((bit) = find_first_bit_inv((addr), (size)); \
219 (bit) < (size); \
220 (bit) = find_next_bit_inv((addr), (size), (bit) + 1))
221
222static inline void set_bit_inv(unsigned long nr, volatile unsigned long *ptr)
223{
224 return set_bit(nr ^ (BITS_PER_LONG - 1), ptr);
225}
226
227static inline void clear_bit_inv(unsigned long nr, volatile unsigned long *ptr)
228{
229 return clear_bit(nr ^ (BITS_PER_LONG - 1), ptr);
230}
231
232static inline bool test_and_clear_bit_inv(unsigned long nr,
233 volatile unsigned long *ptr)
234{
235 return test_and_clear_bit(nr ^ (BITS_PER_LONG - 1), ptr);
236}
237
238static inline void __set_bit_inv(unsigned long nr, volatile unsigned long *ptr)
239{
240 return __set_bit(nr ^ (BITS_PER_LONG - 1), ptr);
241}
242
243static inline void __clear_bit_inv(unsigned long nr, volatile unsigned long *ptr)
244{
245 return __clear_bit(nr ^ (BITS_PER_LONG - 1), ptr);
246}
247
248static inline bool test_bit_inv(unsigned long nr,
249 const volatile unsigned long *ptr)
250{
251 return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
252}
253
254/**
255 * __flogr - find leftmost one
256 * @word - The word to search
257 *
258 * Returns the bit number of the most significant bit set,
259 * where the most significant bit has bit number 0.
260 * If no bit is set this function returns 64.
261 */
262static inline unsigned char __flogr(unsigned long word)
263{
264 if (__builtin_constant_p(word)) {
265 unsigned long bit = 0;
266
267 if (!word)
268 return 64;
269 if (!(word & 0xffffffff00000000UL)) {
270 word <<= 32;
271 bit += 32;
272 }
273 if (!(word & 0xffff000000000000UL)) {
274 word <<= 16;
275 bit += 16;
276 }
277 if (!(word & 0xff00000000000000UL)) {
278 word <<= 8;
279 bit += 8;
280 }
281 if (!(word & 0xf000000000000000UL)) {
282 word <<= 4;
283 bit += 4;
284 }
285 if (!(word & 0xc000000000000000UL)) {
286 word <<= 2;
287 bit += 2;
288 }
289 if (!(word & 0x8000000000000000UL)) {
290 word <<= 1;
291 bit += 1;
292 }
293 return bit;
294 } else {
295 union register_pair rp;
296
297 rp.even = word;
298 asm volatile(
299 " flogr %[rp],%[rp]\n"
300 : [rp] "+d" (rp.pair) : : "cc");
301 return rp.even;
302 }
303}
304
305/**
306 * __ffs - find first bit in word.
307 * @word: The word to search
308 *
309 * Undefined if no bit exists, so code should check against 0 first.
310 */
311static inline unsigned long __ffs(unsigned long word)
312{
313 return __flogr(-word & word) ^ (BITS_PER_LONG - 1);
314}
315
316/**
317 * ffs - find first bit set
318 * @word: the word to search
319 *
320 * This is defined the same way as the libc and
321 * compiler builtin ffs routines (man ffs).
322 */
323static inline int ffs(int word)
324{
325 unsigned long mask = 2 * BITS_PER_LONG - 1;
326 unsigned int val = (unsigned int)word;
327
328 return (1 + (__flogr(-val & val) ^ (BITS_PER_LONG - 1))) & mask;
329}
330
331/**
332 * __fls - find last (most-significant) set bit in a long word
333 * @word: the word to search
334 *
335 * Undefined if no set bit exists, so code should check against 0 first.
336 */
337static inline unsigned long __fls(unsigned long word)
338{
339 return __flogr(word) ^ (BITS_PER_LONG - 1);
340}
341
342/**
343 * fls64 - find last set bit in a 64-bit word
344 * @word: the word to search
345 *
346 * This is defined in a similar way as the libc and compiler builtin
347 * ffsll, but returns the position of the most significant set bit.
348 *
349 * fls64(value) returns 0 if value is 0 or the position of the last
350 * set bit if value is nonzero. The last (most significant) bit is
351 * at position 64.
352 */
353static inline int fls64(unsigned long word)
354{
355 unsigned long mask = 2 * BITS_PER_LONG - 1;
356
357 return (1 + (__flogr(word) ^ (BITS_PER_LONG - 1))) & mask;
358}
359
360/**
361 * fls - find last (most-significant) bit set
362 * @word: the word to search
363 *
364 * This is defined the same way as ffs.
365 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
366 */
367static inline int fls(unsigned int word)
368{
369 return fls64(word);
370}
371
372#include <asm-generic/bitops/ffz.h>
373#include <asm-generic/bitops/hweight.h>
374#include <asm-generic/bitops/sched.h>
375#include <asm-generic/bitops/le.h>
376#include <asm-generic/bitops/ext2-atomic-setbit.h>
377
378#endif /* _S390_BITOPS_H */
1/*
2 * Copyright IBM Corp. 1999,2013
3 *
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
5 *
6 * The description below was taken in large parts from the powerpc
7 * bitops header file:
8 * Within a word, bits are numbered LSB first. Lot's of places make
9 * this assumption by directly testing bits with (val & (1<<nr)).
10 * This can cause confusion for large (> 1 word) bitmaps on a
11 * big-endian system because, unlike little endian, the number of each
12 * bit depends on the word size.
13 *
14 * The bitop functions are defined to work on unsigned longs, so the bits
15 * end up numbered:
16 * |63..............0|127............64|191...........128|255...........192|
17 *
18 * There are a few little-endian macros used mostly for filesystem
19 * bitmaps, these work on similar bit array layouts, but byte-oriented:
20 * |7...0|15...8|23...16|31...24|39...32|47...40|55...48|63...56|
21 *
22 * The main difference is that bit 3-5 in the bit number field needs to be
23 * reversed compared to the big-endian bit fields. This can be achieved by
24 * XOR with 0x38.
25 *
26 * We also have special functions which work with an MSB0 encoding.
27 * The bits are numbered:
28 * |0..............63|64............127|128...........191|192...........255|
29 *
30 * The main difference is that bit 0-63 in the bit number field needs to be
31 * reversed compared to the LSB0 encoded bit fields. This can be achieved by
32 * XOR with 0x3f.
33 *
34 */
35
36#ifndef _S390_BITOPS_H
37#define _S390_BITOPS_H
38
39#ifndef _LINUX_BITOPS_H
40#error only <linux/bitops.h> can be included directly
41#endif
42
43#include <linux/typecheck.h>
44#include <linux/compiler.h>
45#include <asm/atomic_ops.h>
46#include <asm/barrier.h>
47
48#define __BITOPS_WORDS(bits) (((bits) + BITS_PER_LONG - 1) / BITS_PER_LONG)
49
50static inline unsigned long *
51__bitops_word(unsigned long nr, volatile unsigned long *ptr)
52{
53 unsigned long addr;
54
55 addr = (unsigned long)ptr + ((nr ^ (nr & (BITS_PER_LONG - 1))) >> 3);
56 return (unsigned long *)addr;
57}
58
59static inline unsigned char *
60__bitops_byte(unsigned long nr, volatile unsigned long *ptr)
61{
62 return ((unsigned char *)ptr) + ((nr ^ (BITS_PER_LONG - 8)) >> 3);
63}
64
65static inline void set_bit(unsigned long nr, volatile unsigned long *ptr)
66{
67 unsigned long *addr = __bitops_word(nr, ptr);
68 unsigned long mask;
69
70#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
71 if (__builtin_constant_p(nr)) {
72 unsigned char *caddr = __bitops_byte(nr, ptr);
73
74 asm volatile(
75 "oi %0,%b1\n"
76 : "+Q" (*caddr)
77 : "i" (1 << (nr & 7))
78 : "cc", "memory");
79 return;
80 }
81#endif
82 mask = 1UL << (nr & (BITS_PER_LONG - 1));
83 __atomic64_or(mask, addr);
84}
85
86static inline void clear_bit(unsigned long nr, volatile unsigned long *ptr)
87{
88 unsigned long *addr = __bitops_word(nr, ptr);
89 unsigned long mask;
90
91#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
92 if (__builtin_constant_p(nr)) {
93 unsigned char *caddr = __bitops_byte(nr, ptr);
94
95 asm volatile(
96 "ni %0,%b1\n"
97 : "+Q" (*caddr)
98 : "i" (~(1 << (nr & 7)))
99 : "cc", "memory");
100 return;
101 }
102#endif
103 mask = ~(1UL << (nr & (BITS_PER_LONG - 1)));
104 __atomic64_and(mask, addr);
105}
106
107static inline void change_bit(unsigned long nr, volatile unsigned long *ptr)
108{
109 unsigned long *addr = __bitops_word(nr, ptr);
110 unsigned long mask;
111
112#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
113 if (__builtin_constant_p(nr)) {
114 unsigned char *caddr = __bitops_byte(nr, ptr);
115
116 asm volatile(
117 "xi %0,%b1\n"
118 : "+Q" (*caddr)
119 : "i" (1 << (nr & 7))
120 : "cc", "memory");
121 return;
122 }
123#endif
124 mask = 1UL << (nr & (BITS_PER_LONG - 1));
125 __atomic64_xor(mask, addr);
126}
127
128static inline int
129test_and_set_bit(unsigned long nr, volatile unsigned long *ptr)
130{
131 unsigned long *addr = __bitops_word(nr, ptr);
132 unsigned long old, mask;
133
134 mask = 1UL << (nr & (BITS_PER_LONG - 1));
135 old = __atomic64_or_barrier(mask, addr);
136 return (old & mask) != 0;
137}
138
139static inline int
140test_and_clear_bit(unsigned long nr, volatile unsigned long *ptr)
141{
142 unsigned long *addr = __bitops_word(nr, ptr);
143 unsigned long old, mask;
144
145 mask = ~(1UL << (nr & (BITS_PER_LONG - 1)));
146 old = __atomic64_and_barrier(mask, addr);
147 return (old & ~mask) != 0;
148}
149
150static inline int
151test_and_change_bit(unsigned long nr, volatile unsigned long *ptr)
152{
153 unsigned long *addr = __bitops_word(nr, ptr);
154 unsigned long old, mask;
155
156 mask = 1UL << (nr & (BITS_PER_LONG - 1));
157 old = __atomic64_xor_barrier(mask, addr);
158 return (old & mask) != 0;
159}
160
161static inline void __set_bit(unsigned long nr, volatile unsigned long *ptr)
162{
163 unsigned char *addr = __bitops_byte(nr, ptr);
164
165 *addr |= 1 << (nr & 7);
166}
167
168static inline void
169__clear_bit(unsigned long nr, volatile unsigned long *ptr)
170{
171 unsigned char *addr = __bitops_byte(nr, ptr);
172
173 *addr &= ~(1 << (nr & 7));
174}
175
176static inline void __change_bit(unsigned long nr, volatile unsigned long *ptr)
177{
178 unsigned char *addr = __bitops_byte(nr, ptr);
179
180 *addr ^= 1 << (nr & 7);
181}
182
183static inline int
184__test_and_set_bit(unsigned long nr, volatile unsigned long *ptr)
185{
186 unsigned char *addr = __bitops_byte(nr, ptr);
187 unsigned char ch;
188
189 ch = *addr;
190 *addr |= 1 << (nr & 7);
191 return (ch >> (nr & 7)) & 1;
192}
193
194static inline int
195__test_and_clear_bit(unsigned long nr, volatile unsigned long *ptr)
196{
197 unsigned char *addr = __bitops_byte(nr, ptr);
198 unsigned char ch;
199
200 ch = *addr;
201 *addr &= ~(1 << (nr & 7));
202 return (ch >> (nr & 7)) & 1;
203}
204
205static inline int
206__test_and_change_bit(unsigned long nr, volatile unsigned long *ptr)
207{
208 unsigned char *addr = __bitops_byte(nr, ptr);
209 unsigned char ch;
210
211 ch = *addr;
212 *addr ^= 1 << (nr & 7);
213 return (ch >> (nr & 7)) & 1;
214}
215
216static inline int test_bit(unsigned long nr, const volatile unsigned long *ptr)
217{
218 const volatile unsigned char *addr;
219
220 addr = ((const volatile unsigned char *)ptr);
221 addr += (nr ^ (BITS_PER_LONG - 8)) >> 3;
222 return (*addr >> (nr & 7)) & 1;
223}
224
225static inline int test_and_set_bit_lock(unsigned long nr,
226 volatile unsigned long *ptr)
227{
228 if (test_bit(nr, ptr))
229 return 1;
230 return test_and_set_bit(nr, ptr);
231}
232
233static inline void clear_bit_unlock(unsigned long nr,
234 volatile unsigned long *ptr)
235{
236 smp_mb__before_atomic();
237 clear_bit(nr, ptr);
238}
239
240static inline void __clear_bit_unlock(unsigned long nr,
241 volatile unsigned long *ptr)
242{
243 smp_mb();
244 __clear_bit(nr, ptr);
245}
246
247/*
248 * Functions which use MSB0 bit numbering.
249 * The bits are numbered:
250 * |0..............63|64............127|128...........191|192...........255|
251 */
252unsigned long find_first_bit_inv(const unsigned long *addr, unsigned long size);
253unsigned long find_next_bit_inv(const unsigned long *addr, unsigned long size,
254 unsigned long offset);
255
256static inline void set_bit_inv(unsigned long nr, volatile unsigned long *ptr)
257{
258 return set_bit(nr ^ (BITS_PER_LONG - 1), ptr);
259}
260
261static inline void clear_bit_inv(unsigned long nr, volatile unsigned long *ptr)
262{
263 return clear_bit(nr ^ (BITS_PER_LONG - 1), ptr);
264}
265
266static inline void __set_bit_inv(unsigned long nr, volatile unsigned long *ptr)
267{
268 return __set_bit(nr ^ (BITS_PER_LONG - 1), ptr);
269}
270
271static inline void __clear_bit_inv(unsigned long nr, volatile unsigned long *ptr)
272{
273 return __clear_bit(nr ^ (BITS_PER_LONG - 1), ptr);
274}
275
276static inline int test_bit_inv(unsigned long nr,
277 const volatile unsigned long *ptr)
278{
279 return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
280}
281
282#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
283
284/**
285 * __flogr - find leftmost one
286 * @word - The word to search
287 *
288 * Returns the bit number of the most significant bit set,
289 * where the most significant bit has bit number 0.
290 * If no bit is set this function returns 64.
291 */
292static inline unsigned char __flogr(unsigned long word)
293{
294 if (__builtin_constant_p(word)) {
295 unsigned long bit = 0;
296
297 if (!word)
298 return 64;
299 if (!(word & 0xffffffff00000000UL)) {
300 word <<= 32;
301 bit += 32;
302 }
303 if (!(word & 0xffff000000000000UL)) {
304 word <<= 16;
305 bit += 16;
306 }
307 if (!(word & 0xff00000000000000UL)) {
308 word <<= 8;
309 bit += 8;
310 }
311 if (!(word & 0xf000000000000000UL)) {
312 word <<= 4;
313 bit += 4;
314 }
315 if (!(word & 0xc000000000000000UL)) {
316 word <<= 2;
317 bit += 2;
318 }
319 if (!(word & 0x8000000000000000UL)) {
320 word <<= 1;
321 bit += 1;
322 }
323 return bit;
324 } else {
325 register unsigned long bit asm("4") = word;
326 register unsigned long out asm("5");
327
328 asm volatile(
329 " flogr %[bit],%[bit]\n"
330 : [bit] "+d" (bit), [out] "=d" (out) : : "cc");
331 return bit;
332 }
333}
334
335/**
336 * __ffs - find first bit in word.
337 * @word: The word to search
338 *
339 * Undefined if no bit exists, so code should check against 0 first.
340 */
341static inline unsigned long __ffs(unsigned long word)
342{
343 return __flogr(-word & word) ^ (BITS_PER_LONG - 1);
344}
345
346/**
347 * ffs - find first bit set
348 * @word: the word to search
349 *
350 * This is defined the same way as the libc and
351 * compiler builtin ffs routines (man ffs).
352 */
353static inline int ffs(int word)
354{
355 unsigned long mask = 2 * BITS_PER_LONG - 1;
356 unsigned int val = (unsigned int)word;
357
358 return (1 + (__flogr(-val & val) ^ (BITS_PER_LONG - 1))) & mask;
359}
360
361/**
362 * __fls - find last (most-significant) set bit in a long word
363 * @word: the word to search
364 *
365 * Undefined if no set bit exists, so code should check against 0 first.
366 */
367static inline unsigned long __fls(unsigned long word)
368{
369 return __flogr(word) ^ (BITS_PER_LONG - 1);
370}
371
372/**
373 * fls64 - find last set bit in a 64-bit word
374 * @word: the word to search
375 *
376 * This is defined in a similar way as the libc and compiler builtin
377 * ffsll, but returns the position of the most significant set bit.
378 *
379 * fls64(value) returns 0 if value is 0 or the position of the last
380 * set bit if value is nonzero. The last (most significant) bit is
381 * at position 64.
382 */
383static inline int fls64(unsigned long word)
384{
385 unsigned long mask = 2 * BITS_PER_LONG - 1;
386
387 return (1 + (__flogr(word) ^ (BITS_PER_LONG - 1))) & mask;
388}
389
390/**
391 * fls - find last (most-significant) bit set
392 * @word: the word to search
393 *
394 * This is defined the same way as ffs.
395 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
396 */
397static inline int fls(int word)
398{
399 return fls64((unsigned int)word);
400}
401
402#else /* CONFIG_HAVE_MARCH_Z9_109_FEATURES */
403
404#include <asm-generic/bitops/__ffs.h>
405#include <asm-generic/bitops/ffs.h>
406#include <asm-generic/bitops/__fls.h>
407#include <asm-generic/bitops/fls.h>
408#include <asm-generic/bitops/fls64.h>
409
410#endif /* CONFIG_HAVE_MARCH_Z9_109_FEATURES */
411
412#include <asm-generic/bitops/ffz.h>
413#include <asm-generic/bitops/find.h>
414#include <asm-generic/bitops/hweight.h>
415#include <asm-generic/bitops/sched.h>
416#include <asm-generic/bitops/le.h>
417#include <asm-generic/bitops/ext2-atomic-setbit.h>
418
419#endif /* _S390_BITOPS_H */