From patchwork Fri Nov 25 12:57:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 25994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3994422wrr; Fri, 25 Nov 2022 04:58:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5so9S2rwUU1jZTDh/tdjsNs+kFbL1Y/akB03gxHXsSWH7ZVyCcZi3mvV+IWqQjwx4zwcrR X-Received: by 2002:a17:906:a198:b0:7b4:bc42:3b44 with SMTP id s24-20020a170906a19800b007b4bc423b44mr24133541ejy.101.1669381087475; Fri, 25 Nov 2022 04:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669381087; cv=none; d=google.com; s=arc-20160816; b=qn7anDw3HmgvLo5XZO4zLSA5WkAsNZvcYBL4ZKm3784nLf+ewKXIIdHDalP4EfKVKo Tv2uJWGlqjz7jenFo+DLxhMQzVVXyGdGH7aYH2UowSU9TmMZZ2fsrRex0epGxODqfVy7 o5GcZgNkRCjN0s1CrhFQSiulySqC2rNxXmPkVq00phNmiVlxqgGvvZIA9D4eq2Pmwb6y mRgSS9KhJOx6sfvNMzR7u8ZbnXdhitZBspv8q2KvJSC12Rx19BrRSub6eR+HO+ZEerbf 5z/ovyNsmpy19eqziJGHBPxskD6b1y01XuDmGrc3M0hIU/OBCxFtqFaj1pwLAHpyAlYo 8d8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding:cc :content-language:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=Q0AToKOVbn9luxmhnhqf7liEGRw2hYqtxkKNdRnWPZI=; b=sKNw3IvhIa6Ftz5dll3frUEWB6X4ayHnzy2lJMqQ8/MYxKylODubHcnoeCImDJ1gIl ADml9W20xEjnz8/O2BP2cpV8w3aJJdiXfIOLsNx3V8oar7JHS0zyx83x8rr/pijpREzf CHoe25ELQllg6T5okqpoQJxlykie518MW8OTzA6hB5qBmXBJ6vXX/ciBQBtWq0Kb7mTI l7aZzEjEbkj2b0GfqkFkM5b8fERYSyLWQZJK4oEXUV8eUPC7Z/VTHrhH3ULXQq+8n2Ue 07CkrSiTgw8wMzDzQKBNZlahK7cFlfnmBHshHMLvRXo3xnbUDWkyNybbgPVTqUKbdY4O 8KMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=06UAp7aZ; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; 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" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k26-20020a056402049a00b0045d9a3adf48si3095684edv.591.2022.11.25.04.58.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 04:58:07 -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=@suse.cz header.s=susede2_rsa header.b=06UAp7aZ; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85BE73853D7C for ; Fri, 25 Nov 2022 12:58:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id A60123855153 for ; Fri, 25 Nov 2022 12:57:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A60123855153 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9352521ACB; Fri, 25 Nov 2022 12:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1669381055; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Q0AToKOVbn9luxmhnhqf7liEGRw2hYqtxkKNdRnWPZI=; b=06UAp7aZUcLxE1ZYr2B48zTpHPv5/occwOQ8j8y9U64Om+2hIxTW/NL43P2o5iqTVjhIqj tavvEyWzfKy1993oUYy/HutWznkgJec3fQUB1IGyleO+E7sTMqsvS3oFtFFsE4e4CtW5wa THHIzRdKwtw9+Otgp8SIJA09Iq2mYCY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1669381055; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Q0AToKOVbn9luxmhnhqf7liEGRw2hYqtxkKNdRnWPZI=; b=a0rmrGaFwdHJj9kWvAmO3Sb3rtxSVIFUEJpWZHWCnwr0cyGbDbht197sQ5FGXcXMuscHSk 472ojqDN5Hjz6mDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6FFDA13A08; Fri, 25 Nov 2022 12:57:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PLcwGb+7gGPqPAAAMHmgww (envelope-from ); Fri, 25 Nov 2022 12:57:35 +0000 Message-ID: Date: Fri, 25 Nov 2022 13:57:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] i386: fix assert (__builtin_cpu_supports ("x86-64") >= 0) To: gcc-patches@gcc.gnu.org Content-Language: en-US Cc: Uros Bizjak , Jakub Jelinek X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750472943322774676?= X-GMAIL-MSGID: =?utf-8?q?1750472943322774676?= Similar story as PR103661, we again return a negative number for __builtin_cpu_supports: Documentation says: int __builtin_cpu_supports(const char *feature) This function returns a positive integer if the run-time CPU supports feature and returns 0 otherwise. while we return -2147483648. Moreover, I noticed "x86-64" is not a valid option for __builtin_cpu_is, but for __builtin_cpu_supports. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR target/107551 gcc/ChangeLog: * config/i386/i386-builtins.cc (fold_builtin_cpu): Use same path as for PR103661. * doc/extend.texi: Fix "x86-64" use. gcc/testsuite/ChangeLog: * gcc.target/i386/builtin_target.c: Add more checks. --- gcc/config/i386/i386-builtins.cc | 25 ++++++++----------- gcc/doc/extend.texi | 22 ++++++++-------- .../gcc.target/i386/builtin_target.c | 5 ++++ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/gcc/config/i386/i386-builtins.cc b/gcc/config/i386/i386-builtins.cc index eacdf072244..c57c1380298 100644 --- a/gcc/config/i386/i386-builtins.cc +++ b/gcc/config/i386/i386-builtins.cc @@ -2181,18 +2181,14 @@ fold_builtin_cpu (tree fndecl, tree *args) varpool_node::add (ix86_cpu_features2_var); } + /* Skip __cpu_features[0]. */ feature -= INT_TYPE_SIZE; - field_val = 1U << (feature % INT_TYPE_SIZE); tree index = size_int (feature / INT_TYPE_SIZE); + feature = feature % INT_TYPE_SIZE; array_elt = build4 (ARRAY_REF, unsigned_type_node, ix86_cpu_features2_var, index, NULL_TREE, NULL_TREE); /* Return __cpu_features2[index] & field_val */ - final = build2 (BIT_AND_EXPR, unsigned_type_node, - array_elt, - build_int_cstu (unsigned_type_node, - field_val)); - return build1 (NOP_EXPR, integer_type_node, final); } else { @@ -2209,16 +2205,17 @@ fold_builtin_cpu (tree fndecl, tree *args) array_elt = build4 (ARRAY_REF, unsigned_type_node, ref, integer_zero_node, NULL_TREE, NULL_TREE); - field_val = (1U << feature); /* Return __cpu_model.__cpu_features[0] & field_val */ - final = build2 (BIT_AND_EXPR, unsigned_type_node, array_elt, - build_int_cstu (unsigned_type_node, field_val)); - if (feature == (INT_TYPE_SIZE - 1)) - return build2 (NE_EXPR, integer_type_node, final, - build_int_cst (unsigned_type_node, 0)); - else - return build1 (NOP_EXPR, integer_type_node, final); } + + field_val = (1U << feature); + final = build2 (BIT_AND_EXPR, unsigned_type_node, array_elt, + build_int_cstu (unsigned_type_node, field_val)); + if (feature == (INT_TYPE_SIZE - 1)) + return build2 (NE_EXPR, integer_type_node, final, + build_int_cst (unsigned_type_node, 0)); + else + return build1 (NOP_EXPR, integer_type_node, final); } gcc_unreachable (); } diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index b1dd39e64b8..d3812fa55b0 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -21897,18 +21897,6 @@ AMD Family 19h Zen version 3. @item znver4 AMD Family 19h Zen version 4. - -@item x86-64 -Baseline x86-64 microarchitecture level (as defined in x86-64 psABI). - -@item x86-64-v2 -x86-64-v2 microarchitecture level. - -@item x86-64-v3 -x86-64-v3 microarchitecture level. - -@item x86-64-v4 -x86-64-v4 microarchitecture level. @end table Here is an example: @@ -22002,6 +21990,16 @@ VPCLMULQDQ instructions. AVX512VNNI instructions. @item avx512bitalg AVX512BITALG instructions. +@item x86-64 +Baseline x86-64 microarchitecture level (as defined in x86-64 psABI). +@item x86-64-v2 +x86-64-v2 microarchitecture level. +@item x86-64-v3 +x86-64-v3 microarchitecture level. +@item x86-64-v4 +x86-64-v4 microarchitecture level. + + @end table Here is an example: diff --git a/gcc/testsuite/gcc.target/i386/builtin_target.c b/gcc/testsuite/gcc.target/i386/builtin_target.c index 3e7505a8c3a..fff643c13b0 100644 --- a/gcc/testsuite/gcc.target/i386/builtin_target.c +++ b/gcc/testsuite/gcc.target/i386/builtin_target.c @@ -95,6 +95,11 @@ quick_check () assert (__builtin_cpu_supports ("avx512vpopcntdq") >= 0); + assert (__builtin_cpu_supports ("x86-64") >= 0); + assert (__builtin_cpu_supports ("x86-64-v2") >= 0); + assert (__builtin_cpu_supports ("x86-64-v3") >= 0); + assert (__builtin_cpu_supports ("x86-64-v4") >= 0); + /* Check CPU type. */ assert (__builtin_cpu_is ("amd") >= 0);