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