1 #ifndef _ASM_WORD_AT_A_TIME_H
2 #define _ASM_WORD_AT_A_TIME_H
4 #include <linux/kernel.h>
7 * This is largely generic for little-endian machines, but the
8 * optimal byte mask counting is probably going to be something
9 * that is architecture-specific. If you have a reliably fast
10 * bit count instruction, that might be better than the multiply
11 * and shift, for example.
13 struct word_at_a_time
{
14 const unsigned long one_bits
, high_bits
;
17 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
22 * Jan Achrenius on G+: microoptimized version of
23 * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
24 * that works for the bytemasks without having to
27 static inline long count_masked_bytes(unsigned long mask
)
29 return mask
*0x0001020304050608ul
>> 56;
32 #else /* 32-bit case */
34 /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
35 static inline long count_masked_bytes(long mask
)
37 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
38 long a
= (0x0ff0001+mask
) >> 23;
39 /* Fix the 1 for 00 case */
45 /* Return nonzero if it has a zero */
46 static inline unsigned long has_zero(unsigned long a
, unsigned long *bits
, const struct word_at_a_time
*c
)
48 unsigned long mask
= ((a
- c
->one_bits
) & ~a
) & c
->high_bits
;
53 static inline unsigned long prep_zero_mask(unsigned long a
, unsigned long bits
, const struct word_at_a_time
*c
)
58 static inline unsigned long create_zero_mask(unsigned long bits
)
60 bits
= (bits
- 1) & ~bits
;
64 /* The mask we created is directly usable as a bytemask */
65 #define zero_bytemask(mask) (mask)
67 static inline unsigned long find_zero(unsigned long mask
)
69 return count_masked_bytes(mask
);
73 * Load an unaligned word from kernel space.
75 * In the (very unlikely) case of the word being a page-crosser
76 * and the next page not being mapped, take the exception and
77 * return zeroes in the non-existing part.
79 static inline unsigned long load_unaligned_zeropad(const void *addr
)
81 unsigned long ret
, dummy
;
86 ".section .fixup,\"ax\"\n"
98 :"=&r" (ret
),"=&c" (dummy
)
99 :"m" (*(unsigned long *)addr
),
100 "i" (-sizeof(unsigned long)),
101 "i" (sizeof(unsigned long)-1));
105 #endif /* _ASM_WORD_AT_A_TIME_H */