X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8ad349bb6ed4a0be06e34c92be0d98b92e078db4..b0d623f7f2ae71ed96e60569f61f9a9a27016e80:/EXTERNAL_HEADERS/architecture/byte_order.h diff --git a/EXTERNAL_HEADERS/architecture/byte_order.h b/EXTERNAL_HEADERS/architecture/byte_order.h index baf21ec93..72507854a 100644 --- a/EXTERNAL_HEADERS/architecture/byte_order.h +++ b/EXTERNAL_HEADERS/architecture/byte_order.h @@ -1,324 +1,164 @@ /* - * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ + * @APPLE_LICENSE_HEADER_START@ * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. The rights granted to you under the - * License may not be used to create, or enable the creation or - * redistribution of, unlawful or unlicensed copies of an Apple operating - * system, or to circumvent, violate, or enable the circumvention or - * violation of, any terms of an Apple operating system software license - * agreement. - * - * Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ + * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.0 (the 'License'). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1992 NeXT Computer, Inc. * * Byte ordering conversion. + * */ #ifndef _ARCHITECTURE_BYTE_ORDER_H_ #define _ARCHITECTURE_BYTE_ORDER_H_ +#include + typedef unsigned long NXSwappedFloat; typedef unsigned long long NXSwappedDouble; -#if defined (__ppc__) || defined(__ppc64__) -#include "architecture/ppc/byte_order.h" -#elif defined (__i386__) -#include "architecture/i386/byte_order.h" -#else -#error architecture not supported -#endif - -/* - * Identify the byte order - * of the current host. - */ - -enum NXByteOrder { - NX_UnknownByteOrder, - NX_LittleEndian, - NX_BigEndian -}; - -static __inline__ -enum NXByteOrder -NXHostByteOrder(void) -{ - unsigned int _x; - - _x = (NX_BigEndian << 24) | NX_LittleEndian; - - return ((enum NXByteOrder)*((unsigned char *)&_x)); -} - -/* - * The predicated versions - * are defined here in terms - * of the unpredicated ones. - */ - -#if __BIG_ENDIAN__ - static __inline__ -unsigned short -NXSwapBigShortToHost( - unsigned short x +unsigned short +NXSwapShort( + unsigned short inv ) { - return (x); + return (unsigned short)OSSwapInt16((uint16_t)inv); } static __inline__ unsigned int -NXSwapBigIntToHost( - unsigned int x +NXSwapInt( + unsigned int inv ) { - return (x); + return (unsigned int)OSSwapInt32((uint32_t)inv); } static __inline__ unsigned long -NXSwapBigLongToHost( - unsigned long x +NXSwapLong( + unsigned long inv ) { - return (x); + return (unsigned long)OSSwapInt32((uint32_t)inv); } static __inline__ unsigned long long -NXSwapBigLongLongToHost( - unsigned long long x +NXSwapLongLong( + unsigned long long inv ) { - return (x); + return (unsigned long long)OSSwapInt64((uint64_t)inv); } -#ifndef KERNEL - -static __inline__ -double -NXSwapBigDoubleToHost( - NXSwappedDouble x -) +static __inline__ NXSwappedFloat +NXConvertHostFloatToSwapped(float x) { - return NXConvertSwappedDoubleToHost(x); + union fconv { + float number; + NXSwappedFloat sf; + } u; + u.number = x; + return u.sf; } -static __inline__ -float -NXSwapBigFloatToHost( - NXSwappedFloat x -) +static __inline__ float +NXConvertSwappedFloatToHost(NXSwappedFloat x) { - return NXConvertSwappedFloatToHost(x); + union fconv { + float number; + NXSwappedFloat sf; + } u; + u.sf = x; + return u.number; } -#endif /* KERNEL */ - -static __inline__ -unsigned short -NXSwapHostShortToBig( - unsigned short x -) +static __inline__ NXSwappedDouble +NXConvertHostDoubleToSwapped(double x) { - return (x); + union dconv { + double number; + NXSwappedDouble sd; + } u; + u.number = x; + return u.sd; } -static __inline__ -unsigned int -NXSwapHostIntToBig( - unsigned int x -) +static __inline__ double +NXConvertSwappedDoubleToHost(NXSwappedDouble x) { - return (x); + union dconv { + double number; + NXSwappedDouble sd; + } u; + u.sd = x; + return u.number; } -static __inline__ -unsigned long -NXSwapHostLongToBig( - unsigned long x -) -{ - return (x); +static __inline__ NXSwappedFloat +NXSwapFloat(NXSwappedFloat x) +{ + return (NXSwappedFloat)OSSwapInt32((uint32_t)x); } -static __inline__ -unsigned long long -NXSwapHostLongLongToBig( - unsigned long long x -) -{ - return (x); +static __inline__ NXSwappedDouble +NXSwapDouble(NXSwappedDouble x) +{ + return (NXSwappedDouble)OSSwapInt64((uint64_t)x); } -#ifndef KERNEL - -static __inline__ -NXSwappedDouble -NXSwapHostDoubleToBig( - double x -) -{ - return NXConvertHostDoubleToSwapped(x); -} - -static __inline__ -NXSwappedFloat -NXSwapHostFloatToBig( - float x -) -{ - return NXConvertHostFloatToSwapped(x); -} - -#endif /* KERNEL */ - -static __inline__ -unsigned short -NXSwapLittleShortToHost( - unsigned short x -) -{ - return (NXSwapShort(x)); -} - -static __inline__ -unsigned int -NXSwapLittleIntToHost( - unsigned int x -) -{ - return (NXSwapInt(x)); -} - -static __inline__ -unsigned long -NXSwapLittleLongToHost( - unsigned long x -) -{ - return (NXSwapLong(x)); -} - -static __inline__ -unsigned long long -NXSwapLittleLongLongToHost( - unsigned long long x -) -{ - return (NXSwapLongLong(x)); -} - -#ifndef KERNEL - -static __inline__ -double -NXSwapLittleDoubleToHost( - NXSwappedDouble x -) -{ - return NXConvertSwappedDoubleToHost(NXSwapDouble(x)); -} - -static __inline__ -float -NXSwapLittleFloatToHost( - NXSwappedFloat x -) -{ - return NXConvertSwappedFloatToHost(NXSwapFloat(x)); -} - -#endif /* KERNEL */ - -static __inline__ -unsigned short -NXSwapHostShortToLittle( - unsigned short x -) -{ - return (NXSwapShort(x)); -} - -static __inline__ -unsigned int -NXSwapHostIntToLittle( - unsigned int x -) -{ - return (NXSwapInt(x)); -} - -static __inline__ -unsigned long -NXSwapHostLongToLittle( - unsigned long x -) -{ - return (NXSwapLong(x)); -} - -static __inline__ -unsigned long long -NXSwapHostLongLongToLittle( - unsigned long long x -) -{ - return (NXSwapLongLong(x)); -} - -#ifndef KERNEL +/* + * Identify the byte order + * of the current host. + */ -static __inline__ -NXSwappedDouble -NXSwapHostDoubleToLittle( - double x -) -{ - return NXSwapDouble(NXConvertHostDoubleToSwapped(x)); -} +enum NXByteOrder { + NX_UnknownByteOrder, + NX_LittleEndian, + NX_BigEndian +}; static __inline__ -NXSwappedFloat -NXSwapHostFloatToLittle( - float x -) +enum NXByteOrder +NXHostByteOrder(void) { - return NXSwapFloat(NXConvertHostFloatToSwapped(x)); +#if defined(__LITTLE_ENDIAN__) + return NX_LittleEndian; +#elif defined(__BIG_ENDIAN__) + return NX_BigEndian; +#else + return NX_UnknownByteOrder; +#endif } -#endif /* KERNEL */ -#endif /*__BIG_ENDIAN__ */ - -#if __LITTLE_ENDIAN__ - static __inline__ unsigned short NXSwapBigShortToHost( unsigned short x ) { - return (NXSwapShort(x)); + return (unsigned short)OSSwapBigToHostInt16((uint16_t)x); } static __inline__ @@ -327,7 +167,7 @@ NXSwapBigIntToHost( unsigned int x ) { - return (NXSwapInt(x)); + return (unsigned int)OSSwapBigToHostInt32((uint32_t)x); } static __inline__ @@ -336,7 +176,7 @@ NXSwapBigLongToHost( unsigned long x ) { - return (NXSwapLong(x)); + return (unsigned long)OSSwapBigToHostInt32((uint32_t)x); } static __inline__ @@ -345,7 +185,7 @@ NXSwapBigLongLongToHost( unsigned long long x ) { - return (NXSwapLongLong(x)); + return (unsigned long long)OSSwapBigToHostInt64((uint64_t)x); } static __inline__ @@ -354,7 +194,7 @@ NXSwapBigDoubleToHost( NXSwappedDouble x ) { - return NXConvertSwappedDoubleToHost(NXSwapDouble(x)); + return NXConvertSwappedDoubleToHost((NXSwappedDouble)OSSwapBigToHostInt64((uint64_t)x)); } static __inline__ @@ -363,7 +203,7 @@ NXSwapBigFloatToHost( NXSwappedFloat x ) { - return NXConvertSwappedFloatToHost(NXSwapFloat(x)); + return NXConvertSwappedFloatToHost((NXSwappedFloat)OSSwapBigToHostInt32((uint32_t)x)); } static __inline__ @@ -372,7 +212,7 @@ NXSwapHostShortToBig( unsigned short x ) { - return (NXSwapShort(x)); + return (unsigned short)OSSwapHostToBigInt16((uint16_t)x); } static __inline__ @@ -381,7 +221,7 @@ NXSwapHostIntToBig( unsigned int x ) { - return (NXSwapInt(x)); + return (unsigned int)OSSwapHostToBigInt32((uint32_t)x); } static __inline__ @@ -390,7 +230,7 @@ NXSwapHostLongToBig( unsigned long x ) { - return (NXSwapLong(x)); + return (unsigned long)OSSwapHostToBigInt32((uint32_t)x); } static __inline__ @@ -399,25 +239,25 @@ NXSwapHostLongLongToBig( unsigned long long x ) { - return (NXSwapLongLong(x)); + return (unsigned long long)OSSwapHostToBigInt64((uint64_t)x); } static __inline__ NXSwappedDouble NXSwapHostDoubleToBig( - double x + double x ) { - return (NXSwapDouble(NXConvertHostDoubleToSwapped(x))); + return (NXSwappedDouble)OSSwapHostToBigInt64((uint64_t)NXConvertHostDoubleToSwapped(x)); } static __inline__ NXSwappedFloat NXSwapHostFloatToBig( - float x + float x ) { - return (NXSwapFloat(NXConvertHostFloatToSwapped(x))); + return (NXSwappedFloat)OSSwapHostToBigInt32((uint32_t)NXConvertHostFloatToSwapped(x)); } static __inline__ @@ -426,7 +266,7 @@ NXSwapLittleShortToHost( unsigned short x ) { - return (x); + return (unsigned short)OSSwapLittleToHostInt16((uint16_t)x); } static __inline__ @@ -435,7 +275,7 @@ NXSwapLittleIntToHost( unsigned int x ) { - return (x); + return (unsigned int)OSSwapLittleToHostInt32((uint32_t)x); } static __inline__ @@ -444,7 +284,7 @@ NXSwapLittleLongToHost( unsigned long x ) { - return (x); + return (unsigned long)OSSwapLittleToHostInt32((uint32_t)x); } static __inline__ @@ -453,7 +293,7 @@ NXSwapLittleLongLongToHost( unsigned long long x ) { - return (x); + return (unsigned long long)OSSwapLittleToHostInt64((uint64_t)x); } static __inline__ @@ -462,7 +302,7 @@ NXSwapLittleDoubleToHost( NXSwappedDouble x ) { - return NXConvertSwappedDoubleToHost(x); + return NXConvertSwappedDoubleToHost((NXSwappedDouble)OSSwapLittleToHostInt64((uint64_t)x)); } static __inline__ @@ -471,7 +311,7 @@ NXSwapLittleFloatToHost( NXSwappedFloat x ) { - return NXConvertSwappedFloatToHost(x); + return NXConvertSwappedFloatToHost((NXSwappedFloat)OSSwapLittleToHostInt32((uint32_t)x)); } static __inline__ @@ -480,7 +320,7 @@ NXSwapHostShortToLittle( unsigned short x ) { - return (x); + return (unsigned short)OSSwapHostToLittleInt16((uint16_t)x); } static __inline__ @@ -489,7 +329,7 @@ NXSwapHostIntToLittle( unsigned int x ) { - return (x); + return (unsigned int)OSSwapHostToLittleInt32((uint32_t)x); } static __inline__ @@ -498,7 +338,7 @@ NXSwapHostLongToLittle( unsigned long x ) { - return (x); + return (unsigned long)OSSwapHostToLittleInt32((uint32_t)x); } static __inline__ @@ -507,27 +347,25 @@ NXSwapHostLongLongToLittle( unsigned long long x ) { - return (x); + return (unsigned long long)OSSwapHostToLittleInt64((uint64_t)x); } static __inline__ NXSwappedDouble NXSwapHostDoubleToLittle( - double x + double x ) { - return NXConvertHostDoubleToSwapped(x); + return (NXSwappedDouble)OSSwapHostToLittleInt64((uint64_t)NXConvertHostDoubleToSwapped(x)); } static __inline__ NXSwappedFloat NXSwapHostFloatToLittle( - float x + float x ) { - return NXConvertHostFloatToSwapped(x); + return (NXSwappedFloat)OSSwapHostToLittleInt32((uint32_t)NXConvertHostFloatToSwapped(x)); } -#endif /* __LITTLE_ENDIAN__ */ - #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */