From patchwork Wed Aug 9 06:11:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 1819145 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=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=vbLrGXie; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RLKTs2hKgz1yfB for ; Wed, 9 Aug 2023 16:12:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 518EB3857733 for ; Wed, 9 Aug 2023 06:12:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 518EB3857733 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691561551; bh=gUYH3PGibl/i7afxxwN0QTX4uzuW6XZFMTr3DYPUXRo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=vbLrGXieVr9syKv7DyJTFWVgYUXsl7MlRULwmw8Xx70RyIT9K96g8HEWiPGK+aoAv BMOM6rMkySxCfrVFO02zjwS5qyJRHz5ImrluonJ53b0LrZOiJKSCTff5hc1BARWc+8 w1g8tmNUv94E315ylCEIyxgDO0AcPs9d11erkpJ4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 219F53858404 for ; Wed, 9 Aug 2023 06:12:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 219F53858404 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 89068300089; Wed, 9 Aug 2023 06:11:59 +0000 (UTC) To: Tsukasa OI , Kito Cheng , Palmer Dabbelt , Andrew Waterman , Jim Wilson Cc: gcc-patches@gcc.gnu.org Subject: [RFC PATCH 0/2] RISC-V: __builtin_riscv_pause for all environment Date: Wed, 9 Aug 2023 06:11:49 +0000 Message-ID: Mime-Version: 1.0 X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-Patchwork-Original-From: Tsukasa OI via Gcc-patches From: Tsukasa OI Reply-To: Tsukasa OI Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hello, I found that a built-in function "__builtin_riscv_pause" is not usable unless we enable the 'Zihintpause' extension explicitly (still, this built-in exists EVEN IF the 'Zihintpause' extension is disabled). Contents of a.c: > void sample(void) > { > __builtin_riscv_pause(); > } Compiling with the 'Zihintpause' extension is fine. > $ riscv64-unknown-elf-gcc -O2 -march=rv64i_zihintpause -mabi=lp64 -c a.c However, compiling without the 'Zihintpause' causes an assembler error (tested with GNU Binutils 2.41): > $ riscv64-unknown-elf-gcc -O2 -march=rv64i -mabi=lp64 -c a.c > /tmp/ccFjacAz.s: Assembler messages: > /tmp/ccFjacAz.s:11: Error: unrecognized opcode `pause', extension `zihintpause' required This is because: 1. GCC does not handle the 'Zihintpause' extension and 2. "riscv_pause" (insn) unconditionally emits "pause" even if the assembler does not accept it (when the extension is disabled). This patch set (PATCH 1/2) resolves this issue by: 1. Handling the 'Zihintpause' extension and 2. Splitting the "__builtin_riscv_pause" implementation depending on the existence of the 'Zihintpause' extension. Because a released version of GCC defines "__builtin_riscv_pause" unconditionally, I chose to define no-'Zihintpause' version. There is another option to unconditionally emit ".insn 0x0100000f" (the machine code of "pause") but I didn't because I wanted to improve the diagnostics (e.g. *.s output). I also fixed the description of this built-in function (in PATCH 2/2). I'm not sure whether this is a good method to split the implementation depending on the 'Zihintpause' extension. Other than that, I believe that this is okay and approval is appreciated. Note that because I assigned copyright of GCC contribution to FSF, I didn't attach "Signed-off-by" tag. Tell me if I need it. Thanks, Tsukasa Tsukasa OI (2): RISC-V: __builtin_riscv_pause for all environment RISC-V: Fix documentation of __builtin_riscv_pause gcc/common/config/riscv/riscv-common.cc | 2 ++ gcc/config/riscv/riscv-builtins.cc | 6 ++++-- gcc/config/riscv/riscv-opts.h | 2 ++ gcc/config/riscv/riscv.md | 7 ++++++- gcc/doc/extend.texi | 6 +++--- gcc/testsuite/gcc.target/riscv/builtin_pause.c | 10 ---------- gcc/testsuite/gcc.target/riscv/zihintpause-noarch.c | 11 +++++++++++ gcc/testsuite/gcc.target/riscv/zihintpause.c | 11 +++++++++++ 8 files changed, 39 insertions(+), 16 deletions(-) delete mode 100644 gcc/testsuite/gcc.target/riscv/builtin_pause.c create mode 100644 gcc/testsuite/gcc.target/riscv/zihintpause-noarch.c create mode 100644 gcc/testsuite/gcc.target/riscv/zihintpause.c base-commit: c8b396243ec5bfa9b541555131df597ebc84b9d0