Temp: Amaan's improvements
This commit is contained in:
parent
171de68b98
commit
d410f567a7
|
@ -126,7 +126,6 @@ function V86Starter(options)
|
|||
"_cpu_exception_hook": (n) => {
|
||||
return this["cpu_exception_hook"] && this["cpu_exception_hook"](n);
|
||||
},
|
||||
"_jit_store_func": function(index) { return cpu.jit_store_func(index); },
|
||||
"_jit_clear_func": function(index) { return cpu.jit_clear_func(index); },
|
||||
"_hlt_op": function() { return cpu.hlt_op(); },
|
||||
"abort": function() { dbg_assert(false); },
|
||||
|
@ -245,7 +244,7 @@ function V86Starter(options)
|
|||
},
|
||||
"_get_time": () => Date.now(),
|
||||
|
||||
"_codegen_finalize": (virt_start, start, end) => cpu.codegen_finalize(virt_start, start, end),
|
||||
"_codegen_finalize": (cache_index, virt_start, start, end) => cpu.codegen_finalize(cache_index, virt_start, start, end),
|
||||
"_codegen_call_cache": (start) => cpu.codegen_call_cache(start),
|
||||
};
|
||||
|
||||
|
|
45
src/cpu.js
45
src/cpu.js
|
@ -16,32 +16,10 @@ function CPU(bus, wm, codegen)
|
|||
this.wm = wm;
|
||||
this.codegen = codegen;
|
||||
this.wasm_patch(wm);
|
||||
this.jit_patch();
|
||||
this.create_jit_imports();
|
||||
|
||||
this.memory_size = new Uint32Array(wm.memory.buffer, 812, 1);
|
||||
|
||||
{
|
||||
const imports = {
|
||||
"e": {
|
||||
"m": this.wm.memory,
|
||||
},
|
||||
};
|
||||
|
||||
const exports = this.wm.instance.exports;
|
||||
|
||||
for(let name of Object.keys(exports))
|
||||
{
|
||||
if(name[0] !== "_")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
imports["e"][name.slice(1)] = exports[name];
|
||||
}
|
||||
|
||||
this.jit_imports = imports;
|
||||
}
|
||||
|
||||
// XXX: Replace with wasm table
|
||||
// XXX: Not garbage collected currently
|
||||
this.instr_cache = Object.create(null);
|
||||
|
@ -260,7 +238,7 @@ function CPU(bus, wm, codegen)
|
|||
//Object.seal(this);
|
||||
}
|
||||
|
||||
CPU.prototype.jit_patch = function()
|
||||
CPU.prototype.create_jit_imports = function()
|
||||
{
|
||||
// Set this.jit_imports as generated WASM modules will expect
|
||||
const imports = {
|
||||
|
@ -428,16 +406,6 @@ CPU.prototype.wasm_patch = function(wm)
|
|||
this.fxrstor = this.wm.exports['_fxrstor'];
|
||||
};
|
||||
|
||||
CPU.prototype.jit_store_func = function(index)
|
||||
{
|
||||
const gen = this.codegen;
|
||||
let buf = gen.get_module_code();
|
||||
const module = new WebAssembly.Module(buf);
|
||||
const o = new WebAssembly.Instance(module, this.jit_imports);
|
||||
// The following will throw if o.exports.f isn't an exported function
|
||||
this.wm.imports.env.table.set(index, o["exports"]["f"]);
|
||||
};
|
||||
|
||||
CPU.prototype.jit_clear_func = function(index)
|
||||
{
|
||||
this.wm.imports.env.table.set(index, null);
|
||||
|
@ -1416,7 +1384,7 @@ CPU.prototype.codegen_call_cache = function(start)
|
|||
//dbg_log("cached code block from " + h(before) + " to " + h(after));
|
||||
};
|
||||
|
||||
CPU.prototype.codegen_finalize = function(virtual_start, start, end)
|
||||
CPU.prototype.codegen_finalize = function(cache_index, virtual_start, start, end)
|
||||
{
|
||||
dbg_log("finalize");
|
||||
const code = this.codegen.get_module_code();
|
||||
|
@ -1467,6 +1435,9 @@ CPU.prototype.codegen_finalize = function(virtual_start, start, end)
|
|||
|
||||
this.instr_cache[start] = f;
|
||||
|
||||
// The following will throw if o.exports.f isn't an exported function
|
||||
this.wm.imports.env.table.set(cache_index, f);
|
||||
|
||||
this.instruction_pointer[0] = virtual_start;
|
||||
|
||||
const before = this.instruction_pointer[0];
|
||||
|
@ -4221,8 +4192,8 @@ CPU.prototype.update_cs_size = function(new_size)
|
|||
|
||||
if(Boolean(this.is_32[0]) !== new_size)
|
||||
{
|
||||
dbg_log("clear instruction cache", LOG_CPU);
|
||||
this.wm.exports["_jit_empty_cache"]();
|
||||
//dbg_log("clear instruction cache", LOG_CPU);
|
||||
//this.wm.exports["_jit_empty_cache"]();
|
||||
|
||||
this.is_32[0] = +new_size;
|
||||
this.update_operand_size();
|
||||
|
|
|
@ -251,7 +251,7 @@ uint32_t jit_hot_hash(uint32_t addr)
|
|||
}
|
||||
|
||||
static void jit_instruction(int32_t);
|
||||
void codegen_finalize(int32_t, int32_t, int32_t);
|
||||
void codegen_finalize(int32_t, int32_t, int32_t, int32_t);
|
||||
void codegen_call_cache(int32_t);
|
||||
|
||||
void generate_instruction(int32_t opcode)
|
||||
|
@ -297,9 +297,13 @@ void cycle_internal()
|
|||
const bool JIT_ALWAYS = false;
|
||||
const bool JIT_DONT_USE_CACHE = false;
|
||||
|
||||
if(cached && !clean)
|
||||
{
|
||||
//jit_clear_func(addr_index);
|
||||
}
|
||||
|
||||
if(!JIT_DONT_USE_CACHE &&
|
||||
entry->group_status == group_dirtiness[phys_addr >> DIRTY_ARR_SHIFT] &&
|
||||
entry->start_addr == phys_addr)
|
||||
cached && clean)
|
||||
{
|
||||
// XXX: With the code-generation, we need to figure out how we
|
||||
// would call the function from the other module here; likely
|
||||
|
@ -318,7 +322,8 @@ void cycle_internal()
|
|||
(*timestamp_counter)++;
|
||||
}*/
|
||||
|
||||
codegen_call_cache(phys_addr);
|
||||
//codegen_call_cache(phys_addr);
|
||||
call_indirect(addr_index);
|
||||
|
||||
// XXX: Try to find an assert to detect self-modifying code
|
||||
// JIT compiled self-modifying basic blocks may trigger this assert
|
||||
|
@ -368,7 +373,7 @@ void cycle_internal()
|
|||
gen_finish();
|
||||
jit_in_progress = false;
|
||||
|
||||
codegen_finalize(start_addr, entry->start_addr, entry->end_addr);
|
||||
codegen_finalize(addr_index, start_addr, entry->start_addr, entry->end_addr);
|
||||
|
||||
assert(*prefixes == 0);
|
||||
|
||||
|
|
|
@ -53,6 +53,6 @@ int32_t hot_code_addresses[HASH_PRIME] = {0};
|
|||
uint32_t group_dirtiness[1 + (0xffffffff >> DIRTY_ARR_SHIFT)] = {0};
|
||||
|
||||
void call_indirect(int32_t index);
|
||||
void jit_store_func(int32_t index);
|
||||
void jit_clear_func(int32_t index);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue