1
2#ifndef _ASM_WORD_AT_A_TIME_H
3#define _ASM_WORD_AT_A_TIME_H
4
5#include <linux/kernel.h>
6
7
8
9
10
11
12
13
14struct word_at_a_time {
15 const unsigned long one_bits, high_bits;
16};
17
18#define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19
20#ifdef CONFIG_64BIT
21
22
23
24
25
26
27
28static inline long count_masked_bytes(unsigned long mask)
29{
30 return mask*0x0001020304050608ul >> 56;
31}
32
33#else
34
35
36static inline long count_masked_bytes(long mask)
37{
38
39 long a = (0x0ff0001+mask) >> 23;
40
41 return a & mask;
42}
43
44#endif
45
46
47static inline unsigned long has_zero(unsigned long a, unsigned long *bits, const struct word_at_a_time *c)
48{
49 unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits;
50 *bits = mask;
51 return mask;
52}
53
54static inline unsigned long prep_zero_mask(unsigned long a, unsigned long bits, const struct word_at_a_time *c)
55{
56 return bits;
57}
58
59static inline unsigned long create_zero_mask(unsigned long bits)
60{
61 bits = (bits - 1) & ~bits;
62 return bits >> 7;
63}
64
65
66#define zero_bytemask(mask) (mask)
67
68static inline unsigned long find_zero(unsigned long mask)
69{
70 return count_masked_bytes(mask);
71}
72
73
74
75
76
77
78
79
80static inline unsigned long load_unaligned_zeropad(const void *addr)
81{
82 unsigned long ret, dummy;
83
84 asm(
85 "1:\tmov %2,%0\n"
86 "2:\n"
87 ".section .fixup,\"ax\"\n"
88 "3:\t"
89 "lea %2,%1\n\t"
90 "and %3,%1\n\t"
91 "mov (%1),%0\n\t"
92 "leal %2,%%ecx\n\t"
93 "andl %4,%%ecx\n\t"
94 "shll $3,%%ecx\n\t"
95 "shr %%cl,%0\n\t"
96 "jmp 2b\n"
97 ".previous\n"
98 _ASM_EXTABLE(1b, 3b)
99 :"=&r" (ret),"=&c" (dummy)
100 :"m" (*(unsigned long *)addr),
101 "i" (-sizeof(unsigned long)),
102 "i" (sizeof(unsigned long)-1));
103 return ret;
104}
105
106#endif
107