From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 88ED43858D33 for ; Tue, 8 Aug 2023 20:33:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88ED43858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691526808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UxLEbhz2CArTh3McUTw+5N1GLxGeRjJ2l7NCjVQiaDU=; b=fU17pum5j6qnS+6LJ+JqHTeIlcpjcgcYc5KsLM52aRfOCAx9A8GuJgo2GzTaTihN7r/iYd ClTX3c86drshOuzjKK5eJTEGGU0NQ3idITCST5Hb6rAe9p+JMd7UB7HX9z/brXvC9ZDklB FglIiBjF/6SC8FnsRsSt6fWL2fbcq+s= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-aqGryXORNhe9TUp5CEhuGQ-1; Tue, 08 Aug 2023 16:33:24 -0400 X-MC-Unique: aqGryXORNhe9TUp5CEhuGQ-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2b710c5677eso66779041fa.0 for ; Tue, 08 Aug 2023 13:33:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691526803; x=1692131603; h=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=UxLEbhz2CArTh3McUTw+5N1GLxGeRjJ2l7NCjVQiaDU=; b=ECX6wiS7Ljswh0n7uzcwkL8jwdTFBQY+WmHcx2c6QS/4aAwXGjKdQYldXagRMt/uYo D6zP6cz/x3dCCXQZjrhJkCV3D2oUf6YHCo8/lWDVsKqOpWOPARXIEfoRCnFKZziMfRmD U2jUtcVGACUwARMoEdGPkV9PICwfouE6jbOS9fVN2cnGUL38uSabQRFqBQERxyWdyg3t lSXIornjpcxnpvkzcEdLjzdASOcqbgj4xP+O2V1a1L+OmlVTfj2RjAzqyxc2X3cyGnOT /jRfEt7BFEy4xRV1j+WKu49XB1TZMWfWi37pd6jIuFopVvPyVKh2ddGPFioPlGGLKxez ja6g== X-Gm-Message-State: AOJu0YyTzGkmHNAp7nswM5cgJ1bAyEPqmcbZubTm8jJ5DuXCZEoH6Gy5 V8CW07ijkFoCejVRJEV2YhObkYhfrdxQYXSGVO5g9XOUhMqPd2WmznLYolEz0eUpHimfPQZdBOw 40CG0DPOGNMBAgPlnlBDw8zF2lByYmreaLQ== X-Received: by 2002:a2e:a16e:0:b0:2b5:9d78:213e with SMTP id u14-20020a2ea16e000000b002b59d78213emr462774ljl.22.1691526803182; Tue, 08 Aug 2023 13:33:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCVrGoxVvVsYGybUmaJuq923oNPsd2tycTm8Ey0pCk09HBhc+3+ig2e1FFsKf8/ZZSuW1JM4K4FUGOdRBHH4Q= X-Received: by 2002:a2e:a16e:0:b0:2b5:9d78:213e with SMTP id u14-20020a2ea16e000000b002b59d78213emr462765ljl.22.1691526802908; Tue, 08 Aug 2023 13:33:22 -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: <20230718074027.32270-4-kmatsui@gcc.gnu.org> From: Jonathan Wakely Date: Tue, 8 Aug 2023 21:33:11 +0100 Message-ID: Subject: Re: [PATCH v4 4/4] libstdc++: Optimize is_compound trait performance To: Ken Matsui Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="00000000000037412106026f4688" X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP 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: --00000000000037412106026f4688 Content-Type: text/plain; charset="UTF-8" On Tue, 18 Jul 2023 at 08:44, Ken Matsui via Libstdc++ < libstdc++@gcc.gnu.org> 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 efficient now, then I think it's OK to instantiate it here. Otherwise we're duplicating the logic for is_fundamental, and just giving ourselves more code to maintain. Nobody ever uses is_compound anyway! > /// @cond undocumented > template > @@ -3234,7 +3243,7 @@ template > template > inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; > template > - inline constexpr bool is_compound_v = is_compound<_Tp>::value; > + inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>; > template > inline constexpr bool is_member_pointer_v = > is_member_pointer<_Tp>::value; > template > -- > 2.41.0 > > --00000000000037412106026f4688--