From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A1A1F3858C20 for ; Tue, 8 Aug 2023 20:19:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1A1F3858C20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691525943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w9O4OsEcdUq4ENyeraiwnUe7YuBMRG15AutOyynOqvI=; b=UjGeVv1ciP1lHgzrCihEdQ+IViXWrZc5W36uMq7Ac2K2rA2EvsJaWXmj092L2gpBFyABIK g2XMdfBXRmWEfLMdZdsrF9+qwtStDT1/4YD1qisNd+469WZlv1/o9yxckFXZSMODQJZbhM 8/qBa6ReIuaMagZy8d1Tbrx9wEoseTE= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-EyrbG_bSOlOB37Z88l4Kxg-1; Tue, 08 Aug 2023 16:19:01 -0400 X-MC-Unique: EyrbG_bSOlOB37Z88l4Kxg-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2b9dc1bfddcso1402231fa.0 for ; Tue, 08 Aug 2023 13:19:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691525939; x=1692130739; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w9O4OsEcdUq4ENyeraiwnUe7YuBMRG15AutOyynOqvI=; b=jnpVBXn28MyRAHlx0Q4LSeF4FCUS2t727n1OZb269OikqOV6F0N+FMutei7OkFQgkp 4eUiw3nClrvbSFyZjGLk3L7BbCPczZ2z0W+3rQqKNrtVJRGJ0PjHKB2JPglxQAED1QlW Fz5YfeohmUl2NpqMdZex0lC90/FKuXwn8qjZp2zcT8OXGf8gAPtFv2gO5+3oBzu5oi2o /l03HC9X0bJeHzsPjlTEq0S2fF/2bC1xnfUN0PByRs8j2MXb39eFhINsZWhQuV87llDp EF491j3zu6rfJCjtoiLOXVq4s/PoYqMyuYATN8w3sWaPpQYY8c+dvMw/mKBWWFtlvCud a8zA== X-Gm-Message-State: AOJu0YxABs/DKuXMIn0WvL+1sk8xnxXbEwt10f3Z33gcSvafz/TWhzPm NQtXwumkaITlJkHxX9LCCzpD3Fq08vQtvmWxpwgSxUaG/9jU3WpCEy85egSz4/8VSBLJCpozT8+ CIjRlx+h7m3mF/shIbIcFOx/4mkflaGo= X-Received: by 2002:a2e:b53b:0:b0:2b9:dd64:8415 with SMTP id z27-20020a2eb53b000000b002b9dd648415mr3784749ljm.24.1691525939752; Tue, 08 Aug 2023 13:18:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYiqndGrSf7Dp+FYYxkKa/hXMYZScXs1JKECDrG21hNfWzvZyAGAq0bfozPHgBZ71bnnS/hnUQspGVk7ajTQM= X-Received: by 2002:a2e:b53b:0:b0:2b9:dd64:8415 with SMTP id z27-20020a2eb53b000000b002b9dd648415mr3784740ljm.24.1691525939364; Tue, 08 Aug 2023 13:18:59 -0700 (PDT) MIME-Version: 1.0 References: <20230709125715.26884-1-kmatsui@gcc.gnu.org> <20230715045519.50684-1-kmatsui@gcc.gnu.org> <20230715045519.50684-3-kmatsui@gcc.gnu.org> <3aa7cf30-27f1-7e69-7334-fc9918928f90@gmail.com> In-Reply-To: From: Jonathan Wakely Date: Tue, 8 Aug 2023 21:18:48 +0100 Message-ID: Subject: Re: [PATCH v2 3/3] libstdc++: Optimize is_fundamental performance by __is_arithmetic built-in To: Ken Matsui Cc: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= , Ken Matsui , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="000000000000bea1c706026f12b4" X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000bea1c706026f12b4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 18 Jul 2023 at 07:25, Ken Matsui via Libstdc++ < libstdc++@gcc.gnu.org> wrote: > Hi, > > I took a benchmark for this. > > > https://github.com/ken-matsui/gcc-benches/blob/main/is_fundamental-disjun= ction.md#mon-jul-17-105937-pm-pdt-2023 > > template > struct is_fundamental > : public std::bool_constant<__is_arithmetic(_Tp) > || std::is_void<_Tp>::value > || std::is_null_pointer<_Tp>::value> > { }; > > is faster than: > > template > struct is_fundamental > : public std::bool_constant<__is_arithmetic(_Tp) > || std::disjunction, > std::is_null_pointer<_Tp> > >::value> > { }; > > Time: -32.2871% > Peak Memory: -18.5071% > Total Memory: -20.1991% > But what about the fallback implementation of is_fundamental where we don't have the __is_arithmetic built-in? - : public __or_, is_void<_Tp>, - is_null_pointer<_Tp>>::type + : public __bool_constant::value + || is_void<_Tp>::value + || is_null_pointer<_Tp>::value> Here the use of __or_ means that for is_fundamental we don't instantiate is_void and is_null_pointer. Isn't that still worthwhile? > > Sincerely, > Ken Matsui > > On Sun, Jul 16, 2023 at 9:49=E2=80=AFPM Ken Matsui > wrote: > > > > On Sun, Jul 16, 2023 at 5:41=E2=80=AFAM Fran=C3=A7ois Dumont > wrote: > > > > > > > > > On 15/07/2023 06:55, Ken Matsui via Libstdc++ wrote: > > > > This patch optimizes the performance of the is_fundamental trait by > > > > dispatching to the new __is_arithmetic built-in trait. > > > > > > > > libstdc++-v3/ChangeLog: > > > > > > > > * include/std/type_traits (is_fundamental_v): Use > __is_arithmetic > > > > built-in trait. > > > > (is_fundamental): Likewise. Optimize the original > implementation. > > > > > > > > Signed-off-by: Ken Matsui > > > > --- > > > > libstdc++-v3/include/std/type_traits | 21 +++++++++++++++++---- > > > > 1 file changed, 17 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/libstdc++-v3/include/std/type_traits > b/libstdc++-v3/include/std/type_traits > > > > index 7ebbe04c77b..cf24de2fcac 100644 > > > > --- a/libstdc++-v3/include/std/type_traits > > > > +++ b/libstdc++-v3/include/std/type_traits > > > > @@ -668,11 +668,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > > > #endif > > > > > > > > /// is_fundamental > > > > +#if __has_builtin(__is_arithmetic) > > > > + template > > > > + struct is_fundamental > > > > + : public __bool_constant<__is_arithmetic(_Tp) > > > > + || is_void<_Tp>::value > > > > + || is_null_pointer<_Tp>::value> > > > > + { }; > > > > > > What about doing this ? > > > > > > template > > > struct is_fundamental > > > : public __bool_constant<__is_arithmetic(_Tp) > > > || __or_, > > > is_null_pointer<_Tp>>::value> > > > { }; > > > > > > Based on your benches it seems that builtin __is_arithmetic is much > better that std::is_arithmetic. But __or_ could still avoid instantiation > of is_null_pointer. > > > > > Let me take a benchmark for this later. > > --000000000000bea1c706026f12b4--