initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / asm-alpha / unaligned.h
blob2090db872bcc4ac334d82ad5727b93584fd8edd6
1 #ifndef __ALPHA_UNALIGNED_H
2 #define __ALPHA_UNALIGNED_H
4 /*
5 * The main single-value unaligned transfer routines.
6 */
7 #define get_unaligned(ptr) \
8 ((__typeof__(*(ptr)))__get_unaligned((ptr), sizeof(*(ptr))))
9 #define put_unaligned(x,ptr) \
10 __put_unaligned((unsigned long)(x), (ptr), sizeof(*(ptr)))
13 * This is a silly but good way to make sure that
14 * the get/put functions are indeed always optimized,
15 * and that we use the correct sizes.
17 extern void bad_unaligned_access_length(void) __attribute__((noreturn));
20 * EGCS 1.1 knows about arbitrary unaligned loads. Define some
21 * packed structures to talk about such things with.
24 struct __una_u64 { __u64 x __attribute__((packed)); };
25 struct __una_u32 { __u32 x __attribute__((packed)); };
26 struct __una_u16 { __u16 x __attribute__((packed)); };
29 * Elemental unaligned loads
32 extern inline unsigned long __uldq(const unsigned long * r11)
34 const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
35 return ptr->x;
38 extern inline unsigned long __uldl(const unsigned int * r11)
40 const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
41 return ptr->x;
44 extern inline unsigned long __uldw(const unsigned short * r11)
46 const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
47 return ptr->x;
51 * Elemental unaligned stores
54 extern inline void __ustq(unsigned long r5, unsigned long * r11)
56 struct __una_u64 *ptr = (struct __una_u64 *) r11;
57 ptr->x = r5;
60 extern inline void __ustl(unsigned long r5, unsigned int * r11)
62 struct __una_u32 *ptr = (struct __una_u32 *) r11;
63 ptr->x = r5;
66 extern inline void __ustw(unsigned long r5, unsigned short * r11)
68 struct __una_u16 *ptr = (struct __una_u16 *) r11;
69 ptr->x = r5;
72 extern inline unsigned long __get_unaligned(const void *ptr, size_t size)
74 unsigned long val;
75 switch (size) {
76 case 1:
77 val = *(const unsigned char *)ptr;
78 break;
79 case 2:
80 val = __uldw((const unsigned short *)ptr);
81 break;
82 case 4:
83 val = __uldl((const unsigned int *)ptr);
84 break;
85 case 8:
86 val = __uldq((const unsigned long *)ptr);
87 break;
88 default:
89 bad_unaligned_access_length();
91 return val;
94 extern inline void __put_unaligned(unsigned long val, void *ptr, size_t size)
96 switch (size) {
97 case 1:
98 *(unsigned char *)ptr = (val);
99 break;
100 case 2:
101 __ustw(val, (unsigned short *)ptr);
102 break;
103 case 4:
104 __ustl(val, (unsigned int *)ptr);
105 break;
106 case 8:
107 __ustq(val, (unsigned long *)ptr);
108 break;
109 default:
110 bad_unaligned_access_length();
114 #endif