From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x934.google.com (mail-ua1-x934.google.com [IPv6:2607:f8b0:4864:20::934]) by sourceware.org (Postfix) with ESMTPS id CF2DF3858401 for ; Tue, 18 Jul 2023 06:27:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF2DF3858401 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-x934.google.com with SMTP id a1e0cc1a2514c-794cddcab71so1497819241.1 for ; Mon, 17 Jul 2023 23:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1689661626; x=1692253626; 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=Z83aRo8cOqOWSM0hnJRdPssXzOa0NK9qlY+F8z83qLY=; b=jkKtkVsX+laqKpJTuQsBhbSq/B7bo6lMBi5FWdqmZSHoxIa990MKXzW16fVObwzQjN wY/2c2g4Pmnzoym2pn4wGXWtAcyWlxhSAqvMkFVHNCUCbbZuDqEi7swYuHWyuk/pyhge ToB3Y+xCZWEr2ptDsBW8Pcl4jz77J8LDTlAww= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689661626; x=1692253626; 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=Z83aRo8cOqOWSM0hnJRdPssXzOa0NK9qlY+F8z83qLY=; b=jZtXpv5BE8GM/p0OVLqHWnCeWdMQ56HQlPT7JeIwZuIfP7n0lN94TeJiiN9ugVZK6B Ck9jS85FrR1+BucVjwlFugt7nBMHB97LN0TKcvgFlf7n+MrWqSzIKI+pnDhDL00YYuTu TGjhwQkLG5wmDkgdq0RvSsrbU2DwIZQLN5+/hxQdwhVrAd336VQKtgcJuxGzqviYg5+w NMVCbHMZlCQ9fmQd1K7NQv6GHmAEQHtXTL96AT5HXhhwsfEKWIZjYAKHiQFaSrYx0Hnp s6bQr4a88CBgxMUEYo7hVrOYf/T9oW3hDZQDDVEeR3PvBFhxb80880WZW22V4eOfylgl M9Iw== X-Gm-Message-State: ABy/qLaZB2g2BiNdD1uThEau4O5LGU9aB/YRNjl+Rr1T/wqyFmSlsvZX fW4JWnFn/CJLDOzzb+34qtF5tSbmFL8dkqWj48FDOg== X-Google-Smtp-Source: APBJJlGvxEDu+min9eniK14glFvbwOm+BXjGc8Eut4+u6obnSKurDWugF9f3rJ1RGDxVdEwbHkzYXz4+lEuxWkpbME0= X-Received: by 2002:a05:6102:3175:b0:443:f072:4eea with SMTP id l21-20020a056102317500b00443f0724eeamr642458vsm.25.1689661626332; Mon, 17 Jul 2023 23:27:06 -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:26:50 -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.4 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: I will eventually work on disjunction to somehow optimize, but in the meantime, this might be a better implementation. Of course, my benchmark could be wrong. On Mon, Jul 17, 2023 at 11:24=E2=80=AFPM Ken Matsui wrote: > > Hi, > > I took a benchmark for this. > > https://github.com/ken-matsui/gcc-benches/blob/main/is_fundamental-disjun= ction.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_arithm= etic > > > > built-in trait. > > > > (is_fundamental): Likewise. Optimize the original implementat= ion. > > > > > > > > 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/in= clude/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 b= etter that std::is_arithmetic. But __or_ could still avoid instantiation of= is_null_pointer. > > > > > Let me take a benchmark for this later.