1 #ifndef _ASM_WORD_AT_A_TIME_H
2 #define _ASM_WORD_AT_A_TIME_H
5 * This is largely generic for little-endian machines, but the
6 * optimal byte mask counting is probably going to be something
7 * that is architecture-specific. If you have a reliably fast
8 * bit count instruction, that might be better than the multiply
9 * and shift, for example.
15 * Jan Achrenius on G+: microoptimized version of
16 * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
17 * that works for the bytemasks without having to
20 static inline long count_masked_bytes(unsigned long mask)
22 return mask*0x0001020304050608ul >> 56;
25 #else /* 32-bit case */
27 /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
28 static inline long count_masked_bytes(long mask)
30 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
31 long a = (0x0ff0001+mask) >> 23;
32 /* Fix the 1 for 00 case */
38 #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
40 /* Return the high bit set in the first byte that is a zero */
41 static inline unsigned long has_zero(unsigned long a)
43 return ((a - REPEAT_BYTE(0x01)) & ~a) & REPEAT_BYTE(0x80);
47 * Load an unaligned word from kernel space.
49 * In the (very unlikely) case of the word being a page-crosser
50 * and the next page not being mapped, take the exception and
51 * return zeroes in the non-existing part.
53 static inline unsigned long load_unaligned_zeropad(const void *addr)
55 unsigned long ret, dummy;
60 ".section .fixup,\"ax\"\n"
72 :"=&r" (ret),"=&c" (dummy)
73 :"m" (*(unsigned long *)addr),
74 "i" (-sizeof(unsigned long)),
75 "i" (sizeof(unsigned long)-1));
79 #endif /* _ASM_WORD_AT_A_TIME_H */