From patchwork Wed Apr 26 20:28:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 87976 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp489498vqo; Wed, 26 Apr 2023 13:29:23 -0700 (PDT) X-Google-Smtp-Source: AKy350aBv3T9kWmTx5ChF6364xEKsqsJ5XrUUTJtcJLIFvwIZ5y7WMsE6xy65dYKt0wN0xkY6xYh X-Received: by 2002:aa7:c6c8:0:b0:4fe:9555:3a57 with SMTP id b8-20020aa7c6c8000000b004fe95553a57mr17992641eds.16.1682540963277; Wed, 26 Apr 2023 13:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682540963; cv=none; d=google.com; s=arc-20160816; b=t7PyxQZFoBkdE14ePOrcaOiSPAj8FV2O6KX5ocGSLhOTXNxLqsAmJ7EQhI5HgsQbYo 5QB82RPtyKp3An34uJaadHFJyLkSs4KiqdcYAlTdkJ2UdISZbaiPRx8n+u8Mc7L2Cju9 pJdZHXuXapoqLhW+sUEA6eE1W+eRg5Y6XsV4B7/U15U3/Rotmt10Ht9Vql5jZ0SSM3xW 4kH3YeoQwTg4y4uq/Q95H1O1wVOy1nLk/odtr0spJ1lVOC2Mx766SIX6L1d2rCgwkMEg GkyZ89Lr1rdzZkAuvjUza9tmp69JiMAuGcAgs+Lfgrgkik3lG96srsY7X8+3i6dBpzlY noHQ== 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:subject:to:from :content-language:user-agent:mime-version:date:message-id :dkim-signature:dmarc-filter:delivered-to; bh=HP0OA0bfITmsAPKTYArHbckdvTmyz5iv8JHxHVVD/P0=; b=b9ymDJbcxhyftNHVpibv1CRWoEZ/rDJ1uu1gr7K7Zff3Vpke1zJ13tE9xjI/+e3DDm I04XwhvqSOBXUeegk1TyDHki+5Yc9kAjTWbcz56GFS2mGee445ZwQARkTiZN7XWRO5RU npGhPRTrFbS/IBd06spq9vLlVbUlW1LxbdIO3DYXnwOBymq65KMkVeMUyG7j/EDAOwni ASFq8+GFAwhgRudPshlTIr85Jp8HzSEJZpbLyF91CbSLeDbToclHTqR0mAVdWdpPLQ03 OWiPurRx5KiBiSj2iMQDojYR5MfXxorNlCBWfVfvMDnJQG01j9nkC9Ir88prCjlmGm/t YJNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=FaVklwfm; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n24-20020a05640206d800b00504bad84433si12691370edy.203.2023.04.26.13.29.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 13:29:23 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=FaVklwfm; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4CFAA3857723 for ; Wed, 26 Apr 2023 20:28:50 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by sourceware.org (Postfix) with ESMTPS id 4B1263858C54 for ; Wed, 26 Apr 2023 20:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B1263858C54 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-5ef4885bc39so34386176d6.2 for ; Wed, 26 Apr 2023 13:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682540923; x=1685132923; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=HP0OA0bfITmsAPKTYArHbckdvTmyz5iv8JHxHVVD/P0=; b=FaVklwfm5ozh59ZB5xdttPQwIpfE0FyjbctG7ieZgrLG/hKy/Jmt+0ay1X+clt04Al jvsv/g07zQ75ZhuXQ3JRpg8GGaZ0LoNMaGrbaix3DPrY6XH+jgFMAilCaA6NtEkavo7r TDGrr8/EKyTAiyAKDVIPjqmWhar34pWUvQ8XyxnblssrkAvBDIh/P6DFmCbIuLWF/0pj dD3ucmcU6K8Q7XMC2YRHvFfbNc1C4ge7dtqp+PxoQyEdNr6bzrYdKft+OKwVqaeLify1 /gGWNjfg6CZK4v372NxNVE0SixM5PCe8dxcRzAPJ2jcDUrmAQOnLj+rr9pGOaChHCdkE cPwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682540923; x=1685132923; h=subject:to:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HP0OA0bfITmsAPKTYArHbckdvTmyz5iv8JHxHVVD/P0=; b=eC35cUAGfyzRfMpGk0BqMHoMGNLyNUNOFlG2gNxO7WnNH/jdBf1NiAZnhTY/TckZSt +/EROu68wzB43o3HaTfevKSB4Jl5jvt+RhMssTVAeJTFwTONDCl2tnkk1s5E6Grj4XUY ffI2C8Dhvs1zxFewjZ0roDy/BzdWY1xY402r6oRL2XYMTiHsT2dTLiitiSTRNOm4dsxL DaaZxIurcIpQZguwLqxm6jflTgfHEYAqQRimxdq5BIRFRWlCY2E6RhVlNTgI0nueuAfn eecJSVJIC1EOHyMGECU5G09YCaL9VwXBSl118N+bpMoH+FgVWaWtHYiUSiWO0I/QO6ip sTnA== X-Gm-Message-State: AAQBX9fBsT57vYyz1pdLFjeAv7RfcAmu9A9lJpd9KnfHUTMT/YxlYPIP 0WercZ9PEiznB7xpdB2WUiU0vDm/o+urobHWgPM= X-Received: by 2002:a05:6214:2aad:b0:5f1:6b1e:5b20 with SMTP id js13-20020a0562142aad00b005f16b1e5b20mr31802950qvb.27.1682540923303; Wed, 26 Apr 2023 13:28:43 -0700 (PDT) Received: from ?IPV6:2607:fb90:46b:8c5d:83b8:707f:a499:a468? ([2607:fb90:46b:8c5d:83b8:707f:a499:a468]) by smtp.gmail.com with ESMTPSA id v27-20020a05620a091b00b0074ad4cc603dsm5324283qkv.131.2023.04.26.13.28.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Apr 2023 13:28:42 -0700 (PDT) Message-ID: <9b903d19-c4b7-40a3-dce0-84d36e4ff32c@ventanamicro.com> Date: Wed, 26 Apr 2023 14:28:40 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Content-Language: en-US From: Jeff Law To: binutils@sourceware.org Subject: [committed] RISC-V: XVentanaCondops support X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764272073070981350?= X-GMAIL-MSGID: =?utf-8?q?1764272073070981350?= This patch adds support for the Veyron V1's XVentanaCondOps extension. These instructions provide a primitive that corresponds to: x = (a eq/ne 0) ? x : 0; Ie, it's a conditional zero. On top of this primitive the compiler can build a variety of branchless sequences to implement conditional arithmetic, logical and select operations. If you follow the RISC-V world, you'll realize XVentanaCondops is essentially the same as the Zicond extension that is currently going through the ratification process. The only material difference is the instruction encoding. The Veyron V1 processor implements XVentanaCondOps, but not Zicond. That's simply due to timing. This work was done by Philipp Tomsich and the VRULL team for Ventana. Going forward I'm the best point of contact for this code. Reviewed, tested and pushed to the trunk. Jeff commit 1656d3f8ef56a16745689c03269412988ebcaa54 Author: Philipp Tomsich Date: Wed Apr 26 14:09:34 2023 -0600 RISC-V: Support XVentanaCondOps extension Ventana Micro has published the specification for their XVentanaCondOps ("conditional ops") extension at https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf which contains two new instructions - vt.maskc - vt.maskcn that can be used in constructing branchless sequences for various conditional-arithmetic, conditional-logical, and conditional-select operations. To support such vendor-defined instructions in the mainline binutils, this change also adds a riscv_supported_vendor_x_ext secondary dispatch table (but also keeps the behaviour of allowing any unknow X-extension to be specified in addition to the known ones from this table). As discussed, this change already includes the planned/agreed future requirements for X-extensions (which are likely to be captured in the riscv-toolchain-conventions repository): - a public specification document is available (see above) and is referenced from the gas-documentation - the naming follows chapter 27 of the RISC-V ISA specification - instructions are prefixed by a vendor-prefix (vt for Ventana) to ensure that they neither conflict with future standard extensions nor clash with other vendors bfd/ChangeLog: * elfxx-riscv.c (riscv_get_default_ext_version): Add riscv_supported_vendor_x_ext. (riscv_multi_subset_supports): Recognize INSN_CLASS_XVENTANACONDOPS. gas/ChangeLog: * doc/c-riscv.texi: Add section to list custom extensions and their documentation URLs. * testsuite/gas/riscv/x-ventana-condops.d: New test. * testsuite/gas/riscv/x-ventana-condops.s: New test. include/ChangeLog: * opcode/riscv-opc.h Add vt.maskc and vt.maskcn. * opcode/riscv.h (enum riscv_insn_class): Add INSN_CLASS_XVENTANACONDOPS. opcodes/ChangeLog: * riscv-opc.c: Add vt.maskc and vt.maskcn. Series-version: 1 Series-to: binutils@sourceware.org Series-cc: Kito Cheng Series-cc: Nelson Chu Series-cc: Greg Favor Series-cc: Christoph Muellner diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index 19391d94e30..bd0c7c81329 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -1255,6 +1255,8 @@ static struct riscv_supported_ext riscv_supported_vendor_x_ext[] = {"xtheadmemidx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"xtheadmempair", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {"xtheadsync", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + /* XVentanaCondOps: https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf */ + {"xventanacondops", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, {NULL, 0, 0, 0, 0} }; @@ -2383,6 +2385,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps, return riscv_subset_supports (rps, "xtheadmempair"); case INSN_CLASS_XTHEADSYNC: return riscv_subset_supports (rps, "xtheadsync"); + case INSN_CLASS_XVENTANACONDOPS: + return riscv_subset_supports (rps, "xventanacondops"); default: rps->error_handler (_("internal: unreachable INSN_CLASS_*")); diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi index 64fff6a7973..98d5d1bed44 100644 --- a/gas/doc/c-riscv.texi +++ b/gas/doc/c-riscv.texi @@ -763,5 +763,11 @@ It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/rel The XTheadSync extension provides instructions for multi-processor synchronization. It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}. +@item XVentanaCondOps +XVentanaCondOps extension provides instructions for branchless +sequences that perform conditional arithmetic, conditional +bitwise-logic, and conditional select operations. + +It is documented at @url{https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf}. @end table diff --git a/gas/testsuite/gas/riscv/x-ventana-condops.d b/gas/testsuite/gas/riscv/x-ventana-condops.d new file mode 100644 index 00000000000..cab0cc8dc12 --- /dev/null +++ b/gas/testsuite/gas/riscv/x-ventana-condops.d @@ -0,0 +1,12 @@ +#as: -march=rv64i_xventanacondops1p0 +#source: x-ventana-condops.s +#objdump: -d + +.*:[ ]+file format .* + + +Disassembly of section .text: + +0+000 : +[ ]+0:[ ]+00c5e57b[ ]+vt.maskc[ ]+a0,a1,a2 +[ ]+4:[ ]+00e6f57b[ ]+vt.maskcn[ ]+a0,a3,a4 diff --git a/gas/testsuite/gas/riscv/x-ventana-condops.s b/gas/testsuite/gas/riscv/x-ventana-condops.s new file mode 100644 index 00000000000..562cf7384f7 --- /dev/null +++ b/gas/testsuite/gas/riscv/x-ventana-condops.s @@ -0,0 +1,4 @@ +target: + vt.maskc a0, a1, a2 + vt.maskcn a0, a3, a4 + diff --git a/include/opcode/riscv-opc.h b/include/opcode/riscv-opc.h index 85d35c1efc9..91e56c03191 100644 --- a/include/opcode/riscv-opc.h +++ b/include/opcode/riscv-opc.h @@ -2342,6 +2342,11 @@ #define MASK_TH_SYNC_IS 0xffffffff #define MATCH_TH_SYNC_S 0x0190000b #define MASK_TH_SYNC_S 0xffffffff +/* Vendor-specific (Ventana Microsystems) XVentanaCondOps instructions */ +#define MATCH_VT_MASKC 0x607b +#define MASK_VT_MASKC 0xfe00707f +#define MATCH_VT_MASKCN 0x707b +#define MASK_VT_MASKCN 0xfe00707f /* Unprivileged Counter/Timers CSR addresses. */ #define CSR_CYCLE 0xc00 #define CSR_TIME 0xc01 @@ -3236,6 +3241,9 @@ DECLARE_INSN(th_sync, MATCH_TH_SYNC, MASK_TH_SYNC) DECLARE_INSN(th_sync_i, MATCH_TH_SYNC_I, MASK_TH_SYNC_I) DECLARE_INSN(th_sync_is, MATCH_TH_SYNC_IS, MASK_TH_SYNC_IS) DECLARE_INSN(th_sync_s, MATCH_TH_SYNC_S, MASK_TH_SYNC_S) +/* XVentanaCondOps instructions. */ +DECLARE_INSN(vt_maskc, MATCH_VT_MASKC, MASK_VT_MASKC) +DECLARE_INSN(vt_maskcn, MATCH_VT_MASKCN, MASK_VT_MASKCN) #endif /* DECLARE_INSN */ #ifdef DECLARE_CSR /* Unprivileged Counter/Timers CSRs. */ diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h index b4ae55249bb..e86a1bd0824 100644 --- a/include/opcode/riscv.h +++ b/include/opcode/riscv.h @@ -422,6 +422,7 @@ enum riscv_insn_class INSN_CLASS_XTHEADMEMIDX, INSN_CLASS_XTHEADMEMPAIR, INSN_CLASS_XTHEADSYNC, + INSN_CLASS_XVENTANACONDOPS, }; /* This structure holds information for a particular instruction. */ diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c index d9d69cda548..1c3d9b0903e 100644 --- a/opcodes/riscv-opc.c +++ b/opcodes/riscv-opc.c @@ -2009,6 +2009,10 @@ const struct riscv_opcode riscv_opcodes[] = {"th.sync.is", 0, INSN_CLASS_XTHEADSYNC, "", MATCH_TH_SYNC_IS, MASK_TH_SYNC_IS, match_opcode, 0}, {"th.sync.s", 0, INSN_CLASS_XTHEADSYNC, "", MATCH_TH_SYNC_S, MASK_TH_SYNC_S, match_opcode, 0}, +/* Vendor-specific (Ventana Microsystems) XVentanaCondOps instructions */ +{"vt.maskc", 0, INSN_CLASS_XVENTANACONDOPS, "d,s,t", MATCH_VT_MASKC, MASK_VT_MASKC, match_opcode, 0 }, +{"vt.maskcn", 0, INSN_CLASS_XVENTANACONDOPS, "d,s,t", MATCH_VT_MASKCN, MASK_VT_MASKCN, match_opcode, 0 }, + /* Terminate the list. */ {0, 0, INSN_CLASS_NONE, 0, 0, 0, 0, 0} };