From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 717873858D1E; Sat, 22 Jul 2023 13:39:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 717873858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fd190065a8so26353565e9.3; Sat, 22 Jul 2023 06:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690033150; x=1690637950; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=tHIatHbuRHQH96ZqH+Wa06upbjla9HnvTH43P4EgJTY=; b=EYVFAevgjRvtHS7O0RU12xaubpSksMIPmkBa66O848sEO8HLvsOwS8wxKqmfKaBDBK S6YRLYSi9HKyTDALMWlZDDFE5nifjMfcO7ya8HQuEuc7jbJto7ZEIeZ0oWHmkqOTpr0b ZxRFTjEevRG4C4qpkw2LS4zsQsXYflVwzEz0YeCc65Lg+FyUwJgvrUDHly0XmCxkm9qh EtQx37VULFYD5r6l2z0O7JJvxQnfYF1V80cDiPlnGG3oihfZaHwrjI/wh89WSz85IHsm 86OZukhbRquhZOQfMXIDriY8KymdgiVL4x8EWZlZq+uyKrIVkgdShJDpjStNjQ5qaey+ lP4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690033150; x=1690637950; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tHIatHbuRHQH96ZqH+Wa06upbjla9HnvTH43P4EgJTY=; b=K20zb5jOyEiiBhIFIaZkO6uw8OE4DFLV3OqzwsOA3bh708dZptxnSXADsaXSsy2IM4 /H7+kwQMXO+xdOtfCS+aMWKbA3fwQQ9e9FMPOWB/Up74+3GhMFMDWtEjECSK2C31/AFI yt1cUDJV4oYOWDnynhnOoFRGWDyRdypf+7sfHuZQ3qbKc9/VLUDOel3boMbl2bf84LfD uDfZvxWaGbDyQHWZfUg7CdLi3pCKahXweAos9+NoX7GCAqiZfnZKXHNMHJE6K+Lrt4U/ QtL2uH9MQ7Tr2CfEsjtwunQDr0xk2zP9ayH27GtJNqDpils67XJixHOR+ROxwlJ6aTIQ SMLQ== X-Gm-Message-State: ABy/qLZqeuTutUPJmm9BpXzRXp08ic5YmFn1DzsTZyYC9u9Y+nenY2uR VO1LQp/WNl6bs242hu9kjGI= X-Google-Smtp-Source: APBJJlE2gi4pwi3nB+F2X9oMccL4v+khfaqjYF71tFbTd/qQO93ed9S8FEjLW0ljvNgyDfYw2ahRow== X-Received: by 2002:a05:600c:210d:b0:3fa:7b44:7195 with SMTP id u13-20020a05600c210d00b003fa7b447195mr3659647wml.10.1690033149709; Sat, 22 Jul 2023 06:39:09 -0700 (PDT) Received: from [192.168.42.130] (pop.92-184-107-165.mobile.abo.orange.fr. [92.184.107.165]) by smtp.gmail.com with ESMTPSA id u19-20020a05600c211300b003fbc30825fbsm5314891wml.39.2023.07.22.06.39.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Jul 2023 06:39:09 -0700 (PDT) Message-ID: <607569d3-9720-b28c-57cd-d7ca6cd0966d@gmail.com> Date: Sat, 22 Jul 2023 15:39:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v2 2/3] libstdc++: Optimize is_arithmetic performance by __is_arithmetic built-in To: Ken Matsui Cc: Ken Matsui , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org References: <20230709125715.26884-1-kmatsui@gcc.gnu.org> <20230715045519.50684-1-kmatsui@gcc.gnu.org> <20230715045519.50684-2-kmatsui@gcc.gnu.org> <69c70c3c-e197-10b9-1a5b-feef2fe79d61@gmail.com> Content-Language: en-US From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,NICE_REPLY_A,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 17/07/2023 06:48, Ken Matsui wrote: > On Sun, Jul 16, 2023 at 5:32 AM François Dumont wrote: >> >> On 15/07/2023 06:55, Ken Matsui via Libstdc++ wrote: >>> This patch optimizes the performance of the is_arithmetic trait by >>> dispatching to the new __is_arithmetic built-in trait. >>> >>> libstdc++-v3/ChangeLog: >>> >>> * include/std/type_traits (is_arithmetic): Use __is_arithmetic >>> built-in trait. >>> (is_arithmetic_v): Likewise. >>> >>> Signed-off-by: Ken Matsui >>> --- >>> libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ >>> 1 file changed, 14 insertions(+) >>> >>> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits >>> index 0e7a9c9c7f3..7ebbe04c77b 100644 >>> --- a/libstdc++-v3/include/std/type_traits >>> +++ b/libstdc++-v3/include/std/type_traits >>> @@ -655,10 +655,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >>> { }; >>> >>> /// is_arithmetic >>> +#if __has_builtin(__is_arithmetic) >>> + template >>> + struct is_arithmetic >>> + : public __bool_constant<__is_arithmetic(_Tp)> >>> + { }; >>> +#else >>> template >>> struct is_arithmetic >>> : public __or_, is_floating_point<_Tp>>::type >>> { }; >>> +#endif >>> >>> /// is_fundamental >>> template >>> @@ -3198,8 +3205,15 @@ template >>> inline constexpr bool is_reference_v<_Tp&> = true; >>> template >>> inline constexpr bool is_reference_v<_Tp&&> = true; >>> + >>> +#if __has_builtin(__is_arithmetic) >>> +template >>> + inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); >>> +#else >>> template >>> inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; >>> +#endif >>> + >>> template >>> inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; >>> template >> Same remark as the one I did for __is_pointer in cpp_type_traits.h. You >> could implement it as: >> >> template >> struct __is_arithmetic_t >> : public __truth_type<__is_arithmetic(_Tp)> >> { }; >> >> François >> > Thank you for your review! This is from the type_traits header, so the > name should be as-is. Here I meant that current libstdc++ implementation of std::__is_arithmetic in cpp_type_traits.h should also make use of the builtin __is_arithmetic that you are introducing. That is to say replace this:   template     struct __is_arithmetic     : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >     { }; by: #if __has_builtin(__is_arithmetic)   template     struct __is_arithmetic_t     : public __truth_type<__is_arithmetic<_Tp>>     { }; #else   template     struct __is_arithmetic_t     : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >     { }; #endif if you replace '__is_arithmetic' by '__is_arithmetic_t' for the libstdc++, just adapt to the name you eventually adopt.