From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 926533858C50 for ; Fri, 24 Mar 2023 10:47:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 926533858C50 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-ed1-x533.google.com with SMTP id i5so6411170eda.0 for ; Fri, 24 Mar 2023 03:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679654874; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=p9PIZAwClOEho7ycNYjOJdJ0rV3Gi7XzfBeQcC5Am84=; b=ZusS9kT4vYZfCghHhNqf4UG/lxZCkWFMIkz45qDiDtlHWQFJIhTJE964vu0kAC7y+N +DhJiVT1ILKUmHnWwPczQoNJhH8ZD0+dSKFI+gCqYwNtUGlnDkVX9gWMR2H2j023tJOk uCYpgr+2Uksaqt6oxnNTlWsRoo1wNADvIYvlkOreZQUszKVEMtcZZ5CBOQMYj76OTyYW nxclWd2Pd+mFx4T0cA9oBGbi7hasSIXqULk0YKVHaY+nA3D/L5A/ncKsue+DBsiloWqE O6/nS2uqOrZVDifkeZIUgvITwULia+q8AQCeb1Dmq7NtrvIu4gJ5AkRJB6AOyhoeU6Yx X88A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679654874; 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=p9PIZAwClOEho7ycNYjOJdJ0rV3Gi7XzfBeQcC5Am84=; b=q0QuVJhY2WSSy852QV+gn5Ih31fzWA1z/YoF8Q5yjlTCqb/g2evWlJOQlLaPgewd6g YIj/BAkfyDnUr2y/2WgJkc+oYGF0w7T40B8mEP0ylsHqhXDXW+yz3bydGKfsz/hJ87eZ /il7CjL/gUkraJgCR2mSwI9lMXKrT7xdT4Or3IOZHTapz8N8kG+TJWR6FDye9y7xdyhx PXHyRlNbMhMDuIlnxePbR9AZAenOIIOwjy98LqW3Cp9MluOBMGU+CiWFoVdFbStOJQNR r/NEHn+DAk/oGtGG6P2wzh9HGoPmUE/teySGVML30yLKuIv81+DrKPEDoj0SGHWS8XY3 SBrA== X-Gm-Message-State: AAQBX9efCBu0J20Ekcw43c/q413MqHsYJIzmcXpEBp1QQFgS8H00BHG0 7fL+yP5PDhbn0x3n3HrEvcC0foKK6OdSKkJSX/E2DTvH X-Google-Smtp-Source: AKy350aQMgg3aSXaD3zhP0eB66H8YtHgSmo5MI1A3ZvUFwu9EhVInv3zBiYLh7TrtSu5DTjT1Rs2qgOrCTE35Nj7EmI= X-Received: by 2002:a17:906:7c54:b0:932:6a66:fc43 with SMTP id g20-20020a1709067c5400b009326a66fc43mr1069896ejp.13.1679651894420; Fri, 24 Mar 2023 02:58:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 24 Mar 2023 09:58:03 +0000 Message-ID: Subject: Re: [GSoC] Question about Relatively Simple Library Traits To: Ken Matsui Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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 Fri, 24 Mar 2023 at 07:10, Ken Matsui via Gcc wrote: > > Hi, > > I am working on the GSoC project, "C++: Implement compiler built-in > traits for the standard library traits". I found the following library > traits that I am not sure if implementing built-in traits brings > reasonable speed up. > > * std::is_fundamental > * std::is_arithmetic > * std::is_scalar > * std::is_object > * std::is_compound > * std::is_scoped_enum > > For example, std::is_object has no template specializations, but its > inheriting class looks complicated. > > __not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type > > If we define the built-in trait for this trait, we have: (as > equivalence of the above code) > > __bool_constant<__is_object(_Tp)> > > And __is_object built-in trait should be like: > > !(type1 == FUNCTION_TYPE || type1 == ...) > > In this case, could someone tell me which one would be faster? Or, is > there no other way to know which but to benchmark? You should benchmark it anyway, I was always expecting that to be a part of this GSoC project :-) But is_object is NOT a "relatively simple" trait. What you show above is very complex. One of the more complex traits we have. Partial specializations are quite fast to match (in general) so eliminating partial speclializations (e.g. like we have for is_const) should not be the goal. For is_object we instantiate: is_function is_const is_reference is_void __bool_constant __or_ __not_ __bool_constant This is a ton of work! Instantiating class templates is the slowest part of trait evaluation, not matching partial specializations. A built-in for __is_object will mean we only instantiate __bool_constant. That will be MUCH faster. But I think it would be a good idea for you to benchmark it to confirm that.