Skip to content

Commit 145445f

Browse files
committed
Update diff memcpy with COW optimization
1 parent b333b1d commit 145445f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

difftest/difftest.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,19 @@ void DifftestRef::set_regs(diff_context_t *ctx, bool on_demand) {
245245

246246
void DifftestRef::memcpy_from_dut(reg_t dest, void* src, size_t n) {
247247
while (n) {
248-
char *base = sim->addr_to_mem(dest);
248+
bool is_zero = true;
249+
for (int i=0; i < (PGSIZE/sizeof(uint64_t)); i++) {
250+
if (((uint64_t*)src)[i] != 0) {
251+
is_zero = false;
252+
break;
253+
}
254+
}
255+
249256
size_t n_bytes = (n > PGSIZE) ? PGSIZE : n;
250-
memcpy(base, src, n_bytes);
257+
if (!is_zero) {
258+
char *base = sim->addr_to_mem(dest);
259+
memcpy(base, src, n_bytes);
260+
}
251261
dest += PGSIZE;
252262
src = (char *)src + PGSIZE;
253263
n -= n_bytes;

0 commit comments

Comments
 (0)