1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ARM_WORD_AT_A_TIME_H
3 #define __ASM_ARM_WORD_AT_A_TIME_H
8 * Little-endian word-at-a-time zero byte handling.
9 * Heavily based on the x86 algorithm.
11 #include <linux/bitops.h>
12 #include <linux/wordpart.h>
14 struct word_at_a_time
{
15 const unsigned long one_bits
, high_bits
;
18 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20 static inline unsigned long has_zero(unsigned long a
, unsigned long *bits
,
21 const struct word_at_a_time
*c
)
23 unsigned long mask
= ((a
- c
->one_bits
) & ~a
) & c
->high_bits
;
28 #define prep_zero_mask(a, bits, c) (bits)
30 static inline unsigned long create_zero_mask(unsigned long bits
)
32 bits
= (bits
- 1) & ~bits
;
36 static inline unsigned long find_zero(unsigned long mask
)
40 #if __LINUX_ARM_ARCH__ >= 5
41 /* We have clz available. */
44 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
45 ret
= (0x0ff0001 + mask
) >> 23;
46 /* Fix the 1 for 00 case */
53 #define zero_bytemask(mask) (mask)
56 #include <asm-generic/word-at-a-time.h>
59 #ifdef CONFIG_DCACHE_WORD_ACCESS
62 * Load an unaligned word from kernel space.
64 * In the (very unlikely) case of the word being a page-crosser
65 * and the next page not being mapped, take the exception and
66 * return zeroes in the non-existing part.
68 static inline unsigned long load_unaligned_zeropad(const void *addr
)
70 unsigned long ret
, offset
;
72 /* Load word from unaligned pointer addr */
76 " .pushsection .text.fixup,\"ax\"\n"
78 "3: and %1, %2, #0x3\n"
89 " .pushsection __ex_table,\"a\"\n"
93 : "=&r" (ret
), "=&r" (offset
)
94 : "r" (addr
), "Qo" (*(unsigned long *)addr
));
99 #endif /* DCACHE_WORD_ACCESS */
100 #endif /* __ASM_ARM_WORD_AT_A_TIME_H */