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