aboutsummaryrefslogtreecommitdiff
path: root/gcc/machmode.h
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@linaro.org>2017-08-30 11:08:36 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2017-08-30 11:08:36 +0000
commitb77d1a175f94eb49f62a02c4a54fe617e1cd3363 (patch)
tree7838879f1acc681160dd36fd74ccba491b695ba5 /gcc/machmode.h
parent4e10a5a74b2571a72ab944195267334d56b9534b (diff)
downloadgcc-b77d1a175f94eb49f62a02c4a54fe617e1cd3363.zip
gcc-b77d1a175f94eb49f62a02c4a54fe617e1cd3363.tar.gz
gcc-b77d1a175f94eb49f62a02c4a54fe617e1cd3363.tar.bz2
[3/77] Allow machine modes to be classes
This patch makes various changes that allow modes like SImode to be classes rather than enums. Firstly, it adds inline functions for all mode size properties, with the macros being simple wrappers around them. This is necessary for the __builtin_constant_p trick to continue working effectively when the mode arguments are slightly more complex (but still foldable at compile time). These inline functions are trivial and heavily used. There's not much point keeping them out-of-line at -O0: if anything it would make debugging harder rather than easier, and it would also slow things down. The patch therefore marks them as "always_inline", if that's available. Later patches use this approach too. Using inline functions means that it's no longer possible to pass an int to GET_MODE_PRECISION etc. The Fortran and powerpcspe-c.c parts are needed to avoid instances of that. The patch continues to use enums for gencondmd.c, so that more mode comparisons are integer constant expressions when checking for always-true or always-false conditions. This is the only intended use of USE_ENUM_MODES. The patch also enforces the previous replacement of case statements by defining modes as: #define FOOmode ((void) 0, E_FOOmode) This adds no overhead but makes sure that new uses of "case FOOmode:" don't accidentally creep in when FOOmode has no specific class associated with it. 2017-08-30 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> gcc/ * genconditions.c (write_header): Add a "#define USE_ENUM_MODES". * genmodes.c (emit_insn_modes_h): Define FOOmode to E_FOOmode if USE_ENUM_MODES is defined and to ((void) 0, E_FOOmode) otherwise. * machmode.h (mode_size): Move earlier in file. (mode_precision): Likewise. (mode_inner): Likewise. (mode_nunits): Likewise. (mode_unit_size): Likewise. (unit_unit_precision): Likewise. (mode_wider): Likewise. (mode_2xwider): Likewise. (machine_mode): New class. (mode_to_bytes): New function. (mode_to_bits): Likewise. (mode_to_precision): Likewise. (mode_to_inner): Likewise. (mode_to_unit_size): Likewise. (mode_to_unit_precision): Likewise. (mode_to_nunits): Likewise. (GET_MODE_SIZE): Use mode_to_bytes. (GET_MODE_BITSIZE): Use mode_to_bits. (GET_MODE_PRECISION): Use mode_to_precision. (GET_MODE_INNER): Use mode_to_inner. (GET_MODE_UNIT_SIZE): Use mode_to_unit_size. (GET_MODE_UNIT_PRECISION): Use mode_to_unit_precision. (GET_MODE_NUNITS): Use mode_to_nunits. * system.h (ALWAYS_INLINE): New macro. * config/powerpcspe/powerpcspe-c.c (altivec_resolve_overloaded_builtin): Use machine_mode instead of int for arg1_mode and arg2_mode. gcc/fortran/ * trans-types.c (gfc_init_kinds): Use machine_mode instead of int for "mode". Co-Authored-By: Alan Hayward <alan.hayward@arm.com> Co-Authored-By: David Sherwood <david.sherwood@arm.com> From-SVN: r251454
Diffstat (limited to 'gcc/machmode.h')
-rw-r--r--gcc/machmode.h146
1 files changed, 101 insertions, 45 deletions
diff --git a/gcc/machmode.h b/gcc/machmode.h
index 4b861ac..330fdf9 100644
--- a/gcc/machmode.h
+++ b/gcc/machmode.h
@@ -20,6 +20,15 @@ along with GCC; see the file COPYING3. If not see
#ifndef HAVE_MACHINE_MODES
#define HAVE_MACHINE_MODES
+extern CONST_MODE_SIZE unsigned short mode_size[NUM_MACHINE_MODES];
+extern const unsigned short mode_precision[NUM_MACHINE_MODES];
+extern const unsigned char mode_inner[NUM_MACHINE_MODES];
+extern const unsigned char 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 unsigned char mode_wider[NUM_MACHINE_MODES];
+extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
+
/* Get the name of mode MODE as a string. */
extern const char * const mode_name[NUM_MACHINE_MODES];
@@ -174,22 +183,98 @@ extern const unsigned char mode_class[NUM_MACHINE_MODES];
#define POINTER_BOUNDS_MODE_P(MODE) \
(GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
-/* Get the size in bytes and bits of an object of mode MODE. */
+/* Return the base GET_MODE_SIZE value for MODE. */
-extern CONST_MODE_SIZE unsigned short mode_size[NUM_MACHINE_MODES];
+ALWAYS_INLINE unsigned short
+mode_to_bytes (machine_mode mode)
+{
+#if GCC_VERSION >= 4001
+ return (__builtin_constant_p (mode)
+ ? mode_size_inline (mode) : mode_size[mode]);
+#else
+ return mode_size[mode];
+#endif
+}
+
+/* Return the base GET_MODE_BITSIZE value for MODE. */
+
+ALWAYS_INLINE unsigned short
+mode_to_bits (machine_mode mode)
+{
+ return mode_to_bytes (mode) * BITS_PER_UNIT;
+}
+
+/* Return the base GET_MODE_PRECISION value for MODE. */
+
+ALWAYS_INLINE unsigned short
+mode_to_precision (machine_mode mode)
+{
+ return mode_precision[mode];
+}
+
+/* Return the base GET_MODE_INNER value for MODE. */
+
+ALWAYS_INLINE machine_mode
+mode_to_inner (machine_mode mode)
+{
+#if GCC_VERSION >= 4001
+ return (machine_mode) (__builtin_constant_p (mode)
+ ? mode_inner_inline (mode) : mode_inner[mode]);
+#else
+ return (machine_mode) mode_inner[mode];
+#endif
+}
+
+/* Return the base GET_MODE_UNIT_SIZE value for MODE. */
+
+ALWAYS_INLINE unsigned char
+mode_to_unit_size (machine_mode mode)
+{
+#if GCC_VERSION >= 4001
+ return (__builtin_constant_p (mode)
+ ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
+#else
+ return mode_unit_size[mode];
+#endif
+}
+
+/* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
+
+ALWAYS_INLINE unsigned short
+mode_to_unit_precision (machine_mode mode)
+{
+#if GCC_VERSION >= 4001
+ return (__builtin_constant_p (mode)
+ ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
+#else
+ return mode_unit_precision[mode];
+#endif
+}
+
+/* Return the base GET_MODE_NUNITS value for MODE. */
+
+ALWAYS_INLINE unsigned short
+mode_to_nunits (machine_mode mode)
+{
#if GCC_VERSION >= 4001
-#define GET_MODE_SIZE(MODE) \
- ((unsigned short) (__builtin_constant_p (MODE) \
- ? mode_size_inline (MODE) : mode_size[MODE]))
+ return (__builtin_constant_p (mode)
+ ? mode_nunits_inline (mode) : mode_nunits[mode]);
#else
-#define GET_MODE_SIZE(MODE) ((unsigned short) mode_size[MODE])
+ return mode_nunits[mode];
#endif
-#define GET_MODE_BITSIZE(MODE) \
- ((unsigned short) (GET_MODE_SIZE (MODE) * BITS_PER_UNIT))
+}
+
+/* Get the size in bytes of an object of mode MODE. */
+
+#define GET_MODE_SIZE(MODE) (mode_to_bytes (MODE))
+
+/* Get the size in bits of an object of mode MODE. */
+
+#define GET_MODE_BITSIZE(MODE) (mode_to_bits (MODE))
/* Get the number of value bits of an object of mode MODE. */
-extern const unsigned short mode_precision[NUM_MACHINE_MODES];
-#define GET_MODE_PRECISION(MODE) mode_precision[MODE]
+
+#define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
/* Get the number of integral bits of an object of mode MODE. */
extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
@@ -210,51 +295,22 @@ extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
mode of the vector elements. For complex modes it is the mode of the real
and imaginary parts. For other modes it is MODE itself. */
-extern const unsigned char mode_inner[NUM_MACHINE_MODES];
-#if GCC_VERSION >= 4001
-#define GET_MODE_INNER(MODE) \
- ((machine_mode) (__builtin_constant_p (MODE) \
- ? mode_inner_inline (MODE) : mode_inner[MODE]))
-#else
-#define GET_MODE_INNER(MODE) ((machine_mode) mode_inner[MODE])
-#endif
+#define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
/* Get the size in bytes or bits of the basic parts of an
object of mode MODE. */
-extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
-#if GCC_VERSION >= 4001
-#define GET_MODE_UNIT_SIZE(MODE) \
- ((unsigned char) (__builtin_constant_p (MODE) \
- ? mode_unit_size_inline (MODE) : mode_unit_size[MODE]))
-#else
-#define GET_MODE_UNIT_SIZE(MODE) mode_unit_size[MODE]
-#endif
+#define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
#define GET_MODE_UNIT_BITSIZE(MODE) \
((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
-extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
-#if GCC_VERSION >= 4001
-#define GET_MODE_UNIT_PRECISION(MODE) \
- ((unsigned short) (__builtin_constant_p (MODE) \
- ? mode_unit_precision_inline (MODE)\
- : mode_unit_precision[MODE]))
-#else
-#define GET_MODE_UNIT_PRECISION(MODE) mode_unit_precision[MODE]
-#endif
-
+#define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
-/* Get the number of units in the object. */
+/* Get the number of units in an object of mode MODE. This is 2 for
+ complex modes and the number of elements for vector modes. */
-extern const unsigned char mode_nunits[NUM_MACHINE_MODES];
-#if GCC_VERSION >= 4001
-#define GET_MODE_NUNITS(MODE) \
- ((unsigned char) (__builtin_constant_p (MODE) \
- ? mode_nunits_inline (MODE) : mode_nunits[MODE]))
-#else
-#define GET_MODE_NUNITS(MODE) mode_nunits[MODE]
-#endif
+#define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE))
/* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */