From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by sourceware.org (Postfix) with ESMTPS id B57193858D37 for ; Fri, 1 Sep 2023 10:41:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B57193858D37 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-ua1-x92f.google.com with SMTP id a1e0cc1a2514c-7a0254de2fdso729910241.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=JyztLYB67c+2VxaqwXtby6PDeTe39Ze33DSda6fUtZ9m3Hg8nXTqNxVaScg3Ib6dLP mPK2obCA2cT11Ic+W2kmCADd4npf0Ij1Zzr29sWfoVkyTI6l7JlZiau3jjv7yUgZ2w1L C5Z0Zc+ZYdOU9pFY9vmK+hT9aWualUtsJnDcZfkEpW0GpaJIXQi/1JW8So154PeY4UGN R8plDUnWmlKDbmnMMkeNycIBZs6o7jO7C07jhDh5EIAUwx+uyUoJDavZV//ITvooQjtU DItlnxr/z7P1v7AXHmtRV4SGQ8+uUfRzByhu36SAIPRd6DkFuIZLsKOvqLEYH2bq6Rz0 yQPg== X-Gm-Message-State: AOJu0YzJcg7B7LwaR1izB1VrdDQ8z9CNqBoUnEIpaZDY77eZ0becWFK+ haH9BEOwOLQFZMN+zs62wyMogNQ7kiOmsF3BJvVucQ== 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=-10.8 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 >>