Skip to content

Commit 112f2fd

Browse files
authored
feat(Store_event): refactor vector store check (#985)
1 parent 3e47742 commit 112f2fd

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

src/cpu/cpu-exec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ void cpu_exec(uint64_t n) {
837837
cpu.amo = false; // clean up
838838
cpu.pbmt = 0;
839839
cpu.isVldst = false;
840+
cpu.isVecUnitStore = false;
840841

841842
// No need to settle instruction counting here, as it is done in longjmp handler.
842843
// It's necessary to flush tcache for exception: addr space may conflict in different priv/mmu mode.

src/isa/riscv64/include/isa-def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ typedef struct {
156156
bool amo;
157157
uint32_t pbmt;
158158
bool isVldst;
159+
bool isVecUnitStore;
159160
int mem_exception;
160161

161162
#ifdef CONFIG_TVAL_EX_II

src/isa/riscv64/instr/rvv/vldst_impl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,12 @@ void vst(Decode *s, int mode, int mmu_mode) {
541541
if (mode == MODE_STRIDED) {
542542
stride = id_src2->val;
543543
is_unit_stride = 0;
544+
cpu.isVecUnitStore = false;
544545
} else {
545546
stride = 0;
546547
is_unit_stride = 1;
547548
g_nr_vst_unit += 1;
549+
cpu.isVecUnitStore = s->v_nf == 0;
548550
}
549551
// previous decode does not load vals for us
550552
rtl_lr(s, &(s->src1.val), s->src1.reg, 4);
@@ -676,6 +678,7 @@ void vst(Decode *s, int mode, int mmu_mode) {
676678

677679
vstart->val = 0;
678680
cpu.isVldst = false;
681+
cpu.isVecUnitStore = false;
679682
vp_set_dirty();
680683
}
681684

@@ -842,6 +845,7 @@ void vsr(Decode *s, int mmu_mode) {
842845

843846
isa_whole_reg_check(vd, len);
844847

848+
cpu.isVecUnitStore = true;
845849
if (vstart->val < size) {
846850
vreg_idx = vstart->val / elt_per_reg;
847851
offset = vstart->val % elt_per_reg;
@@ -881,6 +885,7 @@ void vsr(Decode *s, int mmu_mode) {
881885

882886
vstart->val = 0;
883887
cpu.isVldst = false;
888+
cpu.isVecUnitStore = false;
884889
vp_set_dirty();
885890
}
886891

src/memory/paddr.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ void miss_align_store_commit_queue_push(uint64_t addr, uint64_t data, int len) {
578578
}
579579
}
580580

581+
#define GEN_BYTE_MASK(len) ((1ULL << (len)) - 1)
582+
#define GEN_BIT_MASK(len) ((len) >= 8 ? (~0ULL) : ((1ULL << ((len) * 8)) - 1))
583+
581584
void store_commit_queue_push(uint64_t addr, uint64_t data, int len, int cross_page_store) {
582585
#ifndef CONFIG_DIFFTEST_STORE_COMMIT_AMO
583586
if (cpu.amo) {
@@ -587,14 +590,51 @@ void store_commit_queue_push(uint64_t addr, uint64_t data, int len, int cross_pa
587590
#ifdef CONFIG_AC_NONE
588591
uint8_t store_miss_align = (addr & (len - 1)) != 0;
589592
if (unlikely(store_miss_align)) {
590-
if (!cross_page_store) {
593+
if (!cross_page_store && !cpu.isVecUnitStore) {
591594
miss_align_store_commit_queue_push(addr, data, len);
592595
return;
593596
}
594597
}
595598
#endif // CONFIG_AC_NONE
596599
Logm("push store addr = " FMT_PADDR ", data = " FMT_WORD ", len = %d", addr, data, len);
597600
store_commit_t store_commit;
601+
602+
if (cpu.isVecUnitStore)
603+
{
604+
bool isCross128Bit = (addr & 0xF) + len > 16;
605+
606+
if (isCross128Bit)
607+
{
608+
paddr_t offset_in_block = addr & 0xF;
609+
paddr_t space_left = 16 - offset_in_block;
610+
611+
paddr_t low_addr = addr;
612+
uint8_t low_len = space_left;
613+
uint16_t low_mask = (1U << low_len) - 1;
614+
word_t low_data = data & ((1ULL << low_len * 8) - 1);
615+
616+
paddr_t high_addr = addr + space_left;
617+
uint8_t high_len = len - space_left;
618+
uint16_t high_mask = (1U << high_len) - 1;
619+
word_t high_data = data >> (low_len * 8);
620+
621+
store_commit_t low_store_commit = {low_addr, low_data, low_mask, prev_s->pc};
622+
store_commit_t high_store_commit = {high_addr, high_data, high_mask, prev_s->pc};
623+
624+
store_queue_push(low_store_commit);
625+
store_queue_push(high_store_commit);
626+
627+
return;
628+
}
629+
store_commit.data = data & GEN_BIT_MASK(len);
630+
store_commit.mask = GEN_BYTE_MASK(len);
631+
assert(len <= 8);
632+
store_commit.addr = addr;
633+
store_commit.pc = prev_s->pc;
634+
635+
store_queue_push(store_commit);
636+
return;
637+
}
598638
uint64_t offset = addr % 8ULL;
599639
store_commit.addr = addr - offset;
600640
switch (len) {

src/memory/store_queue_wrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void store_queue_reset() {
2929
}
3030

3131
void store_queue_push(store_commit_t store_commit) {
32+
Logm("push store addr = " FMT_PADDR ", data = " FMT_WORD ", mask = 0x%x", store_commit.addr, store_commit.data, store_commit.mask);
3233
cpp_store_event_queue.push(store_commit);
3334
}
3435

0 commit comments

Comments
 (0)