target/riscv: add Zicond as an experimental extension
PATCH 1/2 target/riscv: add Zicond as an experimental extension
This implements the Zicond (conditional integer operations) extension, as of version 1.0-draft-20230120 as an experimental extension in QEMU ("x-zicond").
The Zicond extension acts as a building block for branchless sequences including conditional-{arithmetic,logic,select,move}. Refer to the specification for usage scenarios and application guidance.
The following instructions constitute Zicond:
- czero.eqz rd, rs1, rs2 => rd = (rs2 == 0) ? 0 : rs1 - czero.nez rd, rs1, rs2 => rd = (rs2 != 0) ? 0 : rs1
See
https://github.com/riscv/riscv-zicond/releases/download/v1.0-draft-20230120/riscv-zicond_1.0-draft-20230120.pdf
for the (current version of the) Zicond specification and usage details.
---
MAINTAINERS | 7 ++++ target/riscv/cpu.c | 4 ++ target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 4 ++ target/riscv/insn_trans/trans_rvzicond.c.inc | 44 ++++++++++++++++++++ target/riscv/translate.c | 1 + 6 files changed, 61 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzicond.c.inc
MAINTAINERS +7 -0
@@ -295,6 +295,13 @@ F: include/hw/riscv/ F: linux-user/host/riscv32/ F: linux-user/host/riscv64/ +RISC-V Zicond extension +M: Philipp Tomsich <[email protected]> +M: Christoph Muellner <[email protected]> +L: [email protected] +S: Supported +F: target/riscv/insn_trans/trans_zicond.c.inc + RISC-V XVentanaCondOps extension M: Philipp Tomsich <[email protected]> L: [email protected]
target/riscv/cpu.c +4 -0
@@ -73,6 +73,7 @@ struct isa_ext_data {static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (h, false,PRIV_VERSION_1_12_0 , ext_h),ISA_EXT_DATA_ENTRY (v, false,PRIV_VERSION_1_12_0 , ext_v), +ISA_EXT_DATA_ENTRY (zicond, true,PRIV_VERSION_1_12_0 , ext_zicond),ISA_EXT_DATA_ENTRY (zicsr, true,PRIV_VERSION_1_10_0 , ext_icsr),ISA_EXT_DATA_ENTRY (zifencei, true,PRIV_VERSION_1_10_0 , ext_ifencei),ISA_EXT_DATA_ENTRY (zihintpause, true,PRIV_VERSION_1_10_0 , ext_zihintpause),
@@ -1080,6 +1081,9 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false),DEFINE_PROP_BOOL ("x-ssaia" ,RISCVCPU , cfg.ext_ssaia, false), +/* Zicond 1.0-draft-20230120 */ +DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false), + DEFINE_PROP_END_OF_LIST(), };
target/riscv/cpu.h +1 -0
@@ -446,6 +446,7 @@ struct RISCVCPUConfig {bool ext_zkt;bool ext_ifencei;bool ext_icsr; +bool ext_zicond;bool ext_zihintpause;bool ext_smstateen;bool ext_sstc;
target/riscv/insn32.decode +4 -0
@@ -890,3 +890,7 @@ sm3p1 00 01000 01001 ..... 001 ..... 0010011 @r2 # *** RV32 Zksed Standard Extension *** sm4ed .. 11000 ..... ..... 000 ..... 0110011 @k_aes sm4ks .. 11010 ..... ..... 000 ..... 0110011 @k_aes + +# *** Zicond Standard Extension *** +czero_eqz 0000111 ..... ..... 101 ..... 0110011 @r +czero_nez 0000111 ..... ..... 111 ..... 0110011 @r
target/riscv/insn_trans/trans_rvzicond.c.inc new file +44 -0
44 lines not on this page · raw message
target/riscv/translate.c +1 -0
@@ -1061,6 +1061,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" #include "insn_trans/trans_rvzawrs.c.inc" +#include "insn_trans/trans_rvzicond.c.inc" #include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_rvk.c.inc" #include "insn_trans/trans_privileged.c.inc"
Signature · 1 line
2.34.1
PATCH 2/2 target/riscv: redirect XVentanaCondOps to use the Zicond functions
The Zicond standard extension implements the same instruction semantics as XVentanaCondOps, although using different mnemonics and opcodes.
Point XVentanaCondOps to the (newly implemented) Zicond implementation to reduce the future maintenance burden.
Also updating MAINTAINERS as trans_xventanacondops.c.inc will not see active maintenance from here forward.
---
MAINTAINERS | 2 +- .../insn_trans/trans_xventanacondops.c.inc | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-)
MAINTAINERS +1 -1
@@ -305,7 +305,7 @@ F: target/riscv/insn_trans/trans_zicond.c.inc RISC-V XVentanaCondOps extension M: Philipp Tomsich <[email protected]> L: [email protected] -S: Supported +S: Odd Fixes F: target/riscv/XVentanaCondOps.decode F: target/riscv/insn_trans/trans_xventanacondops.c.inc
target/riscv/insn_trans/trans_xventanacondops.c.inc +3 -15
@@ -1,7 +1,7 @@ /* * RISC-V translation routines for the XVentanaCondOps extension. * - * Copyright (c) 2021-2022 VRULL GmbH. + * Copyright (c) 2021-2023 VRULL GmbH. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License,
@@ -16,24 +16,12 @@ * this program. If not, see <http://www.gnu.org/licenses/>. */ -static bool gen_vt_condmask(DisasContext *ctx, arg_r *a, TCGCond cond) -{ - TCGv dest = dest_gpr(ctx, a->rd); - TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); - TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); - - tcg_gen_movcond_tl(cond, dest, src2, ctx->zero, src1, ctx->zero); - - gen_set_gpr(ctx, a->rd, dest); - return true; -} - static bool trans_vt_maskc(DisasContext *ctx, arg_r *a) { - return gen_vt_condmask(ctx, a, TCG_COND_NE); + return trans_czero_eqz(ctx, a); } static bool trans_vt_maskcn(DisasContext *ctx, arg_r *a) { - return gen_vt_condmask(ctx, a, TCG_COND_EQ); + return trans_czero_nez(ctx, a); }
Signature · 1 line
2.34.1