From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) by sourceware.org (Postfix) with ESMTPS id 6E7EB3858D33 for ; Mon, 17 Jul 2023 04:50:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E7EB3858D33 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-xe2b.google.com with SMTP id ada2fe7eead31-4436f2d8bcdso3681203137.1 for ; Sun, 16 Jul 2023 21:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1689569411; x=1692161411; 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=uCIVFX4jnvWTXyixaTcW6cCdWCswcvgzuy9Qs7dYr00=; b=dZcOkEw2EO0LGMikmvrr4CgbC8gp+tHtuZaK4oAMdxHOBU57QH78gk7ba4oMDwiLTT 48UMw1TzNpVN66IAzZLQfif6U9q96jfU48NyZDhY5T5ow2pACSX87v+wWxM4qGuRv9Wx In7XVCzhbAwDgT17VMO1T2rSG8rx/3L63/aeQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689569411; x=1692161411; 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=uCIVFX4jnvWTXyixaTcW6cCdWCswcvgzuy9Qs7dYr00=; b=W2ysPT5Ks+HOKMmncV/oBQSdVdWRwlo2Abdyo5+vaqxXBUGwXxuG0s0nNRBd9FDR21 VWppmPFppjk8l7pyCGepHVo9F41As3t+goG6lSVoZWSwhtNYMlVbr404BsgJZ7Opolbu Ds7ugbt9kfc8Zl0oU8zWhKfgn9EI3iR+/qvcUHk55RdUD85dIPzdXQBsmeK/SgO33fK3 HS089BhHm6nRSrkcAO6px40kUcgCFvu4mxuaguCTgfahxtpsYGcWoWUPvDBM7aIwJxTs N2z7Ad7Yzlc0GqK8I2n1UW2u/kNu0S+LjR95CnMNUPFt36vFOgE7XSQ2Qres3uv4UFmV o9kw== X-Gm-Message-State: ABy/qLYDtVMOZzUYJAcrHKFs2CXKjSBIvenO2hBLgAE5yM1riPwJ9QQn vmhinCbGBr8914T6zokgwL6awoTH0eUYVOzDKiFOP3a2gjhXxvZw X-Google-Smtp-Source: APBJJlG/nDPSL414gw7qAYHVKvFxw53W9oZTL96npDGiIB/RSR39IhKJoRw4SF6RUWJX48vxTp3dL9M11LQ5SBo7pX0= X-Received: by 2002:a67:fe14:0:b0:443:649c:3a44 with SMTP id l20-20020a67fe14000000b00443649c3a44mr2265014vsr.16.1689569411026; Sun, 16 Jul 2023 21:50:11 -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: <3aa7cf30-27f1-7e69-7334-fc9918928f90@gmail.com> From: Ken Matsui Date: Sun, 16 Jul 2023 21:49:55 -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=-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: 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/includ= e/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 bette= r that std::is_arithmetic. But __or_ could still avoid instantiation of is_= null_pointer. > Let me take a benchmark for this later.