initial commit with v3.6.7
[linux-3.6.7-moxart.git] / arch / arm / include / asm / word-at-a-time.h
blob4d52f92967a65a09e57d5e02595bcf8ff3af2351
1 #ifndef __ASM_ARM_WORD_AT_A_TIME_H
2 #define __ASM_ARM_WORD_AT_A_TIME_H
4 #ifndef __ARMEB__
6 /*
7 * Little-endian word-at-a-time zero byte handling.
8 * Heavily based on the x86 algorithm.
9 */
10 #include <linux/kernel.h>
12 struct word_at_a_time {
13 const unsigned long one_bits, high_bits;
16 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18 static inline unsigned long has_zero(unsigned long a, unsigned long *bits,
19 const struct word_at_a_time *c)
21 unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits;
22 *bits = mask;
23 return mask;
26 #define prep_zero_mask(a, bits, c) (bits)
28 static inline unsigned long create_zero_mask(unsigned long bits)
30 bits = (bits - 1) & ~bits;
31 return bits >> 7;
34 static inline unsigned long find_zero(unsigned long mask)
36 unsigned long ret;
38 #if __LINUX_ARM_ARCH__ >= 5
39 /* We have clz available. */
40 ret = fls(mask) >> 3;
41 #else
42 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
43 ret = (0x0ff0001 + mask) >> 23;
44 /* Fix the 1 for 00 case */
45 ret &= mask;
46 #endif
48 return ret;
51 #ifdef CONFIG_DCACHE_WORD_ACCESS
53 #define zero_bytemask(mask) (mask)
56 * Load an unaligned word from kernel space.
58 * In the (very unlikely) case of the word being a page-crosser
59 * and the next page not being mapped, take the exception and
60 * return zeroes in the non-existing part.
62 static inline unsigned long load_unaligned_zeropad(const void *addr)
64 unsigned long ret, offset;
66 /* Load word from unaligned pointer addr */
67 asm(
68 "1: ldr %0, [%2]\n"
69 "2:\n"
70 " .pushsection .fixup,\"ax\"\n"
71 " .align 2\n"
72 "3: and %1, %2, #0x3\n"
73 " bic %2, %2, #0x3\n"
74 " ldr %0, [%2]\n"
75 " lsl %1, %1, #0x3\n"
76 " lsr %0, %0, %1\n"
77 " b 2b\n"
78 " .popsection\n"
79 " .pushsection __ex_table,\"a\"\n"
80 " .align 3\n"
81 " .long 1b, 3b\n"
82 " .popsection"
83 : "=&r" (ret), "=&r" (offset)
84 : "r" (addr), "Qo" (*(unsigned long *)addr));
86 return ret;
90 #endif /* DCACHE_WORD_ACCESS */
92 #else /* __ARMEB__ */
93 #include <asm-generic/word-at-a-time.h>
94 #endif
96 #endif /* __ASM_ARM_WORD_AT_A_TIME_H */