public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Ken Matsui <kmatsui@cs.washington.edu>
Cc: gcc@gcc.gnu.org
Subject: Re: [GSoC] Question about Relatively Simple Library Traits
Date: Fri, 24 Mar 2023 09:58:03 +0000	[thread overview]
Message-ID: <CAH6eHdTpxGzmJQW2wkKEXp26DX+v9=g7NDU9gzQtX2C1O-pfSg@mail.gmail.com> (raw)
In-Reply-To: <CAML+3pVn50Urx8TgnhW=GX1dX27tkxmU3O-1ZUmp-Eyagh8eKQ@mail.gmail.com>

On Fri, 24 Mar 2023 at 07:10, Ken Matsui via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hi,
>
> I am working on the GSoC project, "C++: Implement compiler built-in
> traits for the standard library traits". I found the following library
> traits that I am not sure if implementing built-in traits brings
> reasonable speed up.
>
> * std::is_fundamental
> * std::is_arithmetic
> * std::is_scalar
> * std::is_object
> * std::is_compound
> * std::is_scoped_enum
>
> For example, std::is_object has no template specializations, but its
> inheriting class looks complicated.
>
> __not_<__or_<is_function<_Tp>, is_reference<_Tp>, is_void<_Tp>>>::type
>
> If we define the built-in trait for this trait, we have: (as
> equivalence of the above code)
>
> __bool_constant<__is_object(_Tp)>
>
> And __is_object built-in trait should be like:
>
> !(type1 == FUNCTION_TYPE || type1 == ...)
>
> In this case, could someone tell me which one would be faster? Or, is
> there no other way to know which but to benchmark?

You should benchmark it anyway, I was always expecting that to be a
part of this GSoC project :-)

But is_object is NOT a "relatively simple" trait. What you show above
is very complex. One of the more complex traits we have. Partial
specializations are quite fast to match (in general) so eliminating
partial speclializations (e.g. like we have for is_const) should not
be the goal.

For is_object<const int> we instantiate:

is_function<const int>
is_const<const int>
is_reference<const int>
is_void<const int>
__bool_constant<false>
__or_<false_type, false_type, false_type>
__not_<false_type>
__bool_constant<true>

This is a ton of work! Instantiating class templates is the slowest
part of trait evaluation, not matching partial specializations.

A built-in for __is_object will mean we only instantiate
__bool_constant<true>. That will be MUCH faster. But I think it would
be a good idea for you to benchmark it to confirm that.

  reply	other threads:[~2023-03-24 10:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24  6:57 Ken Matsui
2023-03-24  9:58 ` Jonathan Wakely [this message]
2023-03-24 10:05   ` Jonathan Wakely
2023-03-24 10:41     ` Ken Matsui

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='CAH6eHdTpxGzmJQW2wkKEXp26DX+v9=g7NDU9gzQtX2C1O-pfSg@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=kmatsui@cs.washington.edu \
    /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).