[SPARC64]: Fix cpu trampoline et al. mismatch warnings.
[linux-2.6/openmoko-kernel/knife-kernel.git] / include / asm-mn10300 / unaligned.h
blobcad3afbd035f1744d7c3751d252ab74c257347e3
1 /* MN10300 Unaligned memory access handling
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #ifndef _ASM_UNALIGNED_H
12 #define _ASM_UNALIGNED_H
14 #include <asm/types.h>
16 #if 0
17 extern int __bug_unaligned_x(void *ptr);
20 * What is the most efficient way of loading/storing an unaligned value?
22 * That is the subject of this file. Efficiency here is defined as
23 * minimum code size with minimum register usage for the common cases.
24 * It is currently not believed that long longs are common, so we
25 * trade efficiency for the chars, shorts and longs against the long
26 * longs.
28 * Current stats with gcc 2.7.2.2 for these functions:
30 * ptrsize get: code regs put: code regs
31 * 1 1 1 1 2
32 * 2 3 2 3 2
33 * 4 7 3 7 3
34 * 8 20 6 16 6
36 * gcc 2.95.1 seems to code differently:
38 * ptrsize get: code regs put: code regs
39 * 1 1 1 1 2
40 * 2 3 2 3 2
41 * 4 7 4 7 4
42 * 8 19 8 15 6
44 * which may or may not be more efficient (depending upon whether
45 * you can afford the extra registers). Hopefully the gcc 2.95
46 * is inteligent enough to decide if it is better to use the
47 * extra register, but evidence so far seems to suggest otherwise.
49 * Unfortunately, gcc is not able to optimise the high word
50 * out of long long >> 32, or the low word from long long << 32
53 #define __get_unaligned_2(__p) \
54 (__p[0] | __p[1] << 8)
56 #define __get_unaligned_4(__p) \
57 (__p[0] | __p[1] << 8 | __p[2] << 16 | __p[3] << 24)
59 #define get_unaligned(ptr) \
60 ({ \
61 unsigned int __v1, __v2; \
62 __typeof__(*(ptr)) __v; \
63 __u8 *__p = (__u8 *)(ptr); \
65 switch (sizeof(*(ptr))) { \
66 case 1: __v = *(ptr); break; \
67 case 2: __v = __get_unaligned_2(__p); break; \
68 case 4: __v = __get_unaligned_4(__p); break; \
69 case 8: \
70 __v2 = __get_unaligned_4((__p+4)); \
71 __v1 = __get_unaligned_4(__p); \
72 __v = ((unsigned long long)__v2 << 32 | __v1); \
73 break; \
74 default: __v = __bug_unaligned_x(__p); break; \
75 } \
76 __v; \
80 static inline void __put_unaligned_2(__u32 __v, register __u8 *__p)
82 *__p++ = __v;
83 *__p++ = __v >> 8;
86 static inline void __put_unaligned_4(__u32 __v, register __u8 *__p)
88 __put_unaligned_2(__v >> 16, __p + 2);
89 __put_unaligned_2(__v, __p);
92 static inline void __put_unaligned_8(const unsigned long long __v, __u8 *__p)
95 * tradeoff: 8 bytes of stack for all unaligned puts (2
96 * instructions), or an extra register in the long long
97 * case - go for the extra register.
99 __put_unaligned_4(__v >> 32, __p + 4);
100 __put_unaligned_4(__v, __p);
104 * Try to store an unaligned value as efficiently as possible.
106 #define put_unaligned(val, ptr) \
107 ({ \
108 switch (sizeof(*(ptr))) { \
109 case 1: \
110 *(ptr) = (val); \
111 break; \
112 case 2: \
113 __put_unaligned_2((val), (__u8 *)(ptr)); \
114 break; \
115 case 4: \
116 __put_unaligned_4((val), (__u8 *)(ptr)); \
117 break; \
118 case 8: \
119 __put_unaligned_8((val), (__u8 *)(ptr)); \
120 break; \
121 default: \
122 __bug_unaligned_x(ptr); \
123 break; \
125 (void) 0; \
129 #else
131 #define get_unaligned(ptr) (*(ptr))
132 #define put_unaligned(val, ptr) ({ *(ptr) = (val); (void) 0; })
134 #endif
136 #endif