From 1faec0e66945e5f17154eab48c770330ef603d23 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 25 Jan 2018 14:14:10 -0600 Subject: [PATCH] Remove math_pow, move declarations from shared.h to cpu.h --- src/browser/starter.js | 5 +++- src/native/cpu.h | 51 +++++++++++++++++++++++++++++++++ src/native/fpu.c | 2 +- src/native/js_imports.h | 5 ++++ src/native/memory.h | 2 ++ src/native/shared.h | 62 ----------------------------------------- src/native/sse_instr.h | 2 +- 7 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/browser/starter.js b/src/browser/starter.js index d27ec23a..ff2732e6 100644 --- a/src/browser/starter.js +++ b/src/browser/starter.js @@ -173,7 +173,6 @@ function V86Starter(options) "_mmap_write32": function(addr, value) { return cpu.mmap_write32(addr, value); }, "_int_log2": function(val) { return v86util.int_log2(val); }, - "_math_pow": function(x, y) { return Math.pow(x, y); }, "_popa16": function() { return cpu.popa16.apply(cpu, arguments); }, "_popa32": function() { return cpu.popa32.apply(cpu, arguments); }, @@ -223,6 +222,7 @@ function V86Starter(options) "_codegen_finalize": (cache_index, virt_start, start, end) => cpu.codegen_finalize(cache_index, virt_start, start, end), + // see https://github.com/kripken/emscripten/blob/incoming/src/library.js "_atan2": Math.atan2, "_sin": Math.sin, "_cos": Math.cos, @@ -232,6 +232,9 @@ function V86Starter(options) "_llvm_exp2_f64": (x) => Math.pow(2, x), "_log": Math.log, "_round": Math.round, + "_ldexp": function(x, exp) { + return x * Math.pow(2, exp); + }, }; const wasm_globals = { diff --git a/src/native/cpu.h b/src/native/cpu.h index 50a93cbb..3282a3a2 100644 --- a/src/native/cpu.h +++ b/src/native/cpu.h @@ -1,8 +1,59 @@ #pragma once #include +#include #include "shared.h" +#include "const.h" + +union reg128 { + int8_t i8[16]; + int16_t i16[8]; + int32_t i32[4]; + int64_t i64[2]; + uint8_t u8[16]; + uint16_t u16[8]; + uint32_t u32[4]; + uint64_t u64[2]; +}; +typedef char assert_size_reg128[(sizeof(union reg128) == 16) * 2 - 1]; + +union reg64 { + int8_t i8[8]; + int16_t i16[4]; + int32_t i32[2]; + int64_t i64[1]; + uint8_t u8[8]; + uint16_t u16[4]; + uint32_t u32[2]; + uint64_t u64[1]; + double f64[1]; +}; +typedef char assertion_size_reg64[(sizeof(union reg64) == 8) * 2 - 1]; + +struct code_cache { + // Address of the start of the basic block + uint32_t start_addr; + uint32_t end_addr; + // Address of the instruction immediately after the basic block ends + int32_t opcode[1]; // TODO: Remove in debug mode + int32_t len; + int32_t is_32; + // Cleanliness status of the entry's "group" (based on + // DIRTY_ARR_SHIFT). Value only has meaning in relation with the + // group_dirtiness value. + uint32_t group_status; +}; +struct code_cache jit_cache_arr[WASM_TABLE_SIZE]; + +// Flag indicating whether the instruction that just ran was a jump of some sort +extern uint32_t jit_jump; + +// Count of how many times prime_hash(address) has been called through a jump +extern int32_t hot_code_addresses[HASH_PRIME]; +// An array indicating the current "initial group status" for entries that map +// to the same group due to the shift +extern uint32_t group_dirtiness[GROUP_DIRTINESS_LENGTH]; void after_jump(void); void diverged(void); diff --git a/src/native/fpu.c b/src/native/fpu.c index 886efdc0..267571f1 100644 --- a/src/native/fpu.c +++ b/src/native/fpu.c @@ -187,7 +187,7 @@ double_t fpu_load_m80(uint32_t addr) // An alternative write the mantissa, sign and exponent in the // float64_byte and return float64[0] - return mantissa * math_pow(2, exponent - 63); + return mantissa * pow(2, exponent - 63); } void fpu_stack_fault() diff --git a/src/native/js_imports.h b/src/native/js_imports.h index 6dfcc502..da909095 100644 --- a/src/native/js_imports.h +++ b/src/native/js_imports.h @@ -64,3 +64,8 @@ extern void io_port_write8(int32_t, int32_t); extern void io_port_write16(int32_t, int32_t); extern void io_port_write32(int32_t, int32_t); extern int32_t convert_f64_to_i32(double_t); +extern void call_indirect(int32_t index); +extern void jit_clear_func(int32_t index); +extern void call_interrupt_vector(int32_t interrupt_nr, bool is_software_int, bool has_error_code, int32_t error_code); +extern void throw_cpu_exception(void); +extern double_t microtick(void); diff --git a/src/native/memory.h b/src/native/memory.h index 072a4ba4..4a6f6f44 100644 --- a/src/native/memory.h +++ b/src/native/memory.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include "cpu.h" bool in_mapped_range(uint32_t addr); void jit_dirty_cache(uint32_t start_addr, uint32_t end_addr); diff --git a/src/native/shared.h b/src/native/shared.h index 5c117785..6f70f09b 100644 --- a/src/native/shared.h +++ b/src/native/shared.h @@ -1,63 +1 @@ #pragma once - -#include -#include -#include - -#include "const.h" - -union reg128 { - int8_t i8[16]; - int16_t i16[8]; - int32_t i32[4]; - int64_t i64[2]; - uint8_t u8[16]; - uint16_t u16[8]; - uint32_t u32[4]; - uint64_t u64[2]; -}; -typedef char assert_size_reg128[(sizeof(union reg128) == 16) * 2 - 1]; - -union reg64 { - int8_t i8[8]; - int16_t i16[4]; - int32_t i32[2]; - int64_t i64[1]; - uint8_t u8[8]; - uint16_t u16[4]; - uint32_t u32[2]; - uint64_t u64[1]; - double f64[1]; -}; -typedef char assertion_size_reg64[(sizeof(union reg64) == 8) * 2 - 1]; - -struct code_cache { - // Address of the start of the basic block - uint32_t start_addr; - uint32_t end_addr; - // Address of the instruction immediately after the basic block ends - int32_t opcode[1]; // TODO: Remove in debug mode - int32_t len; - int32_t is_32; - // Cleanliness status of the entry's "group" (based on - // DIRTY_ARR_SHIFT). Value only has meaning in relation with the - // group_dirtiness value. - uint32_t group_status; -}; -struct code_cache jit_cache_arr[WASM_TABLE_SIZE]; - -// Flag indicating whether the instruction that just ran was a jump of some sort -extern uint32_t jit_jump; - -// Count of how many times prime_hash(address) has been called through a jump -extern int32_t hot_code_addresses[HASH_PRIME]; -// An array indicating the current "initial group status" for entries that map -// to the same group due to the shift -extern uint32_t group_dirtiness[GROUP_DIRTINESS_LENGTH]; - -extern void call_indirect(int32_t index); -extern void jit_clear_func(int32_t index); -extern void call_interrupt_vector(int32_t interrupt_nr, bool is_software_int, bool has_error_code, int32_t error_code); -extern void throw_cpu_exception(void); -extern double_t math_pow(double_t, double_t); -extern double_t microtick(void); diff --git a/src/native/sse_instr.h b/src/native/sse_instr.h index abbf43c4..874f027e 100644 --- a/src/native/sse_instr.h +++ b/src/native/sse_instr.h @@ -2,7 +2,7 @@ #include -#include "shared.h" +#include "cpu.h" void mov_r_m64(int32_t addr, int32_t r); void movl_r128_m64(int32_t addr, int32_t r);