diff options
author | Michael Pavone <pavone@retrodev.com> | 2016-10-06 22:25:12 -0700 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2016-10-06 22:25:12 -0700 |
commit | f6eff7d2b0907476b6a47cfe88f896c8dc8f7073 (patch) | |
tree | c2447e74c3b74ca943d256af1fa21507732596a8 /backend_x86.c | |
parent | acea32ab5eb7f2ce704d9e4d939f63daa258471b (diff) |
Made some optimizations to gen_mem_fun to keep the size of chunk handler sections within range of a single byte displacement
Diffstat (limited to 'backend_x86.c')
-rw-r--r-- | backend_x86.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/backend_x86.c b/backend_x86.c index f2bb421..a93a273 100644 --- a/backend_x86.c +++ b/backend_x86.c @@ -81,17 +81,23 @@ code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t n code_ptr lb_jcc = NULL, ub_jcc = NULL; uint16_t access_flag = is_write ? MMAP_WRITE : MMAP_READ; uint32_t ram_flags_off = opts->ram_flags_off; + uint32_t min_address = 0; + uint32_t max_address = opts->max_address; for (uint32_t chunk = 0; chunk < num_chunks; chunk++) { - if (memmap[chunk].start > 0) { + if (memmap[chunk].start > min_address) { cmp_ir(code, memmap[chunk].start, adr_reg, opts->address_size); lb_jcc = code->cur + 1; jcc(code, CC_C, code->cur + 2); + } else { + min_address = memmap[chunk].end; } - if (memmap[chunk].end < opts->max_address) { + if (memmap[chunk].end < max_address) { cmp_ir(code, memmap[chunk].end, adr_reg, opts->address_size); ub_jcc = code->cur + 1; jcc(code, CC_NC, code->cur + 2); + } else { + max_address = memmap[chunk].start; } if (memmap[chunk].mask != opts->address_mask) { @@ -230,7 +236,7 @@ code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t n call(code, opts->save_context); call_args(code, opts->handle_code_write, 2, opts->scratch2, opts->context_reg); mov_rr(code, RAX, opts->context_reg, SZ_PTR); - call(code, opts->load_context); + jmp(code, opts->load_context); *not_code = code->cur - (not_code+1); } retn(code); |