1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_WORD_AT_A_TIME_H
3 #define _ASM_WORD_AT_A_TIME_H
5 #include <linux/bitops.h>
6 #include <linux/wordpart.h>
8 struct word_at_a_time {
9 const unsigned long one_bits, high_bits;
12 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14 /* Return nonzero if it has a zero */
15 static inline unsigned long has_zero(unsigned long a, unsigned long *bits, const struct word_at_a_time *c)
17 unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits;
22 static inline unsigned long prep_zero_mask(unsigned long a, unsigned long bits, const struct word_at_a_time *c)
29 /* Keep the initial has_zero() value for both bitmask and size calc */
30 #define create_zero_mask(bits) (bits)
32 static inline unsigned long zero_bytemask(unsigned long bits)
34 bits = (bits - 1) & ~bits;
38 #define find_zero(bits) (__ffs(bits) >> 3)
42 /* Create the final mask for both bytemask and size */
43 static inline unsigned long create_zero_mask(unsigned long bits)
45 bits = (bits - 1) & ~bits;
49 /* The mask we created is directly usable as a bytemask */
50 #define zero_bytemask(mask) (mask)
52 /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
53 static inline unsigned long find_zero(unsigned long mask)
55 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
56 long a = (0x0ff0001+mask) >> 23;
57 /* Fix the 1 for 00 case */
64 * Load an unaligned word from kernel space.
66 * In the (very unlikely) case of the word being a page-crosser
67 * and the next page not being mapped, take the exception and
68 * return zeroes in the non-existing part.
70 static inline unsigned long load_unaligned_zeropad(const void *addr)
75 "1: mov %[mem], %[ret]\n"
77 _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_ZEROPAD)
79 : [mem] "m" (*(unsigned long *)addr));
84 #endif /* _ASM_WORD_AT_A_TIME_H */