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 081953858CDB for ; Sat, 15 Jul 2023 05:07:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 081953858CDB 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-78a5384a5daso799531241.0 for ; Fri, 14 Jul 2023 22:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1689397661; x=1691989661; 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=UbTsi3zLbbgUPvsblFmldhHBt5bCKwAQxadrCYRSKnw=; b=gHTTWAfQ0ekSkLKi4A+N83uROvzTG5rjUpM6zjsdyA6/r8gNDqww1wDstZ+rBInGYv 5l/4DV1R34Kk3e5bw5jYgzrgwdBMIe774bhMN7CO4eMoy7cojsvNMhNLZLuF4N6fSQjp d/Q2ZUHRlyMFE29MEIE3B3IYd75DexCeBY0zI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689397661; x=1691989661; 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=UbTsi3zLbbgUPvsblFmldhHBt5bCKwAQxadrCYRSKnw=; b=ZI7OG2G7WrBTq0gJ54mZredNuEW0aROpGaRewzJ78YfYxOZOCG37t/3JzKFI46ahkf CkUXTS9Lki1CJBziX+VtLweAcORj0wuA0+5aQSkSm72dzjFUf+XL2MJOzQR0cAK2QCHU 60K6jk9982QYRHQ8nVOmUbQp11XfwMto6r1R9U+x2gfKI44PyMTETedfpxwJ1WSL+5Ey Yli+oWFPHn9HXYevsfcPM90BYv3P37NAtIdchw9wf3x6w5fsQWzFeMHsJUHUzBY684ka YGCNDpN0Lb0hBkDigmwIJZyVOMrQxUH7tfDR7BSLbQ8aXu367FWBQpJqqf0q60uLgO5+ X9Mg== X-Gm-Message-State: ABy/qLY54tWTE5Hl5/XA8b+e1QXHGlWmIjh24th3qSygYZeBINiN4Ksw cbozRL/4TLwB7toqtt5uP2o332cGEn+3FdcANWO6mg== X-Google-Smtp-Source: APBJJlEElAONsW21cnC+j+wbayvwbAbt0yPaSCoiCR/PbLd25mSboZQNvIoOpu/fn6vOAWYETgLac7lhX4BtAgRHUj8= X-Received: by 2002:a1f:5fd1:0:b0:481:2cd7:75a7 with SMTP id t200-20020a1f5fd1000000b004812cd775a7mr2447909vkb.16.1689397660909; Fri, 14 Jul 2023 22:07:40 -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> In-Reply-To: <20230715045519.50684-3-kmatsui@gcc.gnu.org> From: Ken Matsui Date: Fri, 14 Jul 2023 22:07:25 -0700 Message-ID: Subject: Re: [PATCH v2 3/3] libstdc++: Optimize is_fundamental performance by __is_arithmetic built-in To: Ken Matsui Cc: 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.3 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,T_SCC_BODY_TEXT_LINE 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: Hi, Here are the benchmarks for this change: * is_fundamental https://github.com/ken-matsui/gcc-benches/blob/main/is_fundamental.md#fri-j= ul-14-091146-pm-pdt-2023 Time: -37.1619% Peak Memory Usage: -29.4294% Total Memory Usage: -29.4783% * is_fundamental_v https://github.com/ken-matsui/gcc-benches/blob/main/is_fundamental_v.md#fri= -jul-14-091757-pm-pdt-2023 Time: -35.5446% Peak Memory Usage: -30.0096% Total Memory Usage: -30.6021% * is_fundamental with bool_constant (on trunk [18dac101678b8c0aed4bd995351e47f26cd54dec]) https://github.com/ken-matsui/gcc-benches/blob/main/is_fundamental-bool_con= stant.md#fri-jul-14-094237-pm-pdt-2023 Time: -28.3908% Peak Memory Usage: -18.5403% Total Memory Usage: -19.9045% --- It appears using bool_constant is better than disjunction. If my understanding is correct, disjunction can avoid later instantiations when short-circuiting, but might the evaluation of disjunction be more expensive than evaluating is_void and is_null_pointer? Or my benchmark might be just incorrect. Sincerely, Ken Matsui On Fri, Jul 14, 2023 at 9:57=E2=80=AFPM Ken Matsui wr= ote: > > 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> > + { }; > +#else > template > struct is_fundamental > - : public __or_, is_void<_Tp>, > - is_null_pointer<_Tp>>::type > + : public __bool_constant::value > + || is_void<_Tp>::value > + || is_null_pointer<_Tp>::value> > { }; > +#endif > > /// is_object > template > @@ -3209,13 +3219,16 @@ template > #if __has_builtin(__is_arithmetic) > template > inline constexpr bool is_arithmetic_v =3D __is_arithmetic(_Tp); > +template > + inline constexpr bool is_fundamental_v > + =3D __is_arithmetic(_Tp) || is_void_v<_Tp> || is_null_pointer_v<_Tp>= ; > #else > template > inline constexpr bool is_arithmetic_v =3D is_arithmetic<_Tp>::value; > -#endif > - > template > inline constexpr bool is_fundamental_v =3D is_fundamental<_Tp>::value; > +#endif > + > template > inline constexpr bool is_object_v =3D is_object<_Tp>::value; > template > -- > 2.41.0 >