Lines Matching +full:x +full:- +full:y

1 /* Software floating-point emulation.
2 Basic two-word fraction declaration and manipulation.
23 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #define _FP_FRAC_DECL_2(X) _FP_W_TYPE X##_f0 = 0, X##_f1 = 0 argument
30 #define _FP_FRAC_SET_2(X,I) __FP_FRAC_SET_2(X, I) argument
31 #define _FP_FRAC_HIGH_2(X) (X##_f1) argument
32 #define _FP_FRAC_LOW_2(X) (X##_f0) argument
33 #define _FP_FRAC_WORD_2(X,w) (X##_f##w) argument
34 #define _FP_FRAC_SLL_2(X, N) ( \ argument
38 X##_f1 = X##_f1 + X##_f1 + \
39 (((_FP_WS_TYPE) (X##_f0)) < 0); \
40 X##_f0 += X##_f0; \
42 X##_f1 = X##_f1 << (N) | X##_f0 >> \
43 (_FP_W_TYPE_SIZE - (N)); \
44 X##_f0 <<= (N); \
49 X##_f1 = X##_f0 << ((N) - _FP_W_TYPE_SIZE); \
50 X##_f0 = 0; \
54 #define _FP_FRAC_SRL_2(X, N) ( \ argument
57 X##_f0 = X##_f0 >> (N) | X##_f1 << (_FP_W_TYPE_SIZE - (N)); \
58 X##_f1 >>= (N); \
61 X##_f0 = X##_f1 >> ((N) - _FP_W_TYPE_SIZE); \
62 X##_f1 = 0; \
66 /* Right shift with sticky-lsb. */
67 #define _FP_FRAC_SRS_2(X, N, sz) ( \ argument
70 X##_f0 = (X##_f1 << (_FP_W_TYPE_SIZE - (N)) | X##_f0 >> (N) \
72 ? X##_f0 & 1 \
73 : (X##_f0 << (_FP_W_TYPE_SIZE - (N))) != 0)); \
74 X##_f1 >>= (N); \
77 X##_f0 = (X##_f1 >> ((N) - _FP_W_TYPE_SIZE) \
80 : (X##_f1 << (2*_FP_W_TYPE_SIZE - (N)))) \
81 | X##_f0) != 0)); \
82 X##_f1 = 0; \
85 #define _FP_FRAC_ADDI_2(X,I) \ argument
86 __FP_FRAC_ADDI_2(X##_f1, X##_f0, I)
88 #define _FP_FRAC_ADD_2(R,X,Y) \ argument
89 __FP_FRAC_ADD_2(R##_f1, R##_f0, X##_f1, X##_f0, Y##_f1, Y##_f0)
91 #define _FP_FRAC_SUB_2(R,X,Y) \ argument
92 __FP_FRAC_SUB_2(R##_f1, R##_f0, X##_f1, X##_f0, Y##_f1, Y##_f0)
94 #define _FP_FRAC_DEC_2(X,Y) \ argument
95 __FP_FRAC_DEC_2(X##_f1, X##_f0, Y##_f1, Y##_f0)
97 #define _FP_FRAC_CLZ_2(R,X) \ argument
99 if (X##_f1) \
100 __FP_CLZ(R,X##_f1); \
103 __FP_CLZ(R,X##_f0); \
109 #define _FP_FRAC_NEGP_2(X) ((_FP_WS_TYPE)X##_f1 < 0) argument
110 #define _FP_FRAC_ZEROP_2(X) ((X##_f1 | X##_f0) == 0) argument
111 #define _FP_FRAC_OVERP_2(fs,X) (_FP_FRAC_HIGH_##fs(X) & _FP_OVERFLOW_##fs) argument
112 #define _FP_FRAC_CLEAR_OVERP_2(fs,X) (_FP_FRAC_HIGH_##fs(X) &= ~_FP_OVERFLOW_##fs) argument
113 #define _FP_FRAC_EQ_2(X, Y) (X##_f1 == Y##_f1 && X##_f0 == Y##_f0) argument
114 #define _FP_FRAC_GT_2(X, Y) \ argument
115 (X##_f1 > Y##_f1 || (X##_f1 == Y##_f1 && X##_f0 > Y##_f0))
116 #define _FP_FRAC_GE_2(X, Y) \ argument
117 (X##_f1 > Y##_f1 || (X##_f1 == Y##_f1 && X##_f0 >= Y##_f0))
127 #define __FP_FRAC_SET_2(X,I1,I0) (X##_f0 = I0, X##_f1 = I1) argument
152 (rh = xh - yh - ((rl = xl - yl) > xl))
158 xh -= yh + ((xl -= yl) > _t); \
180 #define _FP_UNPACK_RAW_2(fs, X, val) \ argument
184 X##_f0 = _flo.bits.frac0; \
185 X##_f1 = _flo.bits.frac1; \
186 X##_e = _flo.bits.exp; \
187 X##_s = _flo.bits.sign; \
190 #define _FP_UNPACK_RAW_2_P(fs, X, val) \ argument
195 X##_f0 = _flo->bits.frac0; \
196 X##_f1 = _flo->bits.frac1; \
197 X##_e = _flo->bits.exp; \
198 X##_s = _flo->bits.sign; \
206 #define _FP_PACK_RAW_2(fs, val, X) \ argument
210 _flo.bits.frac0 = X##_f0; \
211 _flo.bits.frac1 = X##_f1; \
212 _flo.bits.exp = X##_e; \
213 _flo.bits.sign = X##_s; \
218 #define _FP_PACK_RAW_2_P(fs, val, X) \ argument
223 _flo->bits.frac0 = X##_f0; \
224 _flo->bits.frac1 = X##_f1; \
225 _flo->bits.exp = X##_e; \
226 _flo->bits.sign = X##_s; \
236 #define _FP_MUL_MEAT_2_wide(wfracbits, R, X, Y, doit) \ argument
240 doit(_FP_FRAC_WORD_4(_z,1), _FP_FRAC_WORD_4(_z,0), X##_f0, Y##_f0); \
241 doit(_b_f1, _b_f0, X##_f0, Y##_f1); \
242 doit(_c_f1, _c_f0, X##_f1, Y##_f0); \
243 doit(_FP_FRAC_WORD_4(_z,3), _FP_FRAC_WORD_4(_z,2), X##_f1, Y##_f1); \
256 at either 2B or 2B-1. */ \
257 _FP_FRAC_SRS_4(_z, wfracbits-1, 2*wfracbits); \
266 #define _FP_MUL_MEAT_2_wide_3mul(wfracbits, R, X, Y, doit) \ argument
272 _b_f0 = X##_f0 + X##_f1; \
273 _c1 = _b_f0 < X##_f0; \
274 _b_f1 = Y##_f0 + Y##_f1; \
275 _c2 = _b_f1 < Y##_f0; \
276 doit(_d, _FP_FRAC_WORD_4(_z,0), X##_f0, Y##_f0); \
278 doit(_c_f1, _c_f0, X##_f1, Y##_f1); \
280 _b_f0 &= -_c2; \
281 _b_f1 &= -_c1; \
300 at either 2B or 2B-1. */ \
301 _FP_FRAC_SRS_4(_z, wfracbits-1, 2*wfracbits); \
306 #define _FP_MUL_MEAT_2_gmp(wfracbits, R, X, Y) \ argument
310 _x[0] = X##_f0; _x[1] = X##_f1; \
311 _y[0] = Y##_f0; _y[1] = Y##_f1; \
317 at either 2B or 2B-1. */ \
318 _FP_FRAC_SRS_4(_z, wfracbits-1, 2*wfracbits); \
328 Caller guarantees that X and Y has (1LLL << (wfracbits - 1)) set.
332 #define _FP_MUL_MEAT_2_120_240_double(wfracbits, R, X, Y, setfetz, resetfe) \ argument
335 /* 2^-24 */ 5.9604644775390625e-08, \
336 /* 2^-48 */ 3.5527136788005009e-15, \
337 /* 2^-72 */ 2.1175823681357508e-22, \
338 /* 2^-96 */ 1.2621774483536189e-29, \
341 /* 2^-20 */ 9.5367431640625e-07, \
342 /* 2^-44 */ 5.6843418860808015e-14, \
343 /* 2^-68 */ 3.3881317890172014e-21, \
344 /* 2^-92 */ 2.0194839173657902e-28, \
345 /* 2^-116 */ 1.2037062152420224e-35}; \
357 _e240 = (double)(long)(X##_f0 & 0xffffff); \
358 _j240 = (double)(long)(Y##_f0 & 0xffffff); \
359 _d240 = (double)(long)((X##_f0 >> 24) & 0xffffff); \
360 _i240 = (double)(long)((Y##_f0 >> 24) & 0xffffff); \
361 _c240 = (double)(long)(((X##_f1 << 16) & 0xffffff) | (X##_f0 >> 48)); \
362 _h240 = (double)(long)(((Y##_f1 << 16) & 0xffffff) | (Y##_f0 >> 48)); \
363 _b240 = (double)(long)((X##_f1 >> 8) & 0xffffff); \
364 _g240 = (double)(long)((Y##_f1 >> 8) & 0xffffff); \
365 _a240 = (double)(long)(X##_f1 >> 32); \
366 _f240 = (double)(long)(Y##_f1 >> 32); \
392 _s240.d -= ((_const[10]+_s240.d)-_const[10]); \
393 _r240.d -= ((_const[9]+_r240.d)-_const[9]); \
394 _q240.d -= ((_const[8]+_q240.d)-_const[8]); \
395 _p240.d -= ((_const[7]+_p240.d)-_const[7]); \
409 R##_f1 = (_t240 << (128 - (wfracbits - 1))) \
410 | ((_u240 & 0xffffff) >> ((wfracbits - 1) - 104)); \
411 R##_f0 = ((_u240 & 0xffffff) << (168 - (wfracbits - 1))) \
412 | ((_v240 & 0xffffff) << (144 - (wfracbits - 1))) \
413 | ((_w240 & 0xffffff) << (120 - (wfracbits - 1))) \
414 | ((_x240 & 0xffffff) >> ((wfracbits - 1) - 96)) \
423 #define _FP_DIV_MEAT_2_udiv(fs, R, X, Y) \ argument
426 if (_FP_FRAC_GT_2(X, Y)) \
428 _n_f2 = X##_f1 >> 1; \
429 _n_f1 = X##_f1 << (_FP_W_TYPE_SIZE - 1) | X##_f0 >> 1; \
430 _n_f0 = X##_f0 << (_FP_W_TYPE_SIZE - 1); \
434 R##_e--; \
435 _n_f2 = X##_f1; \
436 _n_f1 = X##_f0; \
442 _FP_FRAC_SLL_2(Y, _FP_WFRACXBITS_##fs); \
444 udiv_qrnnd(R##_f1, _r_f1, _n_f2, _n_f1, Y##_f1); \
445 umul_ppmm(_m_f1, _m_f0, R##_f1, Y##_f0); \
449 R##_f1--; \
450 _FP_FRAC_ADD_2(_r, Y, _r); \
451 if (_FP_FRAC_GE_2(_r, Y) && _FP_FRAC_GT_2(_m, _r)) \
453 R##_f1--; \
454 _FP_FRAC_ADD_2(_r, Y, _r); \
459 if (_r_f1 == Y##_f1) \
462 (_r/Y##_f1 would not fit into UWtype). \
463 As _r is guaranteed to be < Y, R##_f0 can be either \
464 (UWtype)-1 or (UWtype)-2. But as we know what kind \
467 guard bit will be set anyway. -jj */ \
468 R##_f0 = -1; \
472 udiv_qrnnd(R##_f0, _r_f1, _r_f1, _r_f0, Y##_f1); \
473 umul_ppmm(_m_f1, _m_f0, R##_f0, Y##_f0); \
477 R##_f0--; \
478 _FP_FRAC_ADD_2(_r, Y, _r); \
479 if (_FP_FRAC_GE_2(_r, Y) && _FP_FRAC_GT_2(_m, _r)) \
481 R##_f0--; \
482 _FP_FRAC_ADD_2(_r, Y, _r); \
491 #define _FP_DIV_MEAT_2_gmp(fs, R, X, Y) \ argument
494 _y[0] = Y##_f0; _y[1] = Y##_f1; \
496 if (_FP_FRAC_GT_2(X, Y)) \
499 _x[1] = (X##_f0 << (_FP_WFRACBITS_##fs-1 - _FP_W_TYPE_SIZE) | \
500 X##_f1 >> (_FP_W_TYPE_SIZE - \
501 (_FP_WFRACBITS_##fs-1 - _FP_W_TYPE_SIZE))); \
502 _x[2] = X##_f1 << (_FP_WFRACBITS_##fs-1 - _FP_W_TYPE_SIZE); \
506 _x[1] = (X##_f0 << (_FP_WFRACBITS_##fs - _FP_W_TYPE_SIZE) | \
507 X##_f1 >> (_FP_W_TYPE_SIZE - \
508 (_FP_WFRACBITS_##fs - _FP_W_TYPE_SIZE))); \
509 _x[2] = X##_f1 << (_FP_WFRACBITS_##fs - _FP_W_TYPE_SIZE); \
524 #define _FP_SQRT_MEAT_2(R, S, T, X, q) \ argument
529 if (T##_f1 <= X##_f1) \
532 X##_f1 -= T##_f1; \
535 _FP_FRAC_SLL_2(X, 1); \
538 q = (_FP_W_TYPE)1 << (_FP_W_TYPE_SIZE - 1); \
543 if (T##_f1 < X##_f1 || \
544 (T##_f1 == X##_f1 && T##_f0 <= X##_f0)) \
548 _FP_FRAC_DEC_2(X, T); \
551 _FP_FRAC_SLL_2(X, 1); \
554 if (X##_f0 | X##_f1) \
556 if (S##_f1 < X##_f1 || \
557 (S##_f1 == X##_f1 && S##_f0 < X##_f0)) \
569 #define _FP_FRAC_ASSEMBLE_2(r, X, rsize) \ argument
571 ? ({ (r) = X##_f0; }) \
573 (r) = X##_f1; \
575 (r) += X##_f0; \
578 #define _FP_FRAC_DISASSEMBLE_2(X, r, rsize) \ argument
580 X##_f0 = r; \
581 X##_f1 = (rsize <= _FP_W_TYPE_SIZE ? 0 : r >> _FP_W_TYPE_SIZE); \
591 _FP_FRAC_SRS_2(S, (_FP_WFRACBITS_##sfs - _FP_WFRACBITS_##dfs), \
594 _FP_FRAC_SRL_2(S, (_FP_WFRACBITS_##sfs - _FP_WFRACBITS_##dfs)); \
602 _FP_FRAC_SLL_2(D, (_FP_WFRACBITS_##dfs - _FP_WFRACBITS_##sfs)); \