Re: How to add 256 byte sized opaque mode in gcc
Avinash Jayakar via Gcc <[email protected]>
| Newsgroups | gmane.comp.gcc.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Jakub/Richard,
Thank you for these suggestions and review.
I have attached the proposed patch based on your input to dynamically
size the mode_unit_size array based on maximum bytesize declared in
machine modes.
Please do let me know if any tests are required for this before sending
to gcc-patches?
Also as you mentioned these lookups happen quite often in compilation,
so introducing this new mode could potentially increase compile times
for powerpc64le right?
Thanks and regards,
Avinash Jayakar
On Tue, 2026-08-18 at 13:06 +0200, Jakub Jelinek via Gcc wrote:
> On Tue, Aug 18, 2026 at 12:48:55PM +0200, Richard Biener via Gcc
> wrote:
> > I'd use unsigned short, it's important to not use an overly large
> > data
> > structure for those common lookups to reduce cache footprint. We
> > could possibly even dynamically size the component from genmodes?
>
> Yeah, I'd prefer that, emit a typedef/macro in insn-modes.h, say
> MODE_UNIT_SIZE_TYPE, unsigned char or unsigned short depending in
> whether all modes fit or don't fit into 255 bytes and use it for the
> generated array too. Similar to how e.g. the CONST_MODE_* macros
> are defined.
>
> > > @@ -1884,6 +1885,11 @@ rs6000_hard_regno_mode_ok_uncached (int
> > > regno, machine_mode mode)
> > > else
> > > return 0;
> > > }
> > > + /* QDOmode needs even/odd DMR register pairs. */
> > > + if (mode == QDOmode)
> > > + {
> > > + return (TARGET_DMF && DMR_REGNO_P (regno) && (regno & 1)
> > > == 0);
> > > + }
>
> The GCC coding style here is to avoid the {}s around a single
> statement
> body.
Sure I will update this.
>
> Jakub
0001-Using-wider-types-for-mode_unit_size-array-if-bytesi.patch
(text/x-patch, 2.5 KB)
From 17e02d7dd347d2027656354c2738670bea2af0ff Mon Sep 17 00:00:00 2001 From: Avinash Jayakar <[email protected]> Date: Wed, 19 Aug 2026 10:56:22 +0530 Subject: [PATCH] Using wider types for mode_unit_size array if bytesize of mode exceeds unsigned char or short --- gcc/genmodes.cc | 19 ++++++++++++++++--- gcc/machmode.h | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gcc/genmodes.cc b/gcc/genmodes.cc index fa5f8923519..764c6d9c9a1 100644 --- a/gcc/genmodes.cc +++ b/gcc/genmodes.cc @@ -1167,16 +1167,29 @@ emit_mode_unit_size_inline (void) int c; struct mode_data *m; + unsigned int max_type_size = 0; + for_all_modes (c, m) + { + if (max_type_size < m->bytesize) + max_type_size = m->bytesize; + } + if (max_type_size < (1 << 8)) + puts ("#define MODE_UNIT_SIZE_TYPE unsigned char\n"); + else if (max_type_size < (1 << 16)) + puts ("#define MODE_UNIT_SIZE_TYPE unsigned short\n"); + else + puts ("#define MODE_UNIT_SIZE_TYPE unsigned int\n"); + puts ("\ #ifdef __cplusplus\n\ inline __attribute__((__always_inline__))\n\ #else\n\ extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ #endif\n\ -unsigned char\n\ +MODE_UNIT_SIZE_TYPE\n\ mode_unit_size_inline (machine_mode mode)\n\ {\n\ - extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\ + extern CONST_MODE_UNIT_SIZE MODE_UNIT_SIZE_TYPE mode_unit_size[NUM_MACHINE_MODES];\ \n\ gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ switch (mode)\n\ @@ -1683,7 +1696,7 @@ emit_mode_unit_size (void) int c; struct mode_data *m; - print_maybe_const_decl ("%sunsigned char", "mode_unit_size", + print_maybe_const_decl ("%sMODE_UNIT_SIZE_TYPE", "mode_unit_size", "NUM_MACHINE_MODES", adj_bytesize); for_all_modes (c, m) diff --git a/gcc/machmode.h b/gcc/machmode.h index b92b1572d8d..468fa886910 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -26,7 +26,7 @@ extern CONST_MODE_SIZE poly_uint16 mode_size[NUM_MACHINE_MODES]; extern CONST_MODE_PRECISION poly_uint16 mode_precision[NUM_MACHINE_MODES]; extern const unsigned short mode_inner[NUM_MACHINE_MODES]; extern CONST_MODE_NUNITS poly_uint16 mode_nunits[NUM_MACHINE_MODES]; -extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES]; +extern CONST_MODE_UNIT_SIZE MODE_UNIT_SIZE_TYPE mode_unit_size[NUM_MACHINE_MODES]; extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES]; extern const unsigned short mode_next[NUM_MACHINE_MODES]; extern const unsigned short mode_wider[NUM_MACHINE_MODES]; -- 2.54.0