diff options
author | Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2014-06-28 14:17:41 +0000 |
---|---|---|
committer | François-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2014-06-28 14:17:41 +0000 |
commit | 8b198102220210ef6a61477d9a45564c206ee6b5 (patch) | |
tree | e7bff5fef45c93b6d9ac36021ec9edaa569bf861 /gcc/fortran/simplify.c | |
parent | a86471635f38376128e6cea8d6856f025a57b4c2 (diff) | |
download | gcc-8b198102220210ef6a61477d9a45564c206ee6b5.zip gcc-8b198102220210ef6a61477d9a45564c206ee6b5.tar.gz gcc-8b198102220210ef6a61477d9a45564c206ee6b5.tar.bz2 |
re PR fortran/29383 (Fortran 2003/F95[TR15580:1999]: Floating point exception (IEEE) support)
PR fortran/29383
gcc/fortran/
* gfortran.h (gfc_simplify_ieee_selected_real_kind): New prototype.
* libgfortran.h (GFC_FPE_*): Use simple integer values, valid in
both C and Fortran.
* expr.c (gfc_check_init_expr): Simplify IEEE_SELECTED_REAL_KIND.
* simplify.c (gfc_simplify_ieee_selected_real_kind): New function.
* module.c (mio_symbol): Keep track of symbols which came from
intrinsic modules.
(gfc_use_module): Keep track of the IEEE modules.
* trans-decl.c (gfc_get_symbol_decl): Adjust code since
we have new intrinsic modules.
(gfc_build_builtin_function_decls): Build decls for
ieee_procedure_entry and ieee_procedure_exit.
(is_from_ieee_module, is_ieee_module_used, save_fp_state,
restore_fp_state): New functions.
(gfc_generate_function_code): Save and restore floating-point
state on procedure entry/exit, when IEEE modules are used.
* intrinsic.texi: Document the IEEE modules.
libgfortran/
* configure.host: Add checks for IEEE support, rework priorities.
* configure.ac: Define IEEE_SUPPORT, check for fpsetsticky and
fpresetsticky.
* configure: Regenerate.
* Makefile.am: Build new ieee files, install IEEE_* modules.
* Makefile.in: Regenerate.
* gfortran.map (GFORTRAN_1.6): Add new symbols.
* libgfortran.h (get_fpu_trap_exceptions, set_fpu_trap_exceptions,
support_fpu_trap, set_fpu_except_flags, support_fpu_flag,
support_fpu_rounding_mode, get_fpu_state, set_fpu_state): New
prototypes.
* config/fpu-*.h (get_fpu_trap_exceptions,
set_fpu_trap_exceptions, support_fpu_trap, set_fpu_except_flags,
support_fpu_flag, support_fpu_rounding_mode, get_fpu_state,
set_fpu_state): New functions.
* ieee/ieee_features.F90: New file.
* ieee/ieee_exceptions.F90: New file.
* ieee/ieee_arithmetic.F90: New file.
* ieee/ieee_helper.c: New file.
gcc/testsuite/
* lib/target-supports.exp (check_effective_target_fortran_ieee):
New function.
* gfortran.dg/ieee/ieee.exp: New file.
* gfortran.dg/ieee/ieee_1.F90: New file.
* gfortran.dg/ieee/ieee_2.f90: New file.
* gfortran.dg/ieee/ieee_3.f90: New file.
* gfortran.dg/ieee/ieee_4.f90: New file.
* gfortran.dg/ieee/ieee_5.f90: New file.
* gfortran.dg/ieee/ieee_6.f90: New file.
* gfortran.dg/ieee/ieee_7.f90: New file.
* gfortran.dg/ieee/ieee_rounding_1.f90: New file.
From-SVN: r212102
Diffstat (limited to 'gcc/fortran/simplify.c')
-rw-r--r-- | gcc/fortran/simplify.c | 86 |
1 files changed, 84 insertions, 2 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index d18bc08..60d8593 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -5460,12 +5460,13 @@ gfc_simplify_selected_real_kind (gfc_expr *p, gfc_expr *q, gfc_expr *rdx) if (gfc_real_kinds[i].range >= range) found_range = 1; - if (gfc_real_kinds[i].radix >= radix) + if (radix == 0 || gfc_real_kinds[i].radix == radix) found_radix = 1; if (gfc_real_kinds[i].precision >= precision && gfc_real_kinds[i].range >= range - && gfc_real_kinds[i].radix >= radix && gfc_real_kinds[i].kind < kind) + && (radix == 0 || gfc_real_kinds[i].radix == radix) + && gfc_real_kinds[i].kind < kind) kind = gfc_real_kinds[i].kind; } @@ -5488,6 +5489,87 @@ gfc_simplify_selected_real_kind (gfc_expr *p, gfc_expr *q, gfc_expr *rdx) gfc_expr * +gfc_simplify_ieee_selected_real_kind (gfc_expr *expr) +{ + gfc_actual_arglist *arg = expr->value.function.actual; + gfc_expr *p = arg->expr, *r = arg->next->expr, + *rad = arg->next->next->expr; + int precision, range, radix, res; + int found_precision, found_range, found_radix, i; + + if (p) + { + if (p->expr_type != EXPR_CONSTANT + || gfc_extract_int (p, &precision) != NULL) + return NULL; + } + else + precision = 0; + + if (r) + { + if (r->expr_type != EXPR_CONSTANT + || gfc_extract_int (r, &range) != NULL) + return NULL; + } + else + range = 0; + + if (rad) + { + if (rad->expr_type != EXPR_CONSTANT + || gfc_extract_int (rad, &radix) != NULL) + return NULL; + } + else + radix = 0; + + res = INT_MAX; + found_precision = 0; + found_range = 0; + found_radix = 0; + + for (i = 0; gfc_real_kinds[i].kind != 0; i++) + { + /* We only support the target's float and double types. */ + if (!gfc_real_kinds[i].c_float && !gfc_real_kinds[i].c_double) + continue; + + if (gfc_real_kinds[i].precision >= precision) + found_precision = 1; + + if (gfc_real_kinds[i].range >= range) + found_range = 1; + + if (radix == 0 || gfc_real_kinds[i].radix == radix) + found_radix = 1; + + if (gfc_real_kinds[i].precision >= precision + && gfc_real_kinds[i].range >= range + && (radix == 0 || gfc_real_kinds[i].radix == radix) + && gfc_real_kinds[i].kind < res) + res = gfc_real_kinds[i].kind; + } + + if (res == INT_MAX) + { + if (found_radix && found_range && !found_precision) + res = -1; + else if (found_radix && found_precision && !found_range) + res = -2; + else if (found_radix && !found_precision && !found_range) + res = -3; + else if (found_radix) + res = -4; + else + res = -5; + } + + return gfc_get_int_expr (gfc_default_integer_kind, &expr->where, res); +} + + +gfc_expr * gfc_simplify_set_exponent (gfc_expr *x, gfc_expr *i) { gfc_expr *result; |