Skip to content

Commit

Permalink
diff memcpy COW optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
tastynoob committed Dec 14, 2023
1 parent b333b1d commit 2897120
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions difftest/difftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2897120

Please sign in to comment.