]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/arm/OSByteOrder.h
0cd44a579bf0921482a21f9f825d6c313d83398e
2 * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
5 #ifndef _OS_OSBYTEORDERARM_H
6 #define _OS_OSBYTEORDERARM_H
9 #include <arm/arch.h> /* for _ARM_ARCH_6 */
11 /* Generic byte swapping functions. */
19 /* Reduces to 'rev16' with clang */
20 return (uint16_t)(_data
<< 8 | _data
>> 8);
30 _data
= __builtin_bswap32(_data
);
32 /* This actually generates the best code */
33 _data
= (((_data
^ (_data
>> 16 | (_data
<< 16))) & 0xFF00FFFF) >> 8) ^ (_data
>> 8 | _data
<< 24);
46 return __builtin_bswap64(_data
);
53 /* This actually generates the best code */
54 _u
._ul
[0] = (uint32_t)(_data
>> 32);
55 _u
._ul
[1] = (uint32_t)(_data
& 0xffffffff);
56 _u
._ul
[0] = _OSSwapInt32(_u
._ul
[0]);
57 _u
._ul
[1] = _OSSwapInt32(_u
._ul
[1]);
62 /* Functions for byte reversed loads. */
64 struct _OSUnalignedU16
{
65 volatile uint16_t __val
;
66 } __attribute__((__packed__
));
68 struct _OSUnalignedU32
{
69 volatile uint32_t __val
;
70 } __attribute__((__packed__
));
72 struct _OSUnalignedU64
{
73 volatile uint64_t __val
;
74 } __attribute__((__packed__
));
76 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
80 const volatile void * _base
,
84 return _OSSwapInt16(((struct _OSUnalignedU16
*)((uintptr_t)_base
+ _offset
))->__val
);
90 const volatile void * _base
,
94 return _OSSwapInt16(((struct _OSUnalignedU16
*)((uintptr_t)_base
+ _offset
))->__val
);
98 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
102 const volatile void * _base
,
106 return _OSSwapInt32(((struct _OSUnalignedU32
*)((uintptr_t)_base
+ _offset
))->__val
);
112 const volatile void * _base
,
116 return _OSSwapInt32(((struct _OSUnalignedU32
*)((uintptr_t)_base
+ _offset
))->__val
);
120 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
124 const volatile void * _base
,
128 return _OSSwapInt64(((struct _OSUnalignedU64
*)((uintptr_t)_base
+ _offset
))->__val
);
134 const volatile void * _base
,
138 return _OSSwapInt64(((struct _OSUnalignedU64
*)((uintptr_t)_base
+ _offset
))->__val
);
142 /* Functions for byte reversed stores. */
144 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
148 volatile void * _base
,
153 ((struct _OSUnalignedU16
*)((uintptr_t)_base
+ _offset
))->__val
= _OSSwapInt16(_data
);
159 volatile void * _base
,
164 ((struct _OSUnalignedU16
*)((uintptr_t)_base
+ _offset
))->__val
= _OSSwapInt16(_data
);
168 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
172 volatile void * _base
,
177 ((struct _OSUnalignedU32
*)((uintptr_t)_base
+ _offset
))->__val
= _OSSwapInt32(_data
);
183 volatile void * _base
,
188 ((struct _OSUnalignedU32
*)((uintptr_t)_base
+ _offset
))->__val
= _OSSwapInt32(_data
);
192 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
196 volatile void * _base
,
201 ((struct _OSUnalignedU64
*)((uintptr_t)_base
+ _offset
))->__val
= _OSSwapInt64(_data
);
207 volatile void * _base
,
212 ((struct _OSUnalignedU64
*)((uintptr_t)_base
+ _offset
))->__val
= _OSSwapInt64(_data
);
216 #endif /* ! _OS_OSBYTEORDERARM_H */