x86: use generic strncpy_from_user routine
[deliverable/linux.git] / arch / x86 / include / asm / word-at-a-time.h
1 #ifndef _ASM_WORD_AT_A_TIME_H
2 #define _ASM_WORD_AT_A_TIME_H
3
4 #include <linux/kernel.h>
5
6 /*
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.
12 */
13
14 #ifdef CONFIG_64BIT
15
16 /*
17 * Jan Achrenius on G+: microoptimized version of
18 * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
19 * that works for the bytemasks without having to
20 * mask them first.
21 */
22 static inline long count_masked_bytes(unsigned long mask)
23 {
24 return mask*0x0001020304050608ul >> 56;
25 }
26
27 #else /* 32-bit case */
28
29 /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
30 static inline long count_masked_bytes(long mask)
31 {
32 /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
33 long a = (0x0ff0001+mask) >> 23;
34 /* Fix the 1 for 00 case */
35 return a & mask;
36 }
37
38 #endif
39
40 /* Return the high bit set in the first byte that is a zero */
41 static inline unsigned long has_zero(unsigned long a)
42 {
43 return ((a - REPEAT_BYTE(0x01)) & ~a) & REPEAT_BYTE(0x80);
44 }
45
46 /*
47 * Load an unaligned word from kernel space.
48 *
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.
52 */
53 static inline unsigned long load_unaligned_zeropad(const void *addr)
54 {
55 unsigned long ret, dummy;
56
57 asm(
58 "1:\tmov %2,%0\n"
59 "2:\n"
60 ".section .fixup,\"ax\"\n"
61 "3:\t"
62 "lea %2,%1\n\t"
63 "and %3,%1\n\t"
64 "mov (%1),%0\n\t"
65 "leal %2,%%ecx\n\t"
66 "andl %4,%%ecx\n\t"
67 "shll $3,%%ecx\n\t"
68 "shr %%cl,%0\n\t"
69 "jmp 2b\n"
70 ".previous\n"
71 _ASM_EXTABLE(1b, 3b)
72 :"=&r" (ret),"=&c" (dummy)
73 :"m" (*(unsigned long *)addr),
74 "i" (-sizeof(unsigned long)),
75 "i" (sizeof(unsigned long)-1));
76 return ret;
77 }
78
79 #endif /* _ASM_WORD_AT_A_TIME_H */
This page took 0.035481 seconds and 5 git commands to generate.