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