From: Aldy Hernandez <aldyh@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: GCC patches <gcc-patches@gcc.gnu.org>,
Andrew MacLeod <amacleod@redhat.com>,
Richard Sandiford <richard.sandiford@arm.com>
Subject: Re: [RFC] trailing_wide_ints with runtime variable lengths
Date: Fri, 1 Jul 2022 18:47:48 +0200 [thread overview]
Message-ID: <CAGm3qMX+iQED+=VpOmxXzWzqYJh_0kDDHHuPvHAoUEfiDAZj6A@mail.gmail.com> (raw)
In-Reply-To: <Yr8Lmj+0pxyMzyto@tucnak>
On Fri, Jul 1, 2022 at 4:58 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Fri, Jul 01, 2022 at 04:12:55PM +0200, Aldy Hernandez wrote:
> > > --- a/gcc/wide-int.h
> > > +++ b/gcc/wide-int.h
> > > @@ -1373,10 +1373,13 @@ namespace wi
> > > : public int_traits <wide_int_storage> {};
> > > }
> > >
> > > -/* An array of N wide_int-like objects that can be put at the end of
> > > - a variable-sized structure. Use extra_size to calculate how many
> > > - bytes beyond the sizeof need to be allocated. Use set_precision
> > > - to initialize the structure. */
> > > +/* A variable-lengthed array of wide_int-like objects that can be put
> > > + at the end of a variable-sized structure. The number of objects is
> > > + at most N and can be set at runtime by using set_precision().
> > > +
> > > + Use extra_size to calculate how many bytes beyond the
> > > + sizeof need to be allocated. Use set_precision to initialize the
> > > + structure. */
> > > template <int N>
> > > struct GTY((user)) trailing_wide_ints
> > > {
> > > @@ -1387,6 +1390,9 @@ private:
> > > /* The shared maximum length of each number. */
> > > unsigned char m_max_len;
> > >
> > > + /* The number of elements. */
> > > + unsigned char m_num_elements;
>
> IMNSHO you certainly don't want to change like this existing
> trailing_wide_ints, you don't want to grow unnecessarily existing
> trailing_wide_ints users (e.g. const_poly_int_def).
That's precisely what I avoided...touching existing trailing_wide_ints
users. As I explained, there is no cost to either const_poly_int_def
or range_info_def (though I'm about to nuke the latter). There is
some padding that is currently used by m_len[N], and I just took a
byte out to represent the run-time length. That would affect
trailing_wide_int users that have N > 4, but none are. The use in
const_poly_int_def uses 2 (and range_info_def uses 3):
#define NUM_POLY_INT_COEFFS 2
struct GTY((variable_size)) const_poly_int_def {
trailing_wide_ints<NUM_POLY_INT_COEFFS> coeffs;
};
>
> My brief understanding of wide-int.h is that in some cases stuff like this
> is implied from template parameters or exact class instantiation and in
> other cases it is present explicitly and class inheritence is used to hide
> that stuff nicely.
Yeah, it took me a while to decipher it, but I did read it :).
>
> So, you are looking for something like trailing_wide_ints<N> but where that
> N is actually a runtime value? Then e.g. the
> struct {unsigned char len;} m_len[N];
> member can't work properly either, because it isn't constant size.
What my patch does is store the run-time length in the aforementioned
byte, while defaulting to N/MAX. There is no size difference (or code
changes) for existing users. With my change, set_precision() and
extra_size() now take a runtime parameter, but it defaults to N and is
inlined, so there is no penalty for existing users. I benchmarked to
make sure :).
I could hack up a variable_length_wide_int for what I want, but I'd
end up duplicating a lot of the trailing_wide_int_storage, etc.
Another option would be to stream out the HOST_WIDE_INTs in the
tree_int_cst and reconstruct things myself, but that smells of
reinventing the wheel.
Is there another way of allocating an n-bit wide-int at run-time? I'm
happy to entertain other alternatives...
Aldy
next prev parent reply other threads:[~2022-07-01 16:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-29 9:21 Aldy Hernandez
2022-07-01 14:12 ` Aldy Hernandez
2022-07-01 14:58 ` Jakub Jelinek
2022-07-01 16:47 ` Aldy Hernandez [this message]
2022-07-01 16:58 ` Jakub Jelinek
2022-07-01 17:43 ` Aldy Hernandez
2022-07-01 18:53 ` Jakub Jelinek
2022-07-01 20:31 ` Aldy Hernandez
2022-07-01 20:40 ` Aldy Hernandez
2022-07-01 18:26 ` Richard Sandiford
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='CAGm3qMX+iQED+=VpOmxXzWzqYJh_0kDDHHuPvHAoUEfiDAZj6A@mail.gmail.com' \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=richard.sandiford@arm.com \
/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).