]> git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/architecture/byte_order.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / architecture / 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) 1992 NeXT Computer, Inc.
27 *
28 * Byte ordering conversion.
29 *
30 * HISTORY
31 *
32 * 20 October 1992 ? at NeXT
33 * Added #ifdef wrapper to prevent multiple inclusions of this file.
34 *
35 * 8 October 1992 ? at NeXT
36 * Converted to NXxxx versions. Condensed history.
37 *
38 * 18 May 1992 ? at NeXT
39 * Created.
40 */
41
42 #ifndef _ARCHITECTURE_BYTE_ORDER_H_
43 #define _ARCHITECTURE_BYTE_ORDER_H_
44
45 typedef unsigned long NXSwappedFloat;
46 typedef unsigned long long NXSwappedDouble;
47
48 #if defined (__ppc__)
49 #include "architecture/ppc/byte_order.h"
50 #elif defined (__i386__)
51 #include "architecture/i386/byte_order.h"
52 #else
53 #error architecture not supported
54 #endif
55
56 /*
57 * Identify the byte order
58 * of the current host.
59 */
60
61 enum NXByteOrder {
62 NX_UnknownByteOrder,
63 NX_LittleEndian,
64 NX_BigEndian
65 };
66
67 static __inline__
68 enum NXByteOrder
69 NXHostByteOrder(void)
70 {
71 unsigned int _x;
72
73 _x = (NX_BigEndian << 24) | NX_LittleEndian;
74
75 return ((enum NXByteOrder)*((unsigned char *)&_x));
76 }
77
78 /*
79 * The predicated versions
80 * are defined here in terms
81 * of the unpredicated ones.
82 */
83
84 #if __BIG_ENDIAN__
85
86 static __inline__
87 unsigned short
88 NXSwapBigShortToHost(
89 unsigned short x
90 )
91 {
92 return (x);
93 }
94
95 static __inline__
96 unsigned int
97 NXSwapBigIntToHost(
98 unsigned int x
99 )
100 {
101 return (x);
102 }
103
104 static __inline__
105 unsigned long
106 NXSwapBigLongToHost(
107 unsigned long x
108 )
109 {
110 return (x);
111 }
112
113 static __inline__
114 unsigned long long
115 NXSwapBigLongLongToHost(
116 unsigned long long x
117 )
118 {
119 return (x);
120 }
121
122 #ifndef KERNEL
123
124 static __inline__
125 double
126 NXSwapBigDoubleToHost(
127 NXSwappedDouble x
128 )
129 {
130 return NXConvertSwappedDoubleToHost(x);
131 }
132
133 static __inline__
134 float
135 NXSwapBigFloatToHost(
136 NXSwappedFloat x
137 )
138 {
139 return NXConvertSwappedFloatToHost(x);
140 }
141
142 #endif /* KERNEL */
143
144 static __inline__
145 unsigned short
146 NXSwapHostShortToBig(
147 unsigned short x
148 )
149 {
150 return (x);
151 }
152
153 static __inline__
154 unsigned int
155 NXSwapHostIntToBig(
156 unsigned int x
157 )
158 {
159 return (x);
160 }
161
162 static __inline__
163 unsigned long
164 NXSwapHostLongToBig(
165 unsigned long x
166 )
167 {
168 return (x);
169 }
170
171 static __inline__
172 unsigned long long
173 NXSwapHostLongLongToBig(
174 unsigned long long x
175 )
176 {
177 return (x);
178 }
179
180 #ifndef KERNEL
181
182 static __inline__
183 NXSwappedDouble
184 NXSwapHostDoubleToBig(
185 double x
186 )
187 {
188 return NXConvertHostDoubleToSwapped(x);
189 }
190
191 static __inline__
192 NXSwappedFloat
193 NXSwapHostFloatToBig(
194 float x
195 )
196 {
197 return NXConvertHostFloatToSwapped(x);
198 }
199
200 #endif /* KERNEL */
201
202 static __inline__
203 unsigned short
204 NXSwapLittleShortToHost(
205 unsigned short x
206 )
207 {
208 return (NXSwapShort(x));
209 }
210
211 static __inline__
212 unsigned int
213 NXSwapLittleIntToHost(
214 unsigned int x
215 )
216 {
217 return (NXSwapInt(x));
218 }
219
220 static __inline__
221 unsigned long
222 NXSwapLittleLongToHost(
223 unsigned long x
224 )
225 {
226 return (NXSwapLong(x));
227 }
228
229 static __inline__
230 unsigned long long
231 NXSwapLittleLongLongToHost(
232 unsigned long long x
233 )
234 {
235 return (NXSwapLongLong(x));
236 }
237
238 #ifndef KERNEL
239
240 static __inline__
241 double
242 NXSwapLittleDoubleToHost(
243 NXSwappedDouble x
244 )
245 {
246 return NXConvertSwappedDoubleToHost(NXSwapDouble(x));
247 }
248
249 static __inline__
250 float
251 NXSwapLittleFloatToHost(
252 NXSwappedFloat x
253 )
254 {
255 return NXConvertSwappedFloatToHost(NXSwapFloat(x));
256 }
257
258 #endif /* KERNEL */
259
260 static __inline__
261 unsigned short
262 NXSwapHostShortToLittle(
263 unsigned short x
264 )
265 {
266 return (NXSwapShort(x));
267 }
268
269 static __inline__
270 unsigned int
271 NXSwapHostIntToLittle(
272 unsigned int x
273 )
274 {
275 return (NXSwapInt(x));
276 }
277
278 static __inline__
279 unsigned long
280 NXSwapHostLongToLittle(
281 unsigned long x
282 )
283 {
284 return (NXSwapLong(x));
285 }
286
287 static __inline__
288 unsigned long long
289 NXSwapHostLongLongToLittle(
290 unsigned long long x
291 )
292 {
293 return (NXSwapLongLong(x));
294 }
295
296 #ifndef KERNEL
297
298 static __inline__
299 NXSwappedDouble
300 NXSwapHostDoubleToLittle(
301 double x
302 )
303 {
304 return NXSwapDouble(NXConvertHostDoubleToSwapped(x));
305 }
306
307 static __inline__
308 NXSwappedFloat
309 NXSwapHostFloatToLittle(
310 float x
311 )
312 {
313 return NXSwapFloat(NXConvertHostFloatToSwapped(x));
314 }
315
316 #endif /* KERNEL */
317 #endif /*__BIG_ENDIAN__ */
318
319 #if __LITTLE_ENDIAN__
320
321 static __inline__
322 unsigned short
323 NXSwapBigShortToHost(
324 unsigned short x
325 )
326 {
327 return (NXSwapShort(x));
328 }
329
330 static __inline__
331 unsigned int
332 NXSwapBigIntToHost(
333 unsigned int x
334 )
335 {
336 return (NXSwapInt(x));
337 }
338
339 static __inline__
340 unsigned long
341 NXSwapBigLongToHost(
342 unsigned long x
343 )
344 {
345 return (NXSwapLong(x));
346 }
347
348 static __inline__
349 unsigned long long
350 NXSwapBigLongLongToHost(
351 unsigned long long x
352 )
353 {
354 return (NXSwapLongLong(x));
355 }
356
357 static __inline__
358 double
359 NXSwapBigDoubleToHost(
360 NXSwappedDouble x
361 )
362 {
363 return NXConvertSwappedDoubleToHost(NXSwapDouble(x));
364 }
365
366 static __inline__
367 float
368 NXSwapBigFloatToHost(
369 NXSwappedFloat x
370 )
371 {
372 return NXConvertSwappedFloatToHost(NXSwapFloat(x));
373 }
374
375 static __inline__
376 unsigned short
377 NXSwapHostShortToBig(
378 unsigned short x
379 )
380 {
381 return (NXSwapShort(x));
382 }
383
384 static __inline__
385 unsigned int
386 NXSwapHostIntToBig(
387 unsigned int x
388 )
389 {
390 return (NXSwapInt(x));
391 }
392
393 static __inline__
394 unsigned long
395 NXSwapHostLongToBig(
396 unsigned long x
397 )
398 {
399 return (NXSwapLong(x));
400 }
401
402 static __inline__
403 unsigned long long
404 NXSwapHostLongLongToBig(
405 unsigned long long x
406 )
407 {
408 return (NXSwapLongLong(x));
409 }
410
411 static __inline__
412 NXSwappedDouble
413 NXSwapHostDoubleToBig(
414 double x
415 )
416 {
417 return (NXSwapDouble(NXConvertHostDoubleToSwapped(x)));
418 }
419
420 static __inline__
421 NXSwappedFloat
422 NXSwapHostFloatToBig(
423 float x
424 )
425 {
426 return (NXSwapFloat(NXConvertHostFloatToSwapped(x)));
427 }
428
429 static __inline__
430 unsigned short
431 NXSwapLittleShortToHost(
432 unsigned short x
433 )
434 {
435 return (x);
436 }
437
438 static __inline__
439 unsigned int
440 NXSwapLittleIntToHost(
441 unsigned int x
442 )
443 {
444 return (x);
445 }
446
447 static __inline__
448 unsigned long
449 NXSwapLittleLongToHost(
450 unsigned long x
451 )
452 {
453 return (x);
454 }
455
456 static __inline__
457 unsigned long long
458 NXSwapLittleLongLongToHost(
459 unsigned long long x
460 )
461 {
462 return (x);
463 }
464
465 static __inline__
466 double
467 NXSwapLittleDoubleToHost(
468 NXSwappedDouble x
469 )
470 {
471 return NXConvertSwappedDoubleToHost(x);
472 }
473
474 static __inline__
475 float
476 NXSwapLittleFloatToHost(
477 NXSwappedFloat x
478 )
479 {
480 return NXConvertSwappedFloatToHost(x);
481 }
482
483 static __inline__
484 unsigned short
485 NXSwapHostShortToLittle(
486 unsigned short x
487 )
488 {
489 return (x);
490 }
491
492 static __inline__
493 unsigned int
494 NXSwapHostIntToLittle(
495 unsigned int x
496 )
497 {
498 return (x);
499 }
500
501 static __inline__
502 unsigned long
503 NXSwapHostLongToLittle(
504 unsigned long x
505 )
506 {
507 return (x);
508 }
509
510 static __inline__
511 unsigned long long
512 NXSwapHostLongLongToLittle(
513 unsigned long long x
514 )
515 {
516 return (x);
517 }
518
519 static __inline__
520 NXSwappedDouble
521 NXSwapHostDoubleToLittle(
522 double x
523 )
524 {
525 return NXConvertHostDoubleToSwapped(x);
526 }
527
528 static __inline__
529 NXSwappedFloat
530 NXSwapHostFloatToLittle(
531 float x
532 )
533 {
534 return NXConvertHostFloatToSwapped(x);
535 }
536
537 #endif /* __LITTLE_ENDIAN__ */
538
539 #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */