]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/i386/OSByteOrder.h
5783957f00de7e843f4c43b05bf4dc3c31fe3de9
2 * Copyright (c) 1999-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #ifndef _OS_OSBYTEORDERI386_H
24 #define _OS_OSBYTEORDERI386_H
28 #if !defined(OS_INLINE)
29 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
30 # define OS_INLINE static inline
31 # elif defined(__MWERKS__) || defined(__cplusplus)
32 # define OS_INLINE static inline
34 # define OS_INLINE static __inline__
38 /* Generic byte swapping functions. */
46 return ((data
<< 8) | (data
>> 8));
55 __asm__ ("bswap %0" : "+r" (data
));
66 __asm__ ("bswap %%eax\n\t"
72 #elif defined(__x86_64__)
79 __asm__ ("bswap %0" : "+r" (data
));
83 #error Unknown architecture
86 /* Functions for byte reversed loads. */
91 const volatile void * base
,
97 result
= *(volatile uint16_t *)((uintptr_t)base
+ byteOffset
);
98 return _OSSwapInt16(result
);
104 const volatile void * base
,
110 result
= *(volatile uint32_t *)((uintptr_t)base
+ byteOffset
);
111 return _OSSwapInt32(result
);
117 const volatile void * base
,
123 result
= *(volatile uint64_t *)((uintptr_t)base
+ byteOffset
);
124 return _OSSwapInt64(result
);
127 /* Functions for byte reversed stores. */
132 volatile void * base
,
133 uintptr_t byteOffset
,
137 *(volatile uint16_t *)((uintptr_t)base
+ byteOffset
) = _OSSwapInt16(data
);
143 volatile void * base
,
144 uintptr_t byteOffset
,
148 *(volatile uint32_t *)((uintptr_t)base
+ byteOffset
) = _OSSwapInt32(data
);
154 volatile void * base
,
155 uintptr_t byteOffset
,
159 *(volatile uint64_t *)((uintptr_t)base
+ byteOffset
) = _OSSwapInt64(data
);
162 #endif /* ! _OS_OSBYTEORDERI386_H */