From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 675DD3858D1E; Sat, 22 Jul 2023 13:45:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 675DD3858D1E 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-x330.google.com with SMTP id 5b1f17b1804b1-3fbd33a57dcso25954795e9.0; Sat, 22 Jul 2023 06:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690033528; x=1690638328; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=CIN0NC6DySW9+VfJymwtfbw+KPqhHdqzamEcMio3UnU=; b=QXfqshKu4oj021jEM+P0FbnKJTK5aPUJylr4+2rEwOFcyUcRphDgj9JzLfh69OQoAt KqOVA6MrerT5FN4wQp/I2McapLBPX2oaru6ePTgvyiqtC8OE2/h8jNW45wEFDon6fitq ZhGofAmnS2lVtq+NEIe84Zns3x3gOagdL5i/AxC2CgbaDk/9WB93ORtWUXzfwmrg2oez zJm0vgzEj6YOx2QJl/WSw2PrG0PLMoQXynxIC+ycGKHmUr9Gb6acY3l5whP3UMKNV3VB tagl6NwN+R1JDp9zwWiQWfqMHbeqte00zwp8MhbLSVW9AtREqd1eMtBkUYPn+WtwjmuM sAjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690033528; x=1690638328; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CIN0NC6DySW9+VfJymwtfbw+KPqhHdqzamEcMio3UnU=; b=YD9G0NDUkKglxqB/7pqB0QB2uT5kV60X4UlyoV7EWQsiITNvk3AY5xO0wLaDvloPJM CF+YxZlyL6rRQobLhW/KU3IDLmWEEm+i93Z7j0xxiMayfwB2aw9N+0q/zmp47lvw0Bs1 H2lBtRrOlYhBBxv7N2og/7YpaCmPT3SMGpjtWKUq1No2m0fW3ArXrBEiT7maVKeKcvER Zx+4OgmrUgx00uxpQfm0W0DduifEMsf9c0RSlm/ik4rttKg0LSq5p3BB2QWf/sif2g9M j0kSLsvqLSRgdUwQucZsgWCfSMxjJOzPPPFVlVVtGqJwNIEYBC3bvlhjZYhoMjme8gLN ntrA== X-Gm-Message-State: ABy/qLZ4GHQK3cClIwFlBTdJyFyhWOIZ5Ko/ow/eSXhnyZ5voyaxd9aT GYqOJEoh5Ah8nk/t/6VXQUg= X-Google-Smtp-Source: APBJJlGjzDmUdbil0p6DUTWImcsZbk87yEbNmf02y2+tQ8AuPGT6ZoA6BVAo3SQkqNPcDKQtuJw3rg== X-Received: by 2002:a7b:c40f:0:b0:3fc:e1:24b5 with SMTP id k15-20020a7bc40f000000b003fc00e124b5mr3742806wmi.23.1690033527766; Sat, 22 Jul 2023 06:45:27 -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 f14-20020a7bcd0e000000b003fc01f7b415sm8210592wmj.39.2023.07.22.06.45.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Jul 2023 06:45:27 -0700 (PDT) Message-ID: <48a3ea23-13e2-b668-083f-58c2b33a59a3@gmail.com> Date: Sat, 22 Jul 2023 15:45:25 +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 3/3] libstdc++: Optimize is_fundamental performance by __is_arithmetic built-in Content-Language: en-US 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-3-kmatsui@gcc.gnu.org> <3aa7cf30-27f1-7e69-7334-fc9918928f90@gmail.com> 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: It seems rather logical cause std::disjunction is supposed to avoid instantiations but in case of: std::disjunction, std::is_null_pointer<_Tp>> you'll avoid std::is_null_pointer instantiation only for 'void' type and at the price of instantiating std::disjunction so 2 instantiations at best but most of the time 3, clearly useless here. On 18/07/2023 08:24, Ken Matsui wrote: > Hi, > > I took a benchmark for this. > > https://github.com/ken-matsui/gcc-benches/blob/main/is_fundamental-disjunction.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 PM Ken Matsui wrote: >> On Sun, Jul 16, 2023 at 5:41 AM François 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/include/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 better that std::is_arithmetic. But __or_ could still avoid instantiation of is_null_pointer. >>> >> Let me take a benchmark for this later.