Give Rust more indirect function slots and clean up the code
This commit is contained in:
parent
3bb3e21962
commit
38a84342a2
|
@ -105,7 +105,7 @@ function V86Starter(options)
|
||||||
// }, this);
|
// }, this);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
const wasm_table = new WebAssembly.Table({ element: "anyfunc", "initial": 0x10000 + 0x100 });
|
const wasm_table = new WebAssembly.Table({ element: "anyfunc", "initial": WASM_TABLE_SIZE + WASM_TABLE_OFFSET });
|
||||||
|
|
||||||
var wasm_shared_funcs = {
|
var wasm_shared_funcs = {
|
||||||
"__assert_fail": (condition, file, line, fun) => {
|
"__assert_fail": (condition, file, line, fun) => {
|
||||||
|
|
|
@ -358,6 +358,9 @@ const P_RUN_INTERPRETED = 4;
|
||||||
/** @const */
|
/** @const */
|
||||||
var WASM_TABLE_SIZE = 0x10000;
|
var WASM_TABLE_SIZE = 0x10000;
|
||||||
|
|
||||||
|
/** @const */
|
||||||
|
var WASM_TABLE_OFFSET = 1024;
|
||||||
|
|
||||||
/** @const */
|
/** @const */
|
||||||
var JIT_CACHE_ARRAY_SIZE = 0x40000;
|
var JIT_CACHE_ARRAY_SIZE = 0x40000;
|
||||||
|
|
||||||
|
|
|
@ -369,7 +369,7 @@ CPU.prototype.jit_force_generate = function(addr)
|
||||||
CPU.prototype.jit_clear_func = function(index)
|
CPU.prototype.jit_clear_func = function(index)
|
||||||
{
|
{
|
||||||
dbg_assert(index >= 0 && index < WASM_TABLE_SIZE);
|
dbg_assert(index >= 0 && index < WASM_TABLE_SIZE);
|
||||||
this.wm.imports.env[WASM_EXPORT_TABLE_NAME + 0x100].set(index, null);
|
this.wm.imports.env[WASM_EXPORT_TABLE_NAME].set(index + WASM_TABLE_OFFSET, null);
|
||||||
};
|
};
|
||||||
|
|
||||||
CPU.prototype.get_state = function()
|
CPU.prototype.get_state = function()
|
||||||
|
@ -1318,7 +1318,7 @@ CPU.prototype.codegen_finalize = function(wasm_table_index, start, end, first_op
|
||||||
first_opcode, state_flags);
|
first_opcode, state_flags);
|
||||||
|
|
||||||
// The following will throw if f isn't an exported function
|
// The following will throw if f isn't an exported function
|
||||||
this.wm.imports["env"][WASM_EXPORT_TABLE_NAME].set(wasm_table_index + 0x100, f);
|
this.wm.imports["env"][WASM_EXPORT_TABLE_NAME].set(wasm_table_index + WASM_TABLE_OFFSET, f);
|
||||||
|
|
||||||
if(this.test_hook_did_finalize_wasm)
|
if(this.test_hook_did_finalize_wasm)
|
||||||
{
|
{
|
||||||
|
@ -1498,11 +1498,10 @@ CPU.prototype.jit_clear_cache = function()
|
||||||
this.jit_empty_cache();
|
this.jit_empty_cache();
|
||||||
|
|
||||||
const table = this.wm.exports[WASM_EXPORT_TABLE_NAME] || this.wm.imports["env"][WASM_EXPORT_TABLE_NAME];
|
const table = this.wm.exports[WASM_EXPORT_TABLE_NAME] || this.wm.imports["env"][WASM_EXPORT_TABLE_NAME];
|
||||||
const offset = 0x100;
|
|
||||||
|
|
||||||
for(let i = 0; i < WASM_TABLE_SIZE; i++)
|
for(let i = 0; i < WASM_TABLE_SIZE; i++)
|
||||||
{
|
{
|
||||||
table.set(offset + i, null);
|
table.set(WASM_TABLE_OFFSET + i, null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,10 @@ use cpu2::modrm::{resolve_modrm16, resolve_modrm32};
|
||||||
use cpu2::profiler::*;
|
use cpu2::profiler::*;
|
||||||
use cpu2::profiler::{profiler_stat_increment, profiler_stat_increment_by};
|
use cpu2::profiler::{profiler_stat_increment, profiler_stat_increment_by};
|
||||||
|
|
||||||
|
/// The offset for our generated functions in the wasm table. Every index less than this is
|
||||||
|
/// reserved for rustc's indirect functions
|
||||||
|
pub const WASM_TABLE_OFFSET: u32 = 1024;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub union reg64 {
|
pub union reg64 {
|
||||||
|
@ -777,7 +781,7 @@ pub unsafe fn cycle_internal() -> () {
|
||||||
wasm_table_index = (entry & 65535i32 as u32) as u16;
|
wasm_table_index = (entry & 65535i32 as u32) as u16;
|
||||||
initial_state = (entry >> 16i32) as u16;
|
initial_state = (entry >> 16i32) as u16;
|
||||||
call_indirect1(
|
call_indirect1(
|
||||||
(wasm_table_index as u32).wrapping_add(256i32 as u32) as i32,
|
(wasm_table_index as u32).wrapping_add(WASM_TABLE_OFFSET as u32) as i32,
|
||||||
initial_state,
|
initial_state,
|
||||||
);
|
);
|
||||||
profiler_stat_increment_by(
|
profiler_stat_increment_by(
|
||||||
|
|
Loading…
Reference in a new issue