1 | /*
|
---|
2 | ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
|
---|
3 | ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
|
---|
4 | ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
|
---|
5 | ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
|
---|
6 | ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
|
---|
7 | ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
---|
8 | ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
|
---|
9 | ** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
|
---|
10 | **
|
---|
11 | ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
|
---|
12 | ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
|
---|
13 | ** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
|
---|
14 | ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
|
---|
15 | ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
|
---|
16 | ** THE UNITED STATES.
|
---|
17 | **
|
---|
18 | ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
|
---|
19 | **
|
---|
20 | ** $Revision: 1.1 $
|
---|
21 | ** $Date: 2000-02-25 00:33:51 $
|
---|
22 | */
|
---|
23 | #ifndef __FX64_H__
|
---|
24 | #define __FX64_H__
|
---|
25 |
|
---|
26 | #include "3dfx.h"
|
---|
27 |
|
---|
28 | /*
|
---|
29 | ** first figure out what compiler/os we are using and what is supported
|
---|
30 | */
|
---|
31 |
|
---|
32 | #if (__IBMCPP__ >= 360)
|
---|
33 | #define _MSC_VER
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | /*
|
---|
37 | ** WATCOMC
|
---|
38 | */
|
---|
39 | #if defined(__WATCOMC__)
|
---|
40 | #define FX_BIT64(n) ( FX_SHL64( i64_one, n ) )
|
---|
41 | /*
|
---|
42 | ** GCC
|
---|
43 | */
|
---|
44 | #elif defined(__GNUC__)
|
---|
45 | typedef signed long long FxI64;
|
---|
46 | typedef unsigned long long FxU64;
|
---|
47 | #define NATIVE_64_SUPPORT 1
|
---|
48 | #define FX_MASK64(n) (0xFFFFFFFFFFFFFFFFLL >> (64-(n)))
|
---|
49 | #define FX_BIT64(n) (((FxI64)1) << (n))
|
---|
50 | /*
|
---|
51 | ** Microsoft C
|
---|
52 | */
|
---|
53 | #elif defined(_MSC_VER)
|
---|
54 | typedef signed __int64 FxI64;
|
---|
55 | typedef unsigned __int64 FxU64;
|
---|
56 |
|
---|
57 | #define FX_MASK64(n) (0xFFFFFFFFFFFFFFFF >> (64-(n)))
|
---|
58 | #define FX_BIT64(n) (((FxI64)1) << (n))
|
---|
59 | #define NATIVE_64_SUPPORT 1
|
---|
60 |
|
---|
61 | #elif (__IBMCPP__ < 360)
|
---|
62 |
|
---|
63 | #define NATIVE_64_SUPPORT 0
|
---|
64 |
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | /*
|
---|
68 | ** The following code is for systems with native 64-bit data types
|
---|
69 | */
|
---|
70 | #ifdef NATIVE_64_SUPPORT
|
---|
71 |
|
---|
72 | #define FX_ADD64( a, b ) ((a) + (b))
|
---|
73 | #define FX_AND64( a, b ) ((a) & (b))
|
---|
74 | #define FX_CMP64( a, b ) error
|
---|
75 | #define FX_COMP64( a ) (~(a))
|
---|
76 | #define FX_CREATE64( a, b ) ( (((FxI64) (a)) << 32) | (b) )
|
---|
77 | #define FX_COPY32( a, b ) a = (b)
|
---|
78 | #define FX_EQ064( a ) ( (a) == 0 )
|
---|
79 | #define FX_LO64(a) ((FxI32)(a))
|
---|
80 | #define FX_HI64(a) ((FxI32)FX_SHR64(a,32))
|
---|
81 | #define FX_MUL32( a, b ) (( FxI64 )( ( FxI64 ) (a) * ( FxI64 ) (b) ) )
|
---|
82 | #define FX_MUL64( a, b ) ((a) * (b))
|
---|
83 | #define FX_NEG64( a ) (-(a))
|
---|
84 | #define FX_OR64( a, b ) ((a) | (b))
|
---|
85 | #define FX_SET64( a, b, c ) a = (c) | (((FxI64)(b))<<32)
|
---|
86 | #define FX_SHL64( a, n ) ((a) << (n)) // n < 64
|
---|
87 | #define FX_SHR64( a, n ) ((a) >> (n)) // n < 64
|
---|
88 | #define FX_SUB64( a, b ) ((a) - (b))
|
---|
89 | #define FX_XOR64( a, b ) ((a) ^ (b))
|
---|
90 | #define FX_FLOATTO64( a ) ((FxI64)(a))
|
---|
91 | #define FX_64TOFLOAT( a ) (float)(a)
|
---|
92 | #define FX_64TODBL( a ) (double)(a)
|
---|
93 |
|
---|
94 | /*
|
---|
95 | ** The following code is for Watcom C
|
---|
96 | */
|
---|
97 | #else
|
---|
98 |
|
---|
99 | typedef struct
|
---|
100 | {
|
---|
101 | FxI32 hi;
|
---|
102 | FxU32 lo;
|
---|
103 | } FxI64;
|
---|
104 |
|
---|
105 | typedef struct
|
---|
106 | {
|
---|
107 | FxU32 hi;
|
---|
108 | FxU32 lo;
|
---|
109 | } FxU64;
|
---|
110 |
|
---|
111 | extern FxI64 i64_one;
|
---|
112 | extern FxI64 i64_zero;
|
---|
113 |
|
---|
114 | #define FX_ADD64( a, b ) ( __FX_ADD64( (a).hi, (a).lo, (b).hi, (b).lo ) )
|
---|
115 | #define FX_AND64( a, b ) ( __FX_AND64( a, b ) )
|
---|
116 | #define FX_CMP64( a, b ) ( __FX_CMP64( a, b ) )
|
---|
117 | #define FX_COMP64( a ) ( __FX_COMP64( a ) )
|
---|
118 | #define FX_CREATE64( a, b ) ( __FX_CREATE64( a, b ) )
|
---|
119 | #define FX_COPY32( a, b ) ( a = __FX_32TO64( (b) ) )
|
---|
120 | #define FX_EQ064( a ) ( ( (a).lo == 0 ) && ( (a).hi == 0 ) )
|
---|
121 | #define FX_HI64( a ) ( (a).hi )
|
---|
122 | #define FX_LO64( a ) ( (a).lo )
|
---|
123 | #define FX_MASK64( n ) ( __FX_MASK64( n ) )
|
---|
124 | #define FX_MUL32( a, b ) ( __FX_MUL32( (a), (b) ) )
|
---|
125 | #define FX_MUL64( a, b ) ( __FX_MUL64( (a), (b) ) )
|
---|
126 | #define FX_NEG64( a ) ( __FX_NEG64( (a).hi, (a).lo ) )
|
---|
127 | #define FX_OR64( a, b ) ( __FX_OR64( a, b ) )
|
---|
128 | #define FX_SET64( a, b, c ) {(a).hi = b; (a).lo = c;}
|
---|
129 | #define FX_SHL64( a, n ) ( __FX_SHL64( (a).hi, (a).lo, n ) )
|
---|
130 | #define FX_SHR64( a, n ) ( __FX_SHR64( (a).hi, (a).lo, n ) )
|
---|
131 | #define FX_SUB64( a, b ) ( __FX_SUB64( (a).hi, (a).lo, (b).hi, (b).lo ) )
|
---|
132 | #define FX_FLOATTO64( a ) ( __FX_FLOATTO64((a)) )
|
---|
133 | #define FX_64TOFLOAT( a ) ( __FX_64TOFLOAT((a)) )
|
---|
134 |
|
---|
135 | /*
|
---|
136 | ** The following functions are implemented as inline assembly
|
---|
137 | */
|
---|
138 | FxI64 __FX_ADD64( FxI32 a_hi, FxU32 a_lo, FxI32 b_hi, FxU32 b_lo );
|
---|
139 | FxI64 __FX_32TO64( FxI32 value );
|
---|
140 | FxI64 __FX_MASK64( int n );
|
---|
141 | FxI64 __FX_MUL32( FxI32 a, FxI32 b );
|
---|
142 | FxI64 __FX_NEG64( FxI32 hi, FxU32 lo );
|
---|
143 | FxI64 __FX_SHL64( FxI32 hi, FxU32 lo, int n );
|
---|
144 | FxI64 __FX_SHR64( FxI32 hi, FxU32 lo, int n );
|
---|
145 | FxI64 __FX_SUB64( FxI32 a_hi, FxU32 a_lo, FxI32 b_hi, FxU32 b_lo );
|
---|
146 |
|
---|
147 | /*
|
---|
148 | ** The following functions are implemented as C functions
|
---|
149 | */
|
---|
150 | FxI64 __FX_AND64( FxI64 a, FxI64 b );
|
---|
151 | int __FX_CMP64( FxI64 a, FxI64 b );
|
---|
152 | FxI64 __FX_COMP64( FxI64 a );
|
---|
153 | FxI64 __FX_CREATE64( FxI32 a, FxU32 b );
|
---|
154 | FxI64 __FX_FLOATTO64( float a );
|
---|
155 | FxI64 __FX_MUL64( FxI64 a, FxI64 b );
|
---|
156 | FxI64 __FX_OR64( FxI64 a, FxI64 b );
|
---|
157 | float __FX_64TOFLOAT( FxI64 );
|
---|
158 |
|
---|
159 | #pragma aux __FX_32TO64 = \
|
---|
160 | "cdq" \
|
---|
161 | "mov [esi], edx" \
|
---|
162 | "mov [esi+4], eax" \
|
---|
163 | parm [eax] \
|
---|
164 | modify [edx] \
|
---|
165 | value struct struct;
|
---|
166 |
|
---|
167 | #pragma aux __FX_ADD64 = \
|
---|
168 | "add eax, ecx" \
|
---|
169 | "adc edx, ebx" \
|
---|
170 | "mov [esi], edx" \
|
---|
171 | "mov [esi+4], eax" \
|
---|
172 | parm [edx] [eax] [ebx] [ecx] \
|
---|
173 | value struct struct;
|
---|
174 |
|
---|
175 | #pragma aux __FX_MUL32 = \
|
---|
176 | "imul edx" \
|
---|
177 | "mov [esi], edx" \
|
---|
178 | "mov [esi+4], eax" \
|
---|
179 | parm [edx] [eax] \
|
---|
180 | value struct struct;
|
---|
181 |
|
---|
182 | #pragma aux __FX_SUB64 = \
|
---|
183 | "sub eax, ecx" \
|
---|
184 | "sbb edx, ebx" \
|
---|
185 | "mov [esi], edx" \
|
---|
186 | "mov [esi+4], eax" \
|
---|
187 | parm [edx] [eax] [ebx] [ecx] \
|
---|
188 | value struct struct;
|
---|
189 |
|
---|
190 | #pragma aux __FX_SHL64 = \
|
---|
191 | "cmp cl, 32" \
|
---|
192 | "jl SHL_LT32" \
|
---|
193 | "sub cl, 32" \
|
---|
194 | "mov edx, eax " \
|
---|
195 | "mov eax, 0 " \
|
---|
196 | "shl edx, cl" \
|
---|
197 | "jmp SHL_DONE" \
|
---|
198 | "SHL_LT32:" \
|
---|
199 | "shld edx, eax, cl" \
|
---|
200 | "sal eax, cl" \
|
---|
201 | "SHL_DONE:" \
|
---|
202 | "mov [esi], edx" \
|
---|
203 | "mov [esi+4], eax" \
|
---|
204 | parm [edx] [eax] [cx] \
|
---|
205 | value struct struct;
|
---|
206 |
|
---|
207 | #pragma aux __FX_SHR64 = \
|
---|
208 | "cmp cl, 32" \
|
---|
209 | "jl SHR_LT32" \
|
---|
210 | "sub cl, 32 " \
|
---|
211 | "mov eax, edx" \
|
---|
212 | "test edx, 080000000h" \
|
---|
213 | "jz SHR_GE32_POSITIVE" \
|
---|
214 | "SHR_GE32_NEGATIVE:" \
|
---|
215 | "mov edx, 0FFFFFFFFh" \
|
---|
216 | "or eax, 080000000h" \
|
---|
217 | "sar eax, cl" \
|
---|
218 | "jmp SHR_DONE" \
|
---|
219 | "SHR_GE32_POSITIVE:" \
|
---|
220 | "mov edx, 0" \
|
---|
221 | "shr eax, cl" \
|
---|
222 | "jmp SHR_DONE" \
|
---|
223 | "SHR_LT32: " \
|
---|
224 | "shrd eax, edx, cl" \
|
---|
225 | "sar edx, cl" \
|
---|
226 | "SHR_DONE: " \
|
---|
227 | "mov [esi], edx" \
|
---|
228 | "mov [esi+4], eax" \
|
---|
229 | parm [edx] [eax] [cx] \
|
---|
230 | value struct struct;
|
---|
231 |
|
---|
232 | #pragma aux __FX_NEG64 = \
|
---|
233 | "neg eax" \
|
---|
234 | "adc edx, 0" \
|
---|
235 | "neg edx" \
|
---|
236 | "mov [esi], edx" \
|
---|
237 | "mov [esi+4], eax" \
|
---|
238 | parm [edx] [eax] \
|
---|
239 | value struct struct;
|
---|
240 |
|
---|
241 | #pragma aux __FX_MASK64 = \
|
---|
242 | "mov edx, 64" \
|
---|
243 | "sub edx, ecx" \
|
---|
244 | "mov ecx, edx" \
|
---|
245 | "mov edx, 0ffffffffh" \
|
---|
246 | "mov eax, 0ffffffffh" \
|
---|
247 | "cmp cl, 32" \
|
---|
248 | "jl M64_LT32" \
|
---|
249 | "sub cl, 32 " \
|
---|
250 | "mov eax, edx" \
|
---|
251 | "mov edx, 0" \
|
---|
252 | "shr eax, cl" \
|
---|
253 | "jmp M64_DONE" \
|
---|
254 | "M64_LT32: " \
|
---|
255 | "shrd eax, edx, cl" \
|
---|
256 | "shr edx, cl" \
|
---|
257 | "M64_DONE: " \
|
---|
258 | "mov [esi], edx" \
|
---|
259 | "mov [esi+4], eax" \
|
---|
260 | modify [edx eax] \
|
---|
261 | parm [ecx] \
|
---|
262 | value struct struct;
|
---|
263 |
|
---|
264 | #endif /* __WATCOMC__ */
|
---|
265 |
|
---|
266 | /*
|
---|
267 | ** The following is shared between NATIVE64 and Watcom
|
---|
268 | */
|
---|
269 |
|
---|
270 | // a | -(a & (1 << n)) branchless, but may not be good implement for PC
|
---|
271 | // for constant n, does &, -, |
|
---|
272 | #define FX_SGNEXT64( a, n ) (FX_OR64((a), FX_NEG64(FX_AND64((a), FX_SHL64(FX_CREATE64(0,1), (n))))))
|
---|
273 |
|
---|
274 | #endif /* __FX64_H__ */
|
---|
275 |
|
---|