2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1992 NeXT Computer, Inc.
27 * Byte ordering conversion.
31 #ifndef _ARCHITECTURE_BYTE_ORDER_H_
32 #define _ARCHITECTURE_BYTE_ORDER_H_
34 #include <libkern/OSByteOrder.h>
36 typedef unsigned long NXSwappedFloat
;
37 typedef unsigned long long NXSwappedDouble
;
45 return (unsigned short)OSSwapInt16((uint16_t)inv
);
54 return (unsigned int)OSSwapInt32((uint32_t)inv
);
63 return (unsigned long)OSSwapInt32((uint32_t)inv
);
69 unsigned long long inv
72 return (unsigned long long)OSSwapInt64((uint64_t)inv
);
75 static __inline__ NXSwappedFloat
76 NXConvertHostFloatToSwapped(float x
)
86 static __inline__
float
87 NXConvertSwappedFloatToHost(NXSwappedFloat x
)
97 static __inline__ NXSwappedDouble
98 NXConvertHostDoubleToSwapped(double x
)
108 static __inline__
double
109 NXConvertSwappedDoubleToHost(NXSwappedDouble x
)
119 static __inline__ NXSwappedFloat
120 NXSwapFloat(NXSwappedFloat x
)
122 return (NXSwappedFloat
)OSSwapInt32((uint32_t)x
);
125 static __inline__ NXSwappedDouble
126 NXSwapDouble(NXSwappedDouble x
)
128 return (NXSwappedDouble
)OSSwapInt64((uint64_t)x
);
132 * Identify the byte order
133 * of the current host.
144 NXHostByteOrder(void)
146 #if defined(__LITTLE_ENDIAN__)
147 return NX_LittleEndian
;
148 #elif defined(__BIG_ENDIAN__)
151 return NX_UnknownByteOrder
;
157 NXSwapBigShortToHost(
161 return (unsigned short)OSSwapBigToHostInt16((uint16_t)x
);
170 return (unsigned int)OSSwapBigToHostInt32((uint32_t)x
);
179 return (unsigned long)OSSwapBigToHostInt32((uint32_t)x
);
184 NXSwapBigLongLongToHost(
188 return (unsigned long long)OSSwapBigToHostInt64((uint64_t)x
);
193 NXSwapBigDoubleToHost(
197 return NXConvertSwappedDoubleToHost((NXSwappedDouble
)OSSwapBigToHostInt64((uint64_t)x
));
202 NXSwapBigFloatToHost(
206 return NXConvertSwappedFloatToHost((NXSwappedFloat
)OSSwapBigToHostInt32((uint32_t)x
));
211 NXSwapHostShortToBig(
215 return (unsigned short)OSSwapHostToBigInt16((uint16_t)x
);
224 return (unsigned int)OSSwapHostToBigInt32((uint32_t)x
);
233 return (unsigned long)OSSwapHostToBigInt32((uint32_t)x
);
238 NXSwapHostLongLongToBig(
242 return (unsigned long long)OSSwapHostToBigInt64((uint64_t)x
);
247 NXSwapHostDoubleToBig(
251 return (NXSwappedDouble
)OSSwapHostToBigInt64((uint64_t)NXConvertHostDoubleToSwapped(x
));
256 NXSwapHostFloatToBig(
260 return (NXSwappedFloat
)OSSwapHostToBigInt32((uint32_t)NXConvertHostFloatToSwapped(x
));
265 NXSwapLittleShortToHost(
269 return (unsigned short)OSSwapLittleToHostInt16((uint16_t)x
);
274 NXSwapLittleIntToHost(
278 return (unsigned int)OSSwapLittleToHostInt32((uint32_t)x
);
283 NXSwapLittleLongToHost(
287 return (unsigned long)OSSwapLittleToHostInt32((uint32_t)x
);
292 NXSwapLittleLongLongToHost(
296 return (unsigned long long)OSSwapLittleToHostInt64((uint64_t)x
);
301 NXSwapLittleDoubleToHost(
305 return NXConvertSwappedDoubleToHost((NXSwappedDouble
)OSSwapLittleToHostInt64((uint64_t)x
));
310 NXSwapLittleFloatToHost(
314 return NXConvertSwappedFloatToHost((NXSwappedFloat
)OSSwapLittleToHostInt32((uint32_t)x
));
319 NXSwapHostShortToLittle(
323 return (unsigned short)OSSwapHostToLittleInt16((uint16_t)x
);
328 NXSwapHostIntToLittle(
332 return (unsigned int)OSSwapHostToLittleInt32((uint32_t)x
);
337 NXSwapHostLongToLittle(
341 return (unsigned long)OSSwapHostToLittleInt32((uint32_t)x
);
346 NXSwapHostLongLongToLittle(
350 return (unsigned long long)OSSwapHostToLittleInt64((uint64_t)x
);
355 NXSwapHostDoubleToLittle(
359 return (NXSwappedDouble
)OSSwapHostToLittleInt64((uint64_t)NXConvertHostDoubleToSwapped(x
));
364 NXSwapHostFloatToLittle(
368 return (NXSwappedFloat
)OSSwapHostToLittleInt32((uint32_t)NXConvertHostFloatToSwapped(x
));
371 #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */