Add RISCV ZALASR Extension
v2 cover Add RISCV ZALASR Extension
Ping, resending as no responses in over week.
V2:
- rebased patch onto master branch
- added check for RV64() for Load Double, as pointed out by Alistair Palmer.
In response to Alistair Palmer (https://lists.gnu.org/archive/html/qemu-riscv/2025-06/msg00010.html):
"Aren't you missing a check to ensure RL is set?"
- There is no need to check if RL is set, as this is required by Spec for all Store Release instructions.
Roan Richmond (1):
Add RISCV ZALASR extension
target/riscv/cpu.c | 1 + target/riscv/insn32.decode | 10 ++ target/riscv/insn_trans/trans_rvzalasr.c.inc | 110 +++++++++++++++++++ target/riscv/translate.c | 1 + 4 files changed, 122 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzalasr.c.inc
Signature · 1 line
2.43.0
PATCH v2 1/1 Add RISCV ZALASR extension
This is based on version v0.8.3 of the ZALASR specification [1]. The specification is listed as in Frozen state [2].
[1]: https://github.com/riscv/riscv-zalasr/tree/v0.8.3
[2]: https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154882/All+RISC-V+Specifications+Under+Active+Development
--- target/riscv/cpu.c | 1 + target/riscv/insn32.decode | 10 ++ target/riscv/insn_trans/trans_rvzalasr.c.inc | 110 +++++++++++++++++++ target/riscv/translate.c | 1 + 4 files changed, 122 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzalasr.c.inc
target/riscv/cpu.c +1 -0
@@ -128,6 +128,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zabha,PRIV_VERSION_1_13_0 , ext_zabha),ISA_EXT_DATA_ENTRY (zacas,PRIV_VERSION_1_12_0 , ext_zacas),ISA_EXT_DATA_ENTRY (zama16b,PRIV_VERSION_1_13_0 , ext_zama16b), +ISA_EXT_DATA_ENTRY (zalasr,PRIV_VERSION_1_12_0 , ext_zalasr),ISA_EXT_DATA_ENTRY (zalrsc,PRIV_VERSION_1_12_0 , ext_zalrsc),ISA_EXT_DATA_ENTRY (zawrs,PRIV_VERSION_1_12_0 , ext_zawrs), ISA_EXT_DATA_ENTRY(zfa, PRIV_VERSION_1_12_0, ext_zfa),
target/riscv/insn32.decode +10 -0
@@ -1066,3 +1066,13 @@ amominu_h 11000 . . ..... ..... 001 ..... 0101111 @atom_st amomaxu_h 11100 . . ..... ..... 001 ..... 0101111 @atom_st amocas_b 00101 . . ..... ..... 000 ..... 0101111 @atom_st amocas_h 00101 . . ..... ..... 001 ..... 0101111 @atom_st + +# *** Zalasr Standard Extension *** +lb_aqrl 00110 . . ..... ..... 000 ..... 0101111 @atom_st +lh_aqrl 00110 . . ..... ..... 001 ..... 0101111 @atom_st +lw_aqrl 00110 . . ..... ..... 010 ..... 0101111 @atom_st +ld_aqrl 00110 . . ..... ..... 011 ..... 0101111 @atom_st +sb_aqrl 00111 . . ..... ..... 000 ..... 0101111 @atom_st +sh_aqrl 00111 . . ..... ..... 001 ..... 0101111 @atom_st +sw_aqrl 00111 . . ..... ..... 010 ..... 0101111 @atom_st +sd_aqrl 00111 . . ..... ..... 011 ..... 0101111 @atom_st
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +110 -0
110 lines not on this page · raw message
target/riscv/translate.c +1 -0
@@ -1183,6 +1183,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvzicond.c.inc" #include "insn_trans/trans_rvzacas.c.inc" #include "insn_trans/trans_rvzabha.c.inc" +#include "insn_trans/trans_rvzalasr.c.inc" #include "insn_trans/trans_rvzawrs.c.inc" #include "insn_trans/trans_rvzicbo.c.inc" #include "insn_trans/trans_rvzimop.c.inc"
Signature · 1 line
2.43.0
Re: [PATCH v2 1/1] Add RISCV ZALASR extension
Quoted 74 lines · Roan Richmond
This is based on version v0.8.3 of the ZALASR specification [1]. The specification is listed as in Frozen state [2].
[1]: https://github.com/riscv/riscv-zalasr/tree/v0.8.3
[2]: https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154882/All+RISC-V+Specifications+Under+Active+DevelopmentSigned-off-by Roan Richmond <[email protected]>--- target/riscv/cpu.c | 1 + target/riscv/insn32.decode | 10 ++ target/riscv/insn_trans/trans_rvzalasr.c.inc | 110 +++++++++++++++++++ target/riscv/translate.c | 1 + 4 files changed, 122 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzalasr.c.inctarget/riscv/cpu.c +1
-0@@ -128,6 +128,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zabha,PRIV_VERSION_1_13_0 , ext_zabha),ISA_EXT_DATA_ENTRY (zacas,PRIV_VERSION_1_12_0 , ext_zacas),ISA_EXT_DATA_ENTRY (zama16b,PRIV_VERSION_1_13_0 , ext_zama16b), +ISA_EXT_DATA_ENTRY (zalasr,PRIV_VERSION_1_12_0 , ext_zalasr),ISA_EXT_DATA_ENTRY (zalrsc,PRIV_VERSION_1_12_0 , ext_zalrsc),ISA_EXT_DATA_ENTRY (zawrs,PRIV_VERSION_1_12_0 , ext_zawrs), ISA_EXT_DATA_ENTRY(zfa, PRIV_VERSION_1_12_0, ext_zfa),target/riscv/insn32.decode +10
-0@@ -1066,3 +1066,13 @@ amominu_h 11000 . . ..... ..... 001 ..... 0101111 @atom_st amomaxu_h 11100 . . ..... ..... 001 ..... 0101111 @atom_st amocas_b 00101 . . ..... ..... 000 ..... 0101111 @atom_st amocas_h 00101 . . ..... ..... 001 ..... 0101111 @atom_st + +# *** Zalasr Standard Extension *** +lb_aqrl 00110 . . ..... ..... 000 ..... 0101111 @atom_st +lh_aqrl 00110 . . ..... ..... 001 ..... 0101111 @atom_st +lw_aqrl 00110 . . ..... ..... 010 ..... 0101111 @atom_st +ld_aqrl 00110 . . ..... ..... 011 ..... 0101111 @atom_st +sb_aqrl 00111 . . ..... ..... 000 ..... 0101111 @atom_st +sh_aqrl 00111 . . ..... ..... 001 ..... 0101111 @atom_st +sw_aqrl 00111 . . ..... ..... 010 ..... 0101111 @atom_st +sd_aqrl 00111 . . ..... ..... 011 ..... 0101111 @atom_sttarget/riscv/insn_trans/trans_rvzalasr.c.inc new file +22
-0@@ -0,0 +1,110 @@ +/* + * RISC-V translation routines for the ZALASR (Load-Aquire and Store-Release) + * Extension. + * + * Copyright (c) 2025 Roan Richmond, [email protected] + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define REQUIRE_ZALASR(ctx) do { \ + if (!ctx->cfg_ptr->ext_zalasr) { \ + return false; \
target/riscv/insn_trans/trans_rvzalasr.c.inc line 32
Quoted 10 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +10
-0+ } \ +} while (0) + +static bool gen_load_acquire(DisasContext *ctx, arg_lb_aqrl *a, MemOp memop) +{ + decode_save_opc(ctx, 0); + + TCGv addr = get_address(ctx, a->rs1, 0); + TCGv dest = get_gpr(ctx, a->rd, EXT_NONE); + TCGBar bar = (a->rl) ? TCG_BAR_STRL : 0;
I think we should check that aq isn't set
Quoted 34 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +34
-0+ + memop |= (ctx->cfg_ptr->ext_zama16b) ? MO_ATOM_WITHIN16 : 0; + + tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop); + gen_set_gpr(ctx, a->rd, dest); + + /* Add a memory barrier implied by AQ (mandatory) and RL (optional) */ + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ | bar); + + return true; +} + +static bool trans_lb_aqrl(DisasContext *ctx, arg_lb_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_SB)); +} + +static bool trans_lh_aqrl(DisasContext *ctx, arg_lh_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TESW)); +} + +static bool trans_lw_aqrl(DisasContext *ctx, arg_lw_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TESL)); +} + +static bool trans_ld_aqrl(DisasContext *ctx, arg_ld_aqrl *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_ZALASR(ctx);
target/riscv/insn_trans/trans_rvzalasr.c.inc line 76
Quoted 10 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +10
-0+ return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TEUQ)); +} + +static bool gen_store_release(DisasContext *ctx, arg_sb_aqrl *a, MemOp memop) +{ + decode_save_opc(ctx, 0); + + TCGv addr = get_address(ctx, a->rs1, 0); + TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); + TCGBar bar = (a->aq) ? TCG_BAR_LDAQ : 0;
and check here that rq isn't set either
Alistair
Quoted 49 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +34
-0+ + memop |= (ctx->cfg_ptr->ext_zama16b) ? MO_ATOM_WITHIN16 : 0; + + /* Add a memory barrier implied by RL (mandatory) and AQ (optional) */ + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL | bar); + + tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop); + return true; +} + +static bool trans_sb_aqrl(DisasContext *ctx, arg_sb_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_SB)); +} + +static bool trans_sh_aqrl(DisasContext *ctx, arg_sh_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TESW)); +} + +static bool trans_sw_aqrl(DisasContext *ctx, arg_sw_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TESL)); +} + +static bool trans_sd_aqrl(DisasContext *ctx, arg_sd_aqrl *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TEUQ)); +}target/riscv/translate.c +1
-1@@ -1183,6 +1183,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvzicond.c.inc" #include "insn_trans/trans_rvzacas.c.inc" #include "insn_trans/trans_rvzabha.c.inc" +#include "insn_trans/trans_rvzalasr.c.inc" #include "insn_trans/trans_rvzawrs.c.inc" #include "insn_trans/trans_rvzicbo.c.inc" #include "insn_trans/trans_rvzimop.c.inc" --2.43.0
Re: [PATCH v2 1/1] Add RISCV ZALASR extension
Quoted 78 lines · Alistair Francis
Quoted 76 lines · Roan Richmond
This is based on version v0.8.3 of the ZALASR specification [1]. The specification is listed as in Frozen state [2].
[1]: https://github.com/riscv/riscv-zalasr/tree/v0.8.3
[2]: https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154882/All+RISC-V+Specifications+Under+Active+DevelopmentSigned-off-by Roan Richmond <[email protected]>--- target/riscv/cpu.c | 1 + target/riscv/insn32.decode | 10 ++ target/riscv/insn_trans/trans_rvzalasr.c.inc | 110 +++++++++++++++++++ target/riscv/translate.c | 1 + 4 files changed, 122 insertions(+)create mode 100644 target/riscv/insn_trans/trans_rvzalasr.c.inc
target/riscv/cpu.c +1
-0@@ -128,6 +128,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zabha,PRIV_VERSION_1_13_0 , ext_zabha),ISA_EXT_DATA_ENTRY (zacas,PRIV_VERSION_1_12_0 , ext_zacas),ISA_EXT_DATA_ENTRY (zama16b,PRIV_VERSION_1_13_0 , ext_zama16b), +ISA_EXT_DATA_ENTRY (zalasr,PRIV_VERSION_1_12_0 , ext_zalasr),ISA_EXT_DATA_ENTRY (zalrsc,PRIV_VERSION_1_12_0 , ext_zalrsc),ISA_EXT_DATA_ENTRY (zawrs,PRIV_VERSION_1_12_0 , ext_zawrs), ISA_EXT_DATA_ENTRY(zfa, PRIV_VERSION_1_12_0, ext_zfa),target/riscv/insn32.decode +10
-0@@ -1066,3 +1066,13 @@ amominu_h 11000 . . ..... ..... 001 ..... 0101111 @atom_st amomaxu_h 11100 . . ..... ..... 001 ..... 0101111 @atom_st amocas_b 00101 . . ..... ..... 000 ..... 0101111 @atom_st amocas_h 00101 . . ..... ..... 001 ..... 0101111 @atom_st + +# *** Zalasr Standard Extension *** +lb_aqrl 00110 . . ..... ..... 000 ..... 0101111 @atom_st +lh_aqrl 00110 . . ..... ..... 001 ..... 0101111 @atom_st +lw_aqrl 00110 . . ..... ..... 010 ..... 0101111 @atom_st +ld_aqrl 00110 . . ..... ..... 011 ..... 0101111 @atom_st +sb_aqrl 00111 . . ..... ..... 000 ..... 0101111 @atom_st +sh_aqrl 00111 . . ..... ..... 001 ..... 0101111 @atom_st +sw_aqrl 00111 . . ..... ..... 010 ..... 0101111 @atom_st +sd_aqrl 00111 . . ..... ..... 011 ..... 0101111 @atom_sttarget/riscv/insn_trans/trans_rvzalasr.c.inc new file +25
-0@@ -0,0 +1,110 @@ +/* + * RISC-V translation routines for the ZALASR (Load-Aquire and Store-Release) + * Extension. + * + * Copyright (c) 2025 Roan Richmond, [email protected] + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define REQUIRE_ZALASR(ctx) do { \ + if (!ctx->cfg_ptr->ext_zalasr) { \ + return false; \ + } \ +} while (0) +
Quoted 8 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc line 32
Quoted 7 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +7
-0+static bool gen_load_acquire(DisasContext *ctx, arg_lb_aqrl *a, MemOp memop) +{ + decode_save_opc(ctx, 0); + + TCGv addr = get_address(ctx, a->rs1, 0); + TCGv dest = get_gpr(ctx, a->rd, EXT_NONE); + TCGBar bar = (a->rl) ? TCG_BAR_STRL : 0;I think we should check that aq isn't set
According to the spec, it is valid for both of rl and aq to be set.
For the Load Acquire instruction it just states that aq must be set, and rl is optionally set. Therefore, I don't think we should check that aq isn't set here.
Quoted 46 lines
Quoted 34 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +34
-0+ + memop |= (ctx->cfg_ptr->ext_zama16b) ? MO_ATOM_WITHIN16 : 0; + + tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop); + gen_set_gpr(ctx, a->rd, dest); + + /* Add a memory barrier implied by AQ (mandatory) and RL (optional) */ + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ | bar); + + return true; +} + +static bool trans_lb_aqrl(DisasContext *ctx, arg_lb_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_SB)); +} + +static bool trans_lh_aqrl(DisasContext *ctx, arg_lh_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TESW)); +} + +static bool trans_lw_aqrl(DisasContext *ctx, arg_lw_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TESL)); +} + +static bool trans_ld_aqrl(DisasContext *ctx, arg_ld_aqrl *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_ZALASR(ctx);target/riscv/insn_trans/trans_rvzalasr.c.inc line 76
Quoted 10 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +10
-0+ return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TEUQ)); +} + +static bool gen_store_release(DisasContext *ctx, arg_sb_aqrl *a, MemOp memop) +{ + decode_save_opc(ctx, 0); + + TCGv addr = get_address(ctx, a->rs1, 0); + TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); + TCGBar bar = (a->aq) ? TCG_BAR_LDAQ : 0;and check here that rq isn't set either
Quoted 1 line
Alistair
For the Store Release instruction it the spec just states that rl must be set, and aq is optionally set. Therefore, I don't think we should check that rl isn't set here.
Quoted 41 lines
Quoted 41 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +34
-0+ + memop |= (ctx->cfg_ptr->ext_zama16b) ? MO_ATOM_WITHIN16 : 0; + + /* Add a memory barrier implied by RL (mandatory) and AQ (optional) */ + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL | bar); + + tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop); + return true; +} + +static bool trans_sb_aqrl(DisasContext *ctx, arg_sb_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_SB)); +} + +static bool trans_sh_aqrl(DisasContext *ctx, arg_sh_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TESW)); +} + +static bool trans_sw_aqrl(DisasContext *ctx, arg_sw_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TESL)); +} + +static bool trans_sd_aqrl(DisasContext *ctx, arg_sd_aqrl *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TEUQ)); +}target/riscv/translate.c +0
-0@@ -1183,6 +1183,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvzicond.c.inc" #include "insn_trans/trans_rvzacas.c.inc"
Quoted 8 lines
Quoted 8 lines
target/riscv/translate.c +1
-1#include "insn_trans/trans_rvzabha.c.inc" +#include "insn_trans/trans_rvzalasr.c.inc" #include "insn_trans/trans_rvzawrs.c.inc" #include "insn_trans/trans_rvzicbo.c.inc" #include "insn_trans/trans_rvzimop.c.inc" --2.43.0
Thanks,
Roan
Signature · 3 lines
Roan Richmond (he/him) Software Engineer Codethink Ltd
Re: [PATCH v2 1/1] Add RISCV ZALASR extension
Quoted 89 lines · Roan Richmond
Quoted 78 lines · Alistair Francis
Quoted 76 lines · Roan Richmond
This is based on version v0.8.3 of the ZALASR specification [1]. The specification is listed as in Frozen state [2].
[1]: https://github.com/riscv/riscv-zalasr/tree/v0.8.3
[2]: https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154882/All+RISC-V+Specifications+Under+Active+DevelopmentSigned-off-by Roan Richmond <[email protected]>--- target/riscv/cpu.c | 1 + target/riscv/insn32.decode | 10 ++ target/riscv/insn_trans/trans_rvzalasr.c.inc | 110 +++++++++++++++++++ target/riscv/translate.c | 1 + 4 files changed, 122 insertions(+)create mode 100644 target/riscv/insn_trans/trans_rvzalasr.c.inc
target/riscv/cpu.c +1
-0@@ -128,6 +128,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zabha,PRIV_VERSION_1_13_0 , ext_zabha),ISA_EXT_DATA_ENTRY (zacas,PRIV_VERSION_1_12_0 , ext_zacas),ISA_EXT_DATA_ENTRY (zama16b,PRIV_VERSION_1_13_0 , ext_zama16b), +ISA_EXT_DATA_ENTRY (zalasr,PRIV_VERSION_1_12_0 , ext_zalasr),ISA_EXT_DATA_ENTRY (zalrsc,PRIV_VERSION_1_12_0 , ext_zalrsc),ISA_EXT_DATA_ENTRY (zawrs,PRIV_VERSION_1_12_0 , ext_zawrs), ISA_EXT_DATA_ENTRY(zfa, PRIV_VERSION_1_12_0, ext_zfa),target/riscv/insn32.decode +10
-0@@ -1066,3 +1066,13 @@ amominu_h 11000 . . ..... ..... 001 ..... 0101111 @atom_st amomaxu_h 11100 . . ..... ..... 001 ..... 0101111 @atom_st amocas_b 00101 . . ..... ..... 000 ..... 0101111 @atom_st amocas_h 00101 . . ..... ..... 001 ..... 0101111 @atom_st + +# *** Zalasr Standard Extension *** +lb_aqrl 00110 . . ..... ..... 000 ..... 0101111 @atom_st +lh_aqrl 00110 . . ..... ..... 001 ..... 0101111 @atom_st +lw_aqrl 00110 . . ..... ..... 010 ..... 0101111 @atom_st +ld_aqrl 00110 . . ..... ..... 011 ..... 0101111 @atom_st +sb_aqrl 00111 . . ..... ..... 000 ..... 0101111 @atom_st +sh_aqrl 00111 . . ..... ..... 001 ..... 0101111 @atom_st +sw_aqrl 00111 . . ..... ..... 010 ..... 0101111 @atom_st +sd_aqrl 00111 . . ..... ..... 011 ..... 0101111 @atom_sttarget/riscv/insn_trans/trans_rvzalasr.c.inc new file +25
-0@@ -0,0 +1,110 @@ +/* + * RISC-V translation routines for the ZALASR (Load-Aquire and Store-Release) + * Extension. + * + * Copyright (c) 2025 Roan Richmond, [email protected] + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define REQUIRE_ZALASR(ctx) do { \ + if (!ctx->cfg_ptr->ext_zalasr) { \ + return false; \ + } \ +} while (0) +Quoted 8 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc line 32
Quoted 7 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +7
-0+static bool gen_load_acquire(DisasContext *ctx, arg_lb_aqrl *a, MemOp memop) +{ + decode_save_opc(ctx, 0); + + TCGv addr = get_address(ctx, a->rs1, 0); + TCGv dest = get_gpr(ctx, a->rd, EXT_NONE); + TCGBar bar = (a->rl) ? TCG_BAR_STRL : 0;I think we should check that aq isn't set
Quoted 1 line
According to the spec, it is valid for both of
rlandaqto be set.
The spec states:
"The versions without the aq bit set are RESERVED"
Quoted 2 lines
For the Load Acquire instruction it just states that
aqmust be set, andrlis optionally set.
Exactly, so we need to ensure that aq is set, otherwise it's an invalid instruction.
Alistair
Quoted 108 lines
Therefore, I don't think we should check that
aqisn't set here.Quoted 46 lines
Quoted 34 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +34
-0+ + memop |= (ctx->cfg_ptr->ext_zama16b) ? MO_ATOM_WITHIN16 : 0; + + tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop); + gen_set_gpr(ctx, a->rd, dest); + + /* Add a memory barrier implied by AQ (mandatory) and RL (optional) */ + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ | bar); + + return true; +} + +static bool trans_lb_aqrl(DisasContext *ctx, arg_lb_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_SB)); +} + +static bool trans_lh_aqrl(DisasContext *ctx, arg_lh_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TESW)); +} + +static bool trans_lw_aqrl(DisasContext *ctx, arg_lw_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TESL)); +} + +static bool trans_ld_aqrl(DisasContext *ctx, arg_ld_aqrl *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_ZALASR(ctx);target/riscv/insn_trans/trans_rvzalasr.c.inc line 76
Quoted 10 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +10
-0+ return gen_load_acquire(ctx, a, (MO_ALIGN | MO_TEUQ)); +} + +static bool gen_store_release(DisasContext *ctx, arg_sb_aqrl *a, MemOp memop) +{ + decode_save_opc(ctx, 0); + + TCGv addr = get_address(ctx, a->rs1, 0); + TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); + TCGBar bar = (a->aq) ? TCG_BAR_LDAQ : 0;and check here that rq isn't set either
Quoted 1 line
Alistair
For the Store Release instruction it the spec just states that
rlmust be set, andaqis optionally set.
Therefore, I don't think we should check thatrlisn't set here.Quoted 41 lines
Quoted 41 lines
target/riscv/insn_trans/trans_rvzalasr.c.inc new file +34
-0+ + memop |= (ctx->cfg_ptr->ext_zama16b) ? MO_ATOM_WITHIN16 : 0; + + /* Add a memory barrier implied by RL (mandatory) and AQ (optional) */ + tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL | bar); + + tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop); + return true; +} + +static bool trans_sb_aqrl(DisasContext *ctx, arg_sb_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_SB)); +} + +static bool trans_sh_aqrl(DisasContext *ctx, arg_sh_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TESW)); +} + +static bool trans_sw_aqrl(DisasContext *ctx, arg_sw_aqrl *a) +{ + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TESL)); +} + +static bool trans_sd_aqrl(DisasContext *ctx, arg_sd_aqrl *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_ZALASR(ctx); + return gen_store_release(ctx, a, (MO_ALIGN | MO_TEUQ)); +}target/riscv/translate.c +0
-0@@ -1183,6 +1183,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvzicond.c.inc" #include "insn_trans/trans_rvzacas.c.inc" Quoted 8 lines
Quoted 8 lines
target/riscv/translate.c +1
-1#include "insn_trans/trans_rvzabha.c.inc" +#include "insn_trans/trans_rvzalasr.c.inc" #include "insn_trans/trans_rvzawrs.c.inc" #include "insn_trans/trans_rvzicbo.c.inc" #include "insn_trans/trans_rvzimop.c.inc" --2.43.0
Thanks,
Roan--
Roan Richmond (he/him)
Software Engineer
Codethink Ltd
Quoted 10 lines · Roan Richmond
Ping, resending as no responses in over week.
V2:
- rebased patch onto master branch
- added check forRV64()for Load Double, as pointed out by Alistair Palmer.In response to Alistair Palmer (https://lists.gnu.org/archive/html/qemu-riscv/2025-06/msg00010.html):
"Aren't you missing a check to ensure RL is set?"
- There is no need to check if RL is set, as this is required by Spec for all Store Release instructions.
I don't follow this justification.
What would happen on real hardware if an invalid instruction is run? It should cause an exception, which is what we should be doing as well.
Alistair
Quoted 14 lines
Roan Richmond (1):
Add RISCV ZALASR extensiontarget/riscv/cpu.c | 1 + target/riscv/insn32.decode | 10 ++ target/riscv/insn_trans/trans_rvzalasr.c.inc | 110 +++++++++++++++++++ target/riscv/translate.c | 1 + 4 files changed, 122 insertions(+) create mode 100644 target/riscv/insn_trans/trans_rvzalasr.c.inc--
2.43.0
Quoted 11 lines · Alistair Francis
Quoted 9 lines · Roan Richmond
Ping, resending as no responses in over week.
V2:
- rebased patch onto master branch
- added check forRV64()for Load Double, as pointed out by Alistair Palmer.In response to Alistair Palmer (https://lists.gnu.org/archive/html/qemu-riscv/2025-06/msg00010.html):
"Aren't you missing a check to ensure RL is set?"
- There is no need to check if RL is set, as this is required by Spec for all Store Release instructions.
Quoted 6 lines
I don't follow this justification.
What would happen on real hardware if an invalid instruction is run? It should cause an exception, which is what we should be doing as well.
Alistair
Ok - I understand the reasoning, For v3 I will add some check to ensure that:
- aq is set for Load Acquire
- rl is set for Store Release
Quoted 10 lines
Quoted 10 lines
Roan Richmond (1):
Add RISCV ZALASR extensiontarget/riscv/cpu.c | 1 + target/riscv/insn32.decode | 10 ++ target/riscv/insn_trans/trans_rvzalasr.c.inc | 110 +++++++++++++++++++ target/riscv/translate.c | 1 + 4 files changed, 122 insertions(+)create mode 100644 target/riscv/insn_trans/trans_rvzalasr.c.inc
Quoted 3 lines
Quoted 3 lines
--
2.43.0
Thanks,
Roan
Signature · 3 lines
Roan Richmond (he/him) Software Engineer Codethink Ltd