]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/architecture/i386/byte_order.h
xnu-344.34.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / architecture / i386 / byte_order.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
de355530
A
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.
1c79356b 11 *
de355530
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
de355530
A
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.
1c79356b
A
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
36static __inline__
37unsigned short
38NXSwapShort(
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
49static __inline__
50unsigned long
51NXSwapInt(
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
62static __inline__
63unsigned long
64NXSwapLong(
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
79static __inline__
80unsigned long long
81NXSwapLongLong(
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
98static __inline__ NXSwappedFloat
99NXConvertHostFloatToSwapped(float x)
100{
101 union fconv {
102 float number;
103 NXSwappedFloat sf;
104 };
105 return ((union fconv *)&x)->sf;
106}
107
108static __inline__ float
109NXConvertSwappedFloatToHost(NXSwappedFloat x)
110{
111 union fconv {
112 float number;
113 NXSwappedFloat sf;
114 };
115 return ((union fconv *)&x)->number;
116}
117
118static __inline__ NXSwappedDouble
119NXConvertHostDoubleToSwapped(double x)
120{
121 union dconv {
122 double number;
123 NXSwappedDouble sd;
124 };
125 return ((union dconv *)&x)->sd;
126}
127
128static __inline__ double
129NXConvertSwappedDoubleToHost(NXSwappedDouble x)
130{
131 union dconv {
132 double number;
133 NXSwappedDouble sd;
134 };
135 return ((union dconv *)&x)->number;
136}
137
138static __inline__ NXSwappedFloat
139NXSwapFloat(NXSwappedFloat x)
140{
141 return NXSwapLong(x);
142}
143
144static __inline__ NXSwappedDouble
145NXSwapDouble(NXSwappedDouble x)
146{
147 return NXSwapLongLong(x);
148}