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.133.124]) by sourceware.org (Postfix) with ESMTPS id C1F043858C20 for ; Tue, 8 Aug 2023 20:33:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1F043858C20 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=1691526806; 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=RDmXJ7X3ApcjHzZLhJcGEqR9tZi7+Fq5IHOZiRWZHDjWW0vTLgw4lagLW7RShOCPHJYNPL giFKi9+/H/Z0Czd65/j/jUyromeMUlPSXdT1EN3SAKcn++tb0Hs/rM++FcUAzQjD5hCdWx 1SDjujHmNCD6y02Aj+NP2Hhh9Q1gtNQ= 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-634-8kvHuTBAOaGpBYQp7c7iIQ-1; Tue, 08 Aug 2023 16:33:24 -0400 X-MC-Unique: 8kvHuTBAOaGpBYQp7c7iIQ-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2b9bf49342dso66737851fa.1 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=KYXJ94wz3v21126N2R4P/fBFrvu5ZOQfqFHFrj/4DcN1RX6DLwhX7n+M1fNP8Buh4p BuVx07Go5J2TWXj5U6u6paqO+MOqSUAMFKOBoe0ivYRbcAWksdSgosFW3ACpyXr5AZSE GvFypwQ2Y4xpw0gMcOli2f49Y7w3Gic+Z452ipP3UExHOoE/BpGJR3BQXR98puEsqdNj UJN2sVgacc74FgblOC7kopvP8447JuMBCTzcBqeXOkZqMlu1+7hnfCFpfpi51cxhNmvr DHUqDscw6hea0VISNca4cQezPmp70rkxZiGDUsDiNf5Gb+pSu1pdrS6Qh25VFm+sJsU9 RY7w== X-Gm-Message-State: AOJu0YyDczYE9yJzKsKGMpv+w39bXcCg0dlXnfgAiMnHvdDYRY9tq6kL mACY5gPv2Iza7a6N8KDGrAwwlZUlBUSBGFsm9Y0St3Tg61koXJa1vSFBhyzsuwNWdzQ95ut1sPM 2X79uJcLUzlhyFE/Riz73Zgr2PbkRgiPvjoUUFe6iqQ== X-Received: by 2002:a2e:a16e:0:b0:2b5:9d78:213e with SMTP id u14-20020a2ea16e000000b002b59d78213emr462773ljl.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=-13.5 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--