1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
6 * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
9 PA header file
-- do not include
this header file
for non
-PA builds
.
12 /* 32-bit word grabbing functions */
13 #define Dbl_firstword(value) Dallp1(value)
14 #define Dbl_secondword(value) Dallp2(value)
15 #define Dbl_thirdword(value) dummy_location
16 #define Dbl_fourthword(value) dummy_location
18 #define Dbl_sign(object) Dsign(object)
19 #define Dbl_exponent(object) Dexponent(object)
20 #define Dbl_signexponent(object) Dsignexponent(object)
21 #define Dbl_mantissap1(object) Dmantissap1(object)
22 #define Dbl_mantissap2(object) Dmantissap2(object)
23 #define Dbl_exponentmantissap1(object) Dexponentmantissap1(object)
24 #define Dbl_allp1(object) Dallp1(object)
25 #define Dbl_allp2(object) Dallp2(object)
27 /* dbl_and_signs ANDs the sign bits of each argument and puts the result
28 * into the first argument. dbl_or_signs ors those same sign bits */
29 #define Dbl_and_signs( src1dst, src2) \
30 Dallp1(src1dst) = (Dallp1(src2)|~((unsigned int)1<<31)) & Dallp1(src1dst)
31 #define Dbl_or_signs( src1dst, src2) \
32 Dallp1(src1dst) = (Dallp1(src2)&((unsigned int)1<<31)) | Dallp1(src1dst)
34 /* The hidden bit is always the low bit of the exponent */
35 #define Dbl_clear_exponent_set_hidden(srcdst) Deposit_dexponent(srcdst,1)
36 #define Dbl_clear_signexponent_set_hidden(srcdst) \
37 Deposit_dsignexponent(srcdst,1)
38 #define Dbl_clear_sign(srcdst) Dallp1(srcdst) &= ~((unsigned int)1<<31)
39 #define Dbl_clear_signexponent(srcdst) \
40 Dallp1(srcdst) &= Dmantissap1((unsigned int)-1)
42 /* Exponent field for doubles has already been cleared and may be
43 * included in the shift. Here we need to generate two double width
44 * variable shifts. The insignificant bits can be ignored.
46 * VSHD srcdst.high,srcdst.low => srcdst.low
47 * VSHD 0,srcdst.high => srcdst.high
48 * This is very difficult to model with C expressions since the shift amount
50 /* varamount must be less than 64 */
51 #define Dbl_rightshift(srcdstA, srcdstB, varamount) \
52 {if((varamount) >= 32) { \
53 Dallp2(srcdstB) = Dallp1(srcdstA) >> (varamount-32); \
56 else if(varamount > 0) { \
57 Variable_shift_double(Dallp1(srcdstA), Dallp2(srcdstB), \
58 (varamount), Dallp2(srcdstB)); \
59 Dallp1(srcdstA) >>= varamount; \
61 /* varamount must be less than 64 */
62 #define Dbl_rightshift_exponentmantissa(srcdstA, srcdstB, varamount) \
63 {if((varamount) >= 32) { \
64 Dallp2(srcdstB) = Dexponentmantissap1(srcdstA) >> (varamount-32); \
65 Dallp1(srcdstA) &= ((unsigned int)1<<31); /* clear expmant field */ \
67 else if(varamount > 0) { \
68 Variable_shift_double(Dexponentmantissap1(srcdstA), Dallp2(srcdstB), \
69 (varamount), Dallp2(srcdstB)); \
70 Deposit_dexponentmantissap1(srcdstA, \
71 (Dexponentmantissap1(srcdstA)>>varamount)); \
73 /* varamount must be less than 64 */
74 #define Dbl_leftshift(srcdstA, srcdstB, varamount) \
75 {if((varamount) >= 32) { \
76 Dallp1(srcdstA) = Dallp2(srcdstB) << (varamount-32); \
80 if ((varamount) > 0) { \
81 Dallp1(srcdstA) = (Dallp1(srcdstA) << (varamount)) | \
82 (Dallp2(srcdstB) >> (32-(varamount))); \
83 Dallp2(srcdstB) <<= varamount; \
86 #define Dbl_leftshiftby1_withextent(lefta,leftb,right,resulta,resultb) \
87 Shiftdouble(Dallp1(lefta), Dallp2(leftb), 31, Dallp1(resulta)); \
88 Shiftdouble(Dallp2(leftb), Extall(right), 31, Dallp2(resultb))
90 #define Dbl_rightshiftby1_withextent(leftb,right,dst) \
91 Extall(dst) = (Dallp2(leftb) << 31) | ((unsigned int)Extall(right) >> 1) | \
94 #define Dbl_arithrightshiftby1(srcdstA,srcdstB) \
95 Shiftdouble(Dallp1(srcdstA),Dallp2(srcdstB),1,Dallp2(srcdstB));\
96 Dallp1(srcdstA) = (int)Dallp1(srcdstA) >> 1
98 /* Sign extend the sign bit with an integer destination */
99 #define Dbl_signextendedsign(value) Dsignedsign(value)
101 #define Dbl_isone_hidden(dbl_value) (Is_dhidden(dbl_value)!=0)
102 /* Singles and doubles may include the sign and exponent fields. The
103 * hidden bit and the hidden overflow must be included. */
104 #define Dbl_increment(dbl_valueA,dbl_valueB) \
105 if( (Dallp2(dbl_valueB) += 1) == 0 ) Dallp1(dbl_valueA) += 1
106 #define Dbl_increment_mantissa(dbl_valueA,dbl_valueB) \
107 if( (Dmantissap2(dbl_valueB) += 1) == 0 ) \
108 Deposit_dmantissap1(dbl_valueA,dbl_valueA+1)
109 #define Dbl_decrement(dbl_valueA,dbl_valueB) \
110 if( Dallp2(dbl_valueB) == 0 ) Dallp1(dbl_valueA) -= 1; \
111 Dallp2(dbl_valueB) -= 1
113 #define Dbl_isone_sign(dbl_value) (Is_dsign(dbl_value)!=0)
114 #define Dbl_isone_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)!=0)
115 #define Dbl_isone_lowmantissap1(dbl_valueA) (Is_dlowp1(dbl_valueA)!=0)
116 #define Dbl_isone_lowmantissap2(dbl_valueB) (Is_dlowp2(dbl_valueB)!=0)
117 #define Dbl_isone_signaling(dbl_value) (Is_dsignaling(dbl_value)!=0)
118 #define Dbl_is_signalingnan(dbl_value) (Dsignalingnan(dbl_value)==0xfff)
119 #define Dbl_isnotzero(dbl_valueA,dbl_valueB) \
120 (Dallp1(dbl_valueA) || Dallp2(dbl_valueB))
121 #define Dbl_isnotzero_hiddenhigh7mantissa(dbl_value) \
122 (Dhiddenhigh7mantissa(dbl_value)!=0)
123 #define Dbl_isnotzero_exponent(dbl_value) (Dexponent(dbl_value)!=0)
124 #define Dbl_isnotzero_mantissa(dbl_valueA,dbl_valueB) \
125 (Dmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))
126 #define Dbl_isnotzero_mantissap1(dbl_valueA) (Dmantissap1(dbl_valueA)!=0)
127 #define Dbl_isnotzero_mantissap2(dbl_valueB) (Dmantissap2(dbl_valueB)!=0)
128 #define Dbl_isnotzero_exponentmantissa(dbl_valueA,dbl_valueB) \
129 (Dexponentmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))
130 #define Dbl_isnotzero_low4p2(dbl_value) (Dlow4p2(dbl_value)!=0)
131 #define Dbl_iszero(dbl_valueA,dbl_valueB) (Dallp1(dbl_valueA)==0 && \
132 Dallp2(dbl_valueB)==0)
133 #define Dbl_iszero_allp1(dbl_value) (Dallp1(dbl_value)==0)
134 #define Dbl_iszero_allp2(dbl_value) (Dallp2(dbl_value)==0)
135 #define Dbl_iszero_hidden(dbl_value) (Is_dhidden(dbl_value)==0)
136 #define Dbl_iszero_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)==0)
137 #define Dbl_iszero_hiddenhigh3mantissa(dbl_value) \
138 (Dhiddenhigh3mantissa(dbl_value)==0)
139 #define Dbl_iszero_hiddenhigh7mantissa(dbl_value) \
140 (Dhiddenhigh7mantissa(dbl_value)==0)
141 #define Dbl_iszero_sign(dbl_value) (Is_dsign(dbl_value)==0)
142 #define Dbl_iszero_exponent(dbl_value) (Dexponent(dbl_value)==0)
143 #define Dbl_iszero_mantissa(dbl_valueA,dbl_valueB) \
144 (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
145 #define Dbl_iszero_exponentmantissa(dbl_valueA,dbl_valueB) \
146 (Dexponentmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
147 #define Dbl_isinfinity_exponent(dbl_value) \
148 (Dexponent(dbl_value)==DBL_INFINITY_EXPONENT)
149 #define Dbl_isnotinfinity_exponent(dbl_value) \
150 (Dexponent(dbl_value)!=DBL_INFINITY_EXPONENT)
151 #define Dbl_isinfinity(dbl_valueA,dbl_valueB) \
152 (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \
153 Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
154 #define Dbl_isnan(dbl_valueA,dbl_valueB) \
155 (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \
156 (Dmantissap1(dbl_valueA)!=0 || Dmantissap2(dbl_valueB)!=0))
157 #define Dbl_isnotnan(dbl_valueA,dbl_valueB) \
158 (Dexponent(dbl_valueA)!=DBL_INFINITY_EXPONENT || \
159 (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0))
161 #define Dbl_islessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
162 (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \
163 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
164 Dallp2(dbl_op1b) < Dallp2(dbl_op2b)))
165 #define Dbl_isgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
166 (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \
167 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
168 Dallp2(dbl_op1b) > Dallp2(dbl_op2b)))
169 #define Dbl_isnotlessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
170 (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \
171 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
172 Dallp2(dbl_op1b) >= Dallp2(dbl_op2b)))
173 #define Dbl_isnotgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
174 (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \
175 (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
176 Dallp2(dbl_op1b) <= Dallp2(dbl_op2b)))
177 #define Dbl_isequal(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
178 ((Dallp1(dbl_op1a) == Dallp1(dbl_op2a)) && \
179 (Dallp2(dbl_op1b) == Dallp2(dbl_op2b)))
181 #define Dbl_leftshiftby8(dbl_valueA,dbl_valueB) \
182 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),24,Dallp1(dbl_valueA)); \
183 Dallp2(dbl_valueB) <<= 8
184 #define Dbl_leftshiftby7(dbl_valueA,dbl_valueB) \
185 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),25,Dallp1(dbl_valueA)); \
186 Dallp2(dbl_valueB) <<= 7
187 #define Dbl_leftshiftby4(dbl_valueA,dbl_valueB) \
188 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),28,Dallp1(dbl_valueA)); \
189 Dallp2(dbl_valueB) <<= 4
190 #define Dbl_leftshiftby3(dbl_valueA,dbl_valueB) \
191 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),29,Dallp1(dbl_valueA)); \
192 Dallp2(dbl_valueB) <<= 3
193 #define Dbl_leftshiftby2(dbl_valueA,dbl_valueB) \
194 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),30,Dallp1(dbl_valueA)); \
195 Dallp2(dbl_valueB) <<= 2
196 #define Dbl_leftshiftby1(dbl_valueA,dbl_valueB) \
197 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),31,Dallp1(dbl_valueA)); \
198 Dallp2(dbl_valueB) <<= 1
200 #define Dbl_rightshiftby8(dbl_valueA,dbl_valueB) \
201 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),8,Dallp2(dbl_valueB)); \
202 Dallp1(dbl_valueA) >>= 8
203 #define Dbl_rightshiftby4(dbl_valueA,dbl_valueB) \
204 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),4,Dallp2(dbl_valueB)); \
205 Dallp1(dbl_valueA) >>= 4
206 #define Dbl_rightshiftby2(dbl_valueA,dbl_valueB) \
207 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),2,Dallp2(dbl_valueB)); \
208 Dallp1(dbl_valueA) >>= 2
209 #define Dbl_rightshiftby1(dbl_valueA,dbl_valueB) \
210 Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),1,Dallp2(dbl_valueB)); \
211 Dallp1(dbl_valueA) >>= 1
213 /* This magnitude comparison uses the signless first words and
214 * the regular part2 words. The comparison is graphically:
216 * 1st greater? -------------
218 * 1st less?-----------------+---------
220 * 2nd greater or equal----->| |
223 #define Dbl_ismagnitudeless(leftB,rightB,signlessleft,signlessright) \
224 ((signlessleft <= signlessright) && \
225 ( (signlessleft < signlessright) || (Dallp2(leftB)<Dallp2(rightB)) ))
227 #define Dbl_copytoint_exponentmantissap1(src,dest) \
228 dest = Dexponentmantissap1(src)
230 /* A quiet NaN has the high mantissa bit clear and at least on other (in this
231 * case the adjacent bit) bit set. */
232 #define Dbl_set_quiet(dbl_value) Deposit_dhigh2mantissa(dbl_value,1)
233 #define Dbl_set_exponent(dbl_value, exp) Deposit_dexponent(dbl_value,exp)
235 #define Dbl_set_mantissa(desta,destb,valuea,valueb) \
236 Deposit_dmantissap1(desta,valuea); \
237 Dmantissap2(destb) = Dmantissap2(valueb)
238 #define Dbl_set_mantissap1(desta,valuea) \
239 Deposit_dmantissap1(desta,valuea)
240 #define Dbl_set_mantissap2(destb,valueb) \
241 Dmantissap2(destb) = Dmantissap2(valueb)
243 #define Dbl_set_exponentmantissa(desta,destb,valuea,valueb) \
244 Deposit_dexponentmantissap1(desta,valuea); \
245 Dmantissap2(destb) = Dmantissap2(valueb)
246 #define Dbl_set_exponentmantissap1(dest,value) \
247 Deposit_dexponentmantissap1(dest,value)
249 #define Dbl_copyfromptr(src,desta,destb) \
250 Dallp1(desta) = src->wd0; \
251 Dallp2(destb) = src->wd1
252 #define Dbl_copytoptr(srca,srcb,dest) \
253 dest->wd0 = Dallp1(srca); \
254 dest->wd1 = Dallp2(srcb)
256 /* An infinity is represented with the max exponent and a zero mantissa */
257 #define Dbl_setinfinity_exponent(dbl_value) \
258 Deposit_dexponent(dbl_value,DBL_INFINITY_EXPONENT)
259 #define Dbl_setinfinity_exponentmantissa(dbl_valueA,dbl_valueB) \
260 Deposit_dexponentmantissap1(dbl_valueA, \
261 (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH)))); \
262 Dmantissap2(dbl_valueB) = 0
263 #define Dbl_setinfinitypositive(dbl_valueA,dbl_valueB) \
265 = (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
266 Dmantissap2(dbl_valueB) = 0
267 #define Dbl_setinfinitynegative(dbl_valueA,dbl_valueB) \
268 Dallp1(dbl_valueA) = ((unsigned int)1<<31) | \
269 (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
270 Dmantissap2(dbl_valueB) = 0
271 #define Dbl_setinfinity(dbl_valueA,dbl_valueB,sign) \
272 Dallp1(dbl_valueA) = ((unsigned int)sign << 31) | \
273 (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
274 Dmantissap2(dbl_valueB) = 0
276 #define Dbl_sethigh4bits(dbl_value, extsign) Deposit_dhigh4p1(dbl_value,extsign)
277 #define Dbl_set_sign(dbl_value,sign) Deposit_dsign(dbl_value,sign)
278 #define Dbl_invert_sign(dbl_value) Deposit_dsign(dbl_value,~Dsign(dbl_value))
279 #define Dbl_setone_sign(dbl_value) Deposit_dsign(dbl_value,1)
280 #define Dbl_setone_lowmantissap2(dbl_value) Deposit_dlowp2(dbl_value,1)
281 #define Dbl_setzero_sign(dbl_value) Dallp1(dbl_value) &= 0x7fffffff
282 #define Dbl_setzero_exponent(dbl_value) \
283 Dallp1(dbl_value) &= 0x800fffff
284 #define Dbl_setzero_mantissa(dbl_valueA,dbl_valueB) \
285 Dallp1(dbl_valueA) &= 0xfff00000; \
286 Dallp2(dbl_valueB) = 0
287 #define Dbl_setzero_mantissap1(dbl_value) Dallp1(dbl_value) &= 0xfff00000
288 #define Dbl_setzero_mantissap2(dbl_value) Dallp2(dbl_value) = 0
289 #define Dbl_setzero_exponentmantissa(dbl_valueA,dbl_valueB) \
290 Dallp1(dbl_valueA) &= 0x80000000; \
291 Dallp2(dbl_valueB) = 0
292 #define Dbl_setzero_exponentmantissap1(dbl_valueA) \
293 Dallp1(dbl_valueA) &= 0x80000000
294 #define Dbl_setzero(dbl_valueA,dbl_valueB) \
295 Dallp1(dbl_valueA) = 0; Dallp2(dbl_valueB) = 0
296 #define Dbl_setzerop1(dbl_value) Dallp1(dbl_value) = 0
297 #define Dbl_setzerop2(dbl_value) Dallp2(dbl_value) = 0
298 #define Dbl_setnegativezero(dbl_value) \
299 Dallp1(dbl_value) = (unsigned int)1 << 31; Dallp2(dbl_value) = 0
300 #define Dbl_setnegativezerop1(dbl_value) Dallp1(dbl_value) = (unsigned int)1<<31
302 /* Use the following macro for both overflow & underflow conditions */
305 #define Dbl_setwrapped_exponent(dbl_value,exponent,op) \
306 Deposit_dexponent(dbl_value,(exponent op DBL_WRAP))
308 #define Dbl_setlargestpositive(dbl_valueA,dbl_valueB) \
309 Dallp1(dbl_valueA) = ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
310 | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ); \
311 Dallp2(dbl_valueB) = 0xFFFFFFFF
312 #define Dbl_setlargestnegative(dbl_valueA,dbl_valueB) \
313 Dallp1(dbl_valueA) = ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
314 | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ) \
315 | ((unsigned int)1<<31); \
316 Dallp2(dbl_valueB) = 0xFFFFFFFF
317 #define Dbl_setlargest_exponentmantissa(dbl_valueA,dbl_valueB) \
318 Deposit_dexponentmantissap1(dbl_valueA, \
319 (((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
320 | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ))); \
321 Dallp2(dbl_valueB) = 0xFFFFFFFF
323 #define Dbl_setnegativeinfinity(dbl_valueA,dbl_valueB) \
324 Dallp1(dbl_valueA) = ((1<<DBL_EXP_LENGTH) | DBL_INFINITY_EXPONENT) \
325 << (32-(1+DBL_EXP_LENGTH)) ; \
326 Dallp2(dbl_valueB) = 0
327 #define Dbl_setlargest(dbl_valueA,dbl_valueB,sign) \
328 Dallp1(dbl_valueA) = ((unsigned int)sign << 31) | \
329 ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) | \
330 ((1 << (32-(1+DBL_EXP_LENGTH))) - 1 ); \
331 Dallp2(dbl_valueB) = 0xFFFFFFFF
334 /* The high bit is always zero so arithmetic or logical shifts will work. */
335 #define Dbl_right_align(srcdstA,srcdstB,shift,extent) \
338 /* Big shift requires examining the portion shift off \
339 the end to properly set inexact. */ \
344 Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB), \
345 shift-32, Extall(extent)); \
346 if(Dallp2(srcdstB) << 64 - (shift)) Ext_setone_low(extent); \
348 else Extall(extent) = Dallp2(srcdstB); \
349 Dallp2(srcdstB) = Dallp1(srcdstA) >> (shift - 32); \
353 Extall(extent) = Dallp1(srcdstA); \
354 if(Dallp2(srcdstB)) Ext_setone_low(extent); \
355 Dallp2(srcdstB) = 0; \
357 Dallp1(srcdstA) = 0; \
361 /* Small alignment is simpler. Extension is easily set. */ \
364 Extall(extent) = Dallp2(srcdstB) << 32 - (shift); \
365 Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB),shift, \
367 Dallp1(srcdstA) >>= shift; \
369 else Extall(extent) = 0; \
373 * Here we need to shift the result right to correct for an overshift
374 * (due to the exponent becoming negative) during normalization.
376 #define Dbl_fix_overshift(srcdstA,srcdstB,shift,extent) \
377 Extall(extent) = Dallp2(srcdstB) << 32 - (shift); \
378 Dallp2(srcdstB) = (Dallp1(srcdstA) << 32 - (shift)) | \
379 (Dallp2(srcdstB) >> (shift)); \
380 Dallp1(srcdstA) = Dallp1(srcdstA) >> shift
382 #define Dbl_hiddenhigh3mantissa(dbl_value) Dhiddenhigh3mantissa(dbl_value)
383 #define Dbl_hidden(dbl_value) Dhidden(dbl_value)
384 #define Dbl_lowmantissap2(dbl_value) Dlowp2(dbl_value)
386 /* The left argument is never smaller than the right argument */
387 #define Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb) \
388 if( Dallp2(rightb) > Dallp2(leftb) ) Dallp1(lefta)--; \
389 Dallp2(resultb) = Dallp2(leftb) - Dallp2(rightb); \
390 Dallp1(resulta) = Dallp1(lefta) - Dallp1(righta)
392 /* Subtract right augmented with extension from left augmented with zeros and
393 * store into result and extension. */
394 #define Dbl_subtract_withextension(lefta,leftb,righta,rightb,extent,resulta,resultb) \
395 Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb); \
396 if( (Extall(extent) = 0-Extall(extent)) ) \
398 if((Dallp2(resultb)--) == 0) Dallp1(resulta)--; \
401 #define Dbl_addition(lefta,leftb,righta,rightb,resulta,resultb) \
402 /* If the sum of the low words is less than either source, then \
403 * an overflow into the next word occurred. */ \
404 Dallp1(resulta) = Dallp1(lefta) + Dallp1(righta); \
405 if((Dallp2(resultb) = Dallp2(leftb) + Dallp2(rightb)) < Dallp2(rightb)) \
408 #define Dbl_xortointp1(left,right,result) \
409 result = Dallp1(left) XOR Dallp1(right)
411 #define Dbl_xorfromintp1(left,right,result) \
412 Dallp1(result) = left XOR Dallp1(right)
414 #define Dbl_swap_lower(left,right) \
415 Dallp2(left) = Dallp2(left) XOR Dallp2(right); \
416 Dallp2(right) = Dallp2(left) XOR Dallp2(right); \
417 Dallp2(left) = Dallp2(left) XOR Dallp2(right)
419 /* Need to Initialize */
420 #define Dbl_makequietnan(desta,destb) \
421 Dallp1(desta) = ((DBL_EMAX+DBL_BIAS)+1)<< (32-(1+DBL_EXP_LENGTH)) \
422 | (1<<(32-(1+DBL_EXP_LENGTH+2))); \
424 #define Dbl_makesignalingnan(desta,destb) \
425 Dallp1(desta) = ((DBL_EMAX+DBL_BIAS)+1)<< (32-(1+DBL_EXP_LENGTH)) \
426 | (1<<(32-(1+DBL_EXP_LENGTH+1))); \
429 #define Dbl_normalize(dbl_opndA,dbl_opndB,exponent) \
430 while(Dbl_iszero_hiddenhigh7mantissa(dbl_opndA)) { \
431 Dbl_leftshiftby8(dbl_opndA,dbl_opndB); \
434 if(Dbl_iszero_hiddenhigh3mantissa(dbl_opndA)) { \
435 Dbl_leftshiftby4(dbl_opndA,dbl_opndB); \
438 while(Dbl_iszero_hidden(dbl_opndA)) { \
439 Dbl_leftshiftby1(dbl_opndA,dbl_opndB); \
443 #define Twoword_add(src1dstA,src1dstB,src2A,src2B) \
445 * want this macro to generate: \
446 * ADD src1dstB,src2B,src1dstB; \
447 * ADDC src1dstA,src2A,src1dstA; \
449 if ((src1dstB) + (src2B) < (src1dstB)) Dallp1(src1dstA)++; \
450 Dallp1(src1dstA) += (src2A); \
451 Dallp2(src1dstB) += (src2B)
453 #define Twoword_subtract(src1dstA,src1dstB,src2A,src2B) \
455 * want this macro to generate: \
456 * SUB src1dstB,src2B,src1dstB; \
457 * SUBB src1dstA,src2A,src1dstA; \
459 if ((src1dstB) < (src2B)) Dallp1(src1dstA)--; \
460 Dallp1(src1dstA) -= (src2A); \
461 Dallp2(src1dstB) -= (src2B)
463 #define Dbl_setoverflow(resultA,resultB) \
464 /* set result to infinity or largest number */ \
465 switch (Rounding_mode()) { \
467 if (Dbl_isone_sign(resultA)) { \
468 Dbl_setlargestnegative(resultA,resultB); \
471 Dbl_setinfinitypositive(resultA,resultB); \
475 if (Dbl_iszero_sign(resultA)) { \
476 Dbl_setlargestpositive(resultA,resultB); \
479 Dbl_setinfinitynegative(resultA,resultB); \
483 Dbl_setinfinity_exponentmantissa(resultA,resultB); \
486 Dbl_setlargest_exponentmantissa(resultA,resultB); \
489 #define Dbl_denormalize(opndp1,opndp2,exponent,guard,sticky,inexact) \
490 Dbl_clear_signexponent_set_hidden(opndp1); \
491 if (exponent >= (1-DBL_P)) { \
492 if (exponent >= -31) { \
493 guard = (Dallp2(opndp2) >> -exponent) & 1; \
494 if (exponent < 0) sticky |= Dallp2(opndp2) << (32+exponent); \
495 if (exponent > -31) { \
496 Variable_shift_double(opndp1,opndp2,1-exponent,opndp2); \
497 Dallp1(opndp1) >>= 1-exponent; \
500 Dallp2(opndp2) = Dallp1(opndp1); \
501 Dbl_setzerop1(opndp1); \
505 guard = (Dallp1(opndp1) >> -32-exponent) & 1; \
506 if (exponent == -32) sticky |= Dallp2(opndp2); \
507 else sticky |= (Dallp2(opndp2) | Dallp1(opndp1) << 64+exponent); \
508 Dallp2(opndp2) = Dallp1(opndp1) >> -31-exponent; \
509 Dbl_setzerop1(opndp1); \
511 inexact = guard | sticky; \
515 sticky |= (Dallp1(opndp1) | Dallp2(opndp2)); \
516 Dbl_setzero(opndp1,opndp2); \
521 * The fused multiply add instructions requires a double extended format,
522 * with 106 bits of mantissa.
524 #define DBLEXT_THRESHOLD 106
526 #define Dblext_setzero(valA,valB,valC,valD) \
527 Dextallp1(valA) = 0; Dextallp2(valB) = 0; \
528 Dextallp3(valC) = 0; Dextallp4(valD) = 0
531 #define Dblext_isnotzero_mantissap3(valC) (Dextallp3(valC)!=0)
532 #define Dblext_isnotzero_mantissap4(valD) (Dextallp3(valD)!=0)
533 #define Dblext_isone_lowp2(val) (Dextlowp2(val)!=0)
534 #define Dblext_isone_highp3(val) (Dexthighp3(val)!=0)
535 #define Dblext_isnotzero_low31p3(val) (Dextlow31p3(val)!=0)
536 #define Dblext_iszero(valA,valB,valC,valD) (Dextallp1(valA)==0 && \
537 Dextallp2(valB)==0 && Dextallp3(valC)==0 && Dextallp4(valD)==0)
539 #define Dblext_copy(srca,srcb,srcc,srcd,desta,destb,destc,destd) \
540 Dextallp1(desta) = Dextallp4(srca); \
541 Dextallp2(destb) = Dextallp4(srcb); \
542 Dextallp3(destc) = Dextallp4(srcc); \
543 Dextallp4(destd) = Dextallp4(srcd)
545 #define Dblext_swap_lower(leftp2,leftp3,leftp4,rightp2,rightp3,rightp4) \
546 Dextallp2(leftp2) = Dextallp2(leftp2) XOR Dextallp2(rightp2); \
547 Dextallp2(rightp2) = Dextallp2(leftp2) XOR Dextallp2(rightp2); \
548 Dextallp2(leftp2) = Dextallp2(leftp2) XOR Dextallp2(rightp2); \
549 Dextallp3(leftp3) = Dextallp3(leftp3) XOR Dextallp3(rightp3); \
550 Dextallp3(rightp3) = Dextallp3(leftp3) XOR Dextallp3(rightp3); \
551 Dextallp3(leftp3) = Dextallp3(leftp3) XOR Dextallp3(rightp3); \
552 Dextallp4(leftp4) = Dextallp4(leftp4) XOR Dextallp4(rightp4); \
553 Dextallp4(rightp4) = Dextallp4(leftp4) XOR Dextallp4(rightp4); \
554 Dextallp4(leftp4) = Dextallp4(leftp4) XOR Dextallp4(rightp4)
556 #define Dblext_setone_lowmantissap4(dbl_value) Deposit_dextlowp4(dbl_value,1)
558 /* The high bit is always zero so arithmetic or logical shifts will work. */
559 #define Dblext_right_align(srcdstA,srcdstB,srcdstC,srcdstD,shift) \
560 {int shiftamt, sticky; \
561 shiftamt = shift % 32; \
563 switch (shift/32) { \
564 case 0: if (shiftamt > 0) { \
565 sticky = Dextallp4(srcdstD) << 32 - (shiftamt); \
566 Variable_shift_double(Dextallp3(srcdstC), \
567 Dextallp4(srcdstD),shiftamt,Dextallp4(srcdstD)); \
568 Variable_shift_double(Dextallp2(srcdstB), \
569 Dextallp3(srcdstC),shiftamt,Dextallp3(srcdstC)); \
570 Variable_shift_double(Dextallp1(srcdstA), \
571 Dextallp2(srcdstB),shiftamt,Dextallp2(srcdstB)); \
572 Dextallp1(srcdstA) >>= shiftamt; \
575 case 1: if (shiftamt > 0) { \
576 sticky = (Dextallp3(srcdstC) << 31 - shiftamt) | \
577 Dextallp4(srcdstD); \
578 Variable_shift_double(Dextallp2(srcdstB), \
579 Dextallp3(srcdstC),shiftamt,Dextallp4(srcdstD)); \
580 Variable_shift_double(Dextallp1(srcdstA), \
581 Dextallp2(srcdstB),shiftamt,Dextallp3(srcdstC)); \
584 sticky = Dextallp4(srcdstD); \
585 Dextallp4(srcdstD) = Dextallp3(srcdstC); \
586 Dextallp3(srcdstC) = Dextallp2(srcdstB); \
588 Dextallp2(srcdstB) = Dextallp1(srcdstA) >> shiftamt; \
589 Dextallp1(srcdstA) = 0; \
591 case 2: if (shiftamt > 0) { \
592 sticky = (Dextallp2(srcdstB) << 31 - shiftamt) | \
593 Dextallp3(srcdstC) | Dextallp4(srcdstD); \
594 Variable_shift_double(Dextallp1(srcdstA), \
595 Dextallp2(srcdstB),shiftamt,Dextallp4(srcdstD)); \
598 sticky = Dextallp3(srcdstC) | Dextallp4(srcdstD); \
599 Dextallp4(srcdstD) = Dextallp2(srcdstB); \
601 Dextallp3(srcdstC) = Dextallp1(srcdstA) >> shiftamt; \
602 Dextallp1(srcdstA) = Dextallp2(srcdstB) = 0; \
604 case 3: if (shiftamt > 0) { \
605 sticky = (Dextallp1(srcdstA) << 31 - shiftamt) | \
606 Dextallp2(srcdstB) | Dextallp3(srcdstC) | \
607 Dextallp4(srcdstD); \
610 sticky = Dextallp2(srcdstB) | Dextallp3(srcdstC) | \
611 Dextallp4(srcdstD); \
613 Dextallp4(srcdstD) = Dextallp1(srcdstA) >> shiftamt; \
614 Dextallp1(srcdstA) = Dextallp2(srcdstB) = 0; \
615 Dextallp3(srcdstC) = 0; \
618 if (sticky) Dblext_setone_lowmantissap4(srcdstD); \
621 /* The left argument is never smaller than the right argument */
622 #define Dblext_subtract(lefta,leftb,leftc,leftd,righta,rightb,rightc,rightd,resulta,resultb,resultc,resultd) \
623 if( Dextallp4(rightd) > Dextallp4(leftd) ) \
624 if( (Dextallp3(leftc)--) == 0) \
625 if( (Dextallp2(leftb)--) == 0) Dextallp1(lefta)--; \
626 Dextallp4(resultd) = Dextallp4(leftd) - Dextallp4(rightd); \
627 if( Dextallp3(rightc) > Dextallp3(leftc) ) \
628 if( (Dextallp2(leftb)--) == 0) Dextallp1(lefta)--; \
629 Dextallp3(resultc) = Dextallp3(leftc) - Dextallp3(rightc); \
630 if( Dextallp2(rightb) > Dextallp2(leftb) ) Dextallp1(lefta)--; \
631 Dextallp2(resultb) = Dextallp2(leftb) - Dextallp2(rightb); \
632 Dextallp1(resulta) = Dextallp1(lefta) - Dextallp1(righta)
634 #define Dblext_addition(lefta,leftb,leftc,leftd,righta,rightb,rightc,rightd,resulta,resultb,resultc,resultd) \
635 /* If the sum of the low words is less than either source, then \
636 * an overflow into the next word occurred. */ \
637 if ((Dextallp4(resultd) = Dextallp4(leftd)+Dextallp4(rightd)) < \
639 if((Dextallp3(resultc) = Dextallp3(leftc)+Dextallp3(rightc)+1) <= \
641 if((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)+1) \
642 <= Dextallp2(rightb)) \
643 Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
644 else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta); \
646 if ((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)) < \
648 Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
649 else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta); \
651 if ((Dextallp3(resultc) = Dextallp3(leftc)+Dextallp3(rightc)) < \
653 if ((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)+1) \
654 <= Dextallp2(rightb)) \
655 Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
656 else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta); \
658 if ((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)) < \
660 Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
661 else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)
664 #define Dblext_arithrightshiftby1(srcdstA,srcdstB,srcdstC,srcdstD) \
665 Shiftdouble(Dextallp3(srcdstC),Dextallp4(srcdstD),1,Dextallp4(srcdstD)); \
666 Shiftdouble(Dextallp2(srcdstB),Dextallp3(srcdstC),1,Dextallp3(srcdstC)); \
667 Shiftdouble(Dextallp1(srcdstA),Dextallp2(srcdstB),1,Dextallp2(srcdstB)); \
668 Dextallp1(srcdstA) = (int)Dextallp1(srcdstA) >> 1
670 #define Dblext_leftshiftby8(valA,valB,valC,valD) \
671 Shiftdouble(Dextallp1(valA),Dextallp2(valB),24,Dextallp1(valA)); \
672 Shiftdouble(Dextallp2(valB),Dextallp3(valC),24,Dextallp2(valB)); \
673 Shiftdouble(Dextallp3(valC),Dextallp4(valD),24,Dextallp3(valC)); \
674 Dextallp4(valD) <<= 8
675 #define Dblext_leftshiftby4(valA,valB,valC,valD) \
676 Shiftdouble(Dextallp1(valA),Dextallp2(valB),28,Dextallp1(valA)); \
677 Shiftdouble(Dextallp2(valB),Dextallp3(valC),28,Dextallp2(valB)); \
678 Shiftdouble(Dextallp3(valC),Dextallp4(valD),28,Dextallp3(valC)); \
679 Dextallp4(valD) <<= 4
680 #define Dblext_leftshiftby3(valA,valB,valC,valD) \
681 Shiftdouble(Dextallp1(valA),Dextallp2(valB),29,Dextallp1(valA)); \
682 Shiftdouble(Dextallp2(valB),Dextallp3(valC),29,Dextallp2(valB)); \
683 Shiftdouble(Dextallp3(valC),Dextallp4(valD),29,Dextallp3(valC)); \
684 Dextallp4(valD) <<= 3
685 #define Dblext_leftshiftby2(valA,valB,valC,valD) \
686 Shiftdouble(Dextallp1(valA),Dextallp2(valB),30,Dextallp1(valA)); \
687 Shiftdouble(Dextallp2(valB),Dextallp3(valC),30,Dextallp2(valB)); \
688 Shiftdouble(Dextallp3(valC),Dextallp4(valD),30,Dextallp3(valC)); \
689 Dextallp4(valD) <<= 2
690 #define Dblext_leftshiftby1(valA,valB,valC,valD) \
691 Shiftdouble(Dextallp1(valA),Dextallp2(valB),31,Dextallp1(valA)); \
692 Shiftdouble(Dextallp2(valB),Dextallp3(valC),31,Dextallp2(valB)); \
693 Shiftdouble(Dextallp3(valC),Dextallp4(valD),31,Dextallp3(valC)); \
694 Dextallp4(valD) <<= 1
696 #define Dblext_rightshiftby4(valueA,valueB,valueC,valueD) \
697 Shiftdouble(Dextallp3(valueC),Dextallp4(valueD),4,Dextallp4(valueD)); \
698 Shiftdouble(Dextallp2(valueB),Dextallp3(valueC),4,Dextallp3(valueC)); \
699 Shiftdouble(Dextallp1(valueA),Dextallp2(valueB),4,Dextallp2(valueB)); \
700 Dextallp1(valueA) >>= 4
701 #define Dblext_rightshiftby1(valueA,valueB,valueC,valueD) \
702 Shiftdouble(Dextallp3(valueC),Dextallp4(valueD),1,Dextallp4(valueD)); \
703 Shiftdouble(Dextallp2(valueB),Dextallp3(valueC),1,Dextallp3(valueC)); \
704 Shiftdouble(Dextallp1(valueA),Dextallp2(valueB),1,Dextallp2(valueB)); \
705 Dextallp1(valueA) >>= 1
707 #define Dblext_xortointp1(left,right,result) Dbl_xortointp1(left,right,result)
709 #define Dblext_xorfromintp1(left,right,result) \
710 Dbl_xorfromintp1(left,right,result)
712 #define Dblext_copytoint_exponentmantissap1(src,dest) \
713 Dbl_copytoint_exponentmantissap1(src,dest)
715 #define Dblext_ismagnitudeless(leftB,rightB,signlessleft,signlessright) \
716 Dbl_ismagnitudeless(leftB,rightB,signlessleft,signlessright)
718 #define Dbl_copyto_dblext(src1,src2,dest1,dest2,dest3,dest4) \
719 Dextallp1(dest1) = Dallp1(src1); Dextallp2(dest2) = Dallp2(src2); \
720 Dextallp3(dest3) = 0; Dextallp4(dest4) = 0
722 #define Dblext_set_sign(dbl_value,sign) Dbl_set_sign(dbl_value,sign)
723 #define Dblext_clear_signexponent_set_hidden(srcdst) \
724 Dbl_clear_signexponent_set_hidden(srcdst)
725 #define Dblext_clear_signexponent(srcdst) Dbl_clear_signexponent(srcdst)
726 #define Dblext_clear_sign(srcdst) Dbl_clear_sign(srcdst)
727 #define Dblext_isone_hidden(dbl_value) Dbl_isone_hidden(dbl_value)
730 * The Fourword_add() macro assumes that integers are 4 bytes in size.
731 * It will break if this is not the case.
734 #define Fourword_add(src1dstA,src1dstB,src1dstC,src1dstD,src2A,src2B,src2C,src2D) \
736 * want this macro to generate: \
737 * ADD src1dstD,src2D,src1dstD; \
738 * ADDC src1dstC,src2C,src1dstC; \
739 * ADDC src1dstB,src2B,src1dstB; \
740 * ADDC src1dstA,src2A,src1dstA; \
742 if ((unsigned int)(src1dstD += (src2D)) < (unsigned int)(src2D)) { \
743 if ((unsigned int)(src1dstC += (src2C) + 1) <= \
744 (unsigned int)(src2C)) { \
745 if ((unsigned int)(src1dstB += (src2B) + 1) <= \
746 (unsigned int)(src2B)) src1dstA++; \
748 else if ((unsigned int)(src1dstB += (src2B)) < \
749 (unsigned int)(src2B)) src1dstA++; \
752 if ((unsigned int)(src1dstC += (src2C)) < \
753 (unsigned int)(src2C)) { \
754 if ((unsigned int)(src1dstB += (src2B) + 1) <= \
755 (unsigned int)(src2B)) src1dstA++; \
757 else if ((unsigned int)(src1dstB += (src2B)) < \
758 (unsigned int)(src2B)) src1dstA++; \
762 #define Dblext_denormalize(opndp1,opndp2,opndp3,opndp4,exponent,is_tiny) \
763 {int shiftamt, sticky; \
765 if (exponent == 0 && (Dextallp3(opndp3) || Dextallp4(opndp4))) { \
766 switch (Rounding_mode()) { \
768 if (Dbl_iszero_sign(opndp1)) { \
769 Dbl_increment(opndp1,opndp2); \
770 if (Dbl_isone_hiddenoverflow(opndp1)) \
772 Dbl_decrement(opndp1,opndp2); \
776 if (Dbl_isone_sign(opndp1)) { \
777 Dbl_increment(opndp1,opndp2); \
778 if (Dbl_isone_hiddenoverflow(opndp1)) \
780 Dbl_decrement(opndp1,opndp2); \
784 if (Dblext_isone_highp3(opndp3) && \
785 (Dblext_isone_lowp2(opndp2) || \
786 Dblext_isnotzero_low31p3(opndp3))) { \
787 Dbl_increment(opndp1,opndp2); \
788 if (Dbl_isone_hiddenoverflow(opndp1)) \
790 Dbl_decrement(opndp1,opndp2); \
795 Dblext_clear_signexponent_set_hidden(opndp1); \
796 if (exponent >= (1-QUAD_P)) { \
797 shiftamt = (1-exponent) % 32; \
798 switch((1-exponent)/32) { \
799 case 0: sticky = Dextallp4(opndp4) << 32-(shiftamt); \
800 Variableshiftdouble(opndp3,opndp4,shiftamt,opndp4); \
801 Variableshiftdouble(opndp2,opndp3,shiftamt,opndp3); \
802 Variableshiftdouble(opndp1,opndp2,shiftamt,opndp2); \
803 Dextallp1(opndp1) >>= shiftamt; \
805 case 1: sticky = (Dextallp3(opndp3) << 32-(shiftamt)) | \
807 Variableshiftdouble(opndp2,opndp3,shiftamt,opndp4); \
808 Variableshiftdouble(opndp1,opndp2,shiftamt,opndp3); \
809 Dextallp2(opndp2) = Dextallp1(opndp1) >> shiftamt; \
810 Dextallp1(opndp1) = 0; \
812 case 2: sticky = (Dextallp2(opndp2) << 32-(shiftamt)) | \
813 Dextallp3(opndp3) | Dextallp4(opndp4); \
814 Variableshiftdouble(opndp1,opndp2,shiftamt,opndp4); \
815 Dextallp3(opndp3) = Dextallp1(opndp1) >> shiftamt; \
816 Dextallp1(opndp1) = Dextallp2(opndp2) = 0; \
818 case 3: sticky = (Dextallp1(opndp1) << 32-(shiftamt)) | \
819 Dextallp2(opndp2) | Dextallp3(opndp3) | \
821 Dextallp4(opndp4) = Dextallp1(opndp1) >> shiftamt; \
822 Dextallp1(opndp1) = Dextallp2(opndp2) = 0; \
823 Dextallp3(opndp3) = 0; \
828 sticky = Dextallp1(opndp1) | Dextallp2(opndp2) | \
829 Dextallp3(opndp3) | Dextallp4(opndp4); \
830 Dblext_setzero(opndp1,opndp2,opndp3,opndp4); \
832 if (sticky) Dblext_setone_lowmantissap4(opndp4); \