Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / hppa / spmath / dbl_float.h
blobd5cd4ec74423d6f0ba5f7d00e3992ea3e25bab22
1 /* $NetBSD$ */
3 /* $OpenBSD: dbl_float.h,v 1.10 2004/01/02 14:39:01 mickey Exp $ */
5 /*
6 * Copyright 1996 1995 by Open Software Foundation, Inc.
7 * All Rights Reserved
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose and without fee is hereby granted,
11 * provided that the above copyright notice appears in all copies and
12 * that both the copyright notice and this permission notice appear in
13 * supporting documentation.
15 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17 * FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
22 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
23 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 * pmk1.1
29 * (c) Copyright 1986 HEWLETT-PACKARD COMPANY
31 * To anyone who acknowledges that this file is provided "AS IS"
32 * without any express or implied warranty:
33 * permission to use, copy, modify, and distribute this file
34 * for any purpose is hereby granted without fee, provided that
35 * the above copyright notice and this notice appears in all
36 * copies, and that the name of Hewlett-Packard Company not be
37 * used in advertising or publicity pertaining to distribution
38 * of the software without specific, written prior permission.
39 * Hewlett-Packard Company makes no representations about the
40 * suitability of this software for any purpose.
43 #include <sys/cdefs.h>
45 /**************************************
46 * Declare double precision functions *
47 **************************************/
49 /* 32-bit word grabing functions */
50 #define Dbl_firstword(value) Dallp1(value)
51 #define Dbl_secondword(value) Dallp2(value)
52 #define Dbl_thirdword(value) dummy_location
53 #define Dbl_fourthword(value) dummy_location
55 #define Dbl_sign(object) Dsign(object)
56 #define Dbl_exponent(object) Dexponent(object)
57 #define Dbl_signexponent(object) Dsignexponent(object)
58 #define Dbl_mantissap1(object) Dmantissap1(object)
59 #define Dbl_mantissap2(object) Dmantissap2(object)
60 #define Dbl_exponentmantissap1(object) Dexponentmantissap1(object)
61 #define Dbl_allp1(object) Dallp1(object)
62 #define Dbl_allp2(object) Dallp2(object)
64 /* dbl_and_signs ands the sign bits of each argument and puts the result
65 * into the first argument. dbl_or_signs ors those same sign bits */
66 #define Dbl_and_signs( src1dst, src2) \
67 Dallp1(src1dst) = (Dallp1(src2)|~(1<<31)) & Dallp1(src1dst)
68 #define Dbl_or_signs( src1dst, src2) \
69 Dallp1(src1dst) = (Dallp1(src2)&(1<<31)) | Dallp1(src1dst)
71 /* The hidden bit is always the low bit of the exponent */
72 #define Dbl_clear_exponent_set_hidden(srcdst) Deposit_dexponent(srcdst,1)
73 #define Dbl_clear_signexponent_set_hidden(srcdst) \
74 Deposit_dsignexponent(srcdst,1)
75 #define Dbl_clear_sign(srcdst) Dallp1(srcdst) &= ~(1<<31)
76 #define Dbl_clear_signexponent(srcdst) \
77 Dallp1(srcdst) &= Dmantissap1((unsigned)-1)
79 /* Exponent field for doubles has already been cleared and may be
80 * included in the shift. Here we need to generate two double width
81 * variable shifts. The insignificant bits can be ignored.
82 * MTSAR f(varamount)
83 * VSHD srcdst.high,srcdst.low => srcdst.low
84 * VSHD 0,srcdst.high => srcdst.high
85 * This is very difficult to model with C expressions since the shift amount
86 * could exceed 32. */
87 /* varamount must be less than 64 */
88 #define Dbl_rightshift(srcdstA, srcdstB, varamount) \
89 {if((varamount) >= 32) { \
90 Dallp2(srcdstB) = Dallp1(srcdstA) >> (varamount-32); \
91 Dallp1(srcdstA)=0; \
92 } \
93 else if(varamount > 0) { \
94 Variable_shift_double(Dallp1(srcdstA), Dallp2(srcdstB), \
95 (varamount), Dallp2(srcdstB)); \
96 Dallp1(srcdstA) >>= varamount; \
97 } }
98 /* varamount must be less than 64 */
99 #define Dbl_rightshift_exponentmantissa(srcdstA, srcdstB, varamount) \
100 {if((varamount) >= 32) { \
101 Dallp2(srcdstB) = Dexponentmantissap1(srcdstA) >> ((varamount)-32); \
102 Dallp1(srcdstA) &= (1<<31); /* clear exponentmantissa field */ \
104 else if(varamount > 0) { \
105 Variable_shift_double(Dexponentmantissap1(srcdstA), Dallp2(srcdstB), \
106 (varamount), Dallp2(srcdstB)); \
107 Deposit_dexponentmantissap1(srcdstA, \
108 (Dexponentmantissap1(srcdstA)>>(varamount))); \
110 /* varamount must be less than 64 */
111 #define Dbl_leftshift(srcdstA, srcdstB, varamount) \
112 {if((varamount) >= 32) { \
113 Dallp1(srcdstA) = Dallp2(srcdstB) << (varamount-32); \
114 Dallp2(srcdstB)=0; \
116 else { \
117 if ((varamount) > 0) { \
118 Dallp1(srcdstA) = (Dallp1(srcdstA) << (varamount)) | \
119 (Dallp2(srcdstB) >> (32-(varamount))); \
120 Dallp2(srcdstB) <<= varamount; \
123 #define Dbl_leftshiftby1_withextent(lefta,leftb,right,resulta,resultb) \
124 Shiftdouble(Dallp1(lefta), Dallp2(leftb), 31, Dallp1(resulta)); \
125 Shiftdouble(Dallp2(leftb), Extall(right), 31, Dallp2(resultb))
127 #define Dbl_rightshiftby1_withextent(leftb,right,dst) \
128 Extall(dst) = (Dallp2(leftb) << 31) | ((unsigned)Extall(right) >> 1) | \
129 Extlow(right)
131 #define Dbl_arithrightshiftby1(srcdstA,srcdstB) \
132 Shiftdouble(Dallp1(srcdstA),Dallp2(srcdstB),1,Dallp2(srcdstB));\
133 Dallp1(srcdstA) = (int)Dallp1(srcdstA) >> 1
135 /* Sign extend the sign bit with an integer destination */
136 #define Dbl_signextendedsign(value) Dsignedsign(value)
138 #define Dbl_isone_hidden(dbl_value) (Is_dhidden(dbl_value)!=0)
139 /* Singles and doubles may include the sign and exponent fields. The
140 * hidden bit and the hidden overflow must be included. */
141 #define Dbl_increment(dbl_valueA,dbl_valueB) \
142 if( (Dallp2(dbl_valueB) += 1) == 0 ) Dallp1(dbl_valueA) += 1
143 #define Dbl_increment_mantissa(dbl_valueA,dbl_valueB) \
144 if( (Dmantissap2(dbl_valueB) += 1) == 0 ) \
145 Deposit_dmantissap1(dbl_valueA,dbl_valueA+1)
146 #define Dbl_decrement(dbl_valueA,dbl_valueB) \
147 if( Dallp2(dbl_valueB) == 0 ) Dallp1(dbl_valueA) -= 1; \
148 Dallp2(dbl_valueB) -= 1
150 #define Dbl_isone_sign(dbl_value) (Is_dsign(dbl_value)!=0)
151 #define Dbl_isone_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)!=0)
152 #define Dbl_isone_lowmantissap1(dbl_valueA) (Is_dlowp1(dbl_valueA)!=0)
153 #define Dbl_isone_lowmantissap2(dbl_valueB) (Is_dlowp2(dbl_valueB)!=0)
154 #define Dbl_isone_signaling(dbl_value) (Is_dsignaling(dbl_value)!=0)
155 #define Dbl_is_signalingnan(dbl_value) (Dsignalingnan(dbl_value)==0xfff)
156 #define Dbl_isnotzero(dbl_valueA,dbl_valueB) \
157 (Dallp1(dbl_valueA) || Dallp2(dbl_valueB))
158 #define Dbl_isnotzero_hiddenhigh7mantissa(dbl_value) \
159 (Dhiddenhigh7mantissa(dbl_value)!=0)
160 #define Dbl_isnotzero_exponent(dbl_value) (Dexponent(dbl_value)!=0)
161 #define Dbl_isnotzero_mantissa(dbl_valueA,dbl_valueB) \
162 (Dmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))
163 #define Dbl_isnotzero_mantissap1(dbl_valueA) (Dmantissap1(dbl_valueA)!=0)
164 #define Dbl_isnotzero_mantissap2(dbl_valueB) (Dmantissap2(dbl_valueB)!=0)
165 #define Dbl_isnotzero_exponentmantissa(dbl_valueA,dbl_valueB) \
166 (Dexponentmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))
167 #define Dbl_isnotzero_low4p2(dbl_value) (Dlow4p2(dbl_value)!=0)
168 #define Dbl_iszero(dbl_valueA,dbl_valueB) (Dallp1(dbl_valueA)==0 && \
169 Dallp2(dbl_valueB)==0)
170 #define Dbl_iszero_allp1(dbl_value) (Dallp1(dbl_value)==0)
171 #define Dbl_iszero_allp2(dbl_value) (Dallp2(dbl_value)==0)
172 #define Dbl_iszero_hidden(dbl_value) (Is_dhidden(dbl_value)==0)
173 #define Dbl_iszero_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)==0)
174 #define Dbl_iszero_hiddenhigh3mantissa(dbl_value) \
175 (Dhiddenhigh3mantissa(dbl_value)==0)
176 #define Dbl_iszero_hiddenhigh7mantissa(dbl_value) \
177 (Dhiddenhigh7mantissa(dbl_value)==0)
178 #define Dbl_iszero_sign(dbl_value) (Is_dsign(dbl_value)==0)
179 #define Dbl_iszero_exponent(dbl_value) (Dexponent(dbl_value)==0)
180 #define Dbl_iszero_mantissa(dbl_valueA,dbl_valueB) \
181 (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
182 #define Dbl_iszero_exponentmantissa(dbl_valueA,dbl_valueB) \
183 (Dexponentmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
184 #define Dbl_isinfinity_exponent(dbl_value) \
185 (Dexponent(dbl_value)==DBL_INFINITY_EXPONENT)
186 #define Dbl_isnotinfinity_exponent(dbl_value) \
187 (Dexponent(dbl_value)!=DBL_INFINITY_EXPONENT)
188 #define Dbl_isinfinity(dbl_valueA,dbl_valueB) \
189 (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \
190 Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
191 #define Dbl_isnan(dbl_valueA,dbl_valueB) \
192 (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \
193 (Dmantissap1(dbl_valueA)!=0 || Dmantissap2(dbl_valueB)!=0))
194 #define Dbl_isnotnan(dbl_valueA,dbl_valueB) \
195 (Dexponent(dbl_valueA)!=DBL_INFINITY_EXPONENT || \
196 (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0))
198 #define Dbl_islessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
199 (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \
200 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
201 Dallp2(dbl_op1b) < Dallp2(dbl_op2b)))
202 #define Dbl_isgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
203 (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \
204 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
205 Dallp2(dbl_op1b) > Dallp2(dbl_op2b)))
206 #define Dbl_isnotlessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
207 (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \
208 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
209 Dallp2(dbl_op1b) >= Dallp2(dbl_op2b)))
210 #define Dbl_isnotgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
211 (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \
212 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
213 Dallp2(dbl_op1b) <= Dallp2(dbl_op2b)))
214 #define Dbl_isequal(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
215 ((Dallp1(dbl_op1a) == Dallp1(dbl_op2a)) && \
216 (Dallp2(dbl_op1b) == Dallp2(dbl_op2b)))
218 #define Dbl_leftshiftby8(dbl_valueA,dbl_valueB) \
219 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),24,Dallp1(dbl_valueA)); \
220 Dallp2(dbl_valueB) <<= 8
221 #define Dbl_leftshiftby7(dbl_valueA,dbl_valueB) \
222 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),25,Dallp1(dbl_valueA)); \
223 Dallp2(dbl_valueB) <<= 7
224 #define Dbl_leftshiftby4(dbl_valueA,dbl_valueB) \
225 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),28,Dallp1(dbl_valueA)); \
226 Dallp2(dbl_valueB) <<= 4
227 #define Dbl_leftshiftby3(dbl_valueA,dbl_valueB) \
228 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),29,Dallp1(dbl_valueA)); \
229 Dallp2(dbl_valueB) <<= 3
230 #define Dbl_leftshiftby2(dbl_valueA,dbl_valueB) \
231 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),30,Dallp1(dbl_valueA)); \
232 Dallp2(dbl_valueB) <<= 2
233 #define Dbl_leftshiftby1(dbl_valueA,dbl_valueB) \
234 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),31,Dallp1(dbl_valueA)); \
235 Dallp2(dbl_valueB) <<= 1
237 #define Dbl_rightshiftby8(dbl_valueA,dbl_valueB) \
238 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),8,Dallp2(dbl_valueB)); \
239 Dallp1(dbl_valueA) >>= 8
240 #define Dbl_rightshiftby4(dbl_valueA,dbl_valueB) \
241 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),4,Dallp2(dbl_valueB)); \
242 Dallp1(dbl_valueA) >>= 4
243 #define Dbl_rightshiftby2(dbl_valueA,dbl_valueB) \
244 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),2,Dallp2(dbl_valueB)); \
245 Dallp1(dbl_valueA) >>= 2
246 #define Dbl_rightshiftby1(dbl_valueA,dbl_valueB) \
247 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),1,Dallp2(dbl_valueB)); \
248 Dallp1(dbl_valueA) >>= 1
250 /* This magnitude comparison uses the signless first words and
251 * the regular part2 words. The comparison is graphically:
253 * 1st greater? -------------
255 * 1st less?-----------------+---------
256 * | |
257 * 2nd greater or equal----->| |
258 * False True
260 #define Dbl_ismagnitudeless(leftB,rightB,signlessleft,signlessright) \
261 ((signlessleft <= signlessright) && \
262 ( (signlessleft < signlessright) || (Dallp2(leftB)<Dallp2(rightB)) ))
264 #define Dbl_copytoint_exponentmantissap1(src,dest) \
265 dest = Dexponentmantissap1(src)
267 /* A quiet NaN has the high mantissa bit clear and at least on other (in this
268 * case the adjacent bit) bit set. */
269 #define Dbl_set_quiet(dbl_value) Deposit_dhigh2mantissa(dbl_value,1)
270 #define Dbl_set_exponent(dbl_value, exp) Deposit_dexponent(dbl_value,exp)
272 #define Dbl_set_mantissa(desta,destb,valuea,valueb) \
273 Deposit_dmantissap1(desta,valuea); \
274 Dmantissap2(destb) = Dmantissap2(valueb)
275 #define Dbl_set_mantissap1(desta,valuea) \
276 Deposit_dmantissap1(desta,valuea)
277 #define Dbl_set_mantissap2(destb,valueb) \
278 Dmantissap2(destb) = Dmantissap2(valueb)
280 #define Dbl_set_exponentmantissa(desta,destb,valuea,valueb) \
281 Deposit_dexponentmantissap1(desta,valuea); \
282 Dmantissap2(destb) = Dmantissap2(valueb)
283 #define Dbl_set_exponentmantissap1(dest,value) \
284 Deposit_dexponentmantissap1(dest,value)
286 #define Dbl_copyfromptr(src,desta,destb) \
287 Dallp1(desta) = src->wd0; \
288 Dallp2(destb) = src->wd1
289 #define Dbl_copytoptr(srca,srcb,dest) \
290 dest->wd0 = Dallp1(srca); \
291 dest->wd1 = Dallp2(srcb)
293 /* An infinity is represented with the max exponent and a zero mantissa */
294 #define Dbl_setinfinity_exponent(dbl_value) \
295 Deposit_dexponent(dbl_value,DBL_INFINITY_EXPONENT)
296 #define Dbl_setinfinity_exponentmantissa(dbl_valueA,dbl_valueB) \
297 Deposit_dexponentmantissap1(dbl_valueA, \
298 (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH)))); \
299 Dmantissap2(dbl_valueB) = 0
300 #define Dbl_setinfinitypositive(dbl_valueA,dbl_valueB) \
301 Dallp1(dbl_valueA) \
302 = (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
303 Dmantissap2(dbl_valueB) = 0
304 #define Dbl_setinfinitynegative(dbl_valueA,dbl_valueB) \
305 Dallp1(dbl_valueA) = (1<<31) | \
306 (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
307 Dmantissap2(dbl_valueB) = 0
308 #define Dbl_setinfinity(dbl_valueA,dbl_valueB,sign) \
309 Dallp1(dbl_valueA) = (sign << 31) | \
310 (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
311 Dmantissap2(dbl_valueB) = 0
313 #define Dbl_sethigh4bits(dbl_value, extsign) Deposit_dhigh4p1(dbl_value,extsign)
314 #define Dbl_set_sign(dbl_value,sign) Deposit_dsign(dbl_value,sign)
315 #define Dbl_invert_sign(dbl_value) Deposit_dsign(dbl_value,~Dsign(dbl_value))
316 #define Dbl_setone_sign(dbl_value) Deposit_dsign(dbl_value,1)
317 #define Dbl_setone_lowmantissap2(dbl_value) Deposit_dlowp2(dbl_value,1)
318 #define Dbl_setzero_sign(dbl_value) Dallp1(dbl_value) &= 0x7fffffff
319 #define Dbl_setzero_exponent(dbl_value) \
320 Dallp1(dbl_value) &= 0x800fffff
321 #define Dbl_setzero_mantissa(dbl_valueA,dbl_valueB) \
322 Dallp1(dbl_valueA) &= 0xfff00000; \
323 Dallp2(dbl_valueB) = 0
324 #define Dbl_setzero_mantissap1(dbl_value) Dallp1(dbl_value) &= 0xfff00000
325 #define Dbl_setzero_mantissap2(dbl_value) Dallp2(dbl_value) = 0
326 #define Dbl_setzero_exponentmantissa(dbl_valueA,dbl_valueB) \
327 Dallp1(dbl_valueA) &= 0x80000000; \
328 Dallp2(dbl_valueB) = 0
329 #define Dbl_setzero_exponentmantissap1(dbl_valueA) \
330 Dallp1(dbl_valueA) &= 0x80000000
331 #define Dbl_setzero(dbl_valueA,dbl_valueB) \
332 Dallp1(dbl_valueA) = 0; Dallp2(dbl_valueB) = 0
333 #define Dbl_setzerop1(dbl_value) Dallp1(dbl_value) = 0
334 #define Dbl_setzerop2(dbl_value) Dallp2(dbl_value) = 0
335 #define Dbl_setnegativezero(dbl_value) \
336 Dallp1(dbl_value) = 1 << 31; Dallp2(dbl_value) = 0
337 #define Dbl_setnegativezerop1(dbl_value) Dallp1(dbl_value) = 1 << 31
339 /* Use the following macro for both overflow & underflow conditions */
340 #define ovfl -
341 #define unfl +
342 #define Dbl_setwrapped_exponent(dbl_value,exponent,op) \
343 Deposit_dexponent(dbl_value,(exponent op DBL_WRAP))
345 #define Dbl_setlargestpositive(dbl_valueA,dbl_valueB) \
346 Dallp1(dbl_valueA) = ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
347 | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ); \
348 Dallp2(dbl_valueB) = 0xFFFFFFFF
349 #define Dbl_setlargestnegative(dbl_valueA,dbl_valueB) \
350 Dallp1(dbl_valueA) = ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
351 | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ) | (1<<31); \
352 Dallp2(dbl_valueB) = 0xFFFFFFFF
353 #define Dbl_setlargest_exponentmantissa(dbl_valueA,dbl_valueB) \
354 Deposit_dexponentmantissap1(dbl_valueA, \
355 (((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
356 | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ))); \
357 Dallp2(dbl_valueB) = 0xFFFFFFFF
359 #define Dbl_setnegativeinfinity(dbl_valueA,dbl_valueB) \
360 Dallp1(dbl_valueA) = ((1<<DBL_EXP_LENGTH) | DBL_INFINITY_EXPONENT) \
361 << (32-(1+DBL_EXP_LENGTH)) ; \
362 Dallp2(dbl_valueB) = 0
363 #define Dbl_setlargest(dbl_valueA,dbl_valueB,sign) \
364 Dallp1(dbl_valueA) = (sign << 31) | \
365 ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) | \
366 ((1 << (32-(1+DBL_EXP_LENGTH))) - 1 ); \
367 Dallp2(dbl_valueB) = 0xFFFFFFFF
370 /* The high bit is always zero so arithmetic or logical shifts will work. */
371 #define Dbl_right_align(srcdstA,srcdstB,shift,extent) \
372 if( shift >= 32 ) \
374 /* Big shift requires examining the portion shift off \
375 the end to properly set inexact. */ \
376 if(shift < 64) \
378 if(shift > 32) \
380 Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB), \
381 shift-32, Extall(extent)); \
382 if(Dallp2(srcdstB) << (64 - (shift))) Ext_setone_low(extent); \
384 else Extall(extent) = Dallp2(srcdstB); \
385 Dallp2(srcdstB) = Dallp1(srcdstA) >> (shift - 32); \
387 else \
389 Extall(extent) = Dallp1(srcdstA); \
390 if(Dallp2(srcdstB)) Ext_setone_low(extent); \
391 Dallp2(srcdstB) = 0; \
393 Dallp1(srcdstA) = 0; \
395 else \
397 /* Small alignment is simpler. Extension is easily set. */ \
398 if (shift > 0) \
400 Extall(extent) = Dallp2(srcdstB) << (32 - (shift)); \
401 Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB),shift, \
402 Dallp2(srcdstB)); \
403 Dallp1(srcdstA) >>= shift; \
405 else Extall(extent) = 0; \
409 * Here we need to shift the result right to correct for an overshift
410 * (due to the exponent becoming negative) during normalization.
412 #define Dbl_fix_overshift(srcdstA,srcdstB,shift,extent) \
413 Extall(extent) = Dallp2(srcdstB) << (32 - (shift)); \
414 Dallp2(srcdstB) = (Dallp1(srcdstA) << (32 - (shift))) | \
415 (Dallp2(srcdstB) >> (shift)); \
416 Dallp1(srcdstA) = Dallp1(srcdstA) >> shift
418 #define Dbl_hiddenhigh3mantissa(dbl_value) Dhiddenhigh3mantissa(dbl_value)
419 #define Dbl_hidden(dbl_value) Dhidden(dbl_value)
420 #define Dbl_lowmantissap2(dbl_value) Dlowp2(dbl_value)
422 /* The left argument is never smaller than the right argument */
423 #define Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb) \
424 if( Dallp2(rightb) > Dallp2(leftb) ) Dallp1(lefta)--; \
425 Dallp2(resultb) = Dallp2(leftb) - Dallp2(rightb); \
426 Dallp1(resulta) = Dallp1(lefta) - Dallp1(righta)
428 /* Subtract right augmented with extension from left augmented with zeros and
429 * store into result and extension. */
430 #define Dbl_subtract_withextension(lefta,leftb,righta,rightb,extent,resulta,resultb) \
431 Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb); \
432 if( (Extall(extent) = 0-Extall(extent)) ) \
434 if((Dallp2(resultb)--) == 0) Dallp1(resulta)--; \
437 #define Dbl_addition(lefta,leftb,righta,rightb,resulta,resultb) \
438 /* If the sum of the low words is less than either source, then \
439 * an overflow into the next word occurred. */ \
440 Dallp1(resulta) = Dallp1(lefta) + Dallp1(righta); \
441 if((Dallp2(resultb) = Dallp2(leftb) + Dallp2(rightb)) < Dallp2(rightb)) \
442 Dallp1(resulta)++
444 #define Dbl_xortointp1(left,right,result) \
445 result = Dallp1(left) XOR Dallp1(right)
447 #define Dbl_xorfromintp1(left,right,result) \
448 Dallp1(result) = left XOR Dallp1(right)
450 #define Dbl_swap_lower(left,right) \
451 Dallp2(left) = Dallp2(left) XOR Dallp2(right); \
452 Dallp2(right) = Dallp2(left) XOR Dallp2(right); \
453 Dallp2(left) = Dallp2(left) XOR Dallp2(right)
455 /* Need to Initialize */
456 #define Dbl_makequietnan(desta,destb) \
457 Dallp1(desta) = ((DBL_EMAX+DBL_BIAS)+1)<< (32-(1+DBL_EXP_LENGTH)) \
458 | (1<<(32-(1+DBL_EXP_LENGTH+2))); \
459 Dallp2(destb) = 0
460 #define Dbl_makesignalingnan(desta,destb) \
461 Dallp1(desta) = ((DBL_EMAX+DBL_BIAS)+1)<< (32-(1+DBL_EXP_LENGTH)) \
462 | (1<<(32-(1+DBL_EXP_LENGTH+1))); \
463 Dallp2(destb) = 0
465 #define Dbl_normalize(dbl_opndA,dbl_opndB,exponent) \
466 while(Dbl_iszero_hiddenhigh7mantissa(dbl_opndA)) { \
467 Dbl_leftshiftby8(dbl_opndA,dbl_opndB); \
468 exponent -= 8; \
470 if(Dbl_iszero_hiddenhigh3mantissa(dbl_opndA)) { \
471 Dbl_leftshiftby4(dbl_opndA,dbl_opndB); \
472 exponent -= 4; \
474 while(Dbl_iszero_hidden(dbl_opndA)) { \
475 Dbl_leftshiftby1(dbl_opndA,dbl_opndB); \
476 exponent -= 1; \
479 #define Twoword_add(src1dstA,src1dstB,src2A,src2B) \
480 /* \
481 * want this macro to generate: \
482 * ADD src1dstB,src2B,src1dstB; \
483 * ADDC src1dstA,src2A,src1dstA; \
484 */ \
485 if ((src1dstB) + (src2B) < (src1dstB)) Dallp1(src1dstA)++; \
486 Dallp1(src1dstA) += (src2A); \
487 Dallp2(src1dstB) += (src2B)
489 #define Twoword_subtract(src1dstA,src1dstB,src2A,src2B) \
490 /* \
491 * want this macro to generate: \
492 * SUB src1dstB,src2B,src1dstB; \
493 * SUBB src1dstA,src2A,src1dstA; \
494 */ \
495 if ((src1dstB) < (src2B)) Dallp1(src1dstA)--; \
496 Dallp1(src1dstA) -= (src2A); \
497 Dallp2(src1dstB) -= (src2B)
499 #define Dbl_setoverflow(resultA,resultB) \
500 /* set result to infinity or largest number */ \
501 switch (Rounding_mode()) { \
502 case ROUNDPLUS: \
503 if (Dbl_isone_sign(resultA)) { \
504 Dbl_setlargestnegative(resultA,resultB); \
506 else { \
507 Dbl_setinfinitypositive(resultA,resultB); \
509 break; \
510 case ROUNDMINUS: \
511 if (Dbl_iszero_sign(resultA)) { \
512 Dbl_setlargestpositive(resultA,resultB); \
514 else { \
515 Dbl_setinfinitynegative(resultA,resultB); \
517 break; \
518 case ROUNDNEAREST: \
519 Dbl_setinfinity_exponentmantissa(resultA,resultB); \
520 break; \
521 case ROUNDZERO: \
522 Dbl_setlargest_exponentmantissa(resultA,resultB); \
525 #define Dbl_denormalize(opndp1,opndp2,exponent,guard,sticky,inexact) \
526 Dbl_clear_signexponent_set_hidden(opndp1); \
527 if (exponent >= (1-DBL_P)) { \
528 if (exponent >= -31) { \
529 guard = (Dallp2(opndp2) >> (-(exponent))) & 1; \
530 if (exponent < 0) sticky |= Dallp2(opndp2) << (32+exponent); \
531 if (exponent > -31) { \
532 Variable_shift_double(opndp1,opndp2,1-exponent,opndp2); \
533 Dallp1(opndp1) >>= 1-exponent; \
535 else { \
536 Dallp2(opndp2) = Dallp1(opndp1); \
537 Dbl_setzerop1(opndp1); \
540 else { \
541 guard = (Dallp1(opndp1) >> (-32-(exponent))) & 1; \
542 if (exponent == -32) sticky |= Dallp2(opndp2); \
543 else sticky |= (Dallp2(opndp2) | Dallp1(opndp1) << (64+(exponent))); \
544 Dallp2(opndp2) = Dallp1(opndp1) >> (-31-(exponent)); \
545 Dbl_setzerop1(opndp1); \
547 inexact = guard | sticky; \
549 else { \
550 guard = 0; \
551 sticky |= (Dallp1(opndp1) | Dallp2(opndp2)); \
552 Dbl_setzero(opndp1,opndp2); \
553 inexact = sticky; \
557 int dbl_fadd(dbl_floating_point *, dbl_floating_point*, dbl_floating_point*, unsigned int *);
558 int dbl_fcmp(dbl_floating_point *, dbl_floating_point*, unsigned int, unsigned int *);
559 int dbl_fdiv(dbl_floating_point *, dbl_floating_point *, dbl_floating_point *, unsigned int *);
560 int dbl_fmpy(dbl_floating_point *, dbl_floating_point *, dbl_floating_point*, unsigned int *);
561 int dbl_frem(dbl_floating_point *, dbl_floating_point *, dbl_floating_point*, unsigned int *);
562 int dbl_fsqrt(dbl_floating_point *, dbl_floating_point *, unsigned int *);
563 int dbl_fsub(dbl_floating_point *, dbl_floating_point *, dbl_floating_point*, unsigned int *);
565 dbl_floating_point dbl_setoverflow(unsigned int);
567 int sgl_to_dbl_fcnvff(sgl_floating_point *, dbl_floating_point *, unsigned int *);
568 int dbl_to_sgl_fcnvff(dbl_floating_point *, sgl_floating_point *, unsigned int *);
570 int dbl_frnd(dbl_floating_point *, dbl_floating_point *, unsigned int *);