public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Sandiford <rsandifo@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-4991] genmodes: Define NUM_MODE_* macros
Date: Mon,  8 Nov 2021 10:36:50 +0000 (GMT)	[thread overview]
Message-ID: <20211108103650.EE9AB3858423@sourceware.org> (raw)

https://gcc.gnu.org/g:8fd2477ddc358660611f79d8e50f31ed0f3aa105

commit r12-4991-g8fd2477ddc358660611f79d8e50f31ed0f3aa105
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Mon Nov 8 10:36:25 2021 +0000

    genmodes: Define NUM_MODE_* macros
    
    I was working on a patch that needed to calculate the number of
    modes in a particular class.  It seemed better to have genmodes
    generate this directly rather than do the kind of dance that
    expmed.h had.
    
    gcc/
            * genmodes.c (emit_insn_modes_h): Define NUM_MODE_* macros.
            * expmed.h (NUM_MODE_INT): Delete in favor of genmodes definitions.
            (NUM_MODE_PARTIAL_INT, NUM_MODE_VECTOR_INT): Likewise.
            * real.h (real_format_for_mode): Use NUM_MODE_FLOAT and
            NUM_MODE_DECIMAL_FLOAT.
            (REAL_MODE_FORMAT): Likewise.

Diff:
---
 gcc/expmed.h   |  9 ---------
 gcc/genmodes.c | 13 +++++++++++++
 gcc/real.h     |  5 ++---
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/gcc/expmed.h b/gcc/expmed.h
index 93cd6316f0d..6b13ea96c49 100644
--- a/gcc/expmed.h
+++ b/gcc/expmed.h
@@ -133,15 +133,6 @@ struct alg_hash_entry {
 #define NUM_ALG_HASH_ENTRIES 307
 #endif
 
-#define NUM_MODE_INT \
-  (MAX_MODE_INT - MIN_MODE_INT + 1)
-#define NUM_MODE_PARTIAL_INT \
-  (MIN_MODE_PARTIAL_INT == E_VOIDmode ? 0 \
-   : MAX_MODE_PARTIAL_INT - MIN_MODE_PARTIAL_INT + 1)
-#define NUM_MODE_VECTOR_INT \
-  (MIN_MODE_VECTOR_INT == E_VOIDmode ? 0 \
-   : MAX_MODE_VECTOR_INT - MIN_MODE_VECTOR_INT + 1)
-
 #define NUM_MODE_IP_INT (NUM_MODE_INT + NUM_MODE_PARTIAL_INT)
 #define NUM_MODE_IPV_INT (NUM_MODE_IP_INT + NUM_MODE_VECTOR_INT)
 
diff --git a/gcc/genmodes.c b/gcc/genmodes.c
index c9af4efba46..ecc8b448406 100644
--- a/gcc/genmodes.c
+++ b/gcc/genmodes.c
@@ -1316,6 +1316,19 @@ enum machine_mode\n{");
   NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
 };\n");
 
+  /* Define a NUM_* macro for each mode class, giving the number of modes
+     in the class.  */
+  for (c = 0; c < MAX_MODE_CLASS; c++)
+    {
+      printf ("#define NUM_%s ", mode_class_names[c]);
+      if (modes[c])
+	printf ("(MAX_%s - MIN_%s + 1)\n", mode_class_names[c],
+		mode_class_names[c]);
+      else
+	printf ("0\n");
+    }
+  printf ("\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");
diff --git a/gcc/real.h b/gcc/real.h
index 015163d9917..39dd34e3971 100644
--- a/gcc/real.h
+++ b/gcc/real.h
@@ -178,13 +178,12 @@ struct real_format
    decimal float modes indexed by (MODE - first decimal float mode) +
    the number of float modes.  */
 extern const struct real_format *
-  real_format_for_mode[MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1
-		       + MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1];
+  real_format_for_mode[NUM_MODE_FLOAT + NUM_MODE_DECIMAL_FLOAT];
 
 #define REAL_MODE_FORMAT(MODE)						\
   (real_format_for_mode[DECIMAL_FLOAT_MODE_P (MODE)			\
 			? (((MODE) - MIN_MODE_DECIMAL_FLOAT)		\
-			   + (MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1))	\
+			   + NUM_MODE_FLOAT)				\
 			: GET_MODE_CLASS (MODE) == MODE_FLOAT		\
 			? ((MODE) - MIN_MODE_FLOAT)			\
 			: (gcc_unreachable (), 0)])


                 reply	other threads:[~2021-11-08 10:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211108103650.EE9AB3858423@sourceware.org \
    --to=rsandifo@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).