From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) by sourceware.org (Postfix) with ESMTPS id 25A53385841F for ; Tue, 18 Jul 2023 06:24:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25A53385841F 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-vk1-xa36.google.com with SMTP id 71dfb90a1353d-45a0ee1c411so1496173e0c.0 for ; Mon, 17 Jul 2023 23:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1689661481; x=1692253481; 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=nLTotqBnoQYwX7ewgitc+9/CK7iDuxdW59GAzzXSZ0w=; b=XJ55hlxa7Yp3aYKpHS1n7Keann7zT6KwdJbKjyFotA2L5v6yQlY+FH83/SgkHPyhbr 9m3uWQQESF1zUtjcs/dW3ck5gJxFlwVVYLCRCuGrAwU5s3yEIxvX7Il3TThgdaUBmPHK DIyYCFza6FKtZMox4VrgUJlZBEd1hG3QVpnh0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689661481; x=1692253481; 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=nLTotqBnoQYwX7ewgitc+9/CK7iDuxdW59GAzzXSZ0w=; b=I9fp/cNV/RLn7mDOKb2Ygi1WjQLC0Gcn+ToaU5XCngCFdYc6awLHD6lPk0J0/aDCn+ c34DsW0xLsCw1H/tQ2zT1Y/S5aXlphFB0YZ/GO5ah5X6QNRxOcB5ycI7uQsDx+jm3JyC 9atos+G8vuwxy2AKJMP1HFUg1IyQ1eXP2ATyVoSd6E26fdDRHX5uWuECYZ1Ts6prV2Uw TD1ZwqZOgJNhgWUctLV8NqMOgXjuKaOMAkpwoabnA9tOKGlUxkphuvpFitrEa9HbTlIw z0FEe+547nPEgHHMI1u4h2sVPkI5cQuLeaa9WG2n7MyvbAS4TThJlRaP3QltHlbD5PP3 R22w== X-Gm-Message-State: ABy/qLaUOfjKnjtOHos/JGfFrA+8S5qLukf3i+49t4OtqXMQ5x91XJcP XYl1AHMWqWyQGShsNohyb/rq+ZnsPS+Es2q/ajcLkQ== X-Google-Smtp-Source: APBJJlEaABVpX5Y/jeT4vjTDMjy7KtyObGbCVZtT21Kj8o5UmQ8/q28mNOKWoQTbochBYG7DKW+VT4WjYge5wRGxyBk= X-Received: by 2002:a1f:3d46:0:b0:481:4092:99c with SMTP id k67-20020a1f3d46000000b004814092099cmr601917vka.0.1689661481165; Mon, 17 Jul 2023 23:24:41 -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: Ken Matsui Date: Mon, 17 Jul 2023 23:24:25 -0700 Message-ID: Subject: Re: [PATCH v2 3/3] libstdc++: Optimize is_fundamental performance by __is_arithmetic built-in To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= 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.7 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=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: Hi, I took a benchmark for this. https://github.com/ken-matsui/gcc-benches/blob/main/is_fundamental-disjunct= ion.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% 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_arithmet= ic > > > built-in trait. > > > (is_fundamental): Likewise. Optimize the original implementatio= n. > > > > > > 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/incl= ude/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 bet= ter that std::is_arithmetic. But __or_ could still avoid instantiation of i= s_null_pointer. > > > Let me take a benchmark for this later.