]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/byte_order.h
6b6a08ea36bccd5f1ee732ba6cf8a5d01f6e6994
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1992 NeXT Computer, Inc.
31 * Byte ordering conversion.
34 #ifndef _ARCHITECTURE_BYTE_ORDER_H_
35 #define _ARCHITECTURE_BYTE_ORDER_H_
37 typedef unsigned long NXSwappedFloat
;
38 typedef unsigned long long NXSwappedDouble
;
40 #if defined (__ppc__) || defined(__ppc64__)
41 #include "architecture/ppc/byte_order.h"
42 #elif defined (__i386__)
43 #include "architecture/i386/byte_order.h"
45 #error architecture not supported
49 * Identify the byte order
50 * of the current host.
65 _x
= (NX_BigEndian
<< 24) | NX_LittleEndian
;
67 return ((enum NXByteOrder
)*((unsigned char *)&_x
));
71 * The predicated versions
72 * are defined here in terms
73 * of the unpredicated ones.
107 NXSwapBigLongLongToHost(
118 NXSwapBigDoubleToHost(
122 return NXConvertSwappedDoubleToHost(x
);
127 NXSwapBigFloatToHost(
131 return NXConvertSwappedFloatToHost(x
);
138 NXSwapHostShortToBig(
165 NXSwapHostLongLongToBig(
176 NXSwapHostDoubleToBig(
180 return NXConvertHostDoubleToSwapped(x
);
185 NXSwapHostFloatToBig(
189 return NXConvertHostFloatToSwapped(x
);
196 NXSwapLittleShortToHost(
200 return (NXSwapShort(x
));
205 NXSwapLittleIntToHost(
209 return (NXSwapInt(x
));
214 NXSwapLittleLongToHost(
218 return (NXSwapLong(x
));
223 NXSwapLittleLongLongToHost(
227 return (NXSwapLongLong(x
));
234 NXSwapLittleDoubleToHost(
238 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
243 NXSwapLittleFloatToHost(
247 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
254 NXSwapHostShortToLittle(
258 return (NXSwapShort(x
));
263 NXSwapHostIntToLittle(
267 return (NXSwapInt(x
));
272 NXSwapHostLongToLittle(
276 return (NXSwapLong(x
));
281 NXSwapHostLongLongToLittle(
285 return (NXSwapLongLong(x
));
292 NXSwapHostDoubleToLittle(
296 return NXSwapDouble(NXConvertHostDoubleToSwapped(x
));
301 NXSwapHostFloatToLittle(
305 return NXSwapFloat(NXConvertHostFloatToSwapped(x
));
309 #endif /*__BIG_ENDIAN__ */
311 #if __LITTLE_ENDIAN__
315 NXSwapBigShortToHost(
319 return (NXSwapShort(x
));
328 return (NXSwapInt(x
));
337 return (NXSwapLong(x
));
342 NXSwapBigLongLongToHost(
346 return (NXSwapLongLong(x
));
351 NXSwapBigDoubleToHost(
355 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
360 NXSwapBigFloatToHost(
364 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
369 NXSwapHostShortToBig(
373 return (NXSwapShort(x
));
382 return (NXSwapInt(x
));
391 return (NXSwapLong(x
));
396 NXSwapHostLongLongToBig(
400 return (NXSwapLongLong(x
));
405 NXSwapHostDoubleToBig(
409 return (NXSwapDouble(NXConvertHostDoubleToSwapped(x
)));
414 NXSwapHostFloatToBig(
418 return (NXSwapFloat(NXConvertHostFloatToSwapped(x
)));
423 NXSwapLittleShortToHost(
432 NXSwapLittleIntToHost(
441 NXSwapLittleLongToHost(
450 NXSwapLittleLongLongToHost(
459 NXSwapLittleDoubleToHost(
463 return NXConvertSwappedDoubleToHost(x
);
468 NXSwapLittleFloatToHost(
472 return NXConvertSwappedFloatToHost(x
);
477 NXSwapHostShortToLittle(
486 NXSwapHostIntToLittle(
495 NXSwapHostLongToLittle(
504 NXSwapHostLongLongToLittle(
513 NXSwapHostDoubleToLittle(
517 return NXConvertHostDoubleToSwapped(x
);
522 NXSwapHostFloatToLittle(
526 return NXConvertHostFloatToSwapped(x
);
529 #endif /* __LITTLE_ENDIAN__ */
531 #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */