Skip to content

Commit da979d0

Browse files
committed
riscv: Make mzero zero exact matrix register bytes
Emit exact-width stores in mzero so matrix register clearing never rounds up past the selected register size and clobbers adjacent storage.
1 parent 14282c5 commit da979d0

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

target/riscv/insn_trans/trans_rvmm.c.inc

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,20 +483,29 @@ static bool trans_mzero(DisasContext *s, arg_mm_i *a)
483483
len = get_rows(s) * get_rows(s) * (s->cfg_ptr->melen / 8);
484484
}
485485

486-
/* tcg_gen_gvec_dup_imm encodes maxsz in SIMD_MAXSZ_BITS (8 bits, max
487-
* 2040 bytes). Large matrix registers exceed this, so zero in chunks. */
488-
#define MZERO_GVEC_CHUNK 2040U
489-
uint32_t total = ROUND_UP(len, 8);
490486
uint32_t base_ofs = mregs_ofs(s, a->md);
491-
for (uint32_t off = 0; off < total; off += MZERO_GVEC_CHUNK) {
492-
uint32_t this_len = MIN(total - off, MZERO_GVEC_CHUNK);
493-
this_len = ROUND_UP(this_len, 8);
494-
tcg_gen_gvec_dup_imm(MO_64, base_ofs + off, this_len, this_len, 0);
487+
TCGv_i64 zero = tcg_constant_i64(0);
488+
uint32_t off = 0;
489+
490+
while (len - off >= 8) {
491+
tcg_gen_st_i64(zero, tcg_env, base_ofs + off);
492+
off += 8;
493+
}
494+
if (len - off >= 4) {
495+
tcg_gen_st32_i64(zero, tcg_env, base_ofs + off);
496+
off += 4;
497+
}
498+
if (len - off >= 2) {
499+
tcg_gen_st16_i64(zero, tcg_env, base_ofs + off);
500+
off += 2;
501+
}
502+
if (len - off >= 1) {
503+
tcg_gen_st8_i64(zero, tcg_env, base_ofs + off);
495504
}
496-
#undef MZERO_GVEC_CHUNK
497505
return true;
498506
}
499507

508+
500509
static bool trans_minit(DisasContext *s, arg_empty *a)
501510
{
502511
if (!require_matrix(s)) {

0 commit comments

Comments
 (0)