Annotation of XNU/EXTERNAL_HEADERS/architecture/i386/byte_order.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      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.
                     11:  * 
                     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
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /*
                     23:  * Copyright (c) 1992 NeXT Computer, Inc.
                     24:  *
                     25:  * Byte ordering conversion (for i386).
                     26:  *
                     27:  * HISTORY
                     28:  *
                     29:  * 8 October 1992 ? at NeXT
                     30:  *     Converted to NXxxx versions.  Condensed history.
                     31:  *
                     32:  * 18 May 1992 ? at NeXT
                     33:  *     Created.
                     34:  */
                     35:  
                     36: static __inline__
                     37: unsigned short
                     38: NXSwapShort(
                     39:     unsigned short     inv
                     40: )
                     41: {
                     42:     register unsigned short value = inv;
                     43:     
                     44:     __asm__ volatile( "xchgb %h1, %b1" : "=q" (value) : "0" (value));
                     45: 
                     46:     return (value);
                     47: }
                     48:  
                     49: static __inline__
                     50: unsigned long
                     51: NXSwapInt(
                     52:     unsigned long inv
                     53: )
                     54: {
                     55:     register unsigned int outv = inv;
                     56:     
                     57:     __asm__ volatile( "bswap %0" : "=r"        (outv) : "0" (outv));
                     58:        
                     59:     return (outv);
                     60: }
                     61:  
                     62: static __inline__
                     63: unsigned long
                     64: NXSwapLong(
                     65:     unsigned long      inv
                     66: )
                     67: {
                     68:     unsigned long      outv;
                     69:     
                     70:     __asm__ volatile(
                     71:        "bswap %0"
                     72:        
                     73:        : "=r"  (outv)
                     74:        : "0"   (inv));
                     75:        
                     76:     return (outv);
                     77: }
                     78: 
                     79: static __inline__
                     80: unsigned long long
                     81: NXSwapLongLong(
                     82:     unsigned long long inv
                     83: )
                     84: {
                     85:     union llconv {
                     86:        unsigned long long      ull;
                     87:        unsigned long           ul[2];
                     88:     } *inp, outv;
                     89:     
                     90:     inp = (union llconv *)&inv;
                     91:     
                     92:     outv.ul[0] = NXSwapLong(inp->ul[1]);
                     93:     outv.ul[1] = NXSwapLong(inp->ul[0]);
                     94:        
                     95:     return (outv.ull);
                     96: }
                     97: 
                     98: static __inline__ NXSwappedFloat
                     99: NXConvertHostFloatToSwapped(float x)
                    100: {
                    101:     union fconv {
                    102:        float number;
                    103:        NXSwappedFloat sf;
                    104:     };
                    105:     return ((union fconv *)&x)->sf;
                    106: }
                    107: 
                    108: static __inline__ float
                    109: NXConvertSwappedFloatToHost(NXSwappedFloat x)
                    110: {
                    111:     union fconv {
                    112:        float number;
                    113:        NXSwappedFloat sf;
                    114:     };
                    115:     return ((union fconv *)&x)->number;
                    116: }
                    117: 
                    118: static __inline__ NXSwappedDouble
                    119: NXConvertHostDoubleToSwapped(double x)
                    120: {
                    121:     union dconv {
                    122:        double number;
                    123:        NXSwappedDouble sd;
                    124:     };
                    125:     return ((union dconv *)&x)->sd;
                    126: }
                    127: 
                    128: static __inline__ double
                    129: NXConvertSwappedDoubleToHost(NXSwappedDouble x)
                    130: {
                    131:     union dconv {
                    132:        double number;
                    133:        NXSwappedDouble sd;
                    134:     };
                    135:     return ((union dconv *)&x)->number;
                    136: }
                    137: 
                    138: static __inline__ NXSwappedFloat
                    139: NXSwapFloat(NXSwappedFloat x)
                    140: {
                    141:     return NXSwapLong(x);
                    142: }
                    143: 
                    144: static __inline__ NXSwappedDouble
                    145: NXSwapDouble(NXSwappedDouble x)
                    146: {
                    147:     return NXSwapLongLong(x);
                    148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.