]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/byte_order.h
baf21ec93a141fc283a8a2523d1da5187492caac
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1992 NeXT Computer, Inc.
33 * Byte ordering conversion.
36 #ifndef _ARCHITECTURE_BYTE_ORDER_H_
37 #define _ARCHITECTURE_BYTE_ORDER_H_
39 typedef unsigned long NXSwappedFloat
;
40 typedef unsigned long long NXSwappedDouble
;
42 #if defined (__ppc__) || defined(__ppc64__)
43 #include "architecture/ppc/byte_order.h"
44 #elif defined (__i386__)
45 #include "architecture/i386/byte_order.h"
47 #error architecture not supported
51 * Identify the byte order
52 * of the current host.
67 _x
= (NX_BigEndian
<< 24) | NX_LittleEndian
;
69 return ((enum NXByteOrder
)*((unsigned char *)&_x
));
73 * The predicated versions
74 * are defined here in terms
75 * of the unpredicated ones.
109 NXSwapBigLongLongToHost(
120 NXSwapBigDoubleToHost(
124 return NXConvertSwappedDoubleToHost(x
);
129 NXSwapBigFloatToHost(
133 return NXConvertSwappedFloatToHost(x
);
140 NXSwapHostShortToBig(
167 NXSwapHostLongLongToBig(
178 NXSwapHostDoubleToBig(
182 return NXConvertHostDoubleToSwapped(x
);
187 NXSwapHostFloatToBig(
191 return NXConvertHostFloatToSwapped(x
);
198 NXSwapLittleShortToHost(
202 return (NXSwapShort(x
));
207 NXSwapLittleIntToHost(
211 return (NXSwapInt(x
));
216 NXSwapLittleLongToHost(
220 return (NXSwapLong(x
));
225 NXSwapLittleLongLongToHost(
229 return (NXSwapLongLong(x
));
236 NXSwapLittleDoubleToHost(
240 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
245 NXSwapLittleFloatToHost(
249 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
256 NXSwapHostShortToLittle(
260 return (NXSwapShort(x
));
265 NXSwapHostIntToLittle(
269 return (NXSwapInt(x
));
274 NXSwapHostLongToLittle(
278 return (NXSwapLong(x
));
283 NXSwapHostLongLongToLittle(
287 return (NXSwapLongLong(x
));
294 NXSwapHostDoubleToLittle(
298 return NXSwapDouble(NXConvertHostDoubleToSwapped(x
));
303 NXSwapHostFloatToLittle(
307 return NXSwapFloat(NXConvertHostFloatToSwapped(x
));
311 #endif /*__BIG_ENDIAN__ */
313 #if __LITTLE_ENDIAN__
317 NXSwapBigShortToHost(
321 return (NXSwapShort(x
));
330 return (NXSwapInt(x
));
339 return (NXSwapLong(x
));
344 NXSwapBigLongLongToHost(
348 return (NXSwapLongLong(x
));
353 NXSwapBigDoubleToHost(
357 return NXConvertSwappedDoubleToHost(NXSwapDouble(x
));
362 NXSwapBigFloatToHost(
366 return NXConvertSwappedFloatToHost(NXSwapFloat(x
));
371 NXSwapHostShortToBig(
375 return (NXSwapShort(x
));
384 return (NXSwapInt(x
));
393 return (NXSwapLong(x
));
398 NXSwapHostLongLongToBig(
402 return (NXSwapLongLong(x
));
407 NXSwapHostDoubleToBig(
411 return (NXSwapDouble(NXConvertHostDoubleToSwapped(x
)));
416 NXSwapHostFloatToBig(
420 return (NXSwapFloat(NXConvertHostFloatToSwapped(x
)));
425 NXSwapLittleShortToHost(
434 NXSwapLittleIntToHost(
443 NXSwapLittleLongToHost(
452 NXSwapLittleLongLongToHost(
461 NXSwapLittleDoubleToHost(
465 return NXConvertSwappedDoubleToHost(x
);
470 NXSwapLittleFloatToHost(
474 return NXConvertSwappedFloatToHost(x
);
479 NXSwapHostShortToLittle(
488 NXSwapHostIntToLittle(
497 NXSwapHostLongToLittle(
506 NXSwapHostLongLongToLittle(
515 NXSwapHostDoubleToLittle(
519 return NXConvertHostDoubleToSwapped(x
);
524 NXSwapHostFloatToLittle(
528 return NXConvertHostFloatToSwapped(x
);
531 #endif /* __LITTLE_ENDIAN__ */
533 #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */