From patchwork Wed Jan 10 09:22:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1016771dyi; Wed, 10 Jan 2024 11:46:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKWjULyLcec8hbruXeeyvOXj+AIKlgWjUemhDidDysFJKonoRkJ7JXdomxOpOVYWVpMqEl X-Received: by 2002:a05:620a:1910:b0:783:1f6c:1fd1 with SMTP id bj16-20020a05620a191000b007831f6c1fd1mr164670qkb.145.1704916007231; Wed, 10 Jan 2024 11:46:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704916007; cv=pass; d=google.com; s=arc-20160816; b=ea5619hO2vIRBOQwsTZYZ17Pg/9cdUSwVEnJiFI0YsamWbkpf80nH1apL0oCobVAwk rD8LkKyww4lACgJCsfa5IbA+R3xxMcUFBRkRtAGmd3uOnux6HPwm/tn0ex4vW+lVUPYe zbK8R41hPvy448jsRnFEoQ2q7GykWEpXJesG5Qb66ZiRrTwPlqSVcGrv71dDIhUfk6IO L9vB8IeDFIIreagqFIjsKk2ikLx1duet6K4mfCM8HCCUBchezXEyVydpaOprwgE+NIZm RIkQGVKqkZZcN6Tf0jRU8WB9opW6KiuW/QSJYoyIJuc1aj+BopIIGdxDsw14vNwfzpZl Gy7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=A/cV/jkwOMqGB4fNKmrTPoKGnGSMBBL7ZWi1AtiQ57k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=pLFQcCJIlwtUqvfz1JIDEoMZkYVr/aeFpAFt5zs0RLobZJaU+he2CnRcMvcG79T3zw ++XVQJqdQOQ97mh/MLgCvNbywItr3JQR7312dUYFZ3g1QySmSEKcJykRQXKAGlYBCquW 69Y/y2ySK9rKaPUVUmY49dIfA2PRAhSwZ/TFBW5LeKavGhtUyQ5xq6DFTSJ7grqlcOgq iZx+vLo5BBWTTnH2jrsQboajjM/Kr7xNCNuOxQRlMS4igDwn3ts6dxKHzPHq6eNaaVO1 sJYhdY2P5dkFNejyakIaIjnNm1Iqz/nTeM2SVAruPLewrqFjf5wZueEDhcms3Fso1AUH abHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vgD0OXlb; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j2-20020a05620a146200b007819f589450si4532406qkl.456.2024.01.10.11.46.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:46:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vgD0OXlb; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 153A03857830 for ; Wed, 10 Jan 2024 19:46:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 153A03857830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704916005; bh=A/cV/jkwOMqGB4fNKmrTPoKGnGSMBBL7ZWi1AtiQ57k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vgD0OXlbCnaKyQjoeiP9am0uwVOLJrCAp9IyxOsYPXNN9+IedcYIvgtCF+U6KheYL qivh9nXx9I/y+vk7iRPZlztIddi01WRT7rtir3X0PU/zKawTHKwoPjHLsXE/NBPwh/ CU7YatvBcLhlagNBRVlyo0+Ry/Nxy9OwYk8Dz/gI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 0DB8338582AC; Wed, 10 Jan 2024 19:41:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DB8338582AC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0DB8338582AC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915668; cv=none; b=Jx167cfVweXE4jB/3i0ZWmW2KyEqdRTZaJPPHXZd8+c9L9qpl7N2+2CGMmGfJvb3sBplCceTrBYoQRfr0c4aCcWP/nbdU6i1S/ReQ/DxJkDgA49tCA0a2PInXhmTpL7dJHRXgOTAhOENMe890Gf9bTB6FAr58jRZSMYk2SIxCtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915668; c=relaxed/simple; bh=n8QWfpU7eDwDINzPotv0c20d1GpCtyHnE+y+aKFv9+o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CQQvMG6mKHt4MMe7Cus84Pfclxl4P79sCyuXfaHNRscd0bxGVvgRMJU6xPymrQvLlnm5hrQZXDIuPLCQbbQvt40F+4YxVzOtqNxGkzuDPaIvtrntFdnCZ4UDDg7foLr2PBWRdkrk+Qs+c6p8MKSOO2HL6R/8gpu1MH33Osc7Igs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJdV6l025110; Wed, 10 Jan 2024 19:41:04 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vj0g38ptg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegFw027798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnA020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 01/14] c++: Implement __is_integral built-in trait Date: Wed, 10 Jan 2024 01:22:52 -0800 Message-ID: <20240110194031.2384005-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: B0d_q3T3L9I6feR_P9YGlA6CfHW7GY38 X-Proofpoint-GUID: B0d_q3T3L9I6feR_P9YGlA6CfHW7GY38 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 malwarescore=0 spamscore=0 clxscore=1034 priorityscore=1501 adultscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=768 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787734007307587852 X-GMAIL-MSGID: 1787734007307587852 This patch implements built-in trait for std::is_integral. gcc/cp/ChangeLog: * cp-trait.def: Define __is_integral. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_INTEGRAL. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (integral_type_p): New function. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_integral. * g++.dg/ext/is_integral.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 18 +++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_integral.C | 49 ++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_integral.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index fef68cf7ab2..3a105a2ee2a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3755,6 +3755,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FUNCTION: inform (loc, " %qT is not a function", t1); break; + case CPTK_IS_INTEGRAL: + inform (loc, " %qT is not an integral type", t1); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 394f006f20f..2773c3fa10e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) +DEFTRAIT_EXPR (IS_INTEGRAL, "__is_integral", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 3299e270446..1a335f69826 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12258,6 +12258,20 @@ is_corresponding_member_aggr (location_t loc, tree basetype1, tree membertype1, return ret; } +/* Return true if T is an integral type. With __STRICT_ANSI__, __int128 and + unsigned __int128 are not integral types. */ + +static bool +integral_type_p (const_tree t) +{ + if (flag_iso) + return CP_INTEGRAL_TYPE_P (t) + && t != intTI_type_node + && t != unsigned_intTI_type_node; + else + return CP_INTEGRAL_TYPE_P (t); +} + /* Fold __builtin_is_corresponding_member call. */ tree @@ -12465,6 +12479,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FUNCTION: return type_code1 == FUNCTION_TYPE; + case CPTK_IS_INTEGRAL: + return integral_type_p (type1); + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12691,6 +12708,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_ENUM: case CPTK_IS_FUNCTION: + case CPTK_IS_INTEGRAL: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 02b4b4d745d..d621171481c 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_function) # error "__has_builtin (__is_function) failed" #endif +#if !__has_builtin (__is_integral) +# error "__has_builtin (__is_integral) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_integral.C b/gcc/testsuite/g++.dg/ext/is_integral.C new file mode 100644 index 00000000000..d2c732133dd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_integral.C @@ -0,0 +1,49 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_integral, void, false); + +SA_TEST_CATEGORY(__is_integral, char, true); +SA_TEST_CATEGORY(__is_integral, signed char, true); +SA_TEST_CATEGORY(__is_integral, unsigned char, true); +SA_TEST_CATEGORY(__is_integral, wchar_t, true); +#ifdef _GLIBCXX_USE_CHAR8_T +SA_TEST_CATEGORY(__is_integral, char8_t, true); +#endif +SA_TEST_CATEGORY(__is_integral, char16_t, true); +SA_TEST_CATEGORY(__is_integral, char32_t, true); +SA_TEST_CATEGORY(__is_integral, short, true); +SA_TEST_CATEGORY(__is_integral, unsigned short, true); +SA_TEST_CATEGORY(__is_integral, int, true); +SA_TEST_CATEGORY(__is_integral, unsigned int, true); +SA_TEST_CATEGORY(__is_integral, long, true); +SA_TEST_CATEGORY(__is_integral, unsigned long, true); +SA_TEST_CATEGORY(__is_integral, long long, true); +SA_TEST_CATEGORY(__is_integral, unsigned long long, true); + +SA_TEST_CATEGORY(__is_integral, float, false); +SA_TEST_CATEGORY(__is_integral, double, false); +SA_TEST_CATEGORY(__is_integral, long double, false); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_integral, __int128, true); +SA_TEST_CATEGORY(__is_integral, unsigned __int128, true); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_integral, __float128, false); +#endif +#endif + +// Sanity check. +class ClassType { }; +SA_TEST_CATEGORY(__is_integral, ClassType, false); From patchwork Wed Jan 10 09:22:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1016493dyi; Wed, 10 Jan 2024 11:46:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFERebDL5GwbvOq/oGXfCCT/ppXOUk8JeKqFSp48xy9mblqMHfw2KN9A27hPtk82lF2hrC/ X-Received: by 2002:ac8:5bd2:0:b0:429:bafe:6db4 with SMTP id b18-20020ac85bd2000000b00429bafe6db4mr1251246qtb.21.1704915974965; Wed, 10 Jan 2024 11:46:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915974; cv=pass; d=google.com; s=arc-20160816; b=v//12pqhEX49AUJWa+4GbQsbMhWdHIAv2C2JMUFcEdcnkfLCEd8LBZkh4ykrIYNTN5 QMBYhOhmgY9U4xqHHfGfaju58Fi18Js+015ms4tjm4zK1qQARp5AMRpA57tZYNEv7siz ElGQiFA002HZAH00LZdogbQA/bgdc38h+8stgZuHA3IhX2myLgCMdlpipI7pyvT3KnF0 vnZYrklK2QV30HdPjvoC03A5viViPo5iEWPQjDz9ZJde9NzgdtNfRsqkv5k+IdWsThzZ wKnjpbdZEi2Yqb974kK3g77Myv1hvMvIz17FiIbh8ZfAAATtZeOQm9Eud8ANKMY2gkJc nYKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=FxqDKeARRXJgwlSFZ8WkieiUfM4HTiu/i0uMANwsNYQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Umo7TWqPp5s3fPuZSL5Fz0QPpZm8NY2POz8AfHkyBh4L9IjQFoJyJLCxQIVhkj5SZN FfruitxrT4CHmYMJDFBtMXZEM8ynbLmbmBBP+i8NLDNHfA3dOrMgL1wA2fflGzsXPbnm u5+7d+VmAc5w6rjRbVZO2QrLn818x8hqD6FmkOwzQhxaYMqAgTtdUrUUKOvCrbhGazV1 ArDTXgomcTiP2/dTW5oyVuCIwFD4uqVn6C6btUVIaDh9beNoZ99Ew+1qdGPnhcFEBR7q qd6A0KAktu+B8GJXQPyKWxw2K4NaP3QApfJab+C9Zx8uF7fPIILY2SNK6feAmPEDGxQH HShQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=p3US4vHL; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 12-20020ac84e8c000000b00429bc1c30a9si951038qtp.692.2024.01.10.11.46.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:46:14 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=p3US4vHL; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 927753857C4A for ; Wed, 10 Jan 2024 19:46:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 927753857C4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915974; bh=FxqDKeARRXJgwlSFZ8WkieiUfM4HTiu/i0uMANwsNYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=p3US4vHLEGFirZS0DrR0ZSwXo/X/0QL2o+48NV4E73+1cHDW/AlDvRG6leFNaagRb HR320/Cm3Im1JPHlYj4N23g50NVjh+dUDHG6UDtzleoS6dMQiLREt/1OdEJq0+Zmct Zo1zrNLKxp3i84Pxj3tpDnnzQ9nwvgJ0QxB2pkxY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 1D6C73857C4F; Wed, 10 Jan 2024 19:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D6C73857C4F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D6C73857C4F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915678; cv=none; b=kV/yxLp+W0ZOYfAxSza1Nd8AWKZ+MLszo+O0Mg77vAGWG+KLHmmEAGFBGESvEYNxgyMnG/yWIi5LVvWRjXq5eJyTwXNDRWAXPgKG+RDME43Mc1+yKioUn8Dpq07nznp2qgsEpRy9So3x3uoaiidPG+qEUu4SYM9GteH9btSpiSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915678; c=relaxed/simple; bh=OycjGjGKRYCIIezRv53318dfFy9la6Fd3m8SNWB439U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YQHA3nE9Q6hWtHuD8YnucEJdgsfsHrKalSpSzkdofCe6uuvG7Frnpg3BFGd5YUZ2GeHyQVoRXNA40JwzCueH+NscIzWg8yhH1LcgZOzLH6f2Pa5WCjQcwKVB5XJ/tYFdzqtycKsWRPtC//70lvee44tmtMNt5z92zGS3HSwsh5s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJbWV2030182; Wed, 10 Jan 2024 19:41:10 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vj0y6rjd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegqw002134 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnB020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 02/14] libstdc++: Optimize std::is_integral compilation performance Date: Wed, 10 Jan 2024 01:22:53 -0800 Message-ID: <20240110194031.2384005-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: i3O4xxt67GdGM-pJBr5VgplAzpuqv2aS X-Proofpoint-GUID: i3O4xxt67GdGM-pJBr5VgplAzpuqv2aS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxlogscore=494 clxscore=1034 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733973360946557 X-GMAIL-MSGID: 1787733973360946557 This patch optimizes the compilation performance of std::is_integral by dispatching to the new __is_integral built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_integral): Use __is_integral built-in trait. (is_integral_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1cec0822b73..afa281d9cc4 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -334,6 +334,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_void : public true_type { }; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_integral) + /// is_integral + template + struct is_integral + : public __bool_constant<__is_integral(_Tp)> + { }; +#else /// @cond undocumented template struct __is_integral_helper @@ -461,6 +468,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_integral : public __is_integral_helper<__remove_cv_t<_Tp>>::type { }; +#endif /// @cond undocumented template @@ -3221,8 +3229,15 @@ template inline constexpr bool is_void_v = is_void<_Tp>::value; template inline constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_integral) +template + inline constexpr bool is_integral_v = __is_integral(_Tp); +#else template inline constexpr bool is_integral_v = is_integral<_Tp>::value; +#endif + template inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; From patchwork Wed Jan 10 09:22:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1017321dyi; Wed, 10 Jan 2024 11:48:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IELxDN2ijO9WABFCFGu8JjhmOZr0KYqMzJrrVIxV3kGjeC072fRM441MRuubdlMZZDAOgJE X-Received: by 2002:a05:620a:2414:b0:783:100a:9713 with SMTP id d20-20020a05620a241400b00783100a9713mr181011qkn.67.1704916084746; Wed, 10 Jan 2024 11:48:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704916084; cv=pass; d=google.com; s=arc-20160816; b=VHq4KN6gesRYYk3cO/Jg3/sQuAGZitKPk123f/id5Wi9SPc/UdGE88pyOYi9dEk6/Q S/bxgGy2Q6z+sDjwCZ2nS2/tbUrSR2dnGw2RqnV8IzoztFq7UA4sJxhYIgfxvC9TcKih CXDZAIjozX5FV4eQ33JwUJmRmtP8iY2G2Y2HncriAZmgXCXBoiIk3Dy221tY96h5e29H ACYQ43EDhHfPamVRveQ0YrccjX6HvoAvXfgh1tAnpnVjiJVidziZbt/6fe3fH2BHUVE/ quUgXsDb8zw4PiIBw8pPG1eGV/iXEh2AXMgW0Xvq1pjnIAAmNlNVgE1M/s8VHugckewQ HKSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=RMjqgS2RJYGA47zCCDoXZ2LdUIiTsZm/kh0uoeERwnw=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Y9kidDe56QruDUt2c6kiie4zfAmLNvDBH5chF3TVW/3uflwJ0fRZw16WSjV7cCxCfB 4EIuHqSYNZg6IfnGcesSgzSJbDu1npCNeL4iy4NB/mcdt+GmHTQl34w2N4J6ldGUM84Z fEri5edORiU6BMDg4HFxKMPrNk2tYrI+RDyTNxhnPCyaryIphkPVwiUop1GPlYHVYfGd Zq/gfk6zHpKGP9S2XLZ/VaQIwwd8f92HU4FiEsAkITQAZm/erFtB1ALYL2WXo7KPCu83 J4/Kgo2r9lY3ZqnWp2GTuPhjY+7sjWyIODElNjMlG3NsFzuLPcEfwIHqTK0vaJgFXKSV zoAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BKyPOF36; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u5-20020a05620a0c4500b0078321cfec3esi5063788qki.685.2024.01.10.11.48.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:48:04 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BKyPOF36; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 674E038582BD for ; Wed, 10 Jan 2024 19:48:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 674E038582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704916084; bh=RMjqgS2RJYGA47zCCDoXZ2LdUIiTsZm/kh0uoeERwnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BKyPOF360WXR8byZIKCvClPOSYi4Ctg0WVRoR8xr4XLo86t7WLbHbJ31uZm41hcxF GtzUiOwl0KhbZQCw0o7G0o7AYKvZ3seWBoXvpy9/lm+LWpvXxOGC57b6+0KOAjG1z4 slE19duBG3QD7CfL0XIKmTspyRxkRKzIiVPAgN/A= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 7A6653858006; Wed, 10 Jan 2024 19:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A6653858006 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7A6653858006 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; cv=none; b=GkkocOvY5n2vP+1ZpM2qE+54gm/2qr7VjpMnxBdHuZ/Dqmr5havAJ1zGFNwW3Yh9jhABFOtJs/WoHv5sgfz4gV6kZQCJzWbO6NAWIBqzAjyJLOMgIwYCMy51g7hSnAIX5mwnYoAq611AqcMB7IqQFxiq30h0OUfBQQzo+C57yvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; c=relaxed/simple; bh=nBJqnkJ4N2ZM+zlwVn7F029QCgKGqpfD3hg2x/MC0L4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xJU7hGsHHEu0cdZi72QHnR+erMH4Eifda2jC27Qo4eulmz1OErAXOE2W74/wcw1dQyEzWItvPipyDeQkHNQABGM3DB5qpMqRUl4LUSnmumwLZ9utkUxJmMKAHPDRQzRMQPOhqj42xMSZvOetfMueSSegLJdZmG6hAEX1pTNvMsE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJbSDq011353; Wed, 10 Jan 2024 19:41:10 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vhyq0sc4b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegQd006372 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnC020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 03/14] c++: Implement __is_floating_point built-in trait Date: Wed, 10 Jan 2024 01:22:54 -0800 Message-ID: <20240110194031.2384005-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: aBcs1nPUJYyG482W_1hj9KCH5VC30fQj X-Proofpoint-GUID: aBcs1nPUJYyG482W_1hj9KCH5VC30fQj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 clxscore=1034 impostorscore=0 malwarescore=0 spamscore=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=803 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787734088441622601 X-GMAIL-MSGID: 1787734088441622601 This patch implements built-in trait for std::is_floating_point. gcc/cp/ChangeLog: * cp-trait.def: Define __is_floating_point. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FLOATING_POINT. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (floating_point_type_p): New function. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_floating_point. * g++.dg/ext/is_floating_point.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 17 ++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_floating_point.C | 43 ++++++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_floating_point.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 3a105a2ee2a..aca0b91711f 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3752,6 +3752,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FINAL: inform (loc, " %qT is not a final class", t1); break; + case CPTK_IS_FLOATING_POINT: + inform (loc, " %qT is not a floating point type", t1); + break; case CPTK_IS_FUNCTION: inform (loc, " %qT is not a function", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 2773c3fa10e..acf668d48ee 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -69,6 +69,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FLOATING_POINT, "__is_floating_point", 1) DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_INTEGRAL, "__is_integral", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 1a335f69826..c052e47c204 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12272,6 +12272,19 @@ integral_type_p (const_tree t) return CP_INTEGRAL_TYPE_P (t); } +/* Return true if T is a floating point type. With __STRICT_ANSI__, __float128 + is not a floating point type. However, _Float128 is a floating point type. + */ + +static bool +floating_point_type_p (const_tree t) +{ + if (flag_iso) + return SCALAR_FLOAT_TYPE_P (t) && t != float128t_type_node; + else + return SCALAR_FLOAT_TYPE_P (t); +} + /* Fold __builtin_is_corresponding_member call. */ tree @@ -12476,6 +12489,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FLOATING_POINT: + return floating_point_type_p (type1); + case CPTK_IS_FUNCTION: return type_code1 == FUNCTION_TYPE; @@ -12707,6 +12723,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_ENUM: + case CPTK_IS_FLOATING_POINT: case CPTK_IS_FUNCTION: case CPTK_IS_INTEGRAL: case CPTK_IS_MEMBER_FUNCTION_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index d621171481c..5dc70a19e79 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -86,6 +86,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_floating_point) +# error "__has_builtin (__is_floating_point) failed" +#endif #if !__has_builtin (__is_function) # error "__has_builtin (__is_function) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_floating_point.C b/gcc/testsuite/g++.dg/ext/is_floating_point.C new file mode 100644 index 00000000000..1807279dfc2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_floating_point.C @@ -0,0 +1,43 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_floating_point, void, false); +SA_TEST_CATEGORY(__is_floating_point, char, false); +SA_TEST_CATEGORY(__is_floating_point, signed char, false); +SA_TEST_CATEGORY(__is_floating_point, unsigned char, false); +SA_TEST_CATEGORY(__is_floating_point, wchar_t, false); +SA_TEST_CATEGORY(__is_floating_point, short, false); +SA_TEST_CATEGORY(__is_floating_point, unsigned short, false); +SA_TEST_CATEGORY(__is_floating_point, int, false); +SA_TEST_CATEGORY(__is_floating_point, unsigned int, false); +SA_TEST_CATEGORY(__is_floating_point, long, false); +SA_TEST_CATEGORY(__is_floating_point, unsigned long, false); +SA_TEST_CATEGORY(__is_floating_point, long long, false); +SA_TEST_CATEGORY(__is_floating_point, unsigned long long, false); + +SA_TEST_CATEGORY(__is_floating_point, float, true); +SA_TEST_CATEGORY(__is_floating_point, double, true); +SA_TEST_CATEGORY(__is_floating_point, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_floating_point, __float128, true); +#endif + +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_floating_point, __int128, false); +SA_TEST_CATEGORY(__is_floating_point, unsigned __int128, false); +#endif +#endif + +// Sanity check. +class ClassType { }; +SA_TEST_CATEGORY(__is_floating_point, ClassType, false); From patchwork Wed Jan 10 09:22:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1014967dyi; Wed, 10 Jan 2024 11:42:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3kC6+mPdHzA9bMvihT9oG6lVJMVieu80UrVV44xJ5anw40bwe+cYx8uQ1gZ2ZPEd/HN/w X-Received: by 2002:a05:622a:204:b0:429:b595:fe28 with SMTP id b4-20020a05622a020400b00429b595fe28mr82479qtx.37.1704915775080; Wed, 10 Jan 2024 11:42:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915775; cv=pass; d=google.com; s=arc-20160816; b=Kztv76b5jv9hSf6eqH8mzmjg0K4TvUR1FTWy6faIUK8Bns/G2DxpwAHtN+wx2PQDhV +ap1is626arWRS4Xra2lIB+9tcGyatMGptlb6xoJk9bu7/ZjwXzv9uo7NkMfZrU7gSrE YAFdhd6EjxABFln7P/lEJScQF0khHvgN8pw9WMiZIMUPS00txQOk0VLa/SUVU8cKMqpD nqq+2K/MZk+vV8RxleBwk8I1rDo3lTa1PziGltDQXGP/lyJRaPQMuSXY3cctyktQrU6B PfxKQJlZaC9d88fcd33o7io91W9f1TP8B4FjcMOLsIvtazHv1P5XEQKaSi+l7m8lBfSO RtXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=SC1P28lbXGiY05rRjH7hqcBssMd3OMJcIIJzN9X4hHU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=fgqZ5uBTWG1E/ue7H52jb3R+Jz3wjsuSBeP8+YSAYquCnUvcRySlfDY5MkuxUbyd4i 1PU33jmUx4SzMpuVf9ECmZzqCD4LhSsGpXOL6ejIQ/9k3x5+Hcy8GoVE0xIp1vYQCEn0 3qO08BSF7fburUJdNSnb/v89yqCSQf08m9zbhDQTSqITIaNaNEGAM/OgpndDR8FEkKVF MXgNU5Zpf1D0yFR5C14k/3ELuk3heQljM70DBfIodyKgTmexkwL1Xg9dq9suRpd6AV4K teKtnalMfNg1TjfafO9EEfsaLgant3puPO3qbiCyHo+ShHcazGPrHw75hDZg6IpgLCjD eNdQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="IaHWR/jT"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g22-20020ac87d16000000b004299b15b56csi4642922qtb.716.2024.01.10.11.42.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:42:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="IaHWR/jT"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8DEB385801A for ; Wed, 10 Jan 2024 19:42:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8DEB385801A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915774; bh=SC1P28lbXGiY05rRjH7hqcBssMd3OMJcIIJzN9X4hHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IaHWR/jTQDz9weZCMjqB+mx5AwDJ2/McLVfrP6gCYMbmDZGIShAtaKLx54VsHTEc5 H4tYWUjRmyXb/5nF/CwEF0+53/OUES9i72oaKNF/+f/dU4A3X2Bzj2DNM8ybhNGTPY OEktv1Rjp9bXoni2VnskCdA+1AuLTuyLd6O/KEmY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 473283857C4C; Wed, 10 Jan 2024 19:41:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 473283857C4C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 473283857C4C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915667; cv=none; b=UKvLiB//J0Cgwk4FkOGI3bxnr6VMZALA1uVjzj+Gqc6GBrmmBW5SBluInm5aW/6mv8Nl1wBbAmL015hvU3GPjpq5WG2daSV7ora/YCml5QXJIsVrX+2/mqq/EEyuLuVRbRl6BNmQFizeDGKZQ9tpfg3itCyWXnfc08YwKI8ELRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915667; c=relaxed/simple; bh=G5TvNgClny7SC087pzKefYvF4ktWz/RFWqk1cThWWmo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=RwDIzlwRBFIF0rK94tuh3NUnASh8wdrYOZQbJiSMH4RjP4ElsUcHtBI7ujJfJEcyEDded97mHqTZyNiCOozFW9+o+h/TczsBI5f6BMhMlztX3DiXsZ84fWX7VABaS7R6p5E47uKjJI7/G4nf7dkgcKILkI/t57L9zuZfT/gGNdE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJbcSs030470; Wed, 10 Jan 2024 19:41:04 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vj0fjrsd2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJeghl027799 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnD020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 04/14] libstdc++: Optimize std::is_floating_point compilation performance Date: Wed, 10 Jan 2024 01:22:55 -0800 Message-ID: <20240110194031.2384005-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: m1-vzlpp1bij5wp0T7LRH7YIfaHfTOwd X-Proofpoint-ORIG-GUID: m1-vzlpp1bij5wp0T7LRH7YIfaHfTOwd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 adultscore=0 impostorscore=0 phishscore=0 clxscore=1034 mlxlogscore=380 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733763787442359 X-GMAIL-MSGID: 1787733763787442359 This patch optimizes the compilation performance of std::is_floating_point by dispatching to the new __is_floating_point built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_floating_point): Use __is_floating_point built-in trait. (is_floating_point_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index afa281d9cc4..23ea70eca18 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -470,6 +470,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_floating_point) + /// is_floating_point + template + struct is_floating_point + : public __bool_constant<__is_floating_point(_Tp)> + { }; +#else /// @cond undocumented template struct __is_floating_point_helper @@ -529,6 +536,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_floating_point : public __is_floating_point_helper<__remove_cv_t<_Tp>>::type { }; +#endif /// is_array #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) @@ -3238,8 +3246,13 @@ template inline constexpr bool is_integral_v = is_integral<_Tp>::value; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_floating_point) +template + inline constexpr bool is_floating_point_v = __is_floating_point(_Tp); +#else template inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) template From patchwork Wed Jan 10 09:22:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1018337dyi; Wed, 10 Jan 2024 11:50:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0TBJ+tnP0RYiOdsYhK/a0bv3KwvLbLI1iqB2cEcidVfM+1DyRhom1AeZagDqToW4bchH+ X-Received: by 2002:a0c:bf02:0:b0:680:f6a9:14de with SMTP id m2-20020a0cbf02000000b00680f6a914demr747857qvi.31.1704916221326; Wed, 10 Jan 2024 11:50:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704916221; cv=pass; d=google.com; s=arc-20160816; b=s96W/NYNt2U26KJRS08uAtJWHX/6uNI1F+WycIzfrCUMveCvjm8Ffy6dbLwSu/2x6+ MZZkaYaGF+MDX6GE1vGA/S/VPhK9U5oDWrH75GeYUJYIQwyiU7hbuDR4qLb7GVZ/dGSU cyMbF5hymrhFWCcben2j5vIiCjf7LwUalTrTQZNp1aJIZwire9R3+pl7pQU0xD+WdyLR k9KQdL28AEiLc2E8zs505ImAaaExBn5QSrQbfg+F71mH7H+hzKJSEWDtOfWaHnEvgYxL SqxNkXPTNwkAKA0y6/WEmF0u1cbHZTYV30Q4gcO6/+n1t1e08rW1NsQW+HixSU71JPLL S9bg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=4r7eyKFek78iJZOQWXZSwijg5y3rhPPSX5RMOrHJpy0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=SHsAcJq38Ra45jLpj1IS7Ngz2tOAG+MBU84iuMmIWgY6rEp/oGxc5b2MMME7B77JkI ACskI3r+X1Sv9QylbGO4zD1V0vZP6xLZB/qMHOMT4c+v4putDTFg0FrZ9mCgvoMxPMCy Xgy+TXWRIMbN4nScJUIWyXD8ov2WqLiH7xRV9xdP5wtLs8WIoNSutai+NnHgtQSt38yA XDGZWUCMhVbGpfd20dVd2R9OEBTPKFSDJH4XyD+zugFSu+SErfRGvcMa6Gn1ZhaaQ1xK pkPFXJveRwOJ5vNZJW1PoVV0UEazmMQ75ruVZo7pTCwtshuBFHYFeTsD9mLmtiyLGXIn zDAA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ydfbpP+v; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r4-20020a0ccc04000000b0067fc4a628fbsi4859480qvk.217.2024.01.10.11.50.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:50:21 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ydfbpP+v; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90DC438582BD for ; Wed, 10 Jan 2024 19:50:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90DC438582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704916220; bh=4r7eyKFek78iJZOQWXZSwijg5y3rhPPSX5RMOrHJpy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ydfbpP+v98ThYH4QaBQMPydnRDl1GfKvWwSkEqMAdLRNcq2Mq+JytnG8hBrGDtvUi v48liDKcUMDj6znob4O9SDieUhVR0rBsWKnupG6jPUjBcmkoO46EQm4N/nQlIAMT8z sJNGpOi2wL0n7VkmPcmM729dTzl9P832xX972j18= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 16D453858C2C; Wed, 10 Jan 2024 19:41:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16D453858C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16D453858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; cv=none; b=hp3bDpwf021cTVUL6PYU5LRswvn5Q79LTeGt9liu9SBmWEv8Xrob+8aVYCTDNd69jHCxBajbJeJ8MtmoyA8NJ1nDn6Dp+n3Y8MceFrTOzWVc+efPDz1AdJi9ksYcCc/yuPUWJh0qIqP9TtaiPVVaMsMQupI0GS5kkzSmCPN0WNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; c=relaxed/simple; bh=c3ZYtDnbmnDS8FL5VaGwLZ6XU1ox8AErLDBm5KJC8To=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=I+yjs/7IwKtumuHsbATQmL2OksVLcUNlcOulPLjFit82KryPhsH1P0MCOeYuM+PAM1oh12u2ebYoVtgb0r1xNPTUnu3hDAdiFDBfXu9Gsi3Vwb3E8F/jkK6CHWRa0FZWjenpCtboFEn3GSrUJD0vYBXJLIPYex50P3C5GJegsGk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJdtT6002028; Wed, 10 Jan 2024 19:41:13 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vj03v12uh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:13 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegMK025277 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnE020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 05/14] c++: Implement __is_arithmetic built-in trait Date: Wed, 10 Jan 2024 01:22:56 -0800 Message-ID: <20240110194031.2384005-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 9r2DvmT9gdHtUP7w68LwTC4NeTYsydA6 X-Proofpoint-ORIG-GUID: 9r2DvmT9gdHtUP7w68LwTC4NeTYsydA6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=685 spamscore=0 clxscore=1034 impostorscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787734231570062662 X-GMAIL-MSGID: 1787734231570062662 This patch implements built-in trait for std::is_arithmetic. gcc/cp/ChangeLog: * cp-trait.def: Define __is_arithmetic. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic. * g++.dg/ext/is_arithmetic.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 10 +++++--- gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_arithmetic.C | 31 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index aca0b91711f..d25c3109789 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3722,6 +3722,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_ARRAY: inform (loc, " %qT is not an array", t1); break; + case CPTK_IS_ARITHMETIC: + inform (loc, " %qT is not an arithmetic type", t1); + break; case CPTK_IS_ASSIGNABLE: inform (loc, " %qT is not assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index acf668d48ee..8df3ed8fedf 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -60,6 +60,7 @@ DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) +DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index c052e47c204..882e0924ea4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2818,7 +2818,7 @@ perform_koenig_lookup (cp_expr fn_expr, vec *args, if (fn && template_id && fn != error_mark_node) fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args); - + return cp_expr (fn, loc); } @@ -9325,7 +9325,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED && DECL_P (t)) bitmap_clear_bit (&aligned_head, DECL_UID (t)); - + if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t)) share_name = "threadprivate"; else switch (cxx_omp_predetermined_sharing_1 (t)) @@ -12013,7 +12013,7 @@ pointer_interconvertible_base_of_p (tree base, tree derived) if (!NON_UNION_CLASS_TYPE_P (base) || !NON_UNION_CLASS_TYPE_P (derived)) return false; - + if (same_type_p (base, derived)) return true; @@ -12460,6 +12460,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ARRAY: return type_code1 == ARRAY_TYPE; + case CPTK_IS_ARITHMETIC: + return integral_type_p (type1) || floating_point_type_p (type1); + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12720,6 +12723,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_ARITHMETIC: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 5dc70a19e79..a64a6a85bc2 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -59,6 +59,9 @@ #if !__has_builtin (__is_array) # error "__has_builtin (__is_array) failed" #endif +#if !__has_builtin (__is_arithmetic) +# error "__has_builtin (__is_arithmetic) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C new file mode 100644 index 00000000000..719e976fbdf --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_arithmetic, void, false); + +SA_TEST_CATEGORY(__is_arithmetic, char, true); +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); +SA_TEST_CATEGORY(__is_arithmetic, short, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); +SA_TEST_CATEGORY(__is_arithmetic, int, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); +SA_TEST_CATEGORY(__is_arithmetic, long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); +SA_TEST_CATEGORY(__is_arithmetic, long long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); +SA_TEST_CATEGORY(__is_arithmetic, float, true); +SA_TEST_CATEGORY(__is_arithmetic, double, true); +SA_TEST_CATEGORY(__is_arithmetic, long double, true); + +// Sanity check. +class ClassType { }; +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); From patchwork Wed Jan 10 09:22:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1015018dyi; Wed, 10 Jan 2024 11:43:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFu6Lio6vJ0WTlZJPcLmWqOUuh0SqEiv6G914Q0zp01xH8YFJnXwRkXP5VdAfR9szOHoGnu X-Received: by 2002:a05:6870:93c5:b0:203:b690:eaf1 with SMTP id c5-20020a05687093c500b00203b690eaf1mr73634oal.81.1704915782206; Wed, 10 Jan 2024 11:43:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915782; cv=pass; d=google.com; s=arc-20160816; b=wGkTdi6AwCH8GbYsLMYzltirvWBtAhNluk8UKywR2nl7pPWIX/P6xevCLW5CumS/tQ Y146VNaSqyR6kn3tyC2RtaClw1amT/vzm9Uc+Mo0Mt33O4A2YeheC1AtbeedLWc4Qy2t al1dYt4OYcAXCk+9jzRlZpDhCPIb4EJbsq4VdrLvKzdngI5IkgG6aGOo3MREN2l2Bhbn sy+HHfbMqGpqsTOsAtAuBMZzJGjzfVK+MKqQzki6KWgZlbWr8cXfz7Ks4bQxx/6LiFGx KmGQqPZnyy6nYFOWzzcnV90uo1utW/rbCzl87n4HuMo+fAqQM+1b3qmL+He6OyoL/WIa FeEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Zne5f8WqGP8Zt3b1tk1mSUmJx1zUryiwbFAllQn5doM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=f4fI2l8Hzf+hUtfG5Ylr+KgYxe/KChXCxdQT+bHDmKLKJQIDiijY91yNFNeut5OY0r r3FUyHAgG0Tsl3evaOo8RK5prTslbKd/ViOpmuZPiOE5cTWwOd1tKBoye9lKp/VAGsMB bPI8Iv83b76oZtqfEJ85l5Q+sC25ObJ9QAkuhPgkh4xxO1p2Hlfmbtv0UvcXiGR92qN5 KNlkyMgbSUTSZbrLJM14uPRHlMPG+7weO/5m2Ya6Q0UL5/W8XLRMjwDUDM5G8myj4CCr eLK5WzJgmtePiG/mDyJTwmdvjgrMjBSZKVeOdnQFMcY5I2DAYvvrMR9Mx0c/hRk2XBt9 gRjg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gv4gJoCP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t12-20020a05620a004c00b007810ca77e71si4510170qkt.539.2024.01.10.11.43.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:43:02 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gv4gJoCP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8BF93857828 for ; Wed, 10 Jan 2024 19:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8BF93857828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915781; bh=Zne5f8WqGP8Zt3b1tk1mSUmJx1zUryiwbFAllQn5doM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Gv4gJoCPfS6fAigZoRLF3JcDAv9ZWKqmgU3phjcO41xPnITHCsA7NglJfXaKL2R8+ /qIO60rwPKqJJsci8pdWQsq7nQejaCyt/5I7INQuZjTQGBIC4YUqhyugKesAI64Nll 2PKoy93AWioQgE97BKqks9XP4EUXV3D4vmMbTJSE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 2C2123858C52; Wed, 10 Jan 2024 19:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C2123858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2C2123858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; cv=none; b=ojoW0vSrhdd6+S5g8N0GjSXUGJCu0hTiNQ16cqbVm9BSxwNCzzbqf/rwLa8iIT+DXHolELRGRhut2S5M0isp233KAytQxSaDt9bmjTVnElQJV+n7Hw3DNwrAZZa0ib7SRoFxY7OjRgkkGDq4StXaT7CaQKWqlylskYcnyUUFPK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; c=relaxed/simple; bh=d549OKW2xBZlQBAzYI49WJfrqAq5/4dHwPKh52fn3J8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AUnO32u05p+2DEKZy0IGdJgi/3UV4VxwTseO2DLWlQ7XRqwMI4KY7nOwkT9/QCjws7tlNWgrPdgXvXUDZGQLn90IkNBnF65QuMmkDP8xcp8WWKdRBJT0jWFnkm4xEqC6PXZKjxDbqhId0LVJCEmOIRBAPMkxPC9hy7SX+5DNL5c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJdR44018049; Wed, 10 Jan 2024 19:41:10 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vhyq0sc4c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegB6002141 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnF020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 06/14] libstdc++: Optimize std::is_arithmetic compilation performance Date: Wed, 10 Jan 2024 01:22:57 -0800 Message-ID: <20240110194031.2384005-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7Gz9W49gnfzgO7ppa-rVgoFtQZkwgW12 X-Proofpoint-GUID: 7Gz9W49gnfzgO7ppa-rVgoFtQZkwgW12 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 clxscore=1034 impostorscore=0 malwarescore=0 spamscore=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=528 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733771656221453 X-GMAIL-MSGID: 1787733771656221453 This patch optimizes the compilation performance of std::is_arithmetic 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 23ea70eca18..9baf3b2aa46 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -728,10 +728,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_arithmetic +#if _GLIBCXX_USE_BUILTIN_TRAIT(__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 @@ -3317,8 +3324,14 @@ template inline constexpr bool is_reference_v<_Tp&&> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__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; From patchwork Wed Jan 10 09:22:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1016168dyi; Wed, 10 Jan 2024 11:45:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEE9CMxquNtKHhwUuIaNGQDuC2UpWjtJfyXewJb7g/mATHlWy8yfP61/fZzG0fnRZdm7TG0 X-Received: by 2002:a05:622a:d:b0:429:befe:32c2 with SMTP id x13-20020a05622a000d00b00429befe32c2mr78613qtw.67.1704915933851; Wed, 10 Jan 2024 11:45:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915933; cv=pass; d=google.com; s=arc-20160816; b=HpSA8sOUOjuYDM24W5sfxFmiY7+zbW4KKk/d7Wfhv2uIFGzUs1pNZbT29TITkKcIIn g0F2Pjl5uRZpoGagcBb2pLtGSopCdwy4grr6wT6oxkqOr7E0rNDbIHXYTtlPMuhP4B+6 x4S769N4VOXATSLjeac+KoW7aHse8sU8BChqlDOa9aomP2BRN+rX0k26iEh+3v4+X7l7 7gusz7H2I0AhdHo+iDZmBaCnKcUhq+CoOUlub5VG8fQwTQ8/wpk48P6KZY3zAOAJ/G33 1+4z1FrFE10VnmcJ1GXny+7JodDLcNnwjWCJge0baEPq7UPVQcYbf/HKVUFRXWufO6rB h/Zg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=LtUcQyoyHmwKR/S0KY+38I27W52aTG7Bb6Os2fAP2/A=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=UVLQRFvDR5wrJFoHp7Z6soh0kG2ryqCV0bmKPU+Vd9Lr1V2YuVCwg6AjzjdvTWWAv6 u3kuf6IoHyh0gBV/c355UeBkSGTzepyznx6fyhgk3lV/1f1iiZ7W5VWp0aQ4gnG3fJWy EWzjxqHo+2SjdwA9o6wg2bEKY9PNE8g3R+72Q3uCnpXY18iM99KATwvUxUxTgDMdKdA/ 0BHN6PGGHxYlzv9SAyhyZP52diTdyo2gXiSZ2G6ApLW1ilNTBqTh4wIIRcRUJXj/xont kGf3u9EpkRncdGoscOoE4186yZw3X5OmNf8Xqvzuei17/mjxTpdrE56InRRXX5BJPwVw Lc/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=goU8Xl9T; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v4-20020a05622a144400b00429a53d6f6dsi4003431qtx.308.2024.01.10.11.45.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:45:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=goU8Xl9T; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16C113858C52 for ; Wed, 10 Jan 2024 19:45:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16C113858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915933; bh=LtUcQyoyHmwKR/S0KY+38I27W52aTG7Bb6Os2fAP2/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=goU8Xl9TRUqNo4nihxtNR+HePE1JGMASmvAIdecgmHDSvCsO0/fAgGYhcGlvGea/H kI3u0S7uAtx5CMmjSLXgH5v2VNFt1uzYRgCNYdkZH5YzGJthpYjPS6vkNKlye3V3AG /A/cpxsIT2HrBACuog4F+r4YdAgxTMjZTDrxi23Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 16A503857C4B; Wed, 10 Jan 2024 19:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16A503857C4B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16A503857C4B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; cv=none; b=oRvK/hYvTqwz3UWNfhwoO8QYTm65rrJN7gDmmZGBffjXlMsJ9+K/cdAHYwsoHtrtsxsG/6gMsMsFfX63Wk8Ne8ZSkGV1b4wpoFDzMsSB3RE6I52DmwlZUGHZBFSeTAxbKwC8gwDZge2gJv4RDAZpRgZvd3vM/bAS/8+xs0wMfH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; c=relaxed/simple; bh=gto67pHBaYb9xxGExROQB3yVmcSRbHGfwy/gfffkLco=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QbzCW0jZsPWN0UWBvijHXFqdH5Mknu32zPNQx04zkWrFUJtvHzL/Bj+wXiYdtQjMppCz5Kaq5/NYQ7U9VvTb3Gp61Vx0Amn1l9BaXqT7ymzjm0l6jIklDZ83NbvdbaIqYbFhWNkRvc5BzmEJXw3nYLp8plV9CTQfCl4Mx5bEUvY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJbTcZ000342; Wed, 10 Jan 2024 19:41:10 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vh9t6ux8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegDv006375 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnG020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 07/14] libstdc++: Optimize std::is_fundamental compilation performance Date: Wed, 10 Jan 2024 01:22:58 -0800 Message-ID: <20240110194031.2384005-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: G3xVXOLBF_rgzq8jlY3oddmPjxqSj40o X-Proofpoint-ORIG-GUID: G3xVXOLBF_rgzq8jlY3oddmPjxqSj40o X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 clxscore=1034 adultscore=0 impostorscore=0 mlxscore=0 phishscore=0 priorityscore=1501 mlxlogscore=526 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733930187324292 X-GMAIL-MSGID: 1787733930187324292 This patch optimizes the compilation performance of std::is_fundamental 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 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9baf3b2aa46..1c560d97e85 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -741,11 +741,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_fundamental +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) + template + struct is_fundamental + : public __bool_constant<__is_arithmetic(_Tp) + || is_void<_Tp>::value + || is_null_pointer<_Tp>::value> + { }; +#else template struct is_fundamental - : public __or_, is_void<_Tp>, - is_null_pointer<_Tp>>::type + : public __bool_constant::value + || is_void<_Tp>::value + || is_null_pointer<_Tp>::value> { }; +#endif /// is_object #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object) @@ -3327,13 +3337,15 @@ template #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) template inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); +template + inline constexpr bool is_fundamental_v + = __is_arithmetic(_Tp) || is_void_v<_Tp> || is_null_pointer_v<_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; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object) template From patchwork Wed Jan 10 09:22:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1016083dyi; Wed, 10 Jan 2024 11:45:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV25kQC90fx2ZvbyMF27ZdrJ3ZI9OP6l4wVMYwk+o3LeKayecWcCB3My4XDDEoBu2oZ7SB X-Received: by 2002:a05:6214:2aae:b0:681:a12:26b7 with SMTP id js14-20020a0562142aae00b006810a1226b7mr977844qvb.52.1704915921083; Wed, 10 Jan 2024 11:45:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915921; cv=pass; d=google.com; s=arc-20160816; b=BRXUhrLwHhnsS6+pZrS9tC0fmixJcDyh+j6IGukaN4Fb6JTQ4/aImszZb4i7q+kWLa w6UDxe/HUdKnALLkRq2IGK/NKHyc8dwUl1A3X9kBGeh63HtQHSGJ+PVfKmM4V/K6WL4x nHmc7U9LDABIpOjDZNWQ1YsljiIGGcsNb6Ghavn4/sawDHi3DoXlySEydRixRPokWKEu 1UqqhzBhJHDTDv/acNkX5wuES8H7sCaGd0sXTcyiyfmpoeCXXM4HU7KGZgHqw92l/ad7 1GYZyugFLB5qmKPrxpYI/murlIL50c0L/w0fmAL7GdvtnEJdc+zhJ79boy2wr87al1cT becg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=aE6XYey9ECbcKKCCuueZ3g2OH51uiL9QQmzat5VCL54=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=F0+VKP3Ixwkw/caW2GHdNiPFCEtO2j+LxFy4dl8Mr7N3qMC+rtzGLTu9UerFrAWsEx /+pavc3kIoxghbhhCvHai7yRwIKrtJ9stB8DYGiy4PvMm9/GwQE5KSTvmEC/yAVeMQo0 aDEmjMaB8HWi0C4uUQ56+j+N9GWLnFpb94SnBvTK82+0WdxVit53EPTu2RuArtlepoR1 qQflC9WY3R6KSsZ6ee81XoNy72fOn1PeZ2nC+v2ifbGv/CRqvDVBYUWSjiuKNxMbu36k I+rAFnGNEWMMttlmL6C41fROkOJ1GJqN/1WHFR8NLT6OMGKAI0UvcohH+S+cTMOZNiBJ sgfQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="V/IRgMNo"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a5-20020a0ce345000000b0068077cd22c7si5131754qvm.190.2024.01.10.11.45.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:45:21 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="V/IRgMNo"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B411A3858D38 for ; Wed, 10 Jan 2024 19:45:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B411A3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915920; bh=aE6XYey9ECbcKKCCuueZ3g2OH51uiL9QQmzat5VCL54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=V/IRgMNo9pDJX17AL7qgvAC5n2IuR+F84Bbfe3xJ/giJn6jNSxLje2fDxJ8nHVlyi 7OtY+p7JJAeDM66Hecm2zuv0taZuE9S6ETXgxN1qDnjlg/4PmMhrWuRqMSxD6T/eiz PsLShgL4lalNoMmigFpSS6HSfPEc13Z4KfxoPLDg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id E7F9D3858036; Wed, 10 Jan 2024 19:41:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E7F9D3858036 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E7F9D3858036 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915667; cv=none; b=q0rDCo7uwKEeGf7LCnVIOdU1R5c2b3G4cxg2jSKTbfk0NnylooeGtOxFMBCu146SXHSmZDrL3yo8HAPcLN2uR/wOsrhnOKc5uD7PpJEXMspNGNOQoPWsK1UhwTxngV/379xGLxdgY/znOapczfDYjwKwQ65Q+E7BC1szJS5xW0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915667; c=relaxed/simple; bh=nlvkwJQosUyV07pbOUuNIEfSIOQNxQsHRobdL268ZJQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WmOLw/KgxkvrN0Gxme6FsiYL8RBwBbisK1VSXsCDvuzA92X+9lxbTgLe47eBTWwDnmgnmyKL/wi5I9KFsmLJSqzkbPcqMbJC5PrZEfvS+AIehu6LvHmilers37Q6tjbqrAFcsEd+aj10tZowGfVVED1qeZRTbBL120FZ09UK3hI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJdeEL025273; Wed, 10 Jan 2024 19:41:04 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vj0g38ptd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJeghx027801 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnH020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 08/14] libstdc++: Optimize std::is_compound compilation performance Date: Wed, 10 Jan 2024 01:22:59 -0800 Message-ID: <20240110194031.2384005-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: as5GvjQni_Eil-rUwutrcjolzf0WhY48 X-Proofpoint-GUID: as5GvjQni_Eil-rUwutrcjolzf0WhY48 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 malwarescore=0 spamscore=0 clxscore=1034 priorityscore=1501 adultscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=354 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733916702928012 X-GMAIL-MSGID: 1787733916702928012 This patch optimizes the compilation performance of std::is_compound by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_compound): Do not use __not_. (is_compound_v): Use is_fundamental_v instead. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1c560d97e85..6294f5af533 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,7 +784,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_compound template struct is_compound - : public __not_>::type { }; + : public __bool_constant::value> { }; /// is_member_pointer #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) @@ -3358,7 +3358,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>; #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) template From patchwork Wed Jan 10 09:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1015811dyi; Wed, 10 Jan 2024 11:44:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEAucrf45ehwfopsT8gddIz+vdLlqaDX4qZABzEMF2GD2I5ZXGv69SoAo1KQ2mmHc1qvyS X-Received: by 2002:a05:6808:f8c:b0:3bd:4694:ff9 with SMTP id o12-20020a0568080f8c00b003bd46940ff9mr170157oiw.15.1704915886311; Wed, 10 Jan 2024 11:44:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915886; cv=pass; d=google.com; s=arc-20160816; b=HtvPx7sQF/a86lSin/TmYHwuXtyurcykHyFGOdbAn5iBsFrD0sJtPJFfLqZ/5hamgx o5Yp0IcwewfJpMtLJaW7PC9XOxpdOuqXj381oY2OBL6ofByBrKsFjQrTeRf52FSkfgLf d8wn1YQOVznoJuXK8toPprMWfZW0kB1F1zZbxy1Hs8ASWt4oLtL62aBA6KmQjxY06PBW ebvpuI66otUc/FhJm5CWYISMkXP36NWJeR9WP4TOYRzaypOZqz/lSO648ePlfPpop83a jq+gAxNTtnvTSemUYc/ri7Px5smfr6X+HrWgv5PDmvRHwVR/GlMYvBwzjFHhDJe5sgv+ IXjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=00r+0asBSTr2WwifuG2abwBxSJe850+3Zq/LmcBpBj4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=DavAC+po93srlWbMW1AKRc2ag7S6ElHQaUGanEnk9zd98jRmEvgCRr35yO5OlXCYDJ B6beWrCtyIcBTld6ecnHNAOamo7wAySULgC0zf8/RipMpSXoxQdhLu2z/q4zaU2lk7s1 U3zKolG+dK65YmCMGRtq4w1hCWfLzHKM9px4JjmGkce1a3joKvQ9B6JlxIcd9PDcSt0j UdeQSukvAZbk7R+MuN6Hsswo7KGTRvPayRMqyTGtMmKNKqvkIRpAl6Okc9P+EYCBiENE mRTlXIXp7bBA0V5lYI1m0WgD3uepkOwMZtOUQwhRbX0cxBpBmTAfCqy2eayIPgbEwgde XkIw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VIsxT4lS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y20-20020a0cd994000000b0067f8b26ba5bsi4816308qvj.249.2024.01.10.11.44.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:44:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VIsxT4lS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED6403857C4B for ; Wed, 10 Jan 2024 19:44:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED6403857C4B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915886; bh=00r+0asBSTr2WwifuG2abwBxSJe850+3Zq/LmcBpBj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=VIsxT4lSi+6ZNlKfZvgeJ5uOqMFFlJvXEObnOU47ijsyTtEZZjcxFI97aPmJCwtks wM9qbO8sAqY1F2mMlnhfvQwWPVqMgjQhkT2gfYdRsUc1v7Y85N6cYcNzwJQhR0CFRq QFjyW0fy9/xygHExaKObTCQE3CGK78DLfeZF3yVM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id F18DA3858001; Wed, 10 Jan 2024 19:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F18DA3858001 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F18DA3858001 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; cv=none; b=e6dtzhgpB7rdFNNRJeSJXFO49mluE/2HR7Eow2wXquxT1RTevpGj18DJnyX3N+vRySD1lO5/t31MQMxocjL07f+IPbiMJrydqANAAtkPe477afO0LHyNndApjCxRFohNdxawDKCys2kWO45BFdk5roE45UIm8lqISs0uD5dpN/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; c=relaxed/simple; bh=yjEJU773VWaTRd9k62i6946+Dx7f9hFTAsji6eSsX04=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kgRijYMA7TqUL1LGERZy+rzja7mJrNBUeGRaEBA/w+T4/rEW/BCtZbuZ4BT5uS9o5eY9OzQ8AKXwLz2Fc01+nxLFqsjHTeHPikxIJZo8iaamFUN6lehw7v1MM3u9BDCtGm83ZXq7cgXeiYOM+igX1jLyW4gMq3WpPP2uS68uN5w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJbWSv000443; Wed, 10 Jan 2024 19:41:11 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vhm1bdgx9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegxX010851 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:43 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnI020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 09/14] c++: Implement __is_unsigned built-in trait Date: Wed, 10 Jan 2024 01:23:00 -0800 Message-ID: <20240110194031.2384005-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: qh1-WOq4--n0MyptBUeIMFLOZOTkqB8l X-Proofpoint-ORIG-GUID: qh1-WOq4--n0MyptBUeIMFLOZOTkqB8l X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 impostorscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 adultscore=0 mlxlogscore=741 spamscore=0 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733880266723803 X-GMAIL-MSGID: 1787733880266723803 This patch implements built-in trait for std::is_unsigned. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unsigned. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNSIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unsigned. * g++.dg/ext/is_unsigned.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unsigned.C | 45 ++++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_unsigned.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d25c3109789..7e4b3cd38c4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3834,6 +3834,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_UNSIGNED: + inform (loc, " %qT is not an unsigned type", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8df3ed8fedf..734522eb5ba 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -94,6 +94,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_UNSIGNED, "__is_unsigned", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 882e0924ea4..522db3f57e4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12566,6 +12566,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_UNSIGNED: + return TYPE_UNSIGNED (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12738,6 +12741,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNION: + case CPTK_IS_UNSIGNED: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index a64a6a85bc2..062b06234e6 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -164,6 +164,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_unsigned) +# error "__has_builtin (__is_unsigned) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unsigned.C b/gcc/testsuite/g++.dg/ext/is_unsigned.C new file mode 100644 index 00000000000..5694f89dca3 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unsigned.C @@ -0,0 +1,45 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_unsigned, void, false); + +SA_TEST_CATEGORY(__is_unsigned, bool, (bool(-1) > bool(0))); +SA_TEST_CATEGORY(__is_unsigned, char, (char(-1) > char(0))); +SA_TEST_CATEGORY(__is_unsigned, signed char, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned char, true); +SA_TEST_CATEGORY(__is_unsigned, wchar_t, (wchar_t(-1) > wchar_t(0))); +SA_TEST_CATEGORY(__is_unsigned, short, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned short, true); +SA_TEST_CATEGORY(__is_unsigned, int, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned int, true); +SA_TEST_CATEGORY(__is_unsigned, long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long, true); +SA_TEST_CATEGORY(__is_unsigned, long long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long long, true); + +SA_TEST_CATEGORY(__is_unsigned, float, false); +SA_TEST_CATEGORY(__is_unsigned, double, false); +SA_TEST_CATEGORY(__is_unsigned, long double, false); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_unsigned, unsigned __int128, true); +SA_TEST_CATEGORY(__is_unsigned, __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_unsigned, __float128, false); +#endif +#endif + +// Sanity check. +class ClassType { }; +SA_TEST_CATEGORY(__is_unsigned, ClassType, false); From patchwork Wed Jan 10 09:23:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1014854dyi; Wed, 10 Jan 2024 11:42:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEXi9vXUh1bxVW2GHnhn+Lk4EYVHO9A6QnFMVqc3DeIRSHh1FtCMGmmviy4aHvM3U0GpBQ X-Received: by 2002:a05:6870:471f:b0:1fb:75a:6d25 with SMTP id b31-20020a056870471f00b001fb075a6d25mr77103oaq.76.1704915761292; Wed, 10 Jan 2024 11:42:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915761; cv=pass; d=google.com; s=arc-20160816; b=J9sKom8oEz9J2kztDkNUW8i5+yQdSygL5R7gW3s3IeiK3fszyh75lVMjmi4h9EFqfP AhN2ZWW+8+OR0rCaTGAmqljg+oU1xWz8TDyvFC6AM56K454nyxmWiYI7oX1za4nvFzKf KI/kVOg2RyRCIxfFdNYzICM0G7ENDVmMu2sTIyY/dQEOpunZTC7vfBi4NP+mjab+zD5w URQKL8OpTLoImx+z4aZXFS1YlQxto4nK8lMoun7DgDLypVYIoLCxAFNXkqBqbZarJiK1 6SogP4l5WXskjzf6DJhM91ubvUIsTtuq6u6yYOUlgIGpsNAtvCavrKLoV61fb/Jth2lS izYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=7z+4n1zFGxdJfiYu5scWqPl6M/X+tODsvzU3ic/dHU4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qPhVFgcu6RNBk5KgRUYbgTnG7Sp2V0Rb6cMYgX0bn0IH5d/bzkVPWqglsVw6NS09Gl w2ZknwiWaxAdqUv8gS73GmAlKJjgaDEuYUAds4myrAMyFqRnCwZGCQ7srwKI4nZ6DsR9 J6O3yVkqWTTxPwR+mJuS4AiY50K+8fMc7NqxHpxVwH3dOanO5d54uakZ6D0OOZES1rrN d2+Njfu813FrnkSRGtFoJ+6Qp4oPRGBWIo2WD0NvygAiemDUbYr6AXk3gwUnVRo9hxD8 69qJ27HzNzrdnBntmdzsr9xNPBQx350wqf8v4f3Mn7VasulMMGwZaIVfMvSlrbwgw+LA 2G6w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TdvAkVTf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n15-20020a05620a222f00b007831b611265si4373629qkh.169.2024.01.10.11.42.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:42:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TdvAkVTf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6AD93857C76 for ; Wed, 10 Jan 2024 19:42:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6AD93857C76 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915760; bh=7z+4n1zFGxdJfiYu5scWqPl6M/X+tODsvzU3ic/dHU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TdvAkVTfolxI1Kt7TNkD3ZfwvGuP4p3tWy61pBPR87vF8QvfrNR+N3NUgrhPXelI4 i99ama8Liu7/Js0zQr9wrgS+DTFMclUj7yYfdKjbsfbj5PTrlA1RptlcyLrOa0bRbz jNXpVKK0E4SmYoiTLI8lDa+mQYg8+1Jt3YUwHDIQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id C8ABE3858D38; Wed, 10 Jan 2024 19:40:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8ABE3858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C8ABE3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915654; cv=none; b=NfWDwd7UoZnjYiyzSPioqc0jOEhIVRavrebj7h8zb7DaOa9CPKVhyLXravNVEFoy7kYXs0+S0c3SwKglDXnpoV6kg/qpI4A5nnQI1uFnovDPKMzxRAYnjBEaPNZoDLI5hkBiYceSYaWXuU+/hDdiE8w9eI++OeVpDAIS9oflehk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915654; c=relaxed/simple; bh=82Vi4Nwfxv6X1XxUkqhC1Nm1E8vcDepnkTpII4fNqoc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UgsIMH7ntReRKWtnXUs3xvZ1FJBZsn9VcCSpbBerGDO8HEx3v+pzW+aii2rdDV+rRKEEWXsAE4U+eIyoIDIWO/Q2HAuPGOPsxDw15w5AqTDaPK3njtSw/qhKoKYelPhkuBGwmMnVYWWvNE7NZMFZopWG6tfp65c6Xv9uTdU8ad8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJd9YF029817; Wed, 10 Jan 2024 19:40:52 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vhwj2tm89-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:40:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJegjc015829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnJ020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 10/14] libstdc++: Optimize std::is_unsigned compilation performance Date: Wed, 10 Jan 2024 01:23:01 -0800 Message-ID: <20240110194031.2384005-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: VSPtWo7diuvf6vguN9MpSEg8xLhMiRzJ X-Proofpoint-GUID: VSPtWo7diuvf6vguN9MpSEg8xLhMiRzJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 clxscore=1034 spamscore=0 suspectscore=0 bulkscore=0 mlxlogscore=613 mlxscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733749275321603 X-GMAIL-MSGID: 1787733749275321603 This patch optimizes the compilation performance of std::is_unsigned by dispatching to the new __is_unsigned built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unsigned): Use __is_unsigned built-in trait. (is_unsigned_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 6294f5af533..4bcfb1389e3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -987,10 +987,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_unsigned +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) + template + struct is_unsigned + : public __bool_constant<__is_unsigned(_Tp)> + { }; +#else template struct is_unsigned : public __and_, __not_>>::type { }; +#endif /// @cond undocumented template @@ -3413,8 +3420,14 @@ template template inline constexpr bool is_signed_v = is_signed<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) +template + inline constexpr bool is_unsigned_v = __is_unsigned(_Tp); +#else template inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value; +#endif template inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...); From patchwork Wed Jan 10 09:23:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1015885dyi; Wed, 10 Jan 2024 11:44:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPORyF0R0ik8qrijX2I5aF+XG95X6uiuI+95ZfURhLJXFvveMU0OMP9SyLRweZPbwJyaNr X-Received: by 2002:ad4:596f:0:b0:67f:2dc9:b80d with SMTP id eq15-20020ad4596f000000b0067f2dc9b80dmr1747017qvb.4.1704915896922; Wed, 10 Jan 2024 11:44:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915896; cv=pass; d=google.com; s=arc-20160816; b=GOCNmIzWLMsmqZd1CyPbBUsGLoVKhxqOsQIip4putEqQwXz+rDIhy7Gw2CL0MR9Fa6 +6S/xvXzABEMV3g0J5u9XSD5LaWrdtxDfUsR4ua4CkCOUcQlsPM5nN4nmUy34NlR4EIm 24KNQC6D4Ud1GQ2FGRyxPtr4VO2kUPmZSkzX7X5t7HMqRojulb2dB4euHDuf2pLLKZ/u JVAUamuohRum/m5QbG2OydZZWitxb0azLL/2MORnnJL+hNvY8GeVzGgEGtQSKdpAyYix MubVCgiTNPaQvqz3tQrLiSryy/v+cUN2oDSriQU9UOMwURpp2/bs2+P72i7V15HHhHFP Ui0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=HCLXnuySCXA2fhpOOz9Rf2f8NId7W5rLBxVmB5X8s8c=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=m9vDby0dtj42xgkOXTyxHzG+Okk5jq7kKaeq+zbqmncl6lKYZbgLJedpcslA0gLEsS RsWQmOT2lwKDNv55yyNUF4osy7VdhgFAZt7gv8x97niCUssYIIK8f9f8a0yB2EZLcQn+ XS/kRdl5CI0WicJwrFFlAIuho8rbyUPu4gKmDetzWIhHQL9JExCP9I2my27M+paaDbEA engihU7Y2AAahYvEaPv3kXB2GbGlTCPDg8jn681eNLybhPx/1tmmtZr8ex8Nb1RBCv/H 1X/cmdc89fNuA6qiCk5qdOz0JVyuyDz/6uiOfX/rDeLFKSGQIpzZdP5P16MnbjkoDxlD b6Hw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dzUEvOdc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q9-20020a0c8cc9000000b0067f30be7df2si4775270qvb.496.2024.01.10.11.44.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:44:56 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dzUEvOdc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51A3A385800C for ; Wed, 10 Jan 2024 19:44:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51A3A385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915896; bh=HCLXnuySCXA2fhpOOz9Rf2f8NId7W5rLBxVmB5X8s8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dzUEvOdc0uLnffl1ZqmYto+IygGqsLXJ2lnT2s7ELslSKt1/B/FFAV5e+RVLhO77r ZHXdbb4ZfH8SeVrlvT390+RdfWMba+JfWBSW/7eUUsSOjBCJCmCfs4N20bcqq3Tl1J 09e4YI8Fv5+ROTH/tcc4K5dzp4c4xN3nxA40cR2Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 773A938582B3; Wed, 10 Jan 2024 19:41:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 773A938582B3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 773A938582B3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; cv=none; b=fOuRdsIK71ArDeyExBPLDYg2sQiV6HcbDMVhA/BUX/YZr6QsWgWdGI1zYgRh3iWOI4Im3U066G5ok3KkQOMpmEiDwwGS6pWtqwhV7P8ukX8ZLLM2QR6ED6mxe0/V8pCuDYCfTXdYNfLJN3Lj9udlrZQJpzrqPZ3NYpn0hrChqGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; c=relaxed/simple; bh=/t4dTqddvLqvApC8lgG+0FHj/q9+gyZgFWDJrZXmSXk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Kyq3nzXkT4fozcjG5H3rRgxXUi5pGIdqppIY3FhN4bvrHU/jv6eCxfca0YY+UW1AdwSJK1+tz8zBlj73lbycTwqgEBrgTgl8nwEhkpFWzDa6RZR3dx2tmdSyPo6PLV69ibB6mJM4Wv4NXJpieU02TZC93x9v3FmF8yzCyxbcMMQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJbUos000382; Wed, 10 Jan 2024 19:41:10 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vh9t6ux8x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJehbS002144 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:43 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnK020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:42 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 11/14] c++: Implement __is_signed built-in trait Date: Wed, 10 Jan 2024 01:23:02 -0800 Message-ID: <20240110194031.2384005-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: -6S251iXSJAr1N7qfP5x4GYw-PxYgplo X-Proofpoint-ORIG-GUID: -6S251iXSJAr1N7qfP5x4GYw-PxYgplo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 clxscore=1034 adultscore=0 impostorscore=0 mlxscore=0 phishscore=0 priorityscore=1501 mlxlogscore=730 lowpriorityscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733891862436175 X-GMAIL-MSGID: 1787733891862436175 This patch implements built-in trait for std::is_signed. gcc/cp/ChangeLog: * cp-trait.def: Define __is_signed. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_signed. * g++.dg/ext/is_signed.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 6 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_signed.C | 45 ++++++++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 7e4b3cd38c4..d2e41aa053d 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3813,6 +3813,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SCOPED_ENUM: inform (loc, " %qT is not a scoped enum", t1); break; + case CPTK_IS_SIGNED: + inform (loc, " %qT is not a signed type", t1); + break; case CPTK_IS_STD_LAYOUT: inform (loc, " %qT is not an standard layout type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 734522eb5ba..6dac7622a7c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -88,6 +88,7 @@ DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) +DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 522db3f57e4..c3d6fc2d10f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12548,6 +12548,11 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SCOPED_ENUM: return SCOPED_ENUM_P (type1); + case CPTK_IS_SIGNED: + return (integral_type_p (type1) + || floating_point_type_p (type1)) + && TYPE_SIGN (type1) == SIGNED; + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12740,6 +12745,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: + case CPTK_IS_SIGNED: case CPTK_IS_UNION: case CPTK_IS_UNSIGNED: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 062b06234e6..e3d16add403 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -146,6 +146,9 @@ #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif +#if !__has_builtin (__is_signed) +# error "__has_builtin (__is_signed) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a46ba54ac14 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,45 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +class ClassType { }; +SA_TEST_CATEGORY(__is_signed, ClassType, false); From patchwork Wed Jan 10 09:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1018013dyi; Wed, 10 Jan 2024 11:49:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGR49OL901sTOfRXjadblBjI71LvaawaE8dtQKD2nV5NHJ1L7KM4igDv05A4OG8BZG4yIWs X-Received: by 2002:a05:620a:3184:b0:783:24cc:e5a5 with SMTP id bi4-20020a05620a318400b0078324cce5a5mr228632qkb.3.1704916173677; Wed, 10 Jan 2024 11:49:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704916173; cv=pass; d=google.com; s=arc-20160816; b=LTcO16eUmKLkTF4qNuSnw6e3K3zKK/M1Pm9V00p5kbzPM163MU8vktnPvShBhsRYbz PMr6ql+RHGAlEd+TkcerfO61XQA4NMqgZPw3ttcuRv7ViEK0t3W9mLry0dCG3Gm5s0cU FeFjp9W8ensKce0PQhDpRq68bpLvOTIMKvfEujiZvnio2UimDDrVXO3l0cvthnFTDpEt sb0xcQsBAxDs4CKZthAkefomoL7KFvh3s5gyDEvjAKXgeajXsOD3b4+JhgtW5leDoXdA ZNQcc2+zvTl7sBIEbrhuSk65+jf6b2NGzt4avEKpuDDsyWrRf3sQ6F5jz7EcBLLtClK1 yHbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=vOy8wqovTwDMPjs11f24ZzmXt0PZhc1I12U9AuhZMjc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=NY0JDSeN+RnWH8Z/KTeFYc9FwS6GTb4KzTHlokakSnAYZxBpXO91oyLO43N2y53qxV JlhXvvUFCnky5fidRhD+PSk4LngRkNSFgJMybg6GPnIADxmSFOPcvJNS0aVNqkoj3Yz9 +PRYgNQa6L3qXL7oTkJJIOxJBJpIzs9QWYNz7of0rxS2aUOgbL/v3VEhNfWjGv2UPcN3 Rx7/bSEI3MR4uQjFvzbwc/smP2OsR6cSxj7nuHyXz8exugjIJ8zLcH6WTxfc68lZkkmP znKJWT+8YIo+6i1Hhvhpxyo7W+ZlTO1uYqnaw2V77Msd5LPQ9hsqeOokGYbHuu1I9qnN mHAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aLe4Uvv+; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h4-20020a05620a244400b00783159be85esi4938925qkn.550.2024.01.10.11.49.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:49:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aLe4Uvv+; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 481413858001 for ; Wed, 10 Jan 2024 19:49:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 481413858001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704916173; bh=vOy8wqovTwDMPjs11f24ZzmXt0PZhc1I12U9AuhZMjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=aLe4Uvv+RwcBwGSFV2jUIK77Dfe5kiBf/tbN8nL8pCaZj0fuK4i8niwOCHyfm4DPB fb5AzE+5Hg7ozqsOdsY4vFEoY6jpvOPuWUWxF2QedZiArsHIrKBCOYwypXtlib0zSj TUz4pQ1K6sDlJVlE1/WYwUMqgc6mjATpKKXdNA0M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 6CCEB3858C74; Wed, 10 Jan 2024 19:41:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CCEB3858C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6CCEB3858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; cv=none; b=TuaKMJBZw3hUae7DoGht4a5Ff79AEPs28CWrvl08YfHYjyRMOw4Ec6mSoJ3VaWTpxTvqThcQ2ueC/Ctk84Fvr9+eBV0Y92QKhABtP8XXxOmBNqOFLK66KXkqsbeCk9UBfwuGGXS43wDAzLrO7HTprUj9x1n7IKJe8d7rDNo+OTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915681; c=relaxed/simple; bh=/cCXwZUH0GEMhe+N109Rf3z9UgR1uBCoCj8NK1MtTKU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xlsn0o+6H1T5IIudk5OKumP2yBBMaNPmUyZq0w1pbhD6Vc4WDNggIhHKxnr+MVOoiggki/syrArUbPIRJegw+8Id0bkyRIc22SkU+THAyKXBXMSialg/oCH4d89pKNxokOlRNA4fc3fLKRuA8wKOdw07qvoHqMV2/rr1BAD90Aw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJbaMs024982; Wed, 10 Jan 2024 19:41:14 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vhwj2tmdr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:13 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJehZG025278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:43 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnL020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:43 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 12/14] libstdc++: Optimize std::is_signed compilation performance Date: Wed, 10 Jan 2024 01:23:03 -0800 Message-ID: <20240110194031.2384005-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ETIj7fLY23xsO344-O5CZ17fishpf3JP X-Proofpoint-GUID: ETIj7fLY23xsO344-O5CZ17fishpf3JP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 clxscore=1034 spamscore=0 suspectscore=0 bulkscore=0 mlxlogscore=653 mlxscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787734181414324210 X-GMAIL-MSGID: 1787734181414324210 This patch optimizes the compilation performance of std::is_signed by dispatching to the new __is_signed built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_signed): Use __is_signed built-in trait. (is_signed_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 4bcfb1389e3..b917c743aea 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -968,6 +968,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __bool_constant<__is_abstract(_Tp)> { }; + /// is_signed +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_signed) + template + struct is_signed + : public __bool_constant<__is_signed(_Tp)> + { }; +#else /// @cond undocumented template::value> @@ -980,11 +987,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// @endcond - /// is_signed template struct is_signed : public __is_signed_helper<_Tp>::type { }; +#endif /// is_unsigned #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) @@ -3418,8 +3425,13 @@ template template inline constexpr bool is_final_v = __is_final(_Tp); +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_signed) +template + inline constexpr bool is_signed_v = __is_signed(_Tp); +#else template inline constexpr bool is_signed_v = is_signed<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) template From patchwork Wed Jan 10 09:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187012 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1015235dyi; Wed, 10 Jan 2024 11:43:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpLtjjeYAUPRfpoe25MYmAilAfhh7O1LU5fy5vfLaerCknd0i5Gbxybi4OyKtZOoEYol3b X-Received: by 2002:ae9:e70a:0:b0:783:37fa:cd06 with SMTP id m10-20020ae9e70a000000b0078337facd06mr153736qka.92.1704915816974; Wed, 10 Jan 2024 11:43:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915816; cv=pass; d=google.com; s=arc-20160816; b=ouyVcQRetgrTIihWF3x5Oru+9H4KJGZB4WKsn24orQpJqgPwC/jsFKVo26/qANuE/v P2SawElRaVCJvhb7CdhvlRZdr2CONV2SqSTrZtdVPvPQLkd9a6sg8EyHAMQwgDiGjKzx 3kmNAf/S/9R3tA9pMn2IWymhnuJBRKxkH+xJTDsT7D4KVjNCXgisCJRD8fSk+iljVH7h Oc76iYGbP+PnuO3K8VSzz53SGhWexnh9MHjaZ2vmwGU4w4HmZLTemN9r+OEPooyq8w0l DqIMeAJV6i6fZJYccY5Bz6gBnwnfose/8OMdEZL+5HndhGmYf78HarB8+npkyfICuuHJ cIUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=lSo4fgKhtSQ3jYBeyRtBGt9w75fr6TiFX96c5VEekgU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xseAUDChLWwyU5gYvssEIlFc8GrRopfhoRaDOFY8cD3Ql4ai+zGzOK8JiK041mYpuJ GWD1x5dPRGhEV3VoIilrj/fUaOlZrTlQQ2hVqDANZGV8sMFX75dpaQEHXVMExFbixD0h rS2MOsLcjjfAjm3PeQ6spi0wu+znjBxX4H0sfzA7P+JVAjvjh9tp51hpw7BZgJZfMnem SJ9OupBKLyytikfKmMmxuzrZOmwM9BVIr/GQiJtJp9jOP2wig9KXwZTWy3zc2YHcafGF SlX0rPpNOmOyIhQNcniPu0zyr4EHj5ypkGIYcpHrisQeQKtwDP2zfQYQ0XidqdB1jFMh uTzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="YdHX0/aK"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id az9-20020a05620a170900b0078335234933si2184011qkb.291.2024.01.10.11.43.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:43:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="YdHX0/aK"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E65B3857B88 for ; Wed, 10 Jan 2024 19:43:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E65B3857B88 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915816; bh=lSo4fgKhtSQ3jYBeyRtBGt9w75fr6TiFX96c5VEekgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YdHX0/aKy2R+Na4syZjy62muAtUHt93Ix+DJhAe3DGhZISkzimjCJDFiT72L8l1Zn fFTumkso8v7z02pcYt3GjSE/n/+U/gLR/X+ALLjz/tVVZIdnd8G07Ozn9svFA/HCbu M3JuxuDEJ98J+nMF5cK0BDK86nXFwBuY1AyYuNdY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id CBC5C3858C41; Wed, 10 Jan 2024 19:40:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBC5C3858C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CBC5C3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915654; cv=none; b=JyNCH35Yl16/irNA6PtYj2s6Tf870zurvEvItdwkC+sOl00zo7kO+fZybLIG7fo2BvclSQAM8pGWkyDuM2MWY7nXFgvNHObBwvtgTcIVmqjdOt3dAcI7gxfn2rANYiOQNnZp/Nq2ChgCPsablqelWgF+yA+G4brQpTw2nTpTZW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915654; c=relaxed/simple; bh=x7oWPkWI842vO/4miEPfAYIUA+9xXIORB1Dov6nfIF4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=gv7LdhyOpHzQkTRgQjdsFFrSrVijC1Z34aeu4ytMB5f4WaorFrWAttY830tecT0/bBPg32x2EXiwRhgluPP3P9E1ZlWR+i7BvWCIo96eN5pYI8yiCOWippRA6o1gnKqOn4bdA/JgqFyJQ0AcZJSSuriVvhSSSoG3S2I0vxZKoeM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJckxU010557; Wed, 10 Jan 2024 19:40:52 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vj1010eeg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:40:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJehoi015830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:43 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnM020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:43 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 13/14] c++: Implement __is_scalar built-in trait Date: Wed, 10 Jan 2024 01:23:04 -0800 Message-ID: <20240110194031.2384005-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: e0Offga51Jtim6lJFHQ_oTgjuEe1o2b1 X-Proofpoint-GUID: e0Offga51Jtim6lJFHQ_oTgjuEe1o2b1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 mlxscore=0 suspectscore=0 mlxlogscore=633 clxscore=1034 priorityscore=1501 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733808027320578 X-GMAIL-MSGID: 1787733808027320578 This patch implements built-in trait for std::is_scalar. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scalar. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar. * g++.dg/ext/is_scalar.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 10 +++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_scalar.C | 28 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d2e41aa053d..7293f33c676 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3810,6 +3810,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCALAR: + inform (loc, " %qT is not a scalar type", t1); + break; case CPTK_IS_SCOPED_ENUM: inform (loc, " %qT is not a scoped enum", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 6dac7622a7c..48e195b4938 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -87,6 +87,7 @@ DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index c3d6fc2d10f..2426ba629d9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12545,6 +12545,15 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCALAR: + return (TYPE_PTRDATAMEM_P (type1) + || TREE_CODE (type1) == ENUMERAL_TYPE + || integral_type_p (type1) + || floating_point_type_p (type1) + || TYPE_PTR_P (type1) + || TYPE_PTRMEMFUNC_P (type1) + || NULLPTR_TYPE_P (type1)); + case CPTK_IS_SCOPED_ENUM: return SCOPED_ENUM_P (type1); @@ -12744,6 +12753,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_OBJECT: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SCALAR: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_SIGNED: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e3d16add403..c860f7e12ca 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -143,6 +143,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..ad4c2d7ea05 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +class ClassType { }; +enum EnumType { e0 }; + +SA_TEST_CATEGORY(__is_scalar, int, true); +SA_TEST_CATEGORY(__is_scalar, float, true); +SA_TEST_CATEGORY(__is_scalar, EnumType, true); +SA_TEST_CATEGORY(__is_scalar, int*, true); +SA_TEST_FN(__is_scalar, int(*)(int), true); +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true); +SA_TEST_FN(__is_scalar, int (ClassType::*) (int), true); +SA_TEST_CATEGORY(__is_scalar, decltype(nullptr), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_scalar, ClassType, false); From patchwork Wed Jan 10 09:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 187014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1015832dyi; Wed, 10 Jan 2024 11:44:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJfWi4GhKunsZWzfiodnov9vuuhuonY0hgx1gH/75e3dkGAOqq0TrN4rOW7ltZzWTYKV4G X-Received: by 2002:a05:6214:226b:b0:67a:a72d:fba6 with SMTP id gs11-20020a056214226b00b0067aa72dfba6mr1051140qvb.36.1704915889236; Wed, 10 Jan 2024 11:44:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704915889; cv=pass; d=google.com; s=arc-20160816; b=v5cRUoty3CVSXzjy+vOXWAR6b2HlH+t9JSlBZ9YhohhO6USRT6oo1nkhKwvMoFTP/D hpesIv0PNwxTGGNxtffR1Q0UCpR7K+2TLJQQOvv3mdEz3hOii9QagUaIAaeQPApvEQqk aHkgmqTjXU1D70hBlC7vlXwuOLCrdmEe4tQ1bdFGA0daWq0rZhsLpNBiTh9Jdj6QfMPe U+TZnpuYXthpBYGXyM1RUVg10frCjbh1BrVoVSkYyiaV7UbJ1wRyl45GpfKdWUUtaeg+ f9/X4ndEuMimgrKCqiWT39j1w2LZdKrDvuCpJbfLeze2sXNR1RPluSZmQKUnWC5DfgIo 5kyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=p/bt/50MvOdvNPs12hGab96/3fiDTZ7H4V+PLb7nUUc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=OffuJtDIOTJtDzp9CgxaOMuR40Vu30HW3XcrE08/EeyR4uO3mSmbDl2XSBh+gCFJp5 7lt/Io2BWDkSHgC3KRId0xi4bQn9DI95gaP30j8xs87Rm6Zwwm1WQ/AfOuy+sW/Icn1l R007rDJddJramQe5EudkeYOT+vzkt17FB42nQSsT6wSJ8wKRCSf1mVaGk3WeT14B692f HQ9FrKVoe+xvHc5AcDoJKi8IWYAwUIF/2yp7BLFxw6Coo3bKrtx3HTKpzZXHjuIOBml7 43aIQPrXCpxhOIX6yoF03eSbq0zBt3nZXPFhDwmdxAD7UR5zfCvcSXZSwiF0g0B8OhVk FO1w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tvnftIXx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e25-20020a0cb459000000b0067f9fdc4088si4979309qvf.416.2024.01.10.11.44.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:44:49 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tvnftIXx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDC20385801A for ; Wed, 10 Jan 2024 19:44:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDC20385801A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704915888; bh=p/bt/50MvOdvNPs12hGab96/3fiDTZ7H4V+PLb7nUUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tvnftIXxoB3Kk1ijYBRQZMj3Nx5qR0P1iRdfbol2Ru97MZQwW+33o31ORfFkNSkJ3 KK6AM9qJ3TgEcKLHjzY95OX5A6Pr6d8OuoTp8jiY0Nut22XlyWJY3XwVMHoXDuhhr0 k5yLx92fhrINklClYoQTtzragimES6lUBxr4mVzU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 129DB38582B0; Wed, 10 Jan 2024 19:41:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 129DB38582B0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 129DB38582B0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; cv=none; b=vi9n97fa1CuMOS1E4Xv3TWGupzcFKyAaFc31VIIdXhoAirNq1MaxHGuoIr0AdazWOwpgMI6hVT2CdHuiv0PDnc/FCRzxa+V+QPhv3ul1jNrByUslDE59ELit6i8Tvymy1Ke8FHRriL26oOsIHia4xpb+DHBp5vzQObe/i31xAvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704915677; c=relaxed/simple; bh=/4yffQ3HYKtM/51uWFArLBVJvHiGe5kIDpgINFviz3w=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=D3szQ4bPolgl+sD9qNniKo+6BJzzPakjABFSpPQeJX+tUKRnhJs1cji5cizmxXbDjKnnUQJNKBk3qkc7IgM16PMuEygAkMQ3mjvx2789bwCMf5g+M4d58Vb3cYjEI1nFrqFoVRCcK15XMvZcHS2uHIqXgmW05Dn5vpkPpflbj3I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJdlCV019768; Wed, 10 Jan 2024 19:41:10 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3vhyq0sc4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 19:41:09 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 40AJehsA006379 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 11:40:43 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 40AJefnN020412 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 11:40:43 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH 14/14] libstdc++: Optimize std::is_scalar compilation performance Date: Wed, 10 Jan 2024 01:23:05 -0800 Message-ID: <20240110194031.2384005-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> References: <20240110194031.2384005-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: lBfDy4uyXctXAYEgOYxh4B3Z0od2p_q_ X-Proofpoint-GUID: lBfDy4uyXctXAYEgOYxh4B3Z0od2p_q_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 clxscore=1034 impostorscore=0 malwarescore=0 spamscore=0 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=541 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100156 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787733883678056224 X-GMAIL-MSGID: 1787733883678056224 This patch optimizes the compilation performance of std::is_scalar by dispatching to the new __is_scalar built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_scalar): Use __is_scalar built-in trait. (is_scalar_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index b917c743aea..9ace6a9f08f 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -775,11 +775,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_member_pointer; /// is_scalar +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar) + template + struct is_scalar + : public __bool_constant<__is_scalar(_Tp)> + { }; +#else template struct is_scalar : public __or_, is_enum<_Tp>, is_pointer<_Tp>, is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type { }; +#endif /// is_compound template @@ -3369,8 +3376,14 @@ template inline constexpr bool is_object_v = is_object<_Tp>::value; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar) +template + inline constexpr bool is_scalar_v = __is_scalar(_Tp); +#else template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; +#endif + template inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;