port load_m80
This commit is contained in:
parent
27c14b19c2
commit
d7b81d5bb9
|
@ -157,6 +157,7 @@ function V86Starter(options)
|
|||
"_fwait": function() { return cpu.fpu.fwait(); },
|
||||
|
||||
"_int_log2": function(val) { return v86util.int_log2(val); },
|
||||
"_math_pow": function(x, y) { return Math.pow(x, y); },
|
||||
|
||||
"_do_page_translation": function() { return cpu.do_page_translation.apply(cpu, arguments); },
|
||||
"_read_reg_e16": function() { return cpu.read_reg_e16.apply(cpu, arguments); },
|
||||
|
|
|
@ -115,6 +115,7 @@ FPU.prototype.wasm_patch = function(wm)
|
|||
this.load_status_word = wm.funcs["_fpu_load_status_word"];
|
||||
this.store_m80 = wm.funcs["_fpu_store_m80"];
|
||||
this.set_status_word = wm.funcs["_fpu_set_status_word"];
|
||||
this.load_m80 = wm.funcs["_fpu_load_m80"];
|
||||
};
|
||||
|
||||
FPU.prototype.get_state = function()
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
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);
|
||||
|
||||
#include "const.h"
|
||||
#include "global_pointers.h"
|
||||
|
|
|
@ -91,3 +91,52 @@ void fpu_store_m80(uint32_t addr, double_t n)
|
|||
safe_write16(addr + 8, sign << 8 | exponent);
|
||||
}
|
||||
|
||||
double_t fpu_load_m80(uint32_t addr)
|
||||
{
|
||||
int32_t exponent = safe_read16(addr + 8);
|
||||
uint32_t low = ((uint32_t)(safe_read32s(addr))) >> 0;
|
||||
uint32_t high = ((uint32_t)(safe_read32s(addr + 4))) >> 0;
|
||||
|
||||
int32_t sign = exponent >> 15;
|
||||
exponent &= ~0x8000;
|
||||
|
||||
if(exponent == 0)
|
||||
{
|
||||
// TODO: denormal numbers
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(exponent < 0x7FFF)
|
||||
{
|
||||
exponent -= 0x3FFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: NaN, Infinity
|
||||
//dbg_log("Load m80 TODO", LOG_FPU);
|
||||
fpu_float64_byte[7] = 0x7F | sign << 7;
|
||||
fpu_float64_byte[6] = 0xF0 | high >> 30 << 3 & 0x08;
|
||||
|
||||
fpu_float64_byte[5] = 0;
|
||||
fpu_float64_byte[4] = 0;
|
||||
|
||||
fpu_float64_int[0] = 0;
|
||||
|
||||
return *fpu_float64;
|
||||
}
|
||||
|
||||
// Note: some bits might be lost at this point
|
||||
double_t mantissa = ((double_t)(low)) + 0x100000000 * ((double_t)(high));
|
||||
|
||||
if(sign)
|
||||
{
|
||||
mantissa = -mantissa;
|
||||
}
|
||||
|
||||
// Simply compute the 64 bit floating point number.
|
||||
// An alternative write the mantissa, sign and exponent in the
|
||||
// float64_byte and return float64[0]
|
||||
|
||||
return mantissa * math_pow(2, exponent - 63);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue