diff options
Diffstat (limited to 'soft-fp/op-common.h')
-rw-r--r-- | soft-fp/op-common.h | 385 |
1 files changed, 211 insertions, 174 deletions
diff --git a/soft-fp/op-common.h b/soft-fp/op-common.h index 6f8c1f3cb0..5f37a3296c 100644 --- a/soft-fp/op-common.h +++ b/soft-fp/op-common.h @@ -68,11 +68,14 @@ else \ { \ /* a denormalized number */ \ - _FP_I_TYPE _shift; \ - _FP_FRAC_CLZ_##wc (_shift, X); \ - _shift -= _FP_FRACXBITS_##fs; \ - _FP_FRAC_SLL_##wc (X, (_shift+_FP_WORKBITS)); \ - X##_e -= _FP_EXPBIAS_##fs - 1 + _shift; \ + _FP_I_TYPE _FP_UNPACK_CANONICAL_shift; \ + _FP_FRAC_CLZ_##wc (_FP_UNPACK_CANONICAL_shift, \ + X); \ + _FP_UNPACK_CANONICAL_shift -= _FP_FRACXBITS_##fs; \ + _FP_FRAC_SLL_##wc (X, (_FP_UNPACK_CANONICAL_shift \ + + _FP_WORKBITS)); \ + X##_e -= (_FP_EXPBIAS_##fs - 1 \ + + _FP_UNPACK_CANONICAL_shift); \ X##_c = FP_CLS_NORMAL; \ FP_SET_EXCEPTION (FP_EX_DENORM); \ } \ @@ -371,14 +374,14 @@ */ #define _FP_ISSIGNAN(fs, wc, X) \ ({ \ - int __ret = 0; \ + int _FP_ISSIGNAN_ret = 0; \ if (X##_e == _FP_EXPMAX_##fs) \ { \ if (!_FP_FRAC_ZEROP_##wc (X) \ && _FP_FRAC_SNANP (fs, X)) \ - __ret = 1; \ + _FP_ISSIGNAN_ret = 1; \ } \ - __ret; \ + _FP_ISSIGNAN_ret; \ }) @@ -393,8 +396,8 @@ { \ /* Addition. */ \ R##_s = X##_s; \ - int ediff = X##_e - Y##_e; \ - if (ediff > 0) \ + int _FP_ADD_INTERNAL_ediff = X##_e - Y##_e; \ + if (_FP_ADD_INTERNAL_ediff > 0) \ { \ R##_e = X##_e; \ if (Y##_e == 0) \ @@ -409,8 +412,8 @@ else \ { \ FP_SET_EXCEPTION (FP_EX_DENORM); \ - ediff--; \ - if (ediff == 0) \ + _FP_ADD_INTERNAL_ediff--; \ + if (_FP_ADD_INTERNAL_ediff == 0) \ { \ _FP_FRAC_ADD_##wc (R, X, Y); \ goto add3; \ @@ -436,17 +439,19 @@ _FP_FRAC_HIGH_##fs (Y) |= _FP_IMPLBIT_SH_##fs; \ \ add1: \ - /* Shift the mantissa of Y to the right EDIFF steps; \ - remember to account later for the implicit MSB of X. */ \ - if (ediff <= _FP_WFRACBITS_##fs) \ - _FP_FRAC_SRS_##wc (Y, ediff, _FP_WFRACBITS_##fs); \ + /* Shift the mantissa of Y to the right \ + _FP_ADD_INTERNAL_EDIFF steps; remember to account \ + later for the implicit MSB of X. */ \ + if (_FP_ADD_INTERNAL_ediff <= _FP_WFRACBITS_##fs) \ + _FP_FRAC_SRS_##wc (Y, _FP_ADD_INTERNAL_ediff, \ + _FP_WFRACBITS_##fs); \ else if (!_FP_FRAC_ZEROP_##wc (Y)) \ _FP_FRAC_SET_##wc (Y, _FP_MINFRAC_##wc); \ _FP_FRAC_ADD_##wc (R, X, Y); \ } \ - else if (ediff < 0) \ + else if (_FP_ADD_INTERNAL_ediff < 0) \ { \ - ediff = -ediff; \ + _FP_ADD_INTERNAL_ediff = -_FP_ADD_INTERNAL_ediff; \ R##_e = Y##_e; \ if (X##_e == 0) \ { \ @@ -460,8 +465,8 @@ else \ { \ FP_SET_EXCEPTION (FP_EX_DENORM); \ - ediff--; \ - if (ediff == 0) \ + _FP_ADD_INTERNAL_ediff--; \ + if (_FP_ADD_INTERNAL_ediff == 0) \ { \ _FP_FRAC_ADD_##wc (R, Y, X); \ goto add3; \ @@ -487,17 +492,19 @@ _FP_FRAC_HIGH_##fs (X) |= _FP_IMPLBIT_SH_##fs; \ \ add2: \ - /* Shift the mantissa of X to the right EDIFF steps; \ - remember to account later for the implicit MSB of Y. */ \ - if (ediff <= _FP_WFRACBITS_##fs) \ - _FP_FRAC_SRS_##wc (X, ediff, _FP_WFRACBITS_##fs); \ + /* Shift the mantissa of X to the right \ + _FP_ADD_INTERNAL_EDIFF steps; remember to account \ + later for the implicit MSB of Y. */ \ + if (_FP_ADD_INTERNAL_ediff <= _FP_WFRACBITS_##fs) \ + _FP_FRAC_SRS_##wc (X, _FP_ADD_INTERNAL_ediff, \ + _FP_WFRACBITS_##fs); \ else if (!_FP_FRAC_ZEROP_##wc (X)) \ _FP_FRAC_SET_##wc (X, _FP_MINFRAC_##wc); \ _FP_FRAC_ADD_##wc (R, Y, X); \ } \ else \ { \ - /* ediff == 0. */ \ + /* _FP_ADD_INTERNAL_ediff == 0. */ \ if (!_FP_EXP_NORMAL (fs, wc, X)) \ { \ if (X##_e == 0) \ @@ -573,8 +580,8 @@ else \ { \ /* Subtraction. */ \ - int ediff = X##_e - Y##_e; \ - if (ediff > 0) \ + int _FP_ADD_INTERNAL_ediff = X##_e - Y##_e; \ + if (_FP_ADD_INTERNAL_ediff > 0) \ { \ R##_e = X##_e; \ R##_s = X##_s; \ @@ -590,8 +597,8 @@ else \ { \ FP_SET_EXCEPTION (FP_EX_DENORM); \ - ediff--; \ - if (ediff == 0) \ + _FP_ADD_INTERNAL_ediff--; \ + if (_FP_ADD_INTERNAL_ediff == 0) \ { \ _FP_FRAC_SUB_##wc (R, X, Y); \ goto sub3; \ @@ -617,17 +624,19 @@ _FP_FRAC_HIGH_##fs (Y) |= _FP_IMPLBIT_SH_##fs; \ \ sub1: \ - /* Shift the mantissa of Y to the right EDIFF steps; \ - remember to account later for the implicit MSB of X. */ \ - if (ediff <= _FP_WFRACBITS_##fs) \ - _FP_FRAC_SRS_##wc (Y, ediff, _FP_WFRACBITS_##fs); \ + /* Shift the mantissa of Y to the right \ + _FP_ADD_INTERNAL_EDIFF steps; remember to account \ + later for the implicit MSB of X. */ \ + if (_FP_ADD_INTERNAL_ediff <= _FP_WFRACBITS_##fs) \ + _FP_FRAC_SRS_##wc (Y, _FP_ADD_INTERNAL_ediff, \ + _FP_WFRACBITS_##fs); \ else if (!_FP_FRAC_ZEROP_##wc (Y)) \ _FP_FRAC_SET_##wc (Y, _FP_MINFRAC_##wc); \ _FP_FRAC_SUB_##wc (R, X, Y); \ } \ - else if (ediff < 0) \ + else if (_FP_ADD_INTERNAL_ediff < 0) \ { \ - ediff = -ediff; \ + _FP_ADD_INTERNAL_ediff = -_FP_ADD_INTERNAL_ediff; \ R##_e = Y##_e; \ R##_s = Y##_s; \ if (X##_e == 0) \ @@ -642,8 +651,8 @@ else \ { \ FP_SET_EXCEPTION (FP_EX_DENORM); \ - ediff--; \ - if (ediff == 0) \ + _FP_ADD_INTERNAL_ediff--; \ + if (_FP_ADD_INTERNAL_ediff == 0) \ { \ _FP_FRAC_SUB_##wc (R, Y, X); \ goto sub3; \ @@ -669,10 +678,12 @@ _FP_FRAC_HIGH_##fs (X) |= _FP_IMPLBIT_SH_##fs; \ \ sub2: \ - /* Shift the mantissa of X to the right EDIFF steps; \ - remember to account later for the implicit MSB of Y. */ \ - if (ediff <= _FP_WFRACBITS_##fs) \ - _FP_FRAC_SRS_##wc (X, ediff, _FP_WFRACBITS_##fs); \ + /* Shift the mantissa of X to the right \ + _FP_ADD_INTERNAL_EDIFF steps; remember to account \ + later for the implicit MSB of Y. */ \ + if (_FP_ADD_INTERNAL_ediff <= _FP_WFRACBITS_##fs) \ + _FP_FRAC_SRS_##wc (X, _FP_ADD_INTERNAL_ediff, \ + _FP_WFRACBITS_##fs); \ else if (!_FP_FRAC_ZEROP_##wc (X)) \ _FP_FRAC_SET_##wc (X, _FP_MINFRAC_##wc); \ _FP_FRAC_SUB_##wc (R, Y, X); \ @@ -783,24 +794,26 @@ sub3: \ if (_FP_FRAC_HIGH_##fs (R) & _FP_IMPLBIT_SH_##fs) \ { \ - int diff; \ + int _FP_ADD_INTERNAL_diff; \ /* Carry into most significant bit of larger one of X and Y, \ canceling it; renormalize. */ \ _FP_FRAC_HIGH_##fs (R) &= _FP_IMPLBIT_SH_##fs - 1; \ norm: \ - _FP_FRAC_CLZ_##wc (diff, R); \ - diff -= _FP_WFRACXBITS_##fs; \ - _FP_FRAC_SLL_##wc (R, diff); \ - if (R##_e <= diff) \ + _FP_FRAC_CLZ_##wc (_FP_ADD_INTERNAL_diff, R); \ + _FP_ADD_INTERNAL_diff -= _FP_WFRACXBITS_##fs; \ + _FP_FRAC_SLL_##wc (R, _FP_ADD_INTERNAL_diff); \ + if (R##_e <= _FP_ADD_INTERNAL_diff) \ { \ /* R is denormalized. */ \ - diff = diff - R##_e + 1; \ - _FP_FRAC_SRS_##wc (R, diff, _FP_WFRACBITS_##fs); \ + _FP_ADD_INTERNAL_diff \ + = _FP_ADD_INTERNAL_diff - R##_e + 1; \ + _FP_FRAC_SRS_##wc (R, _FP_ADD_INTERNAL_diff, \ + _FP_WFRACBITS_##fs); \ R##_e = 0; \ } \ else \ { \ - R##_e -= diff; \ + R##_e -= _FP_ADD_INTERNAL_diff; \ _FP_FRAC_HIGH_##fs (R) &= ~(_FP_W_TYPE) _FP_IMPLBIT_SH_##fs; \ } \ } \ @@ -904,9 +917,9 @@ #define _FP_FMA(fs, wc, dwc, R, X, Y, Z) \ do \ { \ - FP_DECL_##fs (T); \ - T##_s = X##_s ^ Y##_s; \ - T##_e = X##_e + Y##_e + 1; \ + FP_DECL_##fs (_FP_FMA_T); \ + _FP_FMA_T##_s = X##_s ^ Y##_s; \ + _FP_FMA_T##_e = X##_e + Y##_e + 1; \ switch (_FP_CLS_COMBINE (X##_c, Y##_c)) \ { \ case _FP_CLS_COMBINE (FP_CLS_NORMAL, FP_CLS_NORMAL): \ @@ -921,8 +934,8 @@ \ case FP_CLS_ZERO: \ R##_c = FP_CLS_NORMAL; \ - R##_s = T##_s; \ - R##_e = T##_e; \ + R##_s = _FP_FMA_T##_s; \ + R##_e = _FP_FMA_T##_e; \ \ _FP_MUL_MEAT_##fs (R, X, Y); \ \ @@ -933,38 +946,43 @@ break; \ \ case FP_CLS_NORMAL:; \ - _FP_FRAC_DECL_##dwc (TD); \ - _FP_FRAC_DECL_##dwc (ZD); \ - _FP_FRAC_DECL_##dwc (RD); \ - _FP_MUL_MEAT_DW_##fs (TD, X, Y); \ - R##_e = T##_e; \ - int tsh = _FP_FRAC_HIGHBIT_DW_##dwc (fs, TD) == 0; \ - T##_e -= tsh; \ - int ediff = T##_e - Z##_e; \ - if (ediff >= 0) \ + _FP_FRAC_DECL_##dwc (_FP_FMA_TD); \ + _FP_FRAC_DECL_##dwc (_FP_FMA_ZD); \ + _FP_FRAC_DECL_##dwc (_FP_FMA_RD); \ + _FP_MUL_MEAT_DW_##fs (_FP_FMA_TD, X, Y); \ + R##_e = _FP_FMA_T##_e; \ + int _FP_FMA_tsh \ + = _FP_FRAC_HIGHBIT_DW_##dwc (fs, _FP_FMA_TD) == 0; \ + _FP_FMA_T##_e -= _FP_FMA_tsh; \ + int _FP_FMA_ediff = _FP_FMA_T##_e - Z##_e; \ + if (_FP_FMA_ediff >= 0) \ { \ - int shift = _FP_WFRACBITS_##fs - tsh - ediff; \ - if (shift <= -_FP_WFRACBITS_##fs) \ - _FP_FRAC_SET_##dwc (ZD, _FP_MINFRAC_##dwc); \ + int _FP_FMA_shift \ + = _FP_WFRACBITS_##fs - _FP_FMA_tsh - _FP_FMA_ediff; \ + if (_FP_FMA_shift <= -_FP_WFRACBITS_##fs) \ + _FP_FRAC_SET_##dwc (_FP_FMA_ZD, _FP_MINFRAC_##dwc); \ else \ { \ - _FP_FRAC_COPY_##dwc##_##wc (ZD, Z); \ - if (shift < 0) \ - _FP_FRAC_SRS_##dwc (ZD, -shift, \ + _FP_FRAC_COPY_##dwc##_##wc (_FP_FMA_ZD, Z); \ + if (_FP_FMA_shift < 0) \ + _FP_FRAC_SRS_##dwc (_FP_FMA_ZD, -_FP_FMA_shift, \ _FP_WFRACBITS_DW_##fs); \ - else if (shift > 0) \ - _FP_FRAC_SLL_##dwc (ZD, shift); \ + else if (_FP_FMA_shift > 0) \ + _FP_FRAC_SLL_##dwc (_FP_FMA_ZD, _FP_FMA_shift); \ } \ - R##_s = T##_s; \ - if (T##_s == Z##_s) \ - _FP_FRAC_ADD_##dwc (RD, TD, ZD); \ + R##_s = _FP_FMA_T##_s; \ + if (_FP_FMA_T##_s == Z##_s) \ + _FP_FRAC_ADD_##dwc (_FP_FMA_RD, _FP_FMA_TD, \ + _FP_FMA_ZD); \ else \ { \ - _FP_FRAC_SUB_##dwc (RD, TD, ZD); \ - if (_FP_FRAC_NEGP_##dwc (RD)) \ + _FP_FRAC_SUB_##dwc (_FP_FMA_RD, _FP_FMA_TD, \ + _FP_FMA_ZD); \ + if (_FP_FRAC_NEGP_##dwc (_FP_FMA_RD)) \ { \ R##_s = Z##_s; \ - _FP_FRAC_SUB_##dwc (RD, ZD, TD); \ + _FP_FRAC_SUB_##dwc (_FP_FMA_RD, _FP_FMA_ZD, \ + _FP_FMA_TD); \ } \ } \ } \ @@ -972,22 +990,24 @@ { \ R##_e = Z##_e; \ R##_s = Z##_s; \ - _FP_FRAC_COPY_##dwc##_##wc (ZD, Z); \ - _FP_FRAC_SLL_##dwc (ZD, _FP_WFRACBITS_##fs); \ - int shift = -ediff - tsh; \ - if (shift >= _FP_WFRACBITS_DW_##fs) \ - _FP_FRAC_SET_##dwc (TD, _FP_MINFRAC_##dwc); \ - else if (shift > 0) \ - _FP_FRAC_SRS_##dwc (TD, shift, \ + _FP_FRAC_COPY_##dwc##_##wc (_FP_FMA_ZD, Z); \ + _FP_FRAC_SLL_##dwc (_FP_FMA_ZD, _FP_WFRACBITS_##fs); \ + int _FP_FMA_shift = -_FP_FMA_ediff - _FP_FMA_tsh; \ + if (_FP_FMA_shift >= _FP_WFRACBITS_DW_##fs) \ + _FP_FRAC_SET_##dwc (_FP_FMA_TD, _FP_MINFRAC_##dwc); \ + else if (_FP_FMA_shift > 0) \ + _FP_FRAC_SRS_##dwc (_FP_FMA_TD, _FP_FMA_shift, \ _FP_WFRACBITS_DW_##fs); \ - if (Z##_s == T##_s) \ - _FP_FRAC_ADD_##dwc (RD, ZD, TD); \ + if (Z##_s == _FP_FMA_T##_s) \ + _FP_FRAC_ADD_##dwc (_FP_FMA_RD, _FP_FMA_ZD, \ + _FP_FMA_TD); \ else \ - _FP_FRAC_SUB_##dwc (RD, ZD, TD); \ + _FP_FRAC_SUB_##dwc (_FP_FMA_RD, _FP_FMA_ZD, \ + _FP_FMA_TD); \ } \ - if (_FP_FRAC_ZEROP_##dwc (RD)) \ + if (_FP_FRAC_ZEROP_##dwc (_FP_FMA_RD)) \ { \ - if (T##_s == Z##_s) \ + if (_FP_FMA_T##_s == Z##_s) \ R##_s = Z##_s; \ else \ R##_s = (FP_ROUNDMODE == FP_RND_MINF); \ @@ -996,17 +1016,17 @@ } \ else \ { \ - int rlz; \ - _FP_FRAC_CLZ_##dwc (rlz, RD); \ - rlz -= _FP_WFRACXBITS_DW_##fs; \ - R##_e -= rlz; \ - int shift = _FP_WFRACBITS_##fs - rlz; \ - if (shift > 0) \ - _FP_FRAC_SRS_##dwc (RD, shift, \ + int _FP_FMA_rlz; \ + _FP_FRAC_CLZ_##dwc (_FP_FMA_rlz, _FP_FMA_RD); \ + _FP_FMA_rlz -= _FP_WFRACXBITS_DW_##fs; \ + R##_e -= _FP_FMA_rlz; \ + int _FP_FMA_shift = _FP_WFRACBITS_##fs - _FP_FMA_rlz; \ + if (_FP_FMA_shift > 0) \ + _FP_FRAC_SRS_##dwc (_FP_FMA_RD, _FP_FMA_shift, \ _FP_WFRACBITS_DW_##fs); \ - else if (shift < 0) \ - _FP_FRAC_SLL_##dwc (RD, -shift); \ - _FP_FRAC_COPY_##wc##_##dwc (R, RD); \ + else if (_FP_FMA_shift < 0) \ + _FP_FRAC_SLL_##dwc (_FP_FMA_RD, -_FP_FMA_shift); \ + _FP_FRAC_COPY_##wc##_##dwc (R, _FP_FMA_RD); \ R##_c = FP_CLS_NORMAL; \ } \ break; \ @@ -1014,38 +1034,38 @@ goto done_fma; \ \ case _FP_CLS_COMBINE (FP_CLS_NAN, FP_CLS_NAN): \ - _FP_CHOOSENAN (fs, wc, T, X, Y, '*'); \ + _FP_CHOOSENAN (fs, wc, _FP_FMA_T, X, Y, '*'); \ break; \ \ case _FP_CLS_COMBINE (FP_CLS_NAN, FP_CLS_NORMAL): \ case _FP_CLS_COMBINE (FP_CLS_NAN, FP_CLS_INF): \ case _FP_CLS_COMBINE (FP_CLS_NAN, FP_CLS_ZERO): \ - T##_s = X##_s; \ + _FP_FMA_T##_s = X##_s; \ \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_INF): \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_NORMAL): \ case _FP_CLS_COMBINE (FP_CLS_ZERO, FP_CLS_NORMAL): \ case _FP_CLS_COMBINE (FP_CLS_ZERO, FP_CLS_ZERO): \ - _FP_FRAC_COPY_##wc (T, X); \ - T##_c = X##_c; \ + _FP_FRAC_COPY_##wc (_FP_FMA_T, X); \ + _FP_FMA_T##_c = X##_c; \ break; \ \ case _FP_CLS_COMBINE (FP_CLS_NORMAL, FP_CLS_NAN): \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_NAN): \ case _FP_CLS_COMBINE (FP_CLS_ZERO, FP_CLS_NAN): \ - T##_s = Y##_s; \ + _FP_FMA_T##_s = Y##_s; \ \ case _FP_CLS_COMBINE (FP_CLS_NORMAL, FP_CLS_INF): \ case _FP_CLS_COMBINE (FP_CLS_NORMAL, FP_CLS_ZERO): \ - _FP_FRAC_COPY_##wc (T, Y); \ - T##_c = Y##_c; \ + _FP_FRAC_COPY_##wc (_FP_FMA_T, Y); \ + _FP_FMA_T##_c = Y##_c; \ break; \ \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_ZERO): \ case _FP_CLS_COMBINE (FP_CLS_ZERO, FP_CLS_INF): \ - T##_s = _FP_NANSIGN_##fs; \ - T##_c = FP_CLS_NAN; \ - _FP_FRAC_SET_##wc (T, _FP_NANFRAC_##fs); \ + _FP_FMA_T##_s = _FP_NANSIGN_##fs; \ + _FP_FMA_T##_c = FP_CLS_NAN; \ + _FP_FRAC_SET_##wc (_FP_FMA_T, _FP_NANFRAC_##fs); \ FP_SET_EXCEPTION (FP_EX_INVALID); \ break; \ \ @@ -1054,10 +1074,10 @@ } \ \ /* T = X * Y is zero, infinity or NaN. */ \ - switch (_FP_CLS_COMBINE (T##_c, Z##_c)) \ + switch (_FP_CLS_COMBINE (_FP_FMA_T##_c, Z##_c)) \ { \ case _FP_CLS_COMBINE (FP_CLS_NAN, FP_CLS_NAN): \ - _FP_CHOOSENAN (fs, wc, R, T, Z, '+'); \ + _FP_CHOOSENAN (fs, wc, R, _FP_FMA_T, Z, '+'); \ break; \ \ case _FP_CLS_COMBINE (FP_CLS_NAN, FP_CLS_NORMAL): \ @@ -1065,9 +1085,9 @@ case _FP_CLS_COMBINE (FP_CLS_NAN, FP_CLS_ZERO): \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_NORMAL): \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_ZERO): \ - R##_s = T##_s; \ - _FP_FRAC_COPY_##wc (R, T); \ - R##_c = T##_c; \ + R##_s = _FP_FMA_T##_s; \ + _FP_FRAC_COPY_##wc (R, _FP_FMA_T); \ + R##_c = _FP_FMA_T##_c; \ break; \ \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_NAN): \ @@ -1080,7 +1100,7 @@ break; \ \ case _FP_CLS_COMBINE (FP_CLS_INF, FP_CLS_INF): \ - if (T##_s == Z##_s) \ + if (_FP_FMA_T##_s == Z##_s) \ { \ R##_s = Z##_s; \ _FP_FRAC_COPY_##wc (R, Z); \ @@ -1096,7 +1116,7 @@ break; \ \ case _FP_CLS_COMBINE (FP_CLS_ZERO, FP_CLS_ZERO): \ - if (T##_s == Z##_s) \ + if (_FP_FMA_T##_s == Z##_s) \ R##_s = Z##_s; \ else \ R##_s = (FP_ROUNDMODE == FP_RND_MINF); \ @@ -1193,17 +1213,19 @@ } \ else \ { \ - int __is_zero_x; \ - int __is_zero_y; \ + int _FP_CMP_is_zero_x; \ + int _FP_CMP_is_zero_y; \ \ - __is_zero_x = (!X##_e && _FP_FRAC_ZEROP_##wc (X)) ? 1 : 0; \ - __is_zero_y = (!Y##_e && _FP_FRAC_ZEROP_##wc (Y)) ? 1 : 0; \ + _FP_CMP_is_zero_x \ + = (!X##_e && _FP_FRAC_ZEROP_##wc (X)) ? 1 : 0; \ + _FP_CMP_is_zero_y \ + = (!Y##_e && _FP_FRAC_ZEROP_##wc (Y)) ? 1 : 0; \ \ - if (__is_zero_x && __is_zero_y) \ + if (_FP_CMP_is_zero_x && _FP_CMP_is_zero_y) \ ret = 0; \ - else if (__is_zero_x) \ + else if (_FP_CMP_is_zero_x) \ ret = Y##_s ? 1 : -1; \ - else if (__is_zero_y) \ + else if (_FP_CMP_is_zero_y) \ ret = X##_s ? -1 : 1; \ else if (X##_s != Y##_s) \ ret = X##_s ? -1 : 1; \ @@ -1259,9 +1281,9 @@ #define _FP_SQRT(fs, wc, R, X) \ do \ { \ - _FP_FRAC_DECL_##wc (T); \ - _FP_FRAC_DECL_##wc (S); \ - _FP_W_TYPE q; \ + _FP_FRAC_DECL_##wc (_FP_SQRT_T); \ + _FP_FRAC_DECL_##wc (_FP_SQRT_S); \ + _FP_W_TYPE _FP_SQRT_q; \ switch (X##_c) \ { \ case FP_CLS_NAN: \ @@ -1301,10 +1323,11 @@ if (X##_e & 1) \ _FP_FRAC_SLL_##wc (X, 1); \ R##_e = X##_e >> 1; \ - _FP_FRAC_SET_##wc (S, _FP_ZEROFRAC_##wc); \ + _FP_FRAC_SET_##wc (_FP_SQRT_S, _FP_ZEROFRAC_##wc); \ _FP_FRAC_SET_##wc (R, _FP_ZEROFRAC_##wc); \ - q = _FP_OVERFLOW_##fs >> 1; \ - _FP_SQRT_MEAT_##wc (R, S, T, X, q); \ + _FP_SQRT_q = _FP_OVERFLOW_##fs >> 1; \ + _FP_SQRT_MEAT_##wc (R, _FP_SQRT_S, _FP_SQRT_T, X, \ + _FP_SQRT_q); \ } \ } \ while (0) @@ -1360,10 +1383,10 @@ { \ /* Possibly converting to most negative integer; check the \ mantissa. */ \ - int inexact = 0; \ + int _FP_TO_INT_inexact = 0; \ (void) ((_FP_FRACBITS_##fs > rsize) \ ? ({ \ - _FP_FRAC_SRST_##wc (X, inexact, \ + _FP_FRAC_SRST_##wc (X, _FP_TO_INT_inexact, \ _FP_FRACBITS_##fs - rsize, \ _FP_FRACBITS_##fs); \ 0; \ @@ -1371,7 +1394,7 @@ : 0); \ if (!_FP_FRAC_ZEROP_##wc (X)) \ FP_SET_EXCEPTION (FP_EX_INVALID); \ - else if (inexact) \ + else if (_FP_TO_INT_inexact) \ FP_SET_EXCEPTION (FP_EX_INEXACT); \ } \ else \ @@ -1387,12 +1410,12 @@ } \ else \ { \ - int inexact; \ - _FP_FRAC_SRST_##wc (X, inexact, \ + int _FP_TO_INT_inexact; \ + _FP_FRAC_SRST_##wc (X, _FP_TO_INT_inexact, \ (_FP_FRACBITS_##fs + _FP_EXPBIAS_##fs - 1 \ - X##_e), \ _FP_FRACBITS_##fs); \ - if (inexact) \ + if (_FP_TO_INT_inexact) \ FP_SET_EXCEPTION (FP_EX_INEXACT); \ _FP_FRAC_ASSEMBLE_##wc (r, X, rsize); \ } \ @@ -1409,26 +1432,29 @@ { \ if (r) \ { \ - rtype ur_; \ + rtype _FP_FROM_INT_ur; \ \ if ((X##_s = (r < 0))) \ r = -(rtype) r; \ \ - ur_ = (rtype) r; \ + _FP_FROM_INT_ur = (rtype) r; \ (void) ((rsize <= _FP_W_TYPE_SIZE) \ ? ({ \ - int lz_; \ - __FP_CLZ (lz_, (_FP_W_TYPE) ur_); \ - X##_e = _FP_EXPBIAS_##fs + _FP_W_TYPE_SIZE - 1 - lz_; \ + int _FP_FROM_INT_lz; \ + __FP_CLZ (_FP_FROM_INT_lz, \ + (_FP_W_TYPE) _FP_FROM_INT_ur); \ + X##_e = (_FP_EXPBIAS_##fs + _FP_W_TYPE_SIZE - 1 \ + - _FP_FROM_INT_lz); \ }) \ : ((rsize <= 2 * _FP_W_TYPE_SIZE) \ ? ({ \ - int lz_; \ - __FP_CLZ_2 (lz_, \ - (_FP_W_TYPE) (ur_ >> _FP_W_TYPE_SIZE), \ - (_FP_W_TYPE) ur_); \ + int _FP_FROM_INT_lz; \ + __FP_CLZ_2 (_FP_FROM_INT_lz, \ + (_FP_W_TYPE) (_FP_FROM_INT_ur \ + >> _FP_W_TYPE_SIZE), \ + (_FP_W_TYPE) _FP_FROM_INT_ur); \ X##_e = (_FP_EXPBIAS_##fs + 2 * _FP_W_TYPE_SIZE - 1 \ - - lz_); \ + - _FP_FROM_INT_lz); \ }) \ : (abort (), 0))); \ \ @@ -1445,7 +1471,7 @@ || X##_e < _FP_EXPBIAS_##fs + _FP_FRACBITS_##fs) \ { \ /* Exactly representable; shift left. */ \ - _FP_FRAC_DISASSEMBLE_##wc (X, ur_, rsize); \ + _FP_FRAC_DISASSEMBLE_##wc (X, _FP_FROM_INT_ur, rsize); \ if (_FP_EXPBIAS_##fs + _FP_FRACBITS_##fs - 1 - X##_e > 0) \ _FP_FRAC_SLL_##wc (X, (_FP_EXPBIAS_##fs \ + _FP_FRACBITS_##fs - 1 - X##_e)); \ @@ -1455,12 +1481,14 @@ /* More bits in integer than in floating type; need to \ round. */ \ if (_FP_EXPBIAS_##fs + _FP_WFRACBITS_##fs - 1 < X##_e) \ - ur_ = ((ur_ >> (X##_e - _FP_EXPBIAS_##fs \ - - _FP_WFRACBITS_##fs + 1)) \ - | ((ur_ << (rsize - (X##_e - _FP_EXPBIAS_##fs \ - - _FP_WFRACBITS_##fs + 1))) \ - != 0)); \ - _FP_FRAC_DISASSEMBLE_##wc (X, ur_, rsize); \ + _FP_FROM_INT_ur \ + = ((_FP_FROM_INT_ur >> (X##_e - _FP_EXPBIAS_##fs \ + - _FP_WFRACBITS_##fs + 1)) \ + | ((_FP_FROM_INT_ur \ + << (rsize - (X##_e - _FP_EXPBIAS_##fs \ + - _FP_WFRACBITS_##fs + 1))) \ + != 0)); \ + _FP_FRAC_DISASSEMBLE_##wc (X, _FP_FROM_INT_ur, rsize); \ if ((_FP_EXPBIAS_##fs + _FP_WFRACBITS_##fs - 1 - X##_e) > 0) \ _FP_FRAC_SLL_##wc (X, (_FP_EXPBIAS_##fs \ + _FP_WFRACBITS_##fs - 1 - X##_e)); \ @@ -1513,14 +1541,14 @@ } \ else \ { \ - int _lz; \ + int FP_EXTEND_lz; \ FP_SET_EXCEPTION (FP_EX_DENORM); \ - _FP_FRAC_CLZ_##swc (_lz, S); \ + _FP_FRAC_CLZ_##swc (FP_EXTEND_lz, S); \ _FP_FRAC_SLL_##dwc (D, \ - _lz + _FP_FRACBITS_##dfs \ + FP_EXTEND_lz + _FP_FRACBITS_##dfs \ - _FP_FRACTBITS_##sfs); \ D##_e = (_FP_EXPBIAS_##dfs - _FP_EXPBIAS_##sfs + 1 \ - + _FP_FRACXBITS_##sfs - _lz); \ + + _FP_FRACXBITS_##sfs - FP_EXTEND_lz); \ } \ } \ else \ @@ -1662,42 +1690,51 @@ #define _FP_DIV_MEAT_N_loop(fs, wc, R, X, Y) \ do \ { \ - int count = _FP_WFRACBITS_##fs; \ - _FP_FRAC_DECL_##wc (u); \ - _FP_FRAC_DECL_##wc (v); \ - _FP_FRAC_COPY_##wc (u, X); \ - _FP_FRAC_COPY_##wc (v, Y); \ + int _FP_DIV_MEAT_N_loop_count = _FP_WFRACBITS_##fs; \ + _FP_FRAC_DECL_##wc (_FP_DIV_MEAT_N_loop_u); \ + _FP_FRAC_DECL_##wc (_FP_DIV_MEAT_N_loop_v); \ + _FP_FRAC_COPY_##wc (_FP_DIV_MEAT_N_loop_u, X); \ + _FP_FRAC_COPY_##wc (_FP_DIV_MEAT_N_loop_v, Y); \ _FP_FRAC_SET_##wc (R, _FP_ZEROFRAC_##wc); \ - /* Normalize U and V. */ \ - _FP_FRAC_SLL_##wc (u, _FP_WFRACXBITS_##fs); \ - _FP_FRAC_SLL_##wc (v, _FP_WFRACXBITS_##fs); \ + /* Normalize _FP_DIV_MEAT_N_LOOP_U and _FP_DIV_MEAT_N_LOOP_V. */ \ + _FP_FRAC_SLL_##wc (_FP_DIV_MEAT_N_loop_u, _FP_WFRACXBITS_##fs); \ + _FP_FRAC_SLL_##wc (_FP_DIV_MEAT_N_loop_v, _FP_WFRACXBITS_##fs); \ /* First round. Since the operands are normalized, either the \ first or second bit will be set in the fraction. Produce a \ normalized result by checking which and adjusting the loop \ count and exponent accordingly. */ \ - if (_FP_FRAC_GE_1 (u, v)) \ + if (_FP_FRAC_GE_1 (_FP_DIV_MEAT_N_loop_u, _FP_DIV_MEAT_N_loop_v)) \ { \ - _FP_FRAC_SUB_##wc (u, u, v); \ + _FP_FRAC_SUB_##wc (_FP_DIV_MEAT_N_loop_u, \ + _FP_DIV_MEAT_N_loop_u, \ + _FP_DIV_MEAT_N_loop_v); \ _FP_FRAC_LOW_##wc (R) |= 1; \ - count--; \ + _FP_DIV_MEAT_N_loop_count--; \ } \ else \ R##_e--; \ /* Subsequent rounds. */ \ do \ { \ - int msb = (_FP_WS_TYPE) _FP_FRAC_HIGH_##wc (u) < 0; \ - _FP_FRAC_SLL_##wc (u, 1); \ + int _FP_DIV_MEAT_N_loop_msb \ + = (_FP_WS_TYPE) _FP_FRAC_HIGH_##wc (_FP_DIV_MEAT_N_loop_u) < 0; \ + _FP_FRAC_SLL_##wc (_FP_DIV_MEAT_N_loop_u, 1); \ _FP_FRAC_SLL_##wc (R, 1); \ - if (msb || _FP_FRAC_GE_1 (u, v)) \ + if (_FP_DIV_MEAT_N_loop_msb \ + || _FP_FRAC_GE_1 (_FP_DIV_MEAT_N_loop_u, \ + _FP_DIV_MEAT_N_loop_v)) \ { \ - _FP_FRAC_SUB_##wc (u, u, v); \ + _FP_FRAC_SUB_##wc (_FP_DIV_MEAT_N_loop_u, \ + _FP_DIV_MEAT_N_loop_u, \ + _FP_DIV_MEAT_N_loop_v); \ _FP_FRAC_LOW_##wc (R) |= 1; \ } \ } \ - while (--count > 0); \ - /* If there's anything left in U, the result is inexact. */ \ - _FP_FRAC_LOW_##wc (R) |= !_FP_FRAC_ZEROP_##wc (u); \ + while (--_FP_DIV_MEAT_N_loop_count > 0); \ + /* If there's anything left in _FP_DIV_MEAT_N_LOOP_U, the result \ + is inexact. */ \ + _FP_FRAC_LOW_##wc (R) \ + |= !_FP_FRAC_ZEROP_##wc (_FP_DIV_MEAT_N_loop_u); \ } \ while (0) |