Commit 2e15b172 by Richard Kenner

Add OVERFLOW operand to CHECK_FLOAT_VALUE.

From-SVN: r6770
parent c05f751c
/* Subroutines for insn-output.c for Convex. /* Subroutines for insn-output.c for Convex.
Copyright (C) 1988, 1993 Free Software Foundation, Inc. Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
This file is part of GNU CC. This file is part of GNU CC.
...@@ -413,31 +413,40 @@ expand_movstr_call (operands) ...@@ -413,31 +413,40 @@ expand_movstr_call (operands)
#define MIN_FLOAT 2.9387358770557188e-39 #define MIN_FLOAT 2.9387358770557188e-39
#endif #endif
void int
check_float_value (mode, dp) check_float_value (mode, dp, overflow)
enum machine_mode mode; enum machine_mode mode;
REAL_VALUE_TYPE *dp; REAL_VALUE_TYPE *dp;
int overflow;
{ {
REAL_VALUE_TYPE d = *dp; REAL_VALUE_TYPE d = *dp;
if (overflow)
{
*dp = MAX_FLOAT;
return 1;
}
if (mode == SFmode) if (mode == SFmode)
{ {
if (d > MAX_FLOAT) if (d > MAX_FLOAT)
{ {
error ("magnitude of constant too large for `float'");
*dp = MAX_FLOAT; *dp = MAX_FLOAT;
return 1;
} }
else if (d < -MAX_FLOAT) else if (d < -MAX_FLOAT)
{ {
error ("magnitude of constant too large for `float'");
*dp = -MAX_FLOAT; *dp = -MAX_FLOAT;
return 1;
} }
else if ((d > 0 && d < MIN_FLOAT) || (d < 0 && d > -MIN_FLOAT)) else if ((d > 0 && d < MIN_FLOAT) || (d < 0 && d > -MIN_FLOAT))
{ {
warning ("`float' constant truncated to zero");
*dp = 0.0; *dp = 0.0;
return 1;
} }
} }
return 0;
} }
/* Output the label at the start of a function. /* Output the label at the start of a function.
......
/* Definitions of target machine for GNU compiler. Convex version. /* Definitions of target machine for GNU compiler. Convex version.
Copyright (C) 1988, 1993 Free Software Foundation, Inc. Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
This file is part of GNU CC. This file is part of GNU CC.
...@@ -1180,8 +1180,8 @@ enum reg_class { ...@@ -1180,8 +1180,8 @@ enum reg_class {
extern double atof(); extern double atof();
/* Check a `double' value for validity for a particular machine mode. */ /* Check a `double' value for validity for a particular machine mode. */
#define CHECK_FLOAT_VALUE(mode, d) \ #define CHECK_FLOAT_VALUE(MODE, D, OVERFLOW) \
check_float_value ((mode), &(d)) overflow = check_float_value (MODE, &D, OVERFLOW)
/* Tell final.c how to eliminate redundant test instructions. */ /* Tell final.c how to eliminate redundant test instructions. */
......
/* Definitions of target machine for GNU compiler. Alliant FX version. /* Definitions of target machine for GNU compiler. Alliant FX version.
Copyright (C) 1989, 1993 Free Software Foundation, Inc. Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc.
Adapted from m68k.h by Paul Petersen (petersen@uicsrd.csrd.uiuc.edu) Adapted from m68k.h by Paul Petersen (petersen@uicsrd.csrd.uiuc.edu)
and Joe Weening (weening@gang-of-four.stanford.edu). and Joe Weening (weening@gang-of-four.stanford.edu).
...@@ -887,19 +887,19 @@ extern enum reg_class regno_reg_class[]; ...@@ -887,19 +887,19 @@ extern enum reg_class regno_reg_class[];
/* Check a `double' value for validity for a particular machine mode. /* Check a `double' value for validity for a particular machine mode.
This is defined to avoid crashes outputting certain constants. */ This is defined to avoid crashes outputting certain constants. */
#define CHECK_FLOAT_VALUE(mode, d) \ #define CHECK_FLOAT_VALUE(MODE, D, OVERFLOW) \
if ((mode) == SFmode) \ if (OVERFLOW) \
(D) = 3.4028234663852890e+38; \
else if ((MODE) == SFmode) \
{ \ { \
if ((d) > 3.4028234663852890e+38) \ if ((d) > 3.4028234663852890e+38) \
{ warning ("magnitude of value too large for `float'"); \ (OVERFLOW) = 1, (D) = 3.4028234663852890e+38; \
(d) = 3.4028234663852890e+38; } \ else if ((D) < -3.4028234663852890e+38) \
else if ((d) < -3.4028234663852890e+38) \ (OVERFLOW) = 1, (D) = -3.4028234663852890e+38; \
{ warning ("magnitude of value too large for `float'"); \ else if (((D) > 0) && ((D) < 1.1754943508222873e-38)) \
(d) = -3.4028234663852890e+38; } \ (OVERFLOW) = 1, (D) = 0.0; \
else if (((d) > 0) && ((d) < 1.1754943508222873e-38)) \
(d) = 0.0; \
else if (((d) < 0) && ((d) > -1.1754943508222873e-38)) \ else if (((d) < 0) && ((d) > -1.1754943508222873e-38)) \
(d) = 0.0; \ (OVEFLOW) = 1, (D) = 0.0; \
} }
/* Tell final.c how to eliminate redundant test instructions. */ /* Tell final.c how to eliminate redundant test instructions. */
......
/* Definitions of target machine for GNU compiler. Tahoe version. /* Definitions of target machine for GNU compiler. Tahoe version.
Copyright (C) 1989, 1993 Free Software Foundation, Inc. Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc.
This file is part of GNU CC. This file is part of GNU CC.
...@@ -135,21 +135,19 @@ extern int target_flags; ...@@ -135,21 +135,19 @@ extern int target_flags;
/* this section is borrowed from the vax version since the */ /* this section is borrowed from the vax version since the */
/* formats are the same in both of the architectures */ /* formats are the same in both of the architectures */
#define CHECK_FLOAT_VALUE(mode, d) \ #define CHECK_FLOAT_VALUE(MODE, D, OVEFLOW) \
if ((mode) == SFmode) \ if (OVERFLOW) \
{ \ (D) = 1.7014117331926443e+38; \
if ((d) > 1.7014117331926443e+38) \ else if ((MODE) == SFmode) \
{ error ("magnitude of constant too large for `float'"); \ { \
(d) = 1.7014117331926443e+38; } \ if ((D) > 1.7014117331926443e+38) \
else if ((d) < -1.7014117331926443e+38) \ (OVERFLOW) = 1, (D) = 1.7014117331926443e+38; \
{ error ("magnitude of constant too large for `float'"); \ else if ((D) < -1.7014117331926443e+38) \
(d) = -1.7014117331926443e+38; } \ (OVERFLOW) = 1, (D) = -1.7014117331926443e+38; \
else if (((d) > 0) && ((d) < 2.9387358770557188e-39)) \ else if (((D) > 0) && ((D) < 2.9387358770557188e-39)) \
{ warning ("`float' constant truncated to zero"); \ (OVERFLOW) = 1, (D) = 0.0; \
(d) = 0.0; } \ else if (((D) < 0) && ((D) > -2.9387358770557188e-39)) \
else if (((d) < 0) && ((d) > -2.9387358770557188e-39)) \ (OVERFLOW) = 1, (D) = 0.0; \
{ warning ("`float' constant truncated to zero"); \
(d) = 0.0; } \
} }
......
/* Subroutines for insn-output.c for Vax. /* Subroutines for insn-output.c for Vax.
Copyright (C) 1987 Free Software Foundation, Inc. Copyright (C) 1987, 1994 Free Software Foundation, Inc.
This file is part of GNU CC. This file is part of GNU CC.
...@@ -593,12 +593,12 @@ static REAL_VALUE_TYPE float_values[4]; ...@@ -593,12 +593,12 @@ static REAL_VALUE_TYPE float_values[4];
static int inited_float_values = 0; static int inited_float_values = 0;
void int
check_float_value (mode, d) check_float_value (mode, d, overflow)
enum machine_mode mode; enum machine_mode mode;
REAL_VALUE_TYPE *d; REAL_VALUE_TYPE *d;
int overflow;
{ {
if (inited_float_values == 0) if (inited_float_values == 0)
{ {
int i; int i;
...@@ -606,7 +606,14 @@ check_float_value (mode, d) ...@@ -606,7 +606,14 @@ check_float_value (mode, d)
{ {
float_values[i] = REAL_VALUE_ATOF (float_strings[i], DFmode); float_values[i] = REAL_VALUE_ATOF (float_strings[i], DFmode);
} }
inited_float_values = 1;
inited_float_values = 1;
}
if (overflow)
{
bcopy (&float_values[0], d, sizeof (REAL_VALUE_TYPE));
return 1;
} }
if ((mode) == SFmode) if ((mode) == SFmode)
...@@ -615,27 +622,29 @@ check_float_value (mode, d) ...@@ -615,27 +622,29 @@ check_float_value (mode, d)
bcopy (d, &r, sizeof (REAL_VALUE_TYPE)); bcopy (d, &r, sizeof (REAL_VALUE_TYPE));
if (REAL_VALUES_LESS (float_values[0], r)) if (REAL_VALUES_LESS (float_values[0], r))
{ {
error ("magnitude of constant too large for `float'");
bcopy (&float_values[0], d, sizeof (REAL_VALUE_TYPE)); bcopy (&float_values[0], d, sizeof (REAL_VALUE_TYPE));
return 1;
} }
else if (REAL_VALUES_LESS (r, float_values[1])) else if (REAL_VALUES_LESS (r, float_values[1]))
{ {
error ("magnitude of constant too large for `float'");
bcopy (&float_values[1], d, sizeof (REAL_VALUE_TYPE)); bcopy (&float_values[1], d, sizeof (REAL_VALUE_TYPE));
return 1;
} }
else if (REAL_VALUES_LESS (dconst0, r) else if (REAL_VALUES_LESS (dconst0, r)
&& REAL_VALUES_LESS (r, float_values[2])) && REAL_VALUES_LESS (r, float_values[2]))
{ {
warning ("`float' constant truncated to zero");
bcopy (&dconst0, d, sizeof (REAL_VALUE_TYPE)); bcopy (&dconst0, d, sizeof (REAL_VALUE_TYPE));
return 1;
} }
else if (REAL_VALUES_LESS (r, dconst0) else if (REAL_VALUES_LESS (r, dconst0)
&& REAL_VALUES_LESS (float_values[3], r)) && REAL_VALUES_LESS (float_values[3], r))
{ {
warning ("`float' constant truncated to zero");
bcopy (&dconst0, d, sizeof (REAL_VALUE_TYPE)); bcopy (&dconst0, d, sizeof (REAL_VALUE_TYPE));
return 1;
} }
} }
return 0;
} }
/* Linked list of all externals that are to be emitted when optimizing /* Linked list of all externals that are to be emitted when optimizing
......
/* Definitions of target machine for GNU compiler. Vax version. /* Definitions of target machine for GNU compiler. Vax version.
Copyright (C) 1987, 1988, 1991, 1993 Free Software Foundation, Inc. Copyright (C) 1987, 1988, 1991, 1993, 1994 Free Software Foundation, Inc.
This file is part of GNU CC. This file is part of GNU CC.
...@@ -912,7 +912,8 @@ gen_rtx (PLUS, Pmode, frame, gen_rtx (CONST_INT, VOIDmode, 12)) ...@@ -912,7 +912,8 @@ gen_rtx (PLUS, Pmode, frame, gen_rtx (CONST_INT, VOIDmode, 12))
/* note that it is very hard to accidentally create a number that fits in a /* note that it is very hard to accidentally create a number that fits in a
double but not in a float, since their ranges are almost the same */ double but not in a float, since their ranges are almost the same */
#define CHECK_FLOAT_VALUE(mode, d) (check_float_value (mode, &d)) #define CHECK_FLOAT_VALUE(MODE, D, OVERFLOW)
((OVERFLOW) = check_float_value (MODE, &D, OVERFLOW))
/* For future reference: /* For future reference:
D Float: 9 bit, sign magnitude, excess 128 binary exponent D Float: 9 bit, sign magnitude, excess 128 binary exponent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment