From 145445f218a224e2aaef763e027d94b7b49ba0e4 Mon Sep 17 00:00:00 2001 From: tastynoob <934348725@qq.com> Date: Wed, 13 Dec 2023 18:18:51 +0800 Subject: [PATCH] Update diff memcpy with COW optimization --- difftest/difftest.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/difftest/difftest.cc b/difftest/difftest.cc index e20405f6e7..8dc3dccd7e 100644 --- a/difftest/difftest.cc +++ b/difftest/difftest.cc @@ -245,9 +245,19 @@ void DifftestRef::set_regs(diff_context_t *ctx, bool on_demand) { void DifftestRef::memcpy_from_dut(reg_t dest, void* src, size_t n) { while (n) { - char *base = sim->addr_to_mem(dest); + bool is_zero = true; + for (int i=0; i < (PGSIZE/sizeof(uint64_t)); i++) { + if (((uint64_t*)src)[i] != 0) { + is_zero = false; + break; + } + } + size_t n_bytes = (n > PGSIZE) ? PGSIZE : n; - memcpy(base, src, n_bytes); + if (!is_zero) { + char *base = sim->addr_to_mem(dest); + memcpy(base, src, n_bytes); + } dest += PGSIZE; src = (char *)src + PGSIZE; n -= n_bytes;