Root/
Source at commit 1270 created 12 years 11 months ago. By meklort, Add arm headers. update makefiles | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 1999-2007 Apple Inc. All rights reserved.␊ |
3 | */␊ |
4 | ␊ |
5 | #ifndef _OS_OSBYTEORDERARM_H␊ |
6 | #define _OS_OSBYTEORDERARM_H␊ |
7 | ␊ |
8 | #include <stdint.h>␊ |
9 | #include <arm/arch.h> /* for _ARM_ARCH_6 */␊ |
10 | ␊ |
11 | #if !defined(OS_INLINE)␊ |
12 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L␊ |
13 | # define OS_INLINE static inline␊ |
14 | # else␊ |
15 | # define OS_INLINE static __inline__␊ |
16 | # endif␊ |
17 | #endif␊ |
18 | ␊ |
19 | /* Generic byte swapping functions. */␊ |
20 | ␊ |
21 | OS_INLINE␊ |
22 | uint16_t␊ |
23 | _OSSwapInt16(␊ |
24 | uint16_t data␊ |
25 | )␊ |
26 | {␊ |
27 | #if defined(__llvm__)␊ |
28 | data = (data << 8 | data >> 8);␊ |
29 | #elif defined(_ARM_ARCH_6)␊ |
30 | __asm__ ("rev16 %0, %1\n" : "=l" (data) : "l" (data));␊ |
31 | #else␊ |
32 | data = (data << 8 | data >> 8);␊ |
33 | #endif␊ |
34 | ␊ |
35 | return data;␊ |
36 | }␊ |
37 | ␊ |
38 | OS_INLINE␊ |
39 | uint32_t␊ |
40 | _OSSwapInt32(␊ |
41 | uint32_t data␊ |
42 | )␊ |
43 | {␊ |
44 | #if defined(__llvm__)␊ |
45 | data = __builtin_bswap32(data);␊ |
46 | #elif defined(_ARM_ARCH_6)␊ |
47 | __asm__ ("rev %0, %1\n" : "=l" (data) : "l" (data));␊ |
48 | #else␊ |
49 | /* This actually generates the best code */␊ |
50 | data = (((data ^ (data >> 16 | (data << 16))) & 0xFF00FFFF) >> 8) ^ (data >> 8 | data << 24);␊ |
51 | #endif␊ |
52 | ␊ |
53 | return data;␊ |
54 | }␊ |
55 | ␊ |
56 | OS_INLINE␊ |
57 | uint64_t␊ |
58 | _OSSwapInt64(␊ |
59 | uint64_t data␊ |
60 | )␊ |
61 | {␊ |
62 | #if defined(__llvm__)␊ |
63 | return __builtin_bswap64(data);␊ |
64 | #else␊ |
65 | union {␊ |
66 | uint64_t ull;␊ |
67 | uint32_t ul[2];␊ |
68 | } u;␊ |
69 | ␊ |
70 | /* This actually generates the best code */␊ |
71 | u.ul[0] = (uint32_t)(data >> 32);␊ |
72 | u.ul[1] = (uint32_t)(data & 0xffffffff);␊ |
73 | u.ul[0] = _OSSwapInt32(u.ul[0]);␊ |
74 | u.ul[1] = _OSSwapInt32(u.ul[1]);␊ |
75 | return u.ull;␊ |
76 | #endif␊ |
77 | }␊ |
78 | ␊ |
79 | /* Functions for byte reversed loads. */␊ |
80 | ␊ |
81 | OS_INLINE␊ |
82 | uint16_t␊ |
83 | OSReadSwapInt16(␊ |
84 | const volatile void * base,␊ |
85 | uintptr_t offset␊ |
86 | )␊ |
87 | {␊ |
88 | uint16_t result;␊ |
89 | ␊ |
90 | result = *(volatile uint16_t *)((volatile uintptr_t)base + offset);␊ |
91 | return _OSSwapInt16(result);␊ |
92 | }␊ |
93 | ␊ |
94 | OS_INLINE␊ |
95 | uint32_t␊ |
96 | OSReadSwapInt32(␊ |
97 | const volatile void * base,␊ |
98 | uintptr_t offset␊ |
99 | )␊ |
100 | {␊ |
101 | uint32_t result;␊ |
102 | ␊ |
103 | result = *(volatile uint32_t *)((volatile uintptr_t)base + offset);␊ |
104 | return _OSSwapInt32(result);␊ |
105 | }␊ |
106 | ␊ |
107 | OS_INLINE␊ |
108 | uint64_t␊ |
109 | OSReadSwapInt64(␊ |
110 | const volatile void * base,␊ |
111 | uintptr_t offset␊ |
112 | )␊ |
113 | {␊ |
114 | volatile uint32_t * inp;␊ |
115 | union ullc {␊ |
116 | uint64_t ull;␊ |
117 | uint32_t ul[2];␊ |
118 | } outv;␊ |
119 | ␊ |
120 | inp = (volatile uint32_t *)((volatile uintptr_t)base + offset);␊ |
121 | outv.ul[0] = inp[1];␊ |
122 | outv.ul[1] = inp[0];␊ |
123 | outv.ul[0] = _OSSwapInt32(outv.ul[0]);␊ |
124 | outv.ul[1] = _OSSwapInt32(outv.ul[1]);␊ |
125 | return outv.ull;␊ |
126 | }␊ |
127 | ␊ |
128 | /* Functions for byte reversed stores. */␊ |
129 | ␊ |
130 | OS_INLINE␊ |
131 | void␊ |
132 | OSWriteSwapInt16(␊ |
133 | volatile void * base,␊ |
134 | uintptr_t offset,␊ |
135 | uint16_t data␊ |
136 | )␊ |
137 | {␊ |
138 | *(volatile uint16_t *)((volatile uintptr_t)base + offset) = _OSSwapInt16(data);␊ |
139 | }␊ |
140 | ␊ |
141 | OS_INLINE␊ |
142 | void␊ |
143 | OSWriteSwapInt32(␊ |
144 | volatile void * base,␊ |
145 | uintptr_t offset,␊ |
146 | uint32_t data␊ |
147 | )␊ |
148 | {␊ |
149 | *(volatile uint32_t *)((volatile uintptr_t)base + offset) = _OSSwapInt32(data);␊ |
150 | }␊ |
151 | ␊ |
152 | OS_INLINE␊ |
153 | void␊ |
154 | OSWriteSwapInt64(␊ |
155 | volatile void * base,␊ |
156 | uintptr_t offset,␊ |
157 | uint64_t data␊ |
158 | )␊ |
159 | {␊ |
160 | *(volatile uint64_t *)((volatile uintptr_t)base + offset) = _OSSwapInt64(data);␊ |
161 | }␊ |
162 | ␊ |
163 | #endif /* ! _OS_OSBYTEORDERARM_H */␊ |
164 |