From patchwork Thu Oct 31 13:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 2004656 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfPqk29qLz1xwc for ; Fri, 1 Nov 2024 00:25:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 385703857002 for ; Thu, 31 Oct 2024 13:25:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 82017385734A; Thu, 31 Oct 2024 13:24:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82017385734A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 82017385734A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730381067; cv=none; b=i205TbsW1J76DkmMnXtmo83utSVznvPv8Ky+XSBFf6ORpykf0qLO5Q103yxjOR7kOiGbYBzsCSTyB2yYu5utVswYdXVJXBvdXvBKYG88ILrANQd1sCD90GSX1DvNlw7lI5Cli/+JmvqwfaE/NGmOA06O962oxrwUNUt3EUweX2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730381067; c=relaxed/simple; bh=sN8tSgL/E+QbQ5K6pm0+MToEBM1cbfqo+6Y469zkdMQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=h2tuiy1rf2BitH1spfxtDxO/lFQkEDx8oOvlnbTKW0Z11KuCFzZM9/Kx36otni7v8KFoLRBLr+xbEXVbvYuTDC851WCNSJnemFeqmYpe/1kDzixKvlaaMqWE0qDKhNZNdGOwUHy6REIj+kz1Mi31FrT0d6ZqTkR27SR958AtHow= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1A2541063; Thu, 31 Oct 2024 06:24:52 -0700 (PDT) Received: from udebian.localdomain (unknown [10.1.31.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8AF2F3F528; Thu, 31 Oct 2024 06:24:21 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: nsz@gcc.gnu.org, richard.earnshaw@arm.com, matthieu.longo@arm.com, richard.ball@arm.com, richard.sandiford@arm.com Subject: [PATCH v2 05/21] aarch64: Add __builtin_aarch64_chkfeat tests Date: Thu, 31 Oct 2024 13:23:07 +0000 Message-Id: <20241031132323.948159-6-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241031132323.948159-1-yury.khrustalev@arm.com> References: <20241031132323.948159-1-yury.khrustalev@arm.com> MIME-Version: 1.0 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~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Szabolcs Nagy gcc/testsuite/ChangeLog: * gcc.target/aarch64/chkfeat-1.c: New test. * gcc.target/aarch64/chkfeat-2.c: New test. Co-authored-by: Richard Sandiford --- gcc/testsuite/gcc.target/aarch64/chkfeat-1.c | 75 ++++++++++++++++++++ gcc/testsuite/gcc.target/aarch64/chkfeat-2.c | 30 ++++++++ 2 files changed, 105 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/chkfeat-1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/chkfeat-2.c diff --git a/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c b/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c new file mode 100644 index 00000000000..2fae81e740f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c @@ -0,0 +1,75 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mbranch-protection=none" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +/* +**foo1: +** mov x16, 1 +** hint 40 // chkfeat x16 +** mov x0, x16 +** ret +*/ +unsigned long long +foo1 (void) +{ + return __builtin_aarch64_chkfeat (1); +} + +/* +**foo2: +** mov x16, 1 +** movk x16, 0x5678, lsl 32 +** movk x16, 0x1234, lsl 48 +** hint 40 // chkfeat x16 +** mov x0, x16 +** ret +*/ +unsigned long long +foo2 (void) +{ + return __builtin_aarch64_chkfeat (0x1234567800000001); +} + +/* +**foo3: +** mov x16, x0 +** hint 40 // chkfeat x16 +** mov x0, x16 +** ret +*/ +unsigned long long +foo3 (unsigned long long x) +{ + return __builtin_aarch64_chkfeat (x); +} + +/* +**foo4: +** ldr x16, \[x0\] +** hint 40 // chkfeat x16 +** str x16, \[x0\] +** ret +*/ +void +foo4 (unsigned long long *p) +{ + *p = __builtin_aarch64_chkfeat (*p); +} + +/* +**foo5: +** mov x16, 1 +** hint 40 // chkfeat x16 +** cmp x16, 0 +**( +** csel w0, w1, w0, eq +**| +** csel w0, w0, w1, ne +**) +** ret +*/ +int +foo5 (int x, int y) +{ + return __builtin_aarch64_chkfeat (1) ? x : y; +} diff --git a/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c b/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c new file mode 100644 index 00000000000..f98d7096ffd --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +void bar (void); + +/* Extern call may change enabled HW features. */ + +/* +** foo: +** ... +** mov x16, 1 +** ... +** hint 40 // chkfeat x16 +** ... +** bl bar +** ... +** mov x16, 1 +** ... +** hint 40 // chkfeat x16 +** ... +*/ +unsigned long long +foo (void) +{ + unsigned long long a = __builtin_aarch64_chkfeat (1); + bar (); + unsigned long long b = __builtin_aarch64_chkfeat (1); + return a + b; +}