1 #ifndef __ALPHA_UNALIGNED_H
2 #define __ALPHA_UNALIGNED_H
3
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)))
11
12 /*
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.
16 */
17 extern void bad_unaligned_access_length(void);
18
19 /*
20 * EGCS 1.1 knows about arbitrary unaligned loads. Define some
21 * packed structures to talk about such things with.
22 */
23
24 struct __una_u64 { __u64 x __attribute__((packed)); };
25 struct __una_u32 { __u32 x __attribute__((packed)); };
26 struct __una_u16 { __u16 x __attribute__((packed)); };
27
28 /*
29 * Elemental unaligned loads
30 */
31
__uldq(const unsigned long * r11)32 extern inline unsigned long __uldq(const unsigned long * r11)
33 {
34 const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
35 return ptr->x;
36 }
37
__uldl(const unsigned int * r11)38 extern inline unsigned long __uldl(const unsigned int * r11)
39 {
40 const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
41 return ptr->x;
42 }
43
__uldw(const unsigned short * r11)44 extern inline unsigned long __uldw(const unsigned short * r11)
45 {
46 const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
47 return ptr->x;
48 }
49
50 /*
51 * Elemental unaligned stores
52 */
53
__ustq(unsigned long r5,unsigned long * r11)54 extern inline void __ustq(unsigned long r5, unsigned long * r11)
55 {
56 struct __una_u64 *ptr = (struct __una_u64 *) r11;
57 ptr->x = r5;
58 }
59
__ustl(unsigned long r5,unsigned int * r11)60 extern inline void __ustl(unsigned long r5, unsigned int * r11)
61 {
62 struct __una_u32 *ptr = (struct __una_u32 *) r11;
63 ptr->x = r5;
64 }
65
__ustw(unsigned long r5,unsigned short * r11)66 extern inline void __ustw(unsigned long r5, unsigned short * r11)
67 {
68 struct __una_u16 *ptr = (struct __una_u16 *) r11;
69 ptr->x = r5;
70 }
71
__get_unaligned(const void * ptr,size_t size)72 extern inline unsigned long __get_unaligned(const void *ptr, size_t size)
73 {
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();
90 }
91 return val;
92 }
93
__put_unaligned(unsigned long val,void * ptr,size_t size)94 extern inline void __put_unaligned(unsigned long val, void *ptr, size_t size)
95 {
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();
111 }
112 }
113
114 #endif
115