]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/machine/OSByteOrder.h
97f2a6fbd148d097af70f3b0c467befbc70a24f6
2 * Copyright (c) 2000-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_OSBYTEORDERMACHINE_H
24 #define _OS_OSBYTEORDERMACHINE_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 OSSwapConstInt16(data
);
55 return OSSwapConstInt32(data
);
64 return OSSwapConstInt64(data
);
67 /* Functions for byte reversed loads. */
72 const volatile void * base
,
76 uint16_t data
= *(volatile uint16_t *)((uintptr_t)base
+ byteOffset
);
77 return _OSSwapInt16(data
);
83 const volatile void * base
,
87 uint32_t data
= *(volatile uint32_t *)((uintptr_t)base
+ byteOffset
);
88 return _OSSwapInt32(data
);
94 const volatile void * base
,
98 uint64_t data
= *(volatile uint64_t *)((uintptr_t)base
+ byteOffset
);
99 return _OSSwapInt64(data
);
102 /* Functions for byte reversed stores. */
107 volatile void * base
,
108 uintptr_t byteOffset
,
112 *(volatile uint16_t *)((uintptr_t)base
+ byteOffset
) = _OSSwapInt16(data
);
118 volatile void * base
,
119 uintptr_t byteOffset
,
123 *(volatile uint32_t *)((uintptr_t)base
+ byteOffset
) = _OSSwapInt32(data
);
129 volatile void * base
,
130 uintptr_t byteOffset
,
134 *(volatile uint64_t *)((uintptr_t)base
+ byteOffset
) = _OSSwapInt64(data
);
137 #endif /* ! _OS_OSBYTEORDERMACHINE_H */