Message ID | 20191118203450.8277-1-blomqvist.janne@gmail.com |
---|---|
State | New |
Headers | show |
Series | [1/2] PR 92463 MPFR modernization in GFortran | expand |
Hi Janne, On 11/18/19 9:34 PM, Janne Blomqvist wrote: > Now that we require a minimum of MPFR 3.1.0+ to build GCC, we can do > some modernization of the MPFR usage in the GFortran frontend. OK – thanks for the cleanup. [For reference, those changes were introduced in MPFR 3.0.0, cf. https://www.mpfr.org/mpfr-3.0.0/#changes ; 3.0 and 3.1 also added a bunch of new functions, MPFR_RNDA and did remove some undefined behaviour.] Do you intent update the other places as well? Namely: > This patch replaces > 1) GMP_RND* with MPFR_RND* Also used by: configure.ac, gcc/builtins.c, gcc/fold-const-call.c, gcc/gimple-ssa-sprintf.c, gcc/go/…, gcc/real.c, gcc/realmpfr.h, gcc/ubsan.c. 2) mp_exp_t with mpfr_exp_t gcc/realmpfr.c + gcc/go/… > 3) mp_prec_t with mpfr_prec_t (only used by gcc/fortran) > 4) mp_rnd_t with mpfr_rnd_t gcc/builtins.c, gcc/fold-const-call.c, gcc/realmpfr.c Cheers, Tobias > gcc/fortran/ChangeLog: > > 2019-11-18 Janne Blomqvist <jb@gcc.gnu.org> > > PR fortran/92463 > * arith.c (gfc_mpfr_to_mpz): Change mp_exp_t to mpfr_exp_t. > (gfc_check_real_range): Likewise. > * gfortran.h (GFC_RND_MODE): Change GMP_RNDN to MPFR_RNDN. > * module.c (mio_gmp_real): Change mp_exp_t to mpfr_exp_t. > * simplify.c (degrees_f): Change mp_rnd_t to mpfr_rnd_t. > (radians_f): Likewise. > (fullprec_erfc_scaled): Change mp_prec_t to mpfr_prec_t. > (asympt_erfc_scaled): Likewise. > (gfc_simplify_nearest): Change mp_exp_t to mpfr_exp_t, and > GMP_RND* to MPFR_RND*. > --- > gcc/fortran/arith.c | 8 ++++---- > gcc/fortran/gfortran.h | 2 +- > gcc/fortran/module.c | 2 +- > gcc/fortran/simplify.c | 20 ++++++++++---------- > 4 files changed, 16 insertions(+), 16 deletions(-)
On Wed, Nov 20, 2019 at 5:46 PM Tobias Burnus <Tobias_Burnus@mentor.com> wrote: > > Hi Janne, > > On 11/18/19 9:34 PM, Janne Blomqvist wrote: > > Now that we require a minimum of MPFR 3.1.0+ to build GCC, we can do > > some modernization of the MPFR usage in the GFortran frontend. > > OK – thanks for the cleanup. > > [For reference, those changes were introduced in MPFR 3.0.0, cf. > https://www.mpfr.org/mpfr-3.0.0/#changes ; 3.0 and 3.1 also added a > bunch of new functions, MPFR_RNDA and did remove some undefined behaviour.] > > Do you intent update the other places as well? Namely: > > > This patch replaces > > 1) GMP_RND* with MPFR_RND* > Also used by: configure.ac, gcc/builtins.c, gcc/fold-const-call.c, > gcc/gimple-ssa-sprintf.c, gcc/go/…, gcc/real.c, gcc/realmpfr.h, > gcc/ubsan.c. > > 2) mp_exp_t with mpfr_exp_t > > gcc/realmpfr.c + gcc/go/… > > > 3) mp_prec_t with mpfr_prec_t > (only used by gcc/fortran) > > 4) mp_rnd_t with mpfr_rnd_t > > gcc/builtins.c, gcc/fold-const-call.c, gcc/realmpfr.c > Thanks for the review, committed as r278523. My plan was that once the fortran-specific parts are done, I'll reassign the PR to the middle-end, and then me or somebody else can make a separate patch for that. However, since we're in stage3 now I believe this will have to wait until after the GCC 10 release as the middle-end people seem to take these rules more seriously.
diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c index a40163e8a2d..cf480779709 100644 --- a/gcc/fortran/arith.c +++ b/gcc/fortran/arith.c @@ -38,7 +38,7 @@ along with GCC; see the file COPYING3. If not see void gfc_mpfr_to_mpz (mpz_t z, mpfr_t x, locus *where) { - mp_exp_t e; + mpfr_exp_t e; if (mpfr_inf_p (x) || mpfr_nan_p (x)) { @@ -376,7 +376,7 @@ gfc_check_real_range (mpfr_t p, int kind) } else if (mpfr_cmp (q, gfc_real_kinds[i].tiny) < 0) { - mp_exp_t emin, emax; + mpfr_exp_t emin, emax; int en; /* Save current values of emin and emax. */ @@ -396,9 +396,9 @@ gfc_check_real_range (mpfr_t p, int kind) /* Copy sign if needed. */ if (mpfr_sgn (p) < 0) - mpfr_neg (p, q, GMP_RNDN); + mpfr_neg (p, q, MPFR_RNDN); else - mpfr_set (p, q, GMP_RNDN); + mpfr_set (p, q, MPFR_RNDN); } mpfr_clear (q); diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index e962db59bc5..f4a2b99bdc4 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2130,7 +2130,7 @@ gfc_intrinsic_sym; #include <mpfr.h> #include <mpc.h> -#define GFC_RND_MODE GMP_RNDN +#define GFC_RND_MODE MPFR_RNDN #define GFC_MPC_RND_MODE MPC_RNDNN typedef splay_tree gfc_constructor_base; diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 755f237a0e7..b11a30bea73 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -3343,7 +3343,7 @@ mio_gmp_integer (mpz_t *integer) static void mio_gmp_real (mpfr_t *real) { - mp_exp_t exponent; + mpfr_exp_t exponent; char *p; if (iomode == IO_INPUT) diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 0461d31cd88..a5c940ca2d5 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -1768,7 +1768,7 @@ simplify_trig_call (gfc_expr *icall) /* Convert a floating-point number from radians to degrees. */ static void -degrees_f (mpfr_t x, mp_rnd_t rnd_mode) +degrees_f (mpfr_t x, mpfr_rnd_t rnd_mode) { mpfr_t tmp; mpfr_init (tmp); @@ -1791,7 +1791,7 @@ degrees_f (mpfr_t x, mp_rnd_t rnd_mode) /* Convert a floating-point number from degrees to radians. */ static void -radians_f (mpfr_t x, mp_rnd_t rnd_mode) +radians_f (mpfr_t x, mpfr_rnd_t rnd_mode) { mpfr_t tmp; mpfr_init (tmp); @@ -2681,7 +2681,7 @@ gfc_simplify_erfc (gfc_expr *x) static void fullprec_erfc_scaled (mpfr_t res, mpfr_t arg) { - mp_prec_t prec; + mpfr_prec_t prec; mpfr_t a, b; prec = mpfr_get_default_prec (); @@ -2718,7 +2718,7 @@ asympt_erfc_scaled (mpfr_t res, mpfr_t arg) { mpfr_t sum, x, u, v, w, oldsum, sumtrunc; mpz_t num; - mp_prec_t prec; + mpfr_prec_t prec; unsigned i; prec = mpfr_get_default_prec (); @@ -5914,7 +5914,7 @@ gfc_expr * gfc_simplify_nearest (gfc_expr *x, gfc_expr *s) { gfc_expr *result; - mp_exp_t emin, emax; + mpfr_exp_t emin, emax; int kind; if (x->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT) @@ -5928,20 +5928,20 @@ gfc_simplify_nearest (gfc_expr *x, gfc_expr *s) /* Set emin and emax for the current model number. */ kind = gfc_validate_kind (BT_REAL, x->ts.kind, 0); - mpfr_set_emin ((mp_exp_t) gfc_real_kinds[kind].min_exponent - + mpfr_set_emin ((mpfr_exp_t) gfc_real_kinds[kind].min_exponent - mpfr_get_prec(result->value.real) + 1); - mpfr_set_emax ((mp_exp_t) gfc_real_kinds[kind].max_exponent - 1); - mpfr_check_range (result->value.real, 0, GMP_RNDU); + mpfr_set_emax ((mpfr_exp_t) gfc_real_kinds[kind].max_exponent - 1); + mpfr_check_range (result->value.real, 0, MPFR_RNDU); if (mpfr_sgn (s->value.real) > 0) { mpfr_nextabove (result->value.real); - mpfr_subnormalize (result->value.real, 0, GMP_RNDU); + mpfr_subnormalize (result->value.real, 0, MPFR_RNDU); } else { mpfr_nextbelow (result->value.real); - mpfr_subnormalize (result->value.real, 0, GMP_RNDD); + mpfr_subnormalize (result->value.real, 0, MPFR_RNDD); } mpfr_set_emin (emin);