Mercurial > hg > CbC > CbC_gcc
comparison gcc/real.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* real.c - software floating point emulation. | 1 /* real.c - software floating point emulation. |
2 Copyright (C) 1993-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1993-2018 Free Software Foundation, Inc. |
3 Contributed by Stephen L. Moshier (moshier@world.std.com). | 3 Contributed by Stephen L. Moshier (moshier@world.std.com). |
4 Re-written by Richard Henderson <rth@redhat.com> | 4 Re-written by Richard Henderson <rth@redhat.com> |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
5046 return true; | 5046 return true; |
5047 } | 5047 } |
5048 return false; | 5048 return false; |
5049 } | 5049 } |
5050 | 5050 |
5051 /* Calculate nextafter (X, Y) or nexttoward (X, Y). Return true if | |
5052 underflow or overflow needs to be raised. */ | |
5053 | |
5054 bool | |
5055 real_nextafter (REAL_VALUE_TYPE *r, format_helper fmt, | |
5056 const REAL_VALUE_TYPE *x, const REAL_VALUE_TYPE *y) | |
5057 { | |
5058 int cmp = do_compare (x, y, 2); | |
5059 /* If either operand is NaN, return qNaN. */ | |
5060 if (cmp == 2) | |
5061 { | |
5062 get_canonical_qnan (r, 0); | |
5063 return false; | |
5064 } | |
5065 /* If x == y, return y cast to target type. */ | |
5066 if (cmp == 0) | |
5067 { | |
5068 real_convert (r, fmt, y); | |
5069 return false; | |
5070 } | |
5071 | |
5072 if (x->cl == rvc_zero) | |
5073 { | |
5074 get_zero (r, y->sign); | |
5075 r->cl = rvc_normal; | |
5076 SET_REAL_EXP (r, fmt->emin - fmt->p + 1); | |
5077 r->sig[SIGSZ - 1] = SIG_MSB; | |
5078 return false; | |
5079 } | |
5080 | |
5081 int np2 = SIGNIFICAND_BITS - fmt->p; | |
5082 /* For denormals adjust np2 correspondingly. */ | |
5083 if (x->cl == rvc_normal && REAL_EXP (x) < fmt->emin) | |
5084 np2 += fmt->emin - REAL_EXP (x); | |
5085 | |
5086 REAL_VALUE_TYPE u; | |
5087 get_zero (r, x->sign); | |
5088 get_zero (&u, 0); | |
5089 set_significand_bit (&u, np2); | |
5090 r->cl = rvc_normal; | |
5091 SET_REAL_EXP (r, REAL_EXP (x)); | |
5092 | |
5093 if (x->cl == rvc_inf) | |
5094 { | |
5095 bool borrow = sub_significands (r, r, &u, 0); | |
5096 gcc_assert (borrow); | |
5097 SET_REAL_EXP (r, fmt->emax); | |
5098 } | |
5099 else if (cmp == (x->sign ? 1 : -1)) | |
5100 { | |
5101 if (add_significands (r, x, &u)) | |
5102 { | |
5103 /* Overflow. Means the significand had been all ones, and | |
5104 is now all zeros. Need to increase the exponent, and | |
5105 possibly re-normalize it. */ | |
5106 SET_REAL_EXP (r, REAL_EXP (r) + 1); | |
5107 if (REAL_EXP (r) > fmt->emax) | |
5108 { | |
5109 get_inf (r, x->sign); | |
5110 return true; | |
5111 } | |
5112 r->sig[SIGSZ - 1] = SIG_MSB; | |
5113 } | |
5114 } | |
5115 else | |
5116 { | |
5117 if (REAL_EXP (x) > fmt->emin && x->sig[SIGSZ - 1] == SIG_MSB) | |
5118 { | |
5119 int i; | |
5120 for (i = SIGSZ - 2; i >= 0; i--) | |
5121 if (x->sig[i]) | |
5122 break; | |
5123 if (i < 0) | |
5124 { | |
5125 /* When mantissa is 1.0, we need to subtract only | |
5126 half of u: nextafter (1.0, 0.0) is 1.0 - __DBL_EPSILON__ / 2 | |
5127 rather than 1.0 - __DBL_EPSILON__. */ | |
5128 clear_significand_bit (&u, np2); | |
5129 np2--; | |
5130 set_significand_bit (&u, np2); | |
5131 } | |
5132 } | |
5133 sub_significands (r, x, &u, 0); | |
5134 } | |
5135 | |
5136 /* Clear out trailing garbage. */ | |
5137 clear_significand_below (r, np2); | |
5138 normalize (r); | |
5139 if (REAL_EXP (r) <= fmt->emin - fmt->p) | |
5140 { | |
5141 get_zero (r, x->sign); | |
5142 return true; | |
5143 } | |
5144 return r->cl == rvc_zero || REAL_EXP (r) < fmt->emin; | |
5145 } | |
5146 | |
5051 /* Write into BUF the maximum representable finite floating-point | 5147 /* Write into BUF the maximum representable finite floating-point |
5052 number, (1 - b**-p) * b**emax for a given FP format FMT as a hex | 5148 number, (1 - b**-p) * b**emax for a given FP format FMT as a hex |
5053 float string. LEN is the size of BUF, and the buffer must be large | 5149 float string. LEN is the size of BUF, and the buffer must be large |
5054 enough to contain the resulting string. */ | 5150 enough to contain the resulting string. */ |
5055 | 5151 |
5078 } | 5174 } |
5079 | 5175 |
5080 gcc_assert (strlen (buf) < len); | 5176 gcc_assert (strlen (buf) < len); |
5081 } | 5177 } |
5082 | 5178 |
5179 /* True if all values of integral type can be represented | |
5180 by this floating-point type exactly. */ | |
5181 | |
5182 bool format_helper::can_represent_integral_type_p (tree type) const | |
5183 { | |
5184 gcc_assert (! decimal_p () && INTEGRAL_TYPE_P (type)); | |
5185 | |
5186 /* INT?_MIN is power-of-two so it takes | |
5187 only one mantissa bit. */ | |
5188 bool signed_p = TYPE_SIGN (type) == SIGNED; | |
5189 return TYPE_PRECISION (type) - signed_p <= significand_size (*this); | |
5190 } | |
5191 | |
5083 /* True if mode M has a NaN representation and | 5192 /* True if mode M has a NaN representation and |
5084 the treatment of NaN operands is important. */ | 5193 the treatment of NaN operands is important. */ |
5085 | 5194 |
5086 bool | 5195 bool |
5087 HONOR_NANS (machine_mode m) | 5196 HONOR_NANS (machine_mode m) |
5181 bool | 5290 bool |
5182 HONOR_SIGN_DEPENDENT_ROUNDING (const_rtx x) | 5291 HONOR_SIGN_DEPENDENT_ROUNDING (const_rtx x) |
5183 { | 5292 { |
5184 return HONOR_SIGN_DEPENDENT_ROUNDING (GET_MODE (x)); | 5293 return HONOR_SIGN_DEPENDENT_ROUNDING (GET_MODE (x)); |
5185 } | 5294 } |
5295 | |
5296 /* Fills r with the largest value such that 1 + r*r won't overflow. | |
5297 This is used in both sin (atan (x)) and cos (atan(x)) optimizations. */ | |
5298 | |
5299 void | |
5300 build_sinatan_real (REAL_VALUE_TYPE * r, tree type) | |
5301 { | |
5302 REAL_VALUE_TYPE maxval; | |
5303 mpfr_t mpfr_const1, mpfr_c, mpfr_maxval; | |
5304 machine_mode mode = TYPE_MODE (type); | |
5305 const struct real_format * fmt = REAL_MODE_FORMAT (mode); | |
5306 | |
5307 real_maxval (&maxval, 0, mode); | |
5308 | |
5309 mpfr_inits (mpfr_const1, mpfr_c, mpfr_maxval, NULL); | |
5310 | |
5311 mpfr_from_real (mpfr_const1, &dconst1, GMP_RNDN); | |
5312 mpfr_from_real (mpfr_maxval, &maxval, GMP_RNDN); | |
5313 | |
5314 mpfr_sub (mpfr_c, mpfr_maxval, mpfr_const1, GMP_RNDN); | |
5315 mpfr_sqrt (mpfr_c, mpfr_c, GMP_RNDZ); | |
5316 | |
5317 real_from_mpfr (r, mpfr_c, fmt, GMP_RNDZ); | |
5318 | |
5319 mpfr_clears (mpfr_const1, mpfr_c, mpfr_maxval, NULL); | |
5320 } |