Skip to contentSkip to conversation

Support the true Zicclsm extension

PATCH Superseded [email protected] 1 participant 5 messages May 13 RISC-V

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Support the true Zicclsm extension

From: Frank Chang <[email protected]>

Support the true Zicclsm extension so that we can trap misaligned accesses when the extension is disabled.

Zicclsm is set to true by default to be backwards compatible with the old RISC-V QEMU design.

To disable Zicclsm, simply set zicclsm=false, e.g.:
-cpu rv64,zicclsm=false

QEMU will raise a misaligned load/store exception when executing misaligned load/store instructions.

Changelog:
v2:
* Use (size_memop(size) | mo_endian_env(env)) to calculate MemOp.
* Use (log2_esz << MO_ASHIFT) to calculate aligment MemOp for vector load/store whole register instructions.

Frank Chang (4):
target/riscv: Add Zicclsm CPU option
target/riscv: Support raising misaligned exceptions for scalar
loads/stores
target/riscv: Support raising misaligned exceptions for vector
loads/stores
target/riscv: Expose Zicclsm extension as a CPU property

 target/riscv/cpu.c                      |  4 +-
 target/riscv/cpu_cfg_fields.h.inc       |  2 +
 target/riscv/insn_trans/trans_rvi.c.inc |  6 +++
 target/riscv/insn_trans/trans_rvv.c.inc | 18 +++++--
 target/riscv/vector_helper.c            | 65 +++++++++++++++++++------
 5 files changed, 76 insertions(+), 19 deletions(-)

--
2.43.0

#1 lore raw

PATCH v2 1/4 target/riscv: Add Zicclsm CPU option

From: Frank Chang <[email protected]>

Add Zicclsm CPU option so that user can turn on/off misaligned loads and stores support.

---
 target/riscv/cpu.c                | 2 +-
 target/riscv/cpu_cfg_fields.h.inc | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
index a13727c0d4b..468055ee090 100644
@@ -127,7 +127,7 @@ const RISCVIsaExtData isa_edata_arr[] = {
     ISA_EXT_DATA_ENTRY(zicboz, PRIV_VERSION_1_12_0, ext_zicboz),
     ISA_EXT_DATA_ENTRY(ziccamoa, PRIV_VERSION_1_11_0, has_priv_1_11),
     ISA_EXT_DATA_ENTRY(ziccif, PRIV_VERSION_1_11_0, has_priv_1_11),
-    ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, has_priv_1_11),
+    ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, ext_zicclsm),
     ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, ext_ziccrse),
     ISA_EXT_DATA_ENTRY(zicfilp, PRIV_VERSION_1_12_0, ext_zicfilp),
     ISA_EXT_DATA_ENTRY(zicfiss, PRIV_VERSION_1_13_0, ext_zicfiss),
target/riscv/cpu_cfg_fields.h.inc +2 -0
index 734fa079f28..fc55dc6d892 100644
@@ -139,6 +139,8 @@ BOOL_FIELD(has_priv_1_11)
 /* Always enabled for TCG if has_priv_1_11 */
 BOOL_FIELD(ext_ziccrse)
 
+BOOL_FIELD(ext_zicclsm)
+
 /* Vendor-specific custom extensions */
 BOOL_FIELD(ext_xtheadba)
 BOOL_FIELD(ext_xtheadbb)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/4 target/riscv: Support raising misaligned exceptions for scalar loads/stores

In reply to [email protected]

From: Frank Chang <[email protected]>

When the Zicclsm extension is not enabled, raise misaligned load/store exceptions for misaligned accesses from scalar load/store instructions.

---
 target/riscv/insn_trans/trans_rvi.c.inc | 6 ++++++
 1 file changed, 6 insertions(+)
target/riscv/insn_trans/trans_rvi.c.inc +6 -0
index 2c82ae41a77..2662fc5c2a2 100644
@@ -413,6 +413,9 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemOp memop)
     if (ctx->cfg_ptr->ext_zama16b) {
         memop |= MO_ATOM_WITHIN16;
     }
+    if (!ctx->cfg_ptr->ext_zicclsm) {
+        memop |= MO_ALIGN;
+    }
     decode_save_opc(ctx, 0);
     if (get_xl(ctx) == MXL_RV128) {
         out = gen_load_i128(ctx, a, memop);
@@ -524,6 +527,9 @@ static bool gen_store(DisasContext *ctx, arg_sb *a, MemOp memop)
     if (ctx->cfg_ptr->ext_zama16b) {
         memop |= MO_ATOM_WITHIN16;
     }
+    if (!ctx->cfg_ptr->ext_zicclsm) {
+        memop |= MO_ALIGN;
+    }
     decode_save_opc(ctx, 0);
     if (get_xl(ctx) == MXL_RV128) {
         return gen_store_i128(ctx, a, memop);
Signature · 1 line
2.43.0
#3 lore raw

PATCH v2 3/4 target/riscv: Support raising misaligned exceptions for vector loads/stores

In reply to [email protected]

From: Frank Chang <[email protected]>

When the Zicclsm extension is not enabled, raise misaligned load/store exceptions for misaligned accesses from vector load/store instructions.

We will skip the host fast-path and fall back to the slow TLB-path to raise misaligned load/store exceptions for the misaligned accesses when Zicclsm extension is disabled.

---
 target/riscv/insn_trans/trans_rvv.c.inc | 18 +++++--
 target/riscv/vector_helper.c            | 65 +++++++++++++++++++------
 2 files changed, 65 insertions(+), 18 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +15 -3
index e65356eb7c5..9af628d23f8 100644
@@ -1191,26 +1191,38 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf,
      * Use the helper function if either:
      * - vstart is not 0.
      */
-
     bool use_helper_fn = !s->vstart_eq_zero;
 
     if (!use_helper_fn) {
         uint32_t size = s->cfg_ptr->vlenb * nf;
         TCGv_i64 t8 = tcg_temp_new_i64();
         MemOp atomicity = MO_ATOM_NONE;
+        MemOp alignment = MO_UNALN;
+
+        /*
+         * If Zicclsm is disabled, require alignment based on element size.
+         * Use MO_ALIGN_* based on log2_esz (0 = MO_UNALN, 1 = MO_ALIGN_2, etc).
+         */
+        if (!s->cfg_ptr->ext_zicclsm) {
+            alignment = log2_esz << MO_ASHIFT;
+        }
+
         if (log2_esz == 0) {
             atomicity = MO_ATOM_NONE;
         } else {
             atomicity = MO_ATOM_IFALIGN_PAIR;
         }
+
         for (int i = 0; i < size; i += 8) {
             TCGv addr = get_address(s, rs1, i);
             if (is_load) {
-                tcg_gen_qemu_ld_i64(t8, addr, s->mem_idx, MO_LEUQ | atomicity);
+                tcg_gen_qemu_ld_i64(t8, addr, s->mem_idx,
+                                    MO_LEUQ | atomicity | alignment);
                 tcg_gen_st_i64(t8, tcg_env, vreg_ofs(s, vd) + i);
             } else {
                 tcg_gen_ld_i64(t8, tcg_env, vreg_ofs(s, vd) + i);
-                tcg_gen_qemu_st_i64(t8, addr, s->mem_idx, MO_LEUQ | atomicity);
+                tcg_gen_qemu_st_i64(t8, addr, s->mem_idx,
+                                    MO_LEUQ | atomicity | alignment);
             }
             if (i == size - 8) {
                 tcg_gen_movi_tl(cpu_vstart, 0);
target/riscv/vector_helper.c +50 -15

107 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

PATCH v2 4/4 target/riscv: Expose Zicclsm extension as a CPU property

In reply to [email protected]

From: Frank Chang <[email protected]>

Expose Zicclsm extension as a CPU property to allow user to turn on/off Zicclsm extension.

Zicclsm is set to true by default to be backward compatible with the old RISC-V QEMU design.

---
 target/riscv/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target/riscv/cpu.c +2 -0
index 468055ee090..2456963904d 100644
@@ -1327,6 +1327,8 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
     MULTI_EXT_CFG_BOOL("zicbop", ext_zicbop, true),
     MULTI_EXT_CFG_BOOL("zicboz", ext_zicboz, true),
 
+    MULTI_EXT_CFG_BOOL("zicclsm", ext_zicclsm, true),
+
     MULTI_EXT_CFG_BOOL("zmmul", ext_zmmul, false),
 
     MULTI_EXT_CFG_BOOL("zca", ext_zca, false),
Signature · 1 line
2.43.0