Verified Commit 22c98086 authored by Camil Staps's avatar Camil Staps 🙂

Fix wasm version of RtoAC: compute right number of words needed

parent dd6d2353
Pipeline #22253 passed with stages
in 28 minutes and 7 seconds
......@@ -202,6 +202,16 @@ intp = new Uint8Array(intp);
expR: Math.exp,
lnR: Math.log,
log10R: Math.log10,
RtoAC_words_needed: function (v) {
v=Number(0+v).toLocaleString(
['en-US'],
{
useGrouping: false,
maximumSignificantDigits: 15,
}
);
return 2+((v.length+7)>>3);
},
RtoAC: function (dest, v) {
v=Number(0+v).toLocaleString(
['en-US'],
......
......@@ -316,6 +316,7 @@ where
, "(func $clean_expR (import \"clean\" \"expR\") (param f64) (result f64))"
, "(func $clean_lnR (import \"clean\" \"lnR\") (param f64) (result f64))"
, "(func $clean_log10R (import \"clean\" \"log10R\") (param f64) (result f64))"
, "(func $clean_RtoAC_words_needed (import \"clean\" \"RtoAC_words_needed\") (param f64) (result i32))"
, "(func $clean_RtoAC (import \"clean\" \"RtoAC\") (param i32 f64) (result i32))"
, if debug_instructions "(func $clean_debug_instr (import \"clean\" \"debug_instr\") (param i32 i32))" ""
// For illegal instructions, first the handler is called with arguments (pc,instr,asp,bsp,csp,hp,hp_free).
......@@ -402,13 +403,21 @@ instr_mulUUL :: !Target -> Target
instr_mulUUL t = instr_unimplemented t // TODO
instr_RtoAC :: !Target -> Target
instr_RtoAC t = foldl (flip append) (ensure_hp 3 t) // TODO how many blocks are needed depends on the value
[ "(i64.store offset=8 (i32.wrap_i64 (global.get $asp)) (global.get $hp))"
, "(global.set $hp (i64.extend_i32_u (call $clean_RtoAC (i32.wrap_i64 (global.get $hp)) (f64.reinterpret_i64 (i64.load (i32.wrap_i64 (global.get $bsp)))))))"
, "(global.set $pc (i64.add (global.get $pc) (i64.const 8)))"
, "(global.set $asp (i64.add (global.get $asp) (i64.const 8)))"
, "(global.set $bsp (i64.add (global.get $bsp) (i64.const 8)))"
]
instr_RtoAC t = do_rtoac (ensure_hp vi0 (get_words_needed t))
where
vi0 :: Expr TWord
vi0 = EGlobal "i64" "vi0"
get_words_needed = append
"(global.set $vi0 (i64.extend_i32_u (call $clean_RtoAC_words_needed (f64.reinterpret_i64 (i64.load (i32.wrap_i64 (global.get $bsp)))))))"
do_rtoac t = foldl (flip append) t
[ "(i64.store offset=8 (i32.wrap_i64 (global.get $asp)) (global.get $hp))"
, "(global.set $hp (i64.extend_i32_u (call $clean_RtoAC (i32.wrap_i64 (global.get $hp)) (f64.reinterpret_i64 (i64.load (i32.wrap_i64 (global.get $bsp)))))))"
, "(global.set $pc (i64.add (global.get $pc) (i64.const 8)))"
, "(global.set $asp (i64.add (global.get $asp) (i64.const 8)))"
, "(global.set $bsp (i64.add (global.get $bsp) (i64.const 8)))"
]
lit_word :: !Int -> Expr TWord
lit_word i = Ei64_const i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment