public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work104)] Use unique precisions for 128-bit floating point on Fortran.
@ 2023-01-09 20:40 Michael Meissner
0 siblings, 0 replies; only message in thread
From: Michael Meissner @ 2023-01-09 20:40 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d613e11d7db1fc7ef5f32931129faf89503bdf76
commit d613e11d7db1fc7ef5f32931129faf89503bdf76
Author: Michael Meissner <meissner@linux.ibm.com>
Date: Mon Jan 9 15:40:23 2023 -0500
Use unique precisions for 128-bit floating point on Fortran.
2022-01-09 Michael Meissner <meissner@linux.ibm.com>
gcc/
* config/rs6000/rs6000-modes.def (IFmode): If we are compiling for
Fortran, use unqiue precisions for 128-bit floating point.
(KFmode): Likewise.
(TFmode): Likewise.
* config/rs6000/rs6000.opt (UNIQUE_FLOAT128_PRECISION): New target
variable.
* genmodes.cc (struct mode_data): Add field for adjusting precision.
(blank_mode): Likewise.
(need_precision_adj): New variable to support ADJUST_PRECISION.
(ADJUST_PRECISION): New macro.
(mode_unit_precision_inline): Add support for ADJUST_PRECISION.
(emit_insn_modes_h): Likewise.
(emit_mode_precision): Likewise.
(emit_mode_unit_precision): Likewise.
(emit_mode_adjustments): Likewise.
* machmode.def (ADJUST_PRECISION): Document usage.
* machmode.h (mode_unit_precision): Add support for ADJUST_PRECISION.
Diff:
---
gcc/config/rs6000/rs6000-modes.def | 14 ++++++++++
gcc/config/rs6000/rs6000.cc | 4 +++
gcc/config/rs6000/rs6000.opt | 8 ++++++
gcc/genmodes.cc | 57 ++++++++++++++++++++++++++++++++++----
gcc/machmode.def | 7 +++--
gcc/machmode.h | 2 +-
6 files changed, 83 insertions(+), 9 deletions(-)
diff --git a/gcc/config/rs6000/rs6000-modes.def b/gcc/config/rs6000/rs6000-modes.def
index 571b92c4480..c3c2905525e 100644
--- a/gcc/config/rs6000/rs6000-modes.def
+++ b/gcc/config/rs6000/rs6000-modes.def
@@ -24,16 +24,30 @@
the float_mode_for_size function will only return TFmode if the size is 128
bits. */
+/* Fortran needs to have precisions of 126..128 to differentiate between IEEE
+ and IBM 128-bit floating point. The values used here are what GCC 12 used
+ for the precisions. */
+#define UNIQUE_PRECISION_IFmode 128
+#define UNIQUE_PRECISION_TFmode 127
+#define UNIQUE_PRECISION_KFmode 126
+
/* IBM 128-bit floating point. */
FRACTIONAL_FLOAT_MODE_NO_WIDEN (IF, 128, 16, ibm_extended_format);
+ADJUST_PRECISION (IF,
+ UNIQUE_FLOAT128_PRECISION ? UNIQUE_PRECISION_IFmode : 128);
/* Explicit IEEE 128-bit floating point. */
FRACTIONAL_FLOAT_MODE_NO_WIDEN (KF, 128, 16, ieee_quad_format);
+ADJUST_PRECISION (KF,
+ UNIQUE_FLOAT128_PRECISION ? UNIQUE_PRECISION_KFmode : 128);
/* 128-bit floating point, either IBM 128-bit or IEEE 128-bit. This is
adjusted in rs6000_option_override_internal to be the appropriate floating
point type. */
FRACTIONAL_FLOAT_MODE (TF, 128, 16, ieee_quad_format);
+ADJUST_PRECISION (TF,
+ UNIQUE_FLOAT128_PRECISION ? UNIQUE_PRECISION_TFmode : 128);
+
ADJUST_FLOAT_FORMAT (TF, (TARGET_LONG_DOUBLE_128 && !TARGET_IEEEQUAD
? &ibm_extended_format
: &ieee_quad_format));
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 6bb38c9c1d5..15cefd4e4c1 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -4169,6 +4169,10 @@ rs6000_option_override_internal (bool global_init_p)
the keyword as well as the type. */
TARGET_FLOAT128_TYPE = TARGET_FLOAT128_ENABLE_TYPE && TARGET_VSX;
+/* Fortran needs to have precisions of 126..128 to differentiate between IEEE
+ and IBM 128-bit floating point. */
+ UNIQUE_FLOAT128_PRECISION = lang_GNU_Fortran ();
+
/* IEEE 128-bit floating point requires VSX support. */
if (TARGET_FLOAT128_KEYWORD)
{
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index b63a5d443af..cab848c9836 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -108,6 +108,14 @@ unsigned char x_TARGET_FLOAT128_TYPE
Variable
unsigned char TARGET_FLOAT128_TYPE
+;; Whether each of the 3 128-bit floating point modes (IFmode, KFmode, and
+;; TFmode) have a unique precision number, or whether they all use 128. C
+;; and C++ prefer the precision to be 128, but fortran prefers to have
+;; separate precisions to differentiate between IBM and IEEE 128-bit floating
+;; point.
+TargetVariable
+bool UNIQUE_FLOAT128_PRECISION
+
;; This option existed in the past, but now is always on.
mpowerpc
Target RejectNegative Undocumented Ignore
diff --git a/gcc/genmodes.cc b/gcc/genmodes.cc
index 32ee508a00e..1057c8a7981 100644
--- a/gcc/genmodes.cc
+++ b/gcc/genmodes.cc
@@ -81,6 +81,8 @@ struct mode_data
bool boolean;
bool normal_widen; /* Whether the type should be listed in the
mode_wider and mode_2xwider tables. */
+ bool need_precision_adj; /* true if this mode needs dynamic precision
+ adjustment */
};
static struct mode_data *modes[MAX_MODE_CLASS];
@@ -92,7 +94,7 @@ static const struct mode_data blank_mode = {
0, -1U, -1U, -1U, -1U,
0, 0, 0, 0, 0, 0,
"<unknown>", 0, 0, 0, 0, false, false, 0,
- false, true
+ false, true, false
};
static htab_t modes_by_name;
@@ -116,6 +118,7 @@ static struct mode_adjust *adj_alignment;
static struct mode_adjust *adj_format;
static struct mode_adjust *adj_ibit;
static struct mode_adjust *adj_fbit;
+static struct mode_adjust *adj_precision;
/* Mode class operations. */
static enum mode_class
@@ -828,6 +831,7 @@ make_vector_mode (enum mode_class bclass,
#define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
#define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
#define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
+#define ADJUST_PRECISION(M, X) _ADD_ADJUST (precision, M, X, FLOAT, FLOAT)
static int bits_per_unit;
static int max_bitsize_mode_any_int;
@@ -1229,7 +1233,8 @@ extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
unsigned short\n\
mode_unit_precision_inline (machine_mode mode)\n\
{\n\
- extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
+ extern CONST_MODE_PRECISION unsigned short \n\
+ mode_unit_precision[NUM_MACHINE_MODES];\n\
gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
switch (mode)\n\
{");
@@ -1377,7 +1382,8 @@ enum machine_mode\n{");
/* I can't think of a better idea, can you? */
printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits ? "" : " const");
- printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits ? "" : " const");
+ printf ("#define CONST_MODE_PRECISION%s\n",
+ adj_precision || adj_nunits ? "" : " const");
printf ("#define CONST_MODE_SIZE%s\n",
adj_bytesize || adj_nunits ? "" : " const");
printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize ? "" : " const");
@@ -1496,7 +1502,7 @@ emit_mode_precision (void)
struct mode_data *m;
print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
- "NUM_MACHINE_MODES", adj_nunits);
+ "NUM_MACHINE_MODES", adj_precision || adj_nunits);
for_all_modes (c, m)
if (m->precision != (unsigned int)-1)
@@ -1721,7 +1727,8 @@ emit_mode_unit_precision (void)
int c;
struct mode_data *m;
- print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
+ print_maybe_const_decl ("%sunsigned short", "mode_unit_precision",
+ "NUM_MACHINE_MODES", adj_precision);
for_all_modes (c, m)
{
@@ -1985,6 +1992,46 @@ emit_mode_adjustments (void)
printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
a->file, a->line, a->mode->name, a->adjustment);
+
+ /* Precision adjustments propagate too. */
+ for (a = adj_precision; a; a = a->next)
+ {
+ printf ("\n /* %s:%d */\n s = %s;\n",
+ a->file, a->line, a->adjustment);
+ printf (" mode_unit_precision[E_%smode] = s;\n", a->mode->name);
+
+ for (m = a->mode->contained; m; m = m->next_cont)
+ {
+ switch (m->cl)
+ {
+ case MODE_COMPLEX_INT:
+ case MODE_COMPLEX_FLOAT:
+ printf (" mode_unit_precision[E_%smode] = s;\n", m->name);
+ break;
+
+ case MODE_VECTOR_BOOL:
+ /* Changes to BImode should not affect vector booleans. */
+ break;
+
+ case MODE_VECTOR_INT:
+ case MODE_VECTOR_FLOAT:
+ case MODE_VECTOR_FRACT:
+ case MODE_VECTOR_UFRACT:
+ case MODE_VECTOR_ACCUM:
+ case MODE_VECTOR_UACCUM:
+ printf (" mode_unit_precision[E_%smode] = %d*s;\n",
+ m->name, m->ncomponents);
+ break;
+
+ default:
+ internal_error (
+ "mode %s is neither vector nor complex but contains %s",
+ m->name, a->mode->name);
+ /* NOTREACHED */
+ }
+ }
+ }
+
puts ("}");
}
diff --git a/gcc/machmode.def b/gcc/machmode.def
index fb10a3af705..eb03fd88999 100644
--- a/gcc/machmode.def
+++ b/gcc/machmode.def
@@ -177,9 +177,10 @@ along with GCC; see the file COPYING3. If not see
ADJUST_FLOAT_FORMAT (MODE, EXPR);
ADJUST_IBIT (MODE, EXPR);
ADJUST_FBIT (MODE, EXPR);
- Arrange for the byte size, alignment, floating point format, ibit,
- or fbit of MODE to be adjustable at run time. EXPR will be executed
- once after processing all command line options, and should
+ ADJUST_PRECISION (MODE, EXPR);
+ Arrange for the byte size, alignment, floating point format, ibit, fbit
+ or precision mode of MODE to be adjustable at run time. EXPR will be
+ executed once after processing all command line options, and should
evaluate to the desired byte size, alignment, format, ibit or fbit.
Unlike a FORMAT argument, if you are adjusting a float format
diff --git a/gcc/machmode.h b/gcc/machmode.h
index f1865c1ef42..e4e0caf9abb 100644
--- a/gcc/machmode.h
+++ b/gcc/machmode.h
@@ -27,7 +27,7 @@ extern CONST_MODE_PRECISION poly_uint16_pod mode_precision[NUM_MACHINE_MODES];
extern const unsigned char mode_inner[NUM_MACHINE_MODES];
extern CONST_MODE_NUNITS poly_uint16_pod mode_nunits[NUM_MACHINE_MODES];
extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
-extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
+extern CONST_MODE_PRECISION unsigned short mode_unit_precision[NUM_MACHINE_MODES];
extern const unsigned char mode_next[NUM_MACHINE_MODES];
extern const unsigned char mode_wider[NUM_MACHINE_MODES];
extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-09 20:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 20:40 [gcc(refs/users/meissner/heads/work104)] Use unique precisions for 128-bit floating point on Fortran Michael Meissner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).