1 #ifndef __ASM_ARM_UNALIGNED_H
2 #define __ASM_ARM_UNALIGNED_H
6 extern int __bug_unaligned_x(const void *ptr
);
9 * What is the most efficient way of loading/storing an unaligned value?
11 * That is the subject of this file. Efficiency here is defined as
12 * minimum code size with minimum register usage for the common cases.
13 * It is currently not believed that long longs are common, so we
14 * trade efficiency for the chars, shorts and longs against the long
17 * Current stats with gcc 2.7.2.2 for these functions:
19 * ptrsize get: code regs put: code regs
25 * gcc 2.95.1 seems to code differently:
27 * ptrsize get: code regs put: code regs
33 * which may or may not be more efficient (depending upon whether
34 * you can afford the extra registers). Hopefully the gcc 2.95
35 * is inteligent enough to decide if it is better to use the
36 * extra register, but evidence so far seems to suggest otherwise.
38 * Unfortunately, gcc is not able to optimise the high word
39 * out of long long >> 32, or the low word from long long << 32
42 #define __get_unaligned_2_le(__p) \
43 <<<<<<< HEAD:include/asm-arm/unaligned.h
44 (__p
[0] | __p
[1] << 8)
46 (unsigned int)(__p
[0] | __p
[1] << 8)
47 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/asm-arm
/unaligned
.h
49 #define __get_unaligned_2_be(__p) \
50 <<<<<<< HEAD:include/asm-arm/unaligned.h
51 (__p
[0] << 8 | __p
[1])
53 (unsigned int)(__p
[0] << 8 | __p
[1])
54 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/asm-arm
/unaligned
.h
56 #define __get_unaligned_4_le(__p) \
57 <<<<<<< HEAD:include/asm-arm/unaligned.h
58 (__p
[0] | __p
[1] << 8 | __p
[2] << 16 | __p
[3] << 24)
60 (unsigned int)(__p
[0] | __p
[1] << 8 | __p
[2] << 16 | __p
[3] << 24)
61 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/asm-arm
/unaligned
.h
63 #define __get_unaligned_4_be(__p) \
64 <<<<<<< HEAD:include/asm-arm/unaligned.h
65 (__p
[0] << 24 | __p
[1] << 16 | __p
[2] << 8 | __p
[3])
67 (unsigned int)(__p
[0] << 24 | __p
[1] << 16 | __p
[2] << 8 | __p
[3])
68 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:include
/asm-arm
/unaligned
.h
70 #define __get_unaligned_8_le(__p) \
71 ((unsigned long long)__get_unaligned_4_le((__p+4)) << 32 | \
72 __get_unaligned_4_le(__p))
74 #define __get_unaligned_8_be(__p) \
75 ((unsigned long long)__get_unaligned_4_be(__p) << 32 | \
76 __get_unaligned_4_be((__p+4)))
78 #define __get_unaligned_le(ptr) \
79 ((__force typeof(*(ptr)))({ \
80 const __u8 *__p = (const __u8 *)(ptr); \
81 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \
82 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_le(__p), \
83 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_le(__p), \
84 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_le(__p), \
85 (void)__bug_unaligned_x(__p))))); \
88 #define __get_unaligned_be(ptr) \
89 ((__force typeof(*(ptr)))({ \
90 const __u8 *__p = (const __u8 *)(ptr); \
91 __builtin_choose_expr(sizeof(*(ptr)) == 1, *__p, \
92 __builtin_choose_expr(sizeof(*(ptr)) == 2, __get_unaligned_2_be(__p), \
93 __builtin_choose_expr(sizeof(*(ptr)) == 4, __get_unaligned_4_be(__p), \
94 __builtin_choose_expr(sizeof(*(ptr)) == 8, __get_unaligned_8_be(__p), \
95 (void)__bug_unaligned_x(__p))))); \
99 static inline void __put_unaligned_2_le(__u32 __v
, register __u8
*__p
)
105 static inline void __put_unaligned_2_be(__u32 __v
, register __u8
*__p
)
111 static inline void __put_unaligned_4_le(__u32 __v
, register __u8
*__p
)
113 __put_unaligned_2_le(__v
>> 16, __p
+ 2);
114 __put_unaligned_2_le(__v
, __p
);
117 static inline void __put_unaligned_4_be(__u32 __v
, register __u8
*__p
)
119 __put_unaligned_2_be(__v
>> 16, __p
);
120 __put_unaligned_2_be(__v
, __p
+ 2);
123 static inline void __put_unaligned_8_le(const unsigned long long __v
, register __u8
*__p
)
126 * tradeoff: 8 bytes of stack for all unaligned puts (2
127 * instructions), or an extra register in the long long
128 * case - go for the extra register.
130 __put_unaligned_4_le(__v
>> 32, __p
+4);
131 __put_unaligned_4_le(__v
, __p
);
134 static inline void __put_unaligned_8_be(const unsigned long long __v
, register __u8
*__p
)
137 * tradeoff: 8 bytes of stack for all unaligned puts (2
138 * instructions), or an extra register in the long long
139 * case - go for the extra register.
141 __put_unaligned_4_be(__v
>> 32, __p
);
142 __put_unaligned_4_be(__v
, __p
+4);
146 * Try to store an unaligned value as efficiently as possible.
148 #define __put_unaligned_le(val,ptr) \
150 (void)sizeof(*(ptr) = (val)); \
151 switch (sizeof(*(ptr))) { \
155 case 2: __put_unaligned_2_le((__force u16)(val),(__u8 *)(ptr)); \
157 case 4: __put_unaligned_4_le((__force u32)(val),(__u8 *)(ptr)); \
159 case 8: __put_unaligned_8_le((__force u64)(val),(__u8 *)(ptr)); \
161 default: __bug_unaligned_x(ptr); \
167 #define __put_unaligned_be(val,ptr) \
169 (void)sizeof(*(ptr) = (val)); \
170 switch (sizeof(*(ptr))) { \
174 case 2: __put_unaligned_2_be((__force u16)(val),(__u8 *)(ptr)); \
176 case 4: __put_unaligned_4_be((__force u32)(val),(__u8 *)(ptr)); \
178 case 8: __put_unaligned_8_be((__force u64)(val),(__u8 *)(ptr)); \
180 default: __bug_unaligned_x(ptr); \
190 #define get_unaligned __get_unaligned_le
191 #define put_unaligned __put_unaligned_le
193 #define get_unaligned __get_unaligned_be
194 #define put_unaligned __put_unaligned_be