From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by sourceware.org (Postfix) with ESMTPS id C07E13858C66 for ; Fri, 1 Sep 2023 10:41:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C07E13858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.washington.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.washington.edu Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-44e8f9f3cceso874699137.1 for ; Fri, 01 Sep 2023 03:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1693564895; x=1694169695; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6kBjKHXyP/l2DO7NHe09uoN1Hls8eCs1RGhFSkcBUow=; b=FLHJXDRA6Mnc2xBf4LS0yDuZATTs4l9yRCIrWXb1+1Xv1ZmNT9GfI1Gv5hvZndKGwz QP5hbSePNCBXeWcH9W+iW/E01ZBpzVva6hJsyy4qIps0HqJ+trg+bWbkbJEF1REv/cTj YVuEnf/7c0norD77wRJeYkAIlM/kqipjmolDc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693564895; x=1694169695; h=content-transfer-encoding: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=6kBjKHXyP/l2DO7NHe09uoN1Hls8eCs1RGhFSkcBUow=; b=LiYiE7NxSMfbk7mt0djinQotT511wtLhqIQvG8jm5pC4KwF6bb0/FM6A1Be5QQRBXC G6AsFzl+wBOqrhoak6czWSRFj+LQxul7rHBXO6tj9YryPEN2LNT7e0IxzFgadniNA5qe nAUj05bdpCZu3JOtO42KSoSPqVlgzoKEsw+LWvhv2fCMI+sbUfBVT46iycq69JRkVSxs ZCjQsr9TvP3gJGjhpJXQWLHSq+uwKWHaqIwCPwNIVlwhrY9aINaav8RZ5DbLCOKTnP9w iP2T+sqZxzRfUkycKS3jqT7/VSPCdoNoAXSAp/03meporGuyvQwnrMiBVdCEP5WYWOJ6 oG0w== X-Gm-Message-State: AOJu0YxKn4GukxRTm+tfwEpoonIXTxZ1XawkmrZIDdf6bFw8PIXVkAM5 bssbYywuGYfKYCT5gUZhwzCS3bjFhe/Uq6gj1VUkCw== X-Google-Smtp-Source: AGHT+IFi/ds/B+VKnDbBXNYjDJOyPVv16mfTS3++MWPYkHoWkFERhmzfBt3dvc11RY5CDgTAFLZkN96WalWeQovNY+E= X-Received: by 2002:a05:6102:3a56:b0:44e:b30a:c0da with SMTP id c22-20020a0561023a5600b0044eb30ac0damr2254328vsu.26.1693564894937; Fri, 01 Sep 2023 03:41:34 -0700 (PDT) MIME-Version: 1.0 References: <20230718062745.29470-1-kmatsui@gcc.gnu.org> <20230718074027.32270-1-kmatsui@gcc.gnu.org> <20230718074027.32270-4-kmatsui@gcc.gnu.org> In-Reply-To: From: Ken Matsui Date: Fri, 1 Sep 2023 03:40:59 -0700 Message-ID: Subject: Re: [PATCH v4 4/4] libstdc++: Optimize is_compound trait performance To: Jonathan Wakely Cc: Ken Matsui , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Aug 8, 2023 at 1:33=E2=80=AFPM Jonathan Wakely = wrote: > > > > On Tue, 18 Jul 2023 at 08:44, Ken Matsui via Libstdc++ wrote: >> >> This patch optimizes the performance of the is_compound trait by >> dispatching to the new __is_arithmetic built-in trait. >> >> libstdc++-v3/ChangeLog: >> >> * include/std/type_traits (is_compound): Use __is_arithmetic >> built-in trait. >> (is_compound_v): Use is_fundamental_v instead. >> >> Signed-off-by: Ken Matsui >> --- >> libstdc++-v3/include/std/type_traits | 11 ++++++++++- >> 1 file changed, 10 insertions(+), 1 deletion(-) >> >> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include= /std/type_traits >> index cf24de2fcac..73d9a2b16fc 100644 >> --- a/libstdc++-v3/include/std/type_traits >> +++ b/libstdc++-v3/include/std/type_traits >> @@ -702,9 +702,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >> { }; >> >> /// is_compound >> +#if __has_builtin(__is_arithmetic) >> + template >> + struct is_compound >> + : public __bool_constant> + || is_void<_Tp>::value >> + || is_null_pointer<_Tp>::value)> >> + { }; >> +#else >> template >> struct is_compound >> : public __not_>::type { }; >> +#endif > > > I think it would be simpler to just do this unconditionally (i.e. just a = single definition without using __has_builtin): > > template > struct is_compound > : __bool_constant::value> > { }; > > This still avoids instantiating __not_. If is_fundamental is much more ef= ficient now, then I think it's OK to instantiate it here. Otherwise we're d= uplicating the logic for is_fundamental, and just giving ourselves more cod= e to maintain. > > Nobody ever uses is_compound anyway! > Agreed! Will fix this patch. Thank you! > > >> >> /// @cond undocumented >> template >> @@ -3234,7 +3243,7 @@ template >> template >> inline constexpr bool is_scalar_v =3D is_scalar<_Tp>::value; >> template >> - inline constexpr bool is_compound_v =3D is_compound<_Tp>::value; >> + inline constexpr bool is_compound_v =3D !is_fundamental_v<_Tp>; >> template >> inline constexpr bool is_member_pointer_v =3D is_member_pointer<_Tp>:= :value; >> template >> -- >> 2.41.0 >>