Lines Matching +full:x +full:- +full:y
1 /* Software floating-point emulation. Common operations.
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #define _FP_DECL(wc, X) \ argument
28 _FP_I_TYPE X##_c=0, X##_s=0, X##_e=0; \
29 _FP_FRAC_DECL_##wc(X)
36 #define _FP_UNPACK_CANONICAL(fs, wc, X) \ argument
38 switch (X##_e) \
41 _FP_FRAC_HIGH_RAW_##fs(X) |= _FP_IMPLBIT_##fs; \
42 _FP_FRAC_SLL_##wc(X, _FP_WORKBITS); \
43 X##_e -= _FP_EXPBIAS_##fs; \
44 X##_c = FP_CLS_NORMAL; \
48 if (_FP_FRAC_ZEROP_##wc(X)) \
49 X##_c = FP_CLS_ZERO; \
54 _FP_FRAC_CLZ_##wc(_shift, X); \
55 _shift -= _FP_FRACXBITS_##fs; \
56 _FP_FRAC_SLL_##wc(X, (_shift+_FP_WORKBITS)); \
57 X##_e -= _FP_EXPBIAS_##fs - 1 + _shift; \
58 X##_c = FP_CLS_NORMAL; \
63 X##_c = FP_CLS_ZERO; \
69 if (_FP_FRAC_ZEROP_##wc(X)) \
70 X##_c = FP_CLS_INF; \
73 X##_c = FP_CLS_NAN; \
75 if (!(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
86 * extracted -- but that is ok, we can regenerate them now.
89 #define _FP_PACK_CANONICAL(fs, wc, X) \ argument
91 switch (X##_c) \
94 X##_e += _FP_EXPBIAS_##fs; \
95 if (X##_e > 0) \
97 _FP_ROUND(wc, X); \
98 if (_FP_FRAC_OVERP_##wc(fs, X)) \
100 _FP_FRAC_CLEAR_OVERP_##wc(fs, X); \
101 X##_e++; \
103 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
104 if (X##_e >= _FP_EXPMAX_##fs) \
110 X##_c = FP_CLS_INF; \
113 if (!X##_s) X##_c = FP_CLS_INF; \
116 if (X##_s) X##_c = FP_CLS_INF; \
119 if (X##_c == FP_CLS_INF) \
122 X##_e = _FP_EXPMAX_##fs; \
123 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
128 X##_e = _FP_EXPMAX_##fs - 1; \
129 _FP_FRAC_SET_##wc(X, _FP_MAXFRAC_##wc); \
138 X##_e = -X##_e + 1; \
139 if (X##_e <= _FP_WFRACBITS_##fs) \
141 _FP_FRAC_SRS_##wc(X, X##_e, _FP_WFRACBITS_##fs); \
142 if (_FP_FRAC_HIGH_##fs(X) \
145 X##_e = 1; \
146 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
150 _FP_ROUND(wc, X); \
151 if (_FP_FRAC_HIGH_##fs(X) \
154 X##_e = 1; \
155 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
160 X##_e = 0; \
161 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
171 X##_e = 0; \
172 if (!_FP_FRAC_ZEROP_##wc(X)) \
174 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
175 _FP_ROUND(wc, X); \
176 _FP_FRAC_LOW_##wc(X) >>= (_FP_WORKBITS); \
184 X##_e = 0; \
185 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
189 X##_e = _FP_EXPMAX_##fs; \
190 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
194 X##_e = _FP_EXPMAX_##fs; \
197 _FP_FRAC_SET_##wc(X, _FP_NANFRAC_##fs); \
198 X##_s = _FP_NANSIGN_##fs; \
201 _FP_FRAC_HIGH_RAW_##fs(X) |= _FP_QNANBIT_##fs; \
207 * 1 if X is a signaling NaN.
209 #define _FP_ISSIGNAN(fs, wc, X) \ argument
212 if (X##_e == _FP_EXPMAX_##fs) \
214 if (!_FP_FRAC_ZEROP_##wc(X) \
215 && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
229 #define _FP_ADD_INTERNAL(fs, wc, R, X, Y, OP) \ argument
231 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
236 _FP_I_TYPE diff = X##_e - Y##_e; \
240 diff = -diff; \
242 _FP_FRAC_SRS_##wc(X, diff, _FP_WFRACBITS_##fs); \
243 else if (!_FP_FRAC_ZEROP_##wc(X)) \
244 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
245 R##_e = Y##_e; \
252 _FP_FRAC_SRS_##wc(Y, diff, _FP_WFRACBITS_##fs); \
253 else if (!_FP_FRAC_ZEROP_##wc(Y)) \
254 _FP_FRAC_SET_##wc(Y, _FP_MINFRAC_##wc); \
256 R##_e = X##_e; \
261 if (X##_s == Y##_s) \
263 R##_s = X##_s; \
264 _FP_FRAC_ADD_##wc(R, X, Y); \
273 R##_s = X##_s; \
274 _FP_FRAC_SUB_##wc(R, X, Y); \
279 R##_s |= Y##_s; \
281 R##_s &= Y##_s; \
288 _FP_FRAC_SUB_##wc(R, Y, X); \
289 R##_s = Y##_s; \
294 diff -= _FP_WFRACXBITS_##fs; \
297 R##_e -= diff; \
306 _FP_CHOOSENAN(fs, wc, R, X, Y, OP); \
310 R##_e = X##_e; \
315 _FP_FRAC_COPY_##wc(R, X); \
316 R##_s = X##_s; \
317 R##_c = X##_c; \
321 R##_e = Y##_e; \
326 _FP_FRAC_COPY_##wc(R, Y); \
327 R##_s = Y##_s; \
328 R##_c = Y##_c; \
332 if (X##_s != Y##_s) \
334 /* +INF + -INF => NAN */ \
345 R##_s = X##_s; \
351 R##_s = Y##_s; \
358 R##_s = X##_s | Y##_s; \
360 R##_s = X##_s & Y##_s; \
369 #define _FP_ADD(fs, wc, R, X, Y) _FP_ADD_INTERNAL(fs, wc, R, X, Y, '+') argument
370 #define _FP_SUB(fs, wc, R, X, Y) \ argument
372 if (Y##_c != FP_CLS_NAN) Y##_s ^= 1; \
373 _FP_ADD_INTERNAL(fs, wc, R, X, Y, '-'); \
378 * Main negation routine. FIXME -- when we care about setting exception
382 #define _FP_NEG(fs, wc, R, X) \ argument
384 _FP_FRAC_COPY_##wc(R, X); \
385 R##_c = X##_c; \
386 R##_e = X##_e; \
387 R##_s = 1 ^ X##_s; \
395 #define _FP_MUL(fs, wc, R, X, Y) \ argument
397 R##_s = X##_s ^ Y##_s; \
398 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
402 R##_e = X##_e + Y##_e + 1; \
404 _FP_MUL_MEAT_##fs(R,X,Y); \
409 R##_e--; \
413 _FP_CHOOSENAN(fs, wc, R, X, Y, '*'); \
419 R##_s = X##_s; \
426 _FP_FRAC_COPY_##wc(R, X); \
427 R##_c = X##_c; \
433 R##_s = Y##_s; \
438 _FP_FRAC_COPY_##wc(R, Y); \
439 R##_c = Y##_c; \
460 #define _FP_DIV(fs, wc, R, X, Y) \ argument
462 R##_s = X##_s ^ Y##_s; \
463 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
467 R##_e = X##_e - Y##_e; \
469 _FP_DIV_MEAT_##fs(R,X,Y); \
473 _FP_CHOOSENAN(fs, wc, R, X, Y, '/'); \
479 R##_s = X##_s; \
480 _FP_FRAC_COPY_##wc(R, X); \
481 R##_c = X##_c; \
487 R##_s = Y##_s; \
488 _FP_FRAC_COPY_##wc(R, Y); \
489 R##_c = Y##_c; \
528 * cooked. The return is -1,0,1 for normal values, 2 otherwise.
531 #define _FP_CMP(fs, wc, ret, X, Y, un) \ argument
534 if ((X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X)) \
535 || (Y##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(Y))) \
544 __is_zero_x = (!X##_e && _FP_FRAC_ZEROP_##wc(X)) ? 1 : 0; \
545 __is_zero_y = (!Y##_e && _FP_FRAC_ZEROP_##wc(Y)) ? 1 : 0; \
550 ret = Y##_s ? 1 : -1; \
552 ret = X##_s ? -1 : 1; \
553 else if (X##_s != Y##_s) \
554 ret = X##_s ? -1 : 1; \
555 else if (X##_e > Y##_e) \
556 ret = X##_s ? -1 : 1; \
557 else if (X##_e < Y##_e) \
558 ret = X##_s ? 1 : -1; \
559 else if (_FP_FRAC_GT_##wc(X, Y)) \
560 ret = X##_s ? -1 : 1; \
561 else if (_FP_FRAC_GT_##wc(Y, X)) \
562 ret = X##_s ? 1 : -1; \
571 #define _FP_CMP_EQ(fs, wc, ret, X, Y) \ argument
574 if ((X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X)) \
575 || (Y##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(Y))) \
581 ret = !(X##_e == Y##_e \
582 && _FP_FRAC_EQ_##wc(X, Y) \
583 && (X##_s == Y##_s || !X##_e && _FP_FRAC_ZEROP_##wc(X))); \
591 #define _FP_SQRT(fs, wc, R, X) \ argument
595 switch (X##_c) \
598 _FP_FRAC_COPY_##wc(R, X); \
599 R##_s = X##_s; \
603 if (X##_s) \
617 R##_s = X##_s; \
618 R##_c = FP_CLS_ZERO; /* sqrt(+-0) = +-0 */ \
622 if (X##_s) \
631 if (X##_e & 1) \
632 _FP_FRAC_SLL_##wc(X, 1); \
633 R##_e = X##_e >> 1; \
637 _FP_SQRT_MEAT_##wc(R, S, T, X, q); \
646 * 0: the number is required to be 0..(2^rsize)-1, if not, NV is set plus
647 * the result is either 0 or (2^rsize)-1 depending on the sign in such case.
648 * 1: the number is required to be -(2^(rsize-1))..(2^(rsize-1))-1, if not, NV is
649 * set plus the result is either -(2^(rsize-1)) or (2^(rsize-1))-1 depending
651 * 2: the number is required to be -(2^(rsize-1))..(2^(rsize-1))-1, if not, NV is
653 * -1: the number is required to be -(2^(rsize-1))..(2^rsize)-1, if not, NV is
654 * set plus the result is either -(2^(rsize-1)) or (2^(rsize-1))-1 depending
657 #define _FP_TO_INT(fs, wc, r, X, rsize, rsigned) \ argument
659 switch (X##_c) \
662 if (X##_e < 0) \
669 else if (X##_e >= rsize - (rsigned > 0 || X##_s) \
670 || (!rsigned && X##_s)) \
677 if (X##_c != FP_CLS_NORMAL \
678 || X##_e >= rsize - 1 + _FP_WFRACBITS_##fs) \
682 _FP_FRAC_SLL_##wc(X, (X##_e - _FP_WFRACBITS_##fs + 1)); \
683 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
689 r <<= rsize - 1; \
690 r -= 1 - X##_s; \
695 if (!X##_s) \
704 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
705 r <<= X##_e - _FP_WFRACBITS_##fs; \
709 if (X##_e >= _FP_WFRACBITS_##fs) \
710 _FP_FRAC_SLL_##wc(X, (X##_e - _FP_WFRACBITS_##fs + 1)); \
711 else if (X##_e < _FP_WFRACBITS_##fs - 1) \
713 _FP_FRAC_SRS_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 2), \
715 if (_FP_FRAC_LOW_##wc(X) & 1) \
717 _FP_FRAC_SRL_##wc(X, 1); \
719 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
721 if (rsigned && X##_s) \
722 r = -r; \
728 #define _FP_TO_INT_ROUND(fs, wc, r, X, rsize, rsigned) \ argument
731 switch (X##_c) \
734 if (X##_e >= _FP_FRACBITS_##fs - 1) \
736 if (X##_e < rsize - 1 + _FP_WFRACBITS_##fs) \
738 if (X##_e >= _FP_WFRACBITS_##fs - 1) \
740 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
741 r <<= X##_e - _FP_WFRACBITS_##fs + 1; \
745 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS - X##_e \
746 + _FP_FRACBITS_##fs - 1); \
747 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
754 if (X##_e <= -_FP_WORKBITS - 1) \
755 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
757 _FP_FRAC_SRS_##wc(X, _FP_FRACBITS_##fs - 1 - X##_e, \
759 _FP_FRAC_CLZ_##wc(_lz0, X); \
760 _FP_ROUND(wc, X); \
761 _FP_FRAC_CLZ_##wc(_lz1, X); \
763 X##_e++; /* For overflow detection. */ \
764 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
765 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
767 if (rsigned && X##_s) \
768 r = -r; \
769 if (X##_e >= rsize - (rsigned > 0 || X##_s) \
770 || (!rsigned && X##_s)) \
778 if (!X##_s) \
784 r <<= rsize - 1; \
785 r -= 1 - X##_s; \
795 #define _FP_FROM_INT(fs, wc, X, r, rsize, rtype) \ argument
800 X##_c = FP_CLS_NORMAL; \
802 if ((X##_s = (r < 0))) \
803 ur_ = (unsigned rtype) -r; \
807 ? ({ __FP_CLZ(X##_e, ur_); }) \
809 __FP_CLZ_2(X##_e, (_FP_W_TYPE)(ur_ >> _FP_W_TYPE_SIZE), \
813 X##_e -= (_FP_W_TYPE_SIZE - rsize); \
814 X##_e = rsize - X##_e - 1; \
816 if (_FP_FRACBITS_##fs < rsize && _FP_WFRACBITS_##fs <= X##_e) \
817 __FP_FRAC_SRS_1(ur_, (X##_e - _FP_WFRACBITS_##fs + 1), rsize);\
818 _FP_FRAC_DISASSEMBLE_##wc(X, ur_, rsize); \
819 if ((_FP_WFRACBITS_##fs - X##_e - 1) > 0) \
820 _FP_FRAC_SLL_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 1)); \
824 X##_c = FP_CLS_ZERO, X##_s = 0; \
845 /* this is just to shut the compiler up about shifts > word length -- PMM 02/1998 */
846 #define __FP_CLZ(r, x) \ argument
848 _FP_W_TYPE _t = (x); \
849 r = _FP_W_TYPE_SIZE - 1; \
850 if (_t > 0xffff) r -= 16; \
852 if (_t > 0xff) r -= 8; \
854 if (_t & 0xf0) r -= 4; \
856 if (_t & 0xc) r -= 2; \
858 if (_t & 0x2) r -= 1; \
861 #define __FP_CLZ(r, x) \ argument
863 _FP_W_TYPE _t = (x); \
864 r = _FP_W_TYPE_SIZE - 1; \
865 if (_t > 0xffffffff) r -= 32; \
867 if (_t > 0xffff) r -= 16; \
869 if (_t > 0xff) r -= 8; \
871 if (_t & 0xf0) r -= 4; \
873 if (_t & 0xc) r -= 2; \
875 if (_t & 0x2) r -= 1; \