]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/byte_order.h
2 * Copyright (c) 2000 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 * Copyright (c) 1992 NeXT Computer, Inc.
25 * Byte ordering conversion.
29 * 20 October 1992 ? at NeXT
30 * Added #ifdef wrapper to prevent multiple inclusions of this file.
32 * 8 October 1992 ? at NeXT
33 * Converted to NXxxx versions. Condensed history.
35 * 18 May 1992 ? at NeXT
39 #ifndef _ARCHITECTURE_BYTE_ORDER_H_
40 #define _ARCHITECTURE_BYTE_ORDER_H_
42 typedef unsigned long NXSwappedFloat
;
43 typedef unsigned long long NXSwappedDouble
;
46 #include "architecture/ppc/byte_order.h"
47 #elif defined (__i386__)
48 #include "architecture/i386/byte_order.h"
50 #error architecture not supported
54 * Identify the byte order
55 * of the current host.
70 _x
= (NX_BigEndian
<< 24) | NX_LittleEndian
;
72 return ((enum NXByteOrder
)*((unsigned char *)&_x
));
76 * The predicated versions
77 * are defined here in terms
78 * of the unpredicated ones.
112 NXSwapBigLongLongToHost(
123 NXSwapBigDoubleToHost(
127 return NXConvertSwappedDoubleToHost(x
);
132 NXSwapBigFloatToHost(
136 return NXConvertSwappedFloatToHost(x
);
143 NXSwapHostShortToBig(
170 NXSwapHostLongLongToBig(
181 NXSwapHostDoubleToBig(
185 return NXConvertHostDoubleToSwapped(x
);
190 NXSwapHostFloatToBig(
194 return NXConvertHostFloatToSwapped(x
);
201 NXSwapLittleShortToHost(
205 return (NXSwapShort(x
));
210 NXSwapLittleIntToHost(
214 return (NXSwapInt(x
));
219 NXSwapLittleLongToHost(
223 return (NXSwapLong(x
));
228 NXSwapLittleLongLongToHost(
232 return (NXSwapLongLong(x
));
239 NXSwapLittleDoubleToHost(
243 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
248 NXSwapLittleFloatToHost(
252 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
259 NXSwapHostShortToLittle(
263 return (NXSwapShort(x
));
268 NXSwapHostIntToLittle(
272 return (NXSwapInt(x
));
277 NXSwapHostLongToLittle(
281 return (NXSwapLong(x
));
286 NXSwapHostLongLongToLittle(
290 return (NXSwapLongLong(x
));
297 NXSwapHostDoubleToLittle(
301 return NXSwapDouble(NXConvertHostDoubleToSwapped(x
));
306 NXSwapHostFloatToLittle(
310 return NXSwapFloat(NXConvertHostFloatToSwapped(x
));
314 #endif /*__BIG_ENDIAN__ */
316 #if __LITTLE_ENDIAN__
320 NXSwapBigShortToHost(
324 return (NXSwapShort(x
));
333 return (NXSwapInt(x
));
342 return (NXSwapLong(x
));
347 NXSwapBigLongLongToHost(
351 return (NXSwapLongLong(x
));
356 NXSwapBigDoubleToHost(
360 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
365 NXSwapBigFloatToHost(
369 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
374 NXSwapHostShortToBig(
378 return (NXSwapShort(x
));
387 return (NXSwapInt(x
));
396 return (NXSwapLong(x
));
401 NXSwapHostLongLongToBig(
405 return (NXSwapLongLong(x
));
410 NXSwapHostDoubleToBig(
414 return (NXSwapDouble(NXConvertHostDoubleToSwapped(x
)));
419 NXSwapHostFloatToBig(
423 return (NXSwapFloat(NXConvertHostFloatToSwapped(x
)));
428 NXSwapLittleShortToHost(
437 NXSwapLittleIntToHost(
446 NXSwapLittleLongToHost(
455 NXSwapLittleLongLongToHost(
464 NXSwapLittleDoubleToHost(
468 return NXConvertSwappedDoubleToHost(x
);
473 NXSwapLittleFloatToHost(
477 return NXConvertSwappedFloatToHost(x
);
482 NXSwapHostShortToLittle(
491 NXSwapHostIntToLittle(
500 NXSwapHostLongToLittle(
509 NXSwapHostLongLongToLittle(
518 NXSwapHostDoubleToLittle(
522 return NXConvertHostDoubleToSwapped(x
);
527 NXSwapHostFloatToLittle(
531 return NXConvertHostFloatToSwapped(x
);
534 #endif /* __LITTLE_ENDIAN__ */
536 #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */