]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1992 NeXT Computer, Inc.
28 * Byte ordering conversion.
32 * 20 October 1992 ? at NeXT
33 * Added #ifdef wrapper to prevent multiple inclusions of this file.
35 * 8 October 1992 ? at NeXT
36 * Converted to NXxxx versions. Condensed history.
38 * 18 May 1992 ? at NeXT
42 #ifndef _ARCHITECTURE_BYTE_ORDER_H_
43 #define _ARCHITECTURE_BYTE_ORDER_H_
45 typedef unsigned long NXSwappedFloat
;
46 typedef unsigned long long NXSwappedDouble
;
49 #include "architecture/ppc/byte_order.h"
50 #elif defined (__i386__)
51 #include "architecture/i386/byte_order.h"
53 #error architecture not supported
57 * Identify the byte order
58 * of the current host.
73 _x
= (NX_BigEndian
<< 24) | NX_LittleEndian
;
75 return ((enum NXByteOrder
)*((unsigned char *)&_x
));
79 * The predicated versions
80 * are defined here in terms
81 * of the unpredicated ones.
115 NXSwapBigLongLongToHost(
126 NXSwapBigDoubleToHost(
130 return NXConvertSwappedDoubleToHost(x
);
135 NXSwapBigFloatToHost(
139 return NXConvertSwappedFloatToHost(x
);
146 NXSwapHostShortToBig(
173 NXSwapHostLongLongToBig(
184 NXSwapHostDoubleToBig(
188 return NXConvertHostDoubleToSwapped(x
);
193 NXSwapHostFloatToBig(
197 return NXConvertHostFloatToSwapped(x
);
204 NXSwapLittleShortToHost(
208 return (NXSwapShort(x
));
213 NXSwapLittleIntToHost(
217 return (NXSwapInt(x
));
222 NXSwapLittleLongToHost(
226 return (NXSwapLong(x
));
231 NXSwapLittleLongLongToHost(
235 return (NXSwapLongLong(x
));
242 NXSwapLittleDoubleToHost(
246 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
251 NXSwapLittleFloatToHost(
255 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
262 NXSwapHostShortToLittle(
266 return (NXSwapShort(x
));
271 NXSwapHostIntToLittle(
275 return (NXSwapInt(x
));
280 NXSwapHostLongToLittle(
284 return (NXSwapLong(x
));
289 NXSwapHostLongLongToLittle(
293 return (NXSwapLongLong(x
));
300 NXSwapHostDoubleToLittle(
304 return NXSwapDouble(NXConvertHostDoubleToSwapped(x
));
309 NXSwapHostFloatToLittle(
313 return NXSwapFloat(NXConvertHostFloatToSwapped(x
));
317 #endif /*__BIG_ENDIAN__ */
319 #if __LITTLE_ENDIAN__
323 NXSwapBigShortToHost(
327 return (NXSwapShort(x
));
336 return (NXSwapInt(x
));
345 return (NXSwapLong(x
));
350 NXSwapBigLongLongToHost(
354 return (NXSwapLongLong(x
));
359 NXSwapBigDoubleToHost(
363 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
368 NXSwapBigFloatToHost(
372 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
377 NXSwapHostShortToBig(
381 return (NXSwapShort(x
));
390 return (NXSwapInt(x
));
399 return (NXSwapLong(x
));
404 NXSwapHostLongLongToBig(
408 return (NXSwapLongLong(x
));
413 NXSwapHostDoubleToBig(
417 return (NXSwapDouble(NXConvertHostDoubleToSwapped(x
)));
422 NXSwapHostFloatToBig(
426 return (NXSwapFloat(NXConvertHostFloatToSwapped(x
)));
431 NXSwapLittleShortToHost(
440 NXSwapLittleIntToHost(
449 NXSwapLittleLongToHost(
458 NXSwapLittleLongLongToHost(
467 NXSwapLittleDoubleToHost(
471 return NXConvertSwappedDoubleToHost(x
);
476 NXSwapLittleFloatToHost(
480 return NXConvertSwappedFloatToHost(x
);
485 NXSwapHostShortToLittle(
494 NXSwapHostIntToLittle(
503 NXSwapHostLongToLittle(
512 NXSwapHostLongLongToLittle(
521 NXSwapHostDoubleToLittle(
525 return NXConvertHostDoubleToSwapped(x
);
530 NXSwapHostFloatToLittle(
534 return NXConvertHostFloatToSwapped(x
);
537 #endif /* __LITTLE_ENDIAN__ */
539 #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */