]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/byte_order.h
2 * Copyright (c) 2000-2004 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.
28 #ifndef _ARCHITECTURE_BYTE_ORDER_H_
29 #define _ARCHITECTURE_BYTE_ORDER_H_
31 typedef unsigned long NXSwappedFloat
;
32 typedef unsigned long long NXSwappedDouble
;
34 #if defined (__ppc__) || defined(__ppc64__)
35 #include "architecture/ppc/byte_order.h"
36 #elif defined (__i386__)
37 #include "architecture/i386/byte_order.h"
39 #error architecture not supported
43 * Identify the byte order
44 * of the current host.
59 _x
= (NX_BigEndian
<< 24) | NX_LittleEndian
;
61 return ((enum NXByteOrder
)*((unsigned char *)&_x
));
65 * The predicated versions
66 * are defined here in terms
67 * of the unpredicated ones.
101 NXSwapBigLongLongToHost(
112 NXSwapBigDoubleToHost(
116 return NXConvertSwappedDoubleToHost(x
);
121 NXSwapBigFloatToHost(
125 return NXConvertSwappedFloatToHost(x
);
132 NXSwapHostShortToBig(
159 NXSwapHostLongLongToBig(
170 NXSwapHostDoubleToBig(
174 return NXConvertHostDoubleToSwapped(x
);
179 NXSwapHostFloatToBig(
183 return NXConvertHostFloatToSwapped(x
);
190 NXSwapLittleShortToHost(
194 return (NXSwapShort(x
));
199 NXSwapLittleIntToHost(
203 return (NXSwapInt(x
));
208 NXSwapLittleLongToHost(
212 return (NXSwapLong(x
));
217 NXSwapLittleLongLongToHost(
221 return (NXSwapLongLong(x
));
228 NXSwapLittleDoubleToHost(
232 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
237 NXSwapLittleFloatToHost(
241 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
248 NXSwapHostShortToLittle(
252 return (NXSwapShort(x
));
257 NXSwapHostIntToLittle(
261 return (NXSwapInt(x
));
266 NXSwapHostLongToLittle(
270 return (NXSwapLong(x
));
275 NXSwapHostLongLongToLittle(
279 return (NXSwapLongLong(x
));
286 NXSwapHostDoubleToLittle(
290 return NXSwapDouble(NXConvertHostDoubleToSwapped(x
));
295 NXSwapHostFloatToLittle(
299 return NXSwapFloat(NXConvertHostFloatToSwapped(x
));
303 #endif /*__BIG_ENDIAN__ */
305 #if __LITTLE_ENDIAN__
309 NXSwapBigShortToHost(
313 return (NXSwapShort(x
));
322 return (NXSwapInt(x
));
331 return (NXSwapLong(x
));
336 NXSwapBigLongLongToHost(
340 return (NXSwapLongLong(x
));
345 NXSwapBigDoubleToHost(
349 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
354 NXSwapBigFloatToHost(
358 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
363 NXSwapHostShortToBig(
367 return (NXSwapShort(x
));
376 return (NXSwapInt(x
));
385 return (NXSwapLong(x
));
390 NXSwapHostLongLongToBig(
394 return (NXSwapLongLong(x
));
399 NXSwapHostDoubleToBig(
403 return (NXSwapDouble(NXConvertHostDoubleToSwapped(x
)));
408 NXSwapHostFloatToBig(
412 return (NXSwapFloat(NXConvertHostFloatToSwapped(x
)));
417 NXSwapLittleShortToHost(
426 NXSwapLittleIntToHost(
435 NXSwapLittleLongToHost(
444 NXSwapLittleLongLongToHost(
453 NXSwapLittleDoubleToHost(
457 return NXConvertSwappedDoubleToHost(x
);
462 NXSwapLittleFloatToHost(
466 return NXConvertSwappedFloatToHost(x
);
471 NXSwapHostShortToLittle(
480 NXSwapHostIntToLittle(
489 NXSwapHostLongToLittle(
498 NXSwapHostLongLongToLittle(
507 NXSwapHostDoubleToLittle(
511 return NXConvertHostDoubleToSwapped(x
);
516 NXSwapHostFloatToLittle(
520 return NXConvertHostFloatToSwapped(x
);
523 #endif /* __LITTLE_ENDIAN__ */
525 #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */