]> git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/ppc/byte_order.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / architecture / ppc / byte_order.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1996 NeXT Software, Inc.
27 *
28 * Byte ordering conversion (for ppc).
29 *
30 * HISTORY
31 *
32 * 29-Dec-96 Umesh Vaishampayan (umeshv@NeXT.com)
33 * Ported from m98k.
34 *
35 * 8 October 1992 ? at NeXT
36 * Converted to NXxxx versions. Condensed history.
37 *
38 * 28 August 1992 Bruce Martin @NeXT
39 * Created.
40 */
41
42 static __inline__
43 unsigned short
44 NXSwapShort(
45 unsigned short inv
46 )
47 {
48 union sconv {
49 unsigned short us;
50 unsigned char uc[2];
51 } *inp, outv;
52
53 inp = (union sconv *)&inv;
54
55 outv.uc[0] = inp->uc[1];
56 outv.uc[1] = inp->uc[0];
57
58 return (outv.us);
59 }
60
61 static __inline__
62 unsigned int
63 NXSwapInt(
64 unsigned int inv
65 )
66 {
67 union iconv {
68 unsigned int ui;
69 unsigned char uc[4];
70 } *inp, outv;
71
72 inp = (union iconv *)&inv;
73
74 outv.uc[0] = inp->uc[3];
75 outv.uc[1] = inp->uc[2];
76 outv.uc[2] = inp->uc[1];
77 outv.uc[3] = inp->uc[0];
78
79 return (outv.ui);
80 }
81
82 static __inline__
83 unsigned long
84 NXSwapLong(
85 unsigned long inv
86 )
87 {
88 union lconv {
89 unsigned long ul;
90 unsigned char uc[4];
91 } *inp, outv;
92
93 inp = (union lconv *)&inv;
94
95 outv.uc[0] = inp->uc[3];
96 outv.uc[1] = inp->uc[2];
97 outv.uc[2] = inp->uc[1];
98 outv.uc[3] = inp->uc[0];
99
100 return (outv.ul);
101 }
102
103 static __inline__
104 unsigned long long
105 NXSwapLongLong(
106 unsigned long long inv
107 )
108 {
109 union llconv {
110 unsigned long long ull;
111 unsigned char uc[8];
112 } *inp, outv;
113
114 inp = (union llconv *)&inv;
115
116 outv.uc[0] = inp->uc[7];
117 outv.uc[1] = inp->uc[6];
118 outv.uc[2] = inp->uc[5];
119 outv.uc[3] = inp->uc[4];
120 outv.uc[4] = inp->uc[3];
121 outv.uc[5] = inp->uc[2];
122 outv.uc[6] = inp->uc[1];
123 outv.uc[7] = inp->uc[0];
124
125 return (outv.ull);
126 }
127
128 #ifndef KERNEL
129
130 static __inline__ NXSwappedFloat
131 NXConvertHostFloatToSwapped(float x)
132 {
133 union fconv {
134 float number;
135 NXSwappedFloat sf;
136 };
137 return ((union fconv *)&x)->sf;
138 }
139
140 static __inline__ float
141 NXConvertSwappedFloatToHost(NXSwappedFloat x)
142 {
143 union fconv {
144 float number;
145 NXSwappedFloat sf;
146 };
147 return ((union fconv *)&x)->number;
148 }
149
150 static __inline__ NXSwappedDouble
151 NXConvertHostDoubleToSwapped(double x)
152 {
153 union dconv {
154 double number;
155 NXSwappedDouble sd;
156 };
157 return ((union dconv *)&x)->sd;
158 }
159
160 static __inline__ double
161 NXConvertSwappedDoubleToHost(NXSwappedDouble x)
162 {
163 union dconv {
164 double number;
165 NXSwappedDouble sd;
166 };
167 return ((union dconv *)&x)->number;
168 }
169
170 static __inline__ NXSwappedFloat
171 NXSwapFloat(NXSwappedFloat x)
172 {
173 return NXSwapLong(x);
174 }
175
176 static __inline__ NXSwappedDouble
177 NXSwapDouble(NXSwappedDouble x)
178 {
179 return NXSwapLongLong(x);
180 }
181
182 #endif /* ! KERNEL */