]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * Copyright (c) 1992 NeXT Computer, Inc. | |
27 | * | |
28 | * Byte ordering conversion (for i386). | |
29 | * | |
30 | * HISTORY | |
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 | static __inline__ | |
40 | unsigned short | |
41 | NXSwapShort( | |
42 | unsigned short inv | |
43 | ) | |
44 | { | |
45 | register unsigned short value = inv; | |
46 | ||
47 | __asm__ volatile( "xchgb %h1, %b1" : "=q" (value) : "0" (value)); | |
48 | ||
49 | return (value); | |
50 | } | |
51 | ||
52 | static __inline__ | |
53 | unsigned long | |
54 | NXSwapInt( | |
55 | unsigned long inv | |
56 | ) | |
57 | { | |
58 | register unsigned int outv = inv; | |
59 | ||
60 | __asm__ volatile( "bswap %0" : "=r" (outv) : "0" (outv)); | |
61 | ||
62 | return (outv); | |
63 | } | |
64 | ||
65 | static __inline__ | |
66 | unsigned long | |
67 | NXSwapLong( | |
68 | unsigned long inv | |
69 | ) | |
70 | { | |
71 | unsigned long outv; | |
72 | ||
73 | __asm__ volatile( | |
74 | "bswap %0" | |
75 | ||
76 | : "=r" (outv) | |
77 | : "0" (inv)); | |
78 | ||
79 | return (outv); | |
80 | } | |
81 | ||
82 | static __inline__ | |
83 | unsigned long long | |
84 | NXSwapLongLong( | |
85 | unsigned long long inv | |
86 | ) | |
87 | { | |
88 | union llconv { | |
89 | unsigned long long ull; | |
90 | unsigned long ul[2]; | |
91 | } *inp, outv; | |
92 | ||
93 | inp = (union llconv *)&inv; | |
94 | ||
95 | outv.ul[0] = NXSwapLong(inp->ul[1]); | |
96 | outv.ul[1] = NXSwapLong(inp->ul[0]); | |
97 | ||
98 | return (outv.ull); | |
99 | } | |
100 | ||
101 | static __inline__ NXSwappedFloat | |
102 | NXConvertHostFloatToSwapped(float x) | |
103 | { | |
104 | union fconv { | |
105 | float number; | |
106 | NXSwappedFloat sf; | |
107 | }; | |
108 | return ((union fconv *)&x)->sf; | |
109 | } | |
110 | ||
111 | static __inline__ float | |
112 | NXConvertSwappedFloatToHost(NXSwappedFloat x) | |
113 | { | |
114 | union fconv { | |
115 | float number; | |
116 | NXSwappedFloat sf; | |
117 | }; | |
118 | return ((union fconv *)&x)->number; | |
119 | } | |
120 | ||
121 | static __inline__ NXSwappedDouble | |
122 | NXConvertHostDoubleToSwapped(double x) | |
123 | { | |
124 | union dconv { | |
125 | double number; | |
126 | NXSwappedDouble sd; | |
127 | }; | |
128 | return ((union dconv *)&x)->sd; | |
129 | } | |
130 | ||
131 | static __inline__ double | |
132 | NXConvertSwappedDoubleToHost(NXSwappedDouble x) | |
133 | { | |
134 | union dconv { | |
135 | double number; | |
136 | NXSwappedDouble sd; | |
137 | }; | |
138 | return ((union dconv *)&x)->number; | |
139 | } | |
140 | ||
141 | static __inline__ NXSwappedFloat | |
142 | NXSwapFloat(NXSwappedFloat x) | |
143 | { | |
144 | return NXSwapLong(x); | |
145 | } | |
146 | ||
147 | static __inline__ NXSwappedDouble | |
148 | NXSwapDouble(NXSwappedDouble x) | |
149 | { | |
150 | return NXSwapLongLong(x); | |
151 | } |