Browse Source

fix wat

master
Gabriel Pariat 3 years ago
parent
commit
a4032ce41c
  1. 144
      implementations/wasm/lisp.wat

144
implementations/wasm/lisp.wat

@ -732,8 +732,8 @@
(local $rest i32) (local $rest i32)
(if (i64.eqz (local.get $mantissa)) (if (i64.eqz (local.get $mantissa))
(if (i32.eqz (local.get $sign)) (if (i32.eqz (local.get $sign))
(then (return (f64.reinterpret/i64 (global.get $f64-plus-zero)))) (then (return (f64.reinterpret_i64 (global.get $f64-plus-zero))))
(else (return (f64.reinterpret/i64 (global.get $f64-minus-zero)))))) (else (return (f64.reinterpret_i64 (global.get $f64-minus-zero))))))
(local.set $whole (local.get $mantissa)) (local.set $whole (local.get $mantissa))
(if (i32.gt_s (local.get $exponent) (i32.const 0)) (if (i32.gt_s (local.get $exponent) (i32.const 0))
@ -767,7 +767,7 @@
(br_if $break (i32.eqz (local.get $exponent))) (br_if $break (i32.eqz (local.get $exponent)))
(local.set $exponent (i32.add (local.get $exponent) (i32.const 1))) (local.set $exponent (i32.add (local.get $exponent) (i32.const 1)))
(local.set $rest (i32.wrap/i64 (i64.rem_u (local.get $mantissa) (local.set $rest (i32.wrap_i64 (i64.rem_u (local.get $mantissa)
(i64.const 10)))) (i64.const 10))))
(local.set $rest (call $i32.normalize-left (local.set $rest (call $i32.normalize-left
(i32.div_u (i32.shl (call $i32.normalize-left (i32.div_u (i32.shl (call $i32.normalize-left
@ -832,13 +832,13 @@
(if (i32.gt_s (local.get $2-exponent) (i32.const 1023)) (if (i32.gt_s (local.get $2-exponent) (i32.const 1023))
(then (if (i32.eqz (local.get $sign)) (then (if (i32.eqz (local.get $sign))
(then (return (f64.reinterpret/i64 (global.get $f64-plus-infinity)))) (then (return (f64.reinterpret_i64 (global.get $f64-plus-infinity))))
(else (return (f64.reinterpret/i64 (global.get $f64-minus-infinity))))))) (else (return (f64.reinterpret_i64 (global.get $f64-minus-infinity)))))))
(f64.reinterpret/i64 (f64.reinterpret_i64
(i64.xor (i64.shl (i64.extend_u/i32 (local.get $sign)) (i64.const 63)) (i64.xor (i64.shl (i64.extend_i32_u (local.get $sign)) (i64.const 63))
(i64.xor (i64.shr_u (local.get $mantissa) (i64.const 11)) (i64.xor (i64.shr_u (local.get $mantissa) (i64.const 11))
(i64.shl (i64.add (i64.extend_s/i32 (local.get $2-exponent)) (i64.shl (i64.add (i64.extend_i32_s (local.get $2-exponent))
(i64.const 1023)) (i64.const 1023))
(i64.const 52)))))) (i64.const 52))))))
@ -879,7 +879,7 @@
(if (i32.lt_u (local.get $nums) (i32.const 18)) (if (i32.lt_u (local.get $nums) (i32.const 18))
(then (local.set $nums (i32.add (local.get $nums) (i32.const 1))) (then (local.set $nums (i32.add (local.get $nums) (i32.const 1)))
(local.set $mantissa (i64.add (i64.mul (local.get $mantissa) (i64.const 10)) (local.set $mantissa (i64.add (i64.mul (local.get $mantissa) (i64.const 10))
(i64.extend_u/i32 (i32.sub (local.get $c) (i64.extend_i32_u (i32.sub (local.get $c)
(i32.const 48)))))) (i32.const 48))))))
(else (local.set $exponent (i32.add (local.get $exponent) (i32.const 1))))) (else (local.set $exponent (i32.add (local.get $exponent) (i32.const 1)))))
(local.set $i (i32.add (local.get $i) (i32.const 1))) (local.set $i (i32.add (local.get $i) (i32.const 1)))
@ -908,7 +908,7 @@
(br_if $break (i32.ge_u (local.get $nums) (i32.const 18))) (br_if $break (i32.ge_u (local.get $nums) (i32.const 18)))
(local.set $nums (i32.add (local.get $nums) (i32.const 1))) (local.set $nums (i32.add (local.get $nums) (i32.const 1)))
(local.set $mantissa (i64.add (i64.mul (local.get $mantissa) (i64.const 10)) (local.set $mantissa (i64.add (i64.mul (local.get $mantissa) (i64.const 10))
(i64.extend_u/i32 (i32.sub (local.get $c) (i64.extend_i32_u (i32.sub (local.get $c)
(i32.const 48))))) (i32.const 48)))))
(local.set $exponent (i32.add (local.get $exponent) (i32.const -1))) (local.set $exponent (i32.add (local.get $exponent) (i32.const -1)))
(local.set $i (i32.add (local.get $i) (i32.const 1))) (local.set $i (i32.add (local.get $i) (i32.const 1)))
@ -953,7 +953,7 @@
(local.get $negative) (local.get $negative)
(local.get $mantissa) (local.get $mantissa)
(local.get $exponent))))) (local.get $exponent)))))
(f64.reinterpret/i64 (global.get $f64-nan))) (f64.reinterpret_i64 (global.get $f64-nan)))
(func $get-reader-macro-character (param $c i32) (result i32) (func $get-reader-macro-character (param $c i32) (result i32)
(local $macros i32) (local $macros i32)
@ -981,8 +981,8 @@
(then (local.set $result (call $alloc (i32.const 8))) (then (local.set $result (call $alloc (i32.const 8)))
(drop (call $reader-read)) (drop (call $reader-read))
(drop (call $reader-read)) (drop (call $reader-read))
(i64.store (local.get $result) (i64.xor (i64.extend_u/i32 (global.get $char)) (i64.store (local.get $result) (i64.xor (i64.extend_i32_u (global.get $char))
(i64.shl (i64.extend_u/i32 (call $reader-read)) (i64.shl (i64.extend_i32_u (call $reader-read))
(i64.const 32))))) (i64.const 32)))))
(else (local.set $start (global.get $reader-pos)) (else (local.set $start (global.get $reader-pos))
@ -1005,7 +1005,7 @@
(local.set $num (call $parse-float (local.set $num (call $parse-float
(i32.add (global.get $reader-ptr) (local.get $start)) (i32.add (global.get $reader-ptr) (local.get $start))
(local.get $size))) (local.get $size)))
(if (i64.eq (i64.reinterpret/f64 (local.get $num)) (global.get $f64-nan)) (if (i64.eq (i64.reinterpret_f64 (local.get $num)) (global.get $f64-nan))
(then (local.set $result (call $read-symbol (local.get $start) (local.get $size)))) (then (local.set $result (call $read-symbol (local.get $start) (local.get $size))))
(else (local.set $result (call $alloc (i32.const 12))) (else (local.set $result (call $alloc (i32.const 12)))
(i32.store (local.get $result) (global.get $number)) (i32.store (local.get $result) (global.get $number))
@ -1242,7 +1242,7 @@
(local.set $num (i64.div_u (local.get $num) (i64.const 10))) (local.set $num (i64.div_u (local.get $num) (i64.const 10)))
(if (i64.gt_u (local.get $num) (i64.const 0)) (if (i64.gt_u (local.get $num) (i64.const 0))
(call $print-int (local.get $num))) (call $print-int (local.get $num)))
(call $print-char (i32.wrap/i64 (i64.add (local.get $n) (i64.const 48))))) (call $print-char (i32.wrap_i64 (i64.add (local.get $n) (i64.const 48)))))
(func $print-zeros (param $exponent i32) (func $print-zeros (param $exponent i32)
(loop $continue (loop $continue
@ -1274,7 +1274,7 @@
(local.get $exponent)))))) (local.get $exponent))))))
(if (i32.eqz (i32.add (local.get $exponent) (i32.const 1))) (if (i32.eqz (i32.add (local.get $exponent) (i32.const 1)))
(call $print-char (i32.const 46))) (call $print-char (i32.const 46)))
(call $print-char (i32.wrap/i64 (i64.add (local.get $n) (i64.const 48))))) (call $print-char (i32.wrap_i64 (i64.add (local.get $n) (i64.const 48)))))
(func $print-number* (param $num f64) (func $print-number* (param $num f64)
(local $n i64) (local $n i64)
@ -1284,8 +1284,8 @@
(local $10-exponent i32) (local $10-exponent i32)
(local $whole i64) (local $whole i64)
(local $fraction i64) (local $fraction i64)
(local.set $n (i64.reinterpret/f64 (local.get $num))) (local.set $n (i64.reinterpret_f64 (local.get $num)))
(local.set $is-negative (i32.wrap/i64 (i64.shr_u (i64.and (local.get $n) (local.set $is-negative (i32.wrap_i64 (i64.shr_u (i64.and (local.get $n)
(i64.const 0x8000000000000000)) (i64.const 0x8000000000000000))
(i64.const 63)))) (i64.const 63))))
@ -1296,7 +1296,7 @@
(then (call $print-char (i32.const 0x30)) (then (call $print-char (i32.const 0x30))
(return))) (return)))
(local.set $2-exponent (i32.sub (i32.wrap/i64 (i64.shr_u (i64.and (local.get $n) (local.set $2-exponent (i32.sub (i32.wrap_i64 (i64.shr_u (i64.and (local.get $n)
(i64.const 0x7FF0000000000000)) (i64.const 0x7FF0000000000000))
(i64.const 52))) (i64.const 52)))
(i32.const 1023))) (i32.const 1023)))
@ -1699,7 +1699,7 @@
(return (local.get $car)))) ;; ERROR: Can't add NaN! (return (local.get $car)))) ;; ERROR: Can't add NaN!
(local.set $num (i64.xor (local.get $num) (local.set $num (i64.xor (local.get $num)
(i64.trunc_s/f64 (f64.load (i32.add (local.get $car) (i64.trunc_f64_s (f64.load (i32.add (local.get $car)
(i32.const 4)))))) (i32.const 4))))))
(br_if $break (i32.eq (local.get $cdr) (global.get $nil))) (br_if $break (i32.eq (local.get $cdr) (global.get $nil)))
@ -1713,7 +1713,7 @@
(f64.store (i32.add (local.get $result) (i32.const 4)) (f64.store (i32.add (local.get $result) (i32.const 4))
(f64.convert_s/i64 (local.get $num))) (f64.convert_i64_s (local.get $num)))
(local.get $result)) (local.get $result))
(func $bit-or (param $cons i32) (result i32) (func $bit-or (param $cons i32) (result i32)
@ -1748,7 +1748,7 @@
(return (local.get $car)))) ;; ERROR: Can't add NaN! (return (local.get $car)))) ;; ERROR: Can't add NaN!
(local.set $num (i64.or (local.get $num) (local.set $num (i64.or (local.get $num)
(i64.trunc_s/f64 (f64.load (i32.add (local.get $car) (i64.trunc_f64_s (f64.load (i32.add (local.get $car)
(i32.const 4)))))) (i32.const 4))))))
(br_if $break (i32.eq (local.get $cdr) (global.get $nil))) (br_if $break (i32.eq (local.get $cdr) (global.get $nil)))
@ -1762,7 +1762,7 @@
(f64.store (i32.add (local.get $result) (i32.const 4)) (f64.store (i32.add (local.get $result) (i32.const 4))
(f64.convert_s/i64 (local.get $num))) (f64.convert_i64_s (local.get $num)))
(local.get $result)) (local.get $result))
(func $bit-and (param $cons i32) (result i32) (func $bit-and (param $cons i32) (result i32)
@ -1788,7 +1788,7 @@
(local.set $result (call $alloc (i32.const 12))) (local.set $result (call $alloc (i32.const 12)))
(i32.store (local.get $result) (global.get $number)) (i32.store (local.get $result) (global.get $number))
(local.set $num (i64.trunc_s/f64 (f64.load (i32.add (local.get $car) (local.set $num (i64.trunc_f64_s (f64.load (i32.add (local.get $car)
(i32.const 4))))) (i32.const 4)))))
(loop $continue (loop $continue
(block $break (block $break
@ -1801,7 +1801,7 @@
(return (local.get $car)))) ;; ERROR: Can't add NaN! (return (local.get $car)))) ;; ERROR: Can't add NaN!
(local.set $num (i64.and (local.get $num) (local.set $num (i64.and (local.get $num)
(i64.trunc_s/f64 (f64.load (i32.add (local.get $car) (i64.trunc_f64_s (f64.load (i32.add (local.get $car)
(i32.const 4)))))) (i32.const 4))))))
(br_if $break (i32.eq (local.get $cdr) (global.get $nil))) (br_if $break (i32.eq (local.get $cdr) (global.get $nil)))
@ -1815,7 +1815,7 @@
(f64.store (i32.add (local.get $result) (i32.const 4)) (f64.store (i32.add (local.get $result) (i32.const 4))
(f64.convert_s/i64 (local.get $num))) (f64.convert_i64_s (local.get $num)))
(local.get $result)) (local.get $result))
(func $bit-not (param $cons i32) (result i32) (func $bit-not (param $cons i32) (result i32)
@ -1837,12 +1837,12 @@
(local.set $result (call $alloc (i32.const 12))) (local.set $result (call $alloc (i32.const 12)))
(i32.store (local.get $result) (global.get $number)) (i32.store (local.get $result) (global.get $number))
(local.set $num (i64.trunc_s/f64 (f64.load (i32.add (local.get $car) (local.set $num (i64.trunc_f64_s (f64.load (i32.add (local.get $car)
(i32.const 4))))) (i32.const 4)))))
(local.set $num (i64.sub (i64.mul (local.get $num) (i64.const -1)) (local.set $num (i64.sub (i64.mul (local.get $num) (i64.const -1))
(i64.const 1))) (i64.const 1)))
(f64.store (i32.add (local.get $result) (i32.const 4)) (f64.store (i32.add (local.get $result) (i32.const 4))
(f64.convert_s/i64 (local.get $num))) (f64.convert_i64_s (local.get $num)))
(local.get $result)) (local.get $result))
;; pow! ;; pow!
@ -1880,22 +1880,22 @@
(global $two54 f64 (f64.const 1.80143985094819840000e+16)) (global $two54 f64 (f64.const 1.80143985094819840000e+16))
(global $twom54 f64 (f64.const 5.55111512312578270212e-17)) (global $twom54 f64 (f64.const 5.55111512312578270212e-17))
(func $copysign (param $x f64) (param $y f64) (result f64) (func $copysign (param $x f64) (param $y f64) (result f64)
(f64.reinterpret/i64 (i64.or (i64.and (i64.reinterpret/f64 (local.get $x)) (f64.reinterpret_i64 (i64.or (i64.and (i64.reinterpret_f64 (local.get $x))
(i64.const 0x7FFFFFFFFFFFFFFF)) (i64.const 0x7FFFFFFFFFFFFFFF))
(i64.and (i64.reinterpret/f64 (local.get $y)) (i64.and (i64.reinterpret_f64 (local.get $y))
(i64.const 0x8000000000000000))))) (i64.const 0x8000000000000000)))))
(func $scalbn (param $x f64) (param $n i32) (result f64) (func $scalbn (param $x f64) (param $n i32) (result f64)
(local $k i32) (local $k i32)
(local $hx i32) (local $hx i32)
(local $lx i32) (local $lx i32)
(local.set $hx (i32.wrap/i64 (i64.shr_u (i64.reinterpret/f64 (local.get $x)) (i64.const 32)))) (local.set $hx (i32.wrap_i64 (i64.shr_u (i64.reinterpret_f64 (local.get $x)) (i64.const 32))))
(local.set $lx (i32.wrap/i64 (i64.reinterpret/f64 (local.get $x)))) (local.set $lx (i32.wrap_i64 (i64.reinterpret_f64 (local.get $x))))
(local.set $k (i32.shr_u (i32.and (local.get $hx) (i32.const 0x7ff00000)) (i32.const 20))) (local.set $k (i32.shr_u (i32.and (local.get $hx) (i32.const 0x7ff00000)) (i32.const 20)))
(if (i32.eqz (local.get $k)) (if (i32.eqz (local.get $k))
(then (if (i32.eqz (i32.or (local.get $lx) (i32.and (local.get $hx) (i32.const 0x7fffffff)))) (then (if (i32.eqz (i32.or (local.get $lx) (i32.and (local.get $hx) (i32.const 0x7fffffff))))
(return (local.get $x))) (return (local.get $x)))
(local.set $x (f64.mul (local.get $x) (global.get $two54))) (local.set $x (f64.mul (local.get $x) (global.get $two54)))
(local.set $hx (i32.wrap/i64 (i64.shr_u (i64.reinterpret/f64 (local.get $x)) (local.set $hx (i32.wrap_i64 (i64.shr_u (i64.reinterpret_f64 (local.get $x))
(i64.const 32)))) (i64.const 32))))
(local.set $k (i32.sub (i32.shr_u (i32.and (local.get $hx) (i32.const 0x7ff00000)) (local.set $k (i32.sub (i32.shr_u (i32.and (local.get $hx) (i32.const 0x7ff00000))
(i32.const 20)) (i32.const 20))
@ -1907,14 +1907,14 @@
(if (i32.gt_s (local.get $k) (i32.const 0x7FE)) (if (i32.gt_s (local.get $k) (i32.const 0x7FE))
(return (f64.mul (global.get $huge) (call $copysign (global.get $huge) (local.get $x))))) (return (f64.mul (global.get $huge) (call $copysign (global.get $huge) (local.get $x)))))
(if (i32.gt_s (local.get $k) (i32.const 0)) (if (i32.gt_s (local.get $k) (i32.const 0))
(return (f64.reinterpret/i64 (return (f64.reinterpret_i64
(i64.or (i64.or
(i64.shl (i64.extend_u/i32 (i32.or (i32.and (local.get $hx) (i64.shl (i64.extend_i32_u (i32.or (i32.and (local.get $hx)
(i32.const 0x800fffff)) (i32.const 0x800fffff))
(i32.shl (local.get $k) (i32.shl (local.get $k)
(i32.const 20)))) (i32.const 20))))
(i64.const 32)) (i64.const 32))
(i64.and (i64.reinterpret/f64 (local.get $x)) (i64.and (i64.reinterpret_f64 (local.get $x))
(i64.const 0x00000000FFFFFFFF)))))) (i64.const 0x00000000FFFFFFFF))))))
(if (i32.lt_s (local.get $k) (i32.const -54)) (if (i32.lt_s (local.get $k) (i32.const -54))
(if (i32.gt_s (local.get $n) (i32.const 50000)) (if (i32.gt_s (local.get $n) (i32.const 50000))
@ -1925,14 +1925,14 @@
(global.get $tiny) (global.get $tiny)
(local.get $x))))))) (local.get $x)))))))
(local.set $k (i32.add (local.get $k) (i32.const 54))) (local.set $k (i32.add (local.get $k) (i32.const 54)))
(f64.mul (f64.reinterpret/i64 (f64.mul (f64.reinterpret_i64
(i64.or (i64.or
(i64.shl (i64.extend_u/i32 (i32.or (i32.and (local.get $hx) (i64.shl (i64.extend_i32_u (i32.or (i32.and (local.get $hx)
(i32.const 0x800fffff)) (i32.const 0x800fffff))
(i32.shl (local.get $k) (i32.shl (local.get $k)
(i32.const 20)))) (i32.const 20))))
(i64.const 32)) (i64.const 32))
(i64.and (i64.reinterpret/f64 (local.get $x)) (i64.and (i64.reinterpret_f64 (local.get $x))
(i64.const 0x00000000FFFFFFFF)))) (i64.const 0x00000000FFFFFFFF))))
(global.get $twom54))) (global.get $twom54)))
@ -1969,10 +1969,10 @@
(local $s_l f64) (local $s_l f64)
(local $t_h f64) (local $t_h f64)
(local $t_l f64) (local $t_l f64)
(local.set $hx (i32.wrap/i64 (i64.shr_u (i64.reinterpret/f64 (local.get $x)) (i64.const 32)))) (local.set $hx (i32.wrap_i64 (i64.shr_u (i64.reinterpret_f64 (local.get $x)) (i64.const 32))))
(local.set $lx (i32.wrap/i64 (i64.reinterpret/f64 (local.get $x)))) (local.set $lx (i32.wrap_i64 (i64.reinterpret_f64 (local.get $x))))
(local.set $hy (i32.wrap/i64 (i64.shr_u (i64.reinterpret/f64 (local.get $y)) (i64.const 32)))) (local.set $hy (i32.wrap_i64 (i64.shr_u (i64.reinterpret_f64 (local.get $y)) (i64.const 32))))
(local.set $ly (i32.wrap/i64 (i64.reinterpret/f64 (local.get $y)))) (local.set $ly (i32.wrap_i64 (i64.reinterpret_f64 (local.get $y))))
(local.set $ix (i32.and (local.get $hx) (i32.const 0x7fffffff))) (local.set $ix (i32.and (local.get $hx) (i32.const 0x7fffffff)))
(local.set $iy (i32.and (local.get $hy) (i32.const 0x7fffffff))) (local.set $iy (i32.and (local.get $hy) (i32.const 0x7fffffff)))
@ -2117,8 +2117,8 @@
(local.set $u (f64.mul (global.get $ivln2_h) (local.get $t))) ;; ivln2_h has 21 sig. bits (local.set $u (f64.mul (global.get $ivln2_h) (local.get $t))) ;; ivln2_h has 21 sig. bits
(local.set $v (f64.sub (f64.mul (local.get $t) (global.get $ivln2_l)) (local.set $v (f64.sub (f64.mul (local.get $t) (global.get $ivln2_l))
(f64.mul (local.get $w) (global.get $ivln2)))) (f64.mul (local.get $w) (global.get $ivln2))))
(local.set $t1 (f64.reinterpret/i64 (local.set $t1 (f64.reinterpret_i64
(i64.and (i64.reinterpret/f64 (f64.add (local.get $u) (i64.and (i64.reinterpret_f64 (f64.add (local.get $u)
(local.get $v))) (local.get $v)))
(i64.const 0xFFFFFFFF00000000)))) (i64.const 0xFFFFFFFF00000000))))
(local.set $t2 (f64.sub (local.get $v) (local.set $t2 (f64.sub (local.get $v)
@ -2128,7 +2128,7 @@
(if (i32.lt_u (local.get $ix) (i32.const 0x00100000)) (if (i32.lt_u (local.get $ix) (i32.const 0x00100000))
(then (local.set $ax (f64.mul (local.get $ax) (global.get $two53))) (then (local.set $ax (f64.mul (local.get $ax) (global.get $two53)))
(local.set $n (i32.sub (local.get $n) (i32.const 53))) (local.set $n (i32.sub (local.get $n) (i32.const 53)))
(local.set $ix (i32.wrap/i64 (i64.shr_u (i64.reinterpret/f64 (local.get $ax)) (local.set $ix (i32.wrap_i64 (i64.shr_u (i64.reinterpret_f64 (local.get $ax))
(i64.const 32)))))) (i64.const 32))))))
(local.set $n (i32.add (local.get $n) (local.set $n (i32.add (local.get $n)
(i32.sub (i32.shr_u (local.get $ix) (i32.sub (i32.shr_u (local.get $ix)
@ -2145,27 +2145,27 @@
(else (local.set $k (i32.const 0)) (else (local.set $k (i32.const 0))
(local.set $n (i32.add (local.get $n) (i32.const 1))) (local.set $n (i32.add (local.get $n) (i32.const 1)))
(local.set $ix (i32.sub (local.get $ix) (i32.const 0x00100000))))))) (local.set $ix (i32.sub (local.get $ix) (i32.const 0x00100000)))))))
(local.set $ax (f64.reinterpret/i64 (local.set $ax (f64.reinterpret_i64
(i64.xor (i64.and (i64.reinterpret/f64 (local.get $ax)) (i64.xor (i64.and (i64.reinterpret_f64 (local.get $ax))
(i64.const 0x00000000FFFFFFFF)) (i64.const 0x00000000FFFFFFFF))
(i64.shl (i64.extend_u/i32 (local.get $ix)) (i64.const 32))))) (i64.shl (i64.extend_i32_u (local.get $ix)) (i64.const 32)))))
;; compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) ;; compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5)
(local.set $u (f64.sub (local.get $ax) (local.set $u (f64.sub (local.get $ax)
(f64.add (global.get $one) (f64.add (global.get $one)
(f64.mul (f64.convert_s/i32 (local.get $k)) (f64.mul (f64.convert_i32_s (local.get $k))
(global.get $bp))))) (global.get $bp)))))
(local.set $v (f64.div (global.get $one) (local.set $v (f64.div (global.get $one)
(f64.add (local.get $ax) (f64.add (local.get $ax)
(f64.add (global.get $one) (f64.add (global.get $one)
(f64.mul (f64.convert_s/i32 (local.get $k)) (f64.mul (f64.convert_i32_s (local.get $k))
(global.get $bp)))))) (global.get $bp))))))
(local.set $ss (f64.mul (local.get $u) (local.get $v))) (local.set $ss (f64.mul (local.get $u) (local.get $v)))
(local.set $s_h (f64.reinterpret/i64 (i64.and (i64.reinterpret/f64 (local.get $ss)) (local.set $s_h (f64.reinterpret_i64 (i64.and (i64.reinterpret_f64 (local.get $ss))
(i64.const 0xFFFFFFFF00000000)))) (i64.const 0xFFFFFFFF00000000))))
;; t_h=ax+bp[k] High ;; t_h=ax+bp[k] High
(local.set $t_h (f64.reinterpret/i64 (local.set $t_h (f64.reinterpret_i64
(i64.shl (i64.extend_u/i32 (i32.add (i32.or (i32.shr_u (local.get $ix) (i64.shl (i64.extend_i32_u (i32.add (i32.or (i32.shr_u (local.get $ix)
(i32.const 1)) (i32.const 1))
(i32.const 0x20000000)) (i32.const 0x20000000))
(i32.add (i32.const 0x00080000) (i32.add (i32.const 0x00080000)
@ -2175,7 +2175,7 @@
(local.set $t_l (f64.sub (local.get $ax) (local.set $t_l (f64.sub (local.get $ax)
(f64.sub (local.get $t_h) (f64.sub (local.get $t_h)
(f64.add (global.get $one) (f64.add (global.get $one)
(f64.mul (f64.convert_s/i32 (local.get $k)) (f64.mul (f64.convert_i32_s (local.get $k))
(global.get $bp)))))) (global.get $bp))))))
(local.set $s_l (f64.mul (local.get $v) (local.set $s_l (f64.mul (local.get $v)
(f64.sub (f64.sub (local.get $u) (f64.sub (f64.sub (local.get $u)
@ -2218,7 +2218,7 @@
(local.set $s2 (f64.mul (local.get $s_h) (local.set $s2 (f64.mul (local.get $s_h)
(local.get $s_h))) (local.get $s_h)))
(local.set $t_h (f64.add (f64.const 3.0) (f64.add (local.get $s2) (local.get $r)))) (local.set $t_h (f64.add (f64.const 3.0) (f64.add (local.get $s2) (local.get $r))))
(local.set $t_h (f64.reinterpret/i64 (i64.and (i64.reinterpret/f64 (local.get $t_h)) (local.set $t_h (f64.reinterpret_i64 (i64.and (i64.reinterpret_f64 (local.get $t_h))
(i64.const 0xFFFFFFFF00000000)))) (i64.const 0xFFFFFFFF00000000))))
(local.set $t_l (f64.sub (local.get $r) (local.set $t_l (f64.sub (local.get $r)
(f64.sub (f64.sub (local.get $t_h) (f64.sub (f64.sub (local.get $t_h)
@ -2232,7 +2232,7 @@
(local.get $ss)))) (local.get $ss))))
;; 2/(3log2)*(ss+...) ;; 2/(3log2)*(ss+...)
(local.set $p_h (f64.add (local.get $u) (local.get $v))) (local.set $p_h (f64.add (local.get $u) (local.get $v)))
(local.set $p_h (f64.reinterpret/i64 (i64.and (i64.reinterpret/f64 (local.get $p_h)) (local.set $p_h (f64.reinterpret_i64 (i64.and (i64.reinterpret_f64 (local.get $p_h))
(i64.const 0xFFFFFFFF00000000)))) (i64.const 0xFFFFFFFF00000000))))
(local.set $p_l (f64.sub (local.get $v) (local.set $p_l (f64.sub (local.get $v)
(f64.sub (local.get $p_h) (f64.sub (local.get $p_h)
@ -2240,25 +2240,25 @@
(local.set $z_h (f64.mul (global.get $cp_h) (local.get $p_h))) ;; cp_h + cp_l = 2/(3*log2) (local.set $z_h (f64.mul (global.get $cp_h) (local.get $p_h))) ;; cp_h + cp_l = 2/(3*log2)
(local.set $z_l (f64.add (f64.add (f64.mul (global.get $cp_l) (local.get $p_h)) (local.set $z_l (f64.add (f64.add (f64.mul (global.get $cp_l) (local.get $p_h))
(f64.mul (local.get $p_l) (global.get $cp))) (f64.mul (local.get $p_l) (global.get $cp)))
(f64.mul (f64.convert_u/i32 (local.get $k)) (f64.mul (f64.convert_i32_u (local.get $k))
(global.get $dp_l)))) (global.get $dp_l))))
;; log2(ax) = (ss++..)*2/(3*log2) = n + dp_h + z_h + z_l ;; log2(ax) = (ss++..)*2/(3*log2) = n + dp_h + z_h + z_l
(local.set $t (f64.convert_s/i32 (local.get $n))) (local.set $t (f64.convert_i32_s (local.get $n)))
(local.set $t1 (f64.add (f64.add (f64.add (local.get $z_h) (local.get $z_l)) (local.set $t1 (f64.add (f64.add (f64.add (local.get $z_h) (local.get $z_l))
(f64.mul (f64.convert_u/i32 (local.get $k)) (f64.mul (f64.convert_i32_u (local.get $k))
(global.get $dp_h))) (global.get $dp_h)))
(local.get $t))) (local.get $t)))
(local.set $t1 (f64.reinterpret/i64 (i64.and (i64.reinterpret/f64 (local.get $t1)) (local.set $t1 (f64.reinterpret_i64 (i64.and (i64.reinterpret_f64 (local.get $t1))
(i64.const 0xFFFFFFFF00000000)))) (i64.const 0xFFFFFFFF00000000))))
(local.set $t2 (f64.sub (local.get $z_l) (local.set $t2 (f64.sub (local.get $z_l)
(f64.sub (f64.sub (f64.sub (local.get $t1) (local.get $t)) (f64.sub (f64.sub (f64.sub (local.get $t1) (local.get $t))
(f64.mul (f64.convert_u/i32 (local.get $k)) (f64.mul (f64.convert_i32_u (local.get $k))
(global.get $dp_h))) (global.get $dp_h)))
(local.get $z_h)))))) (local.get $z_h))))))
;; split up y into y1 + y2 and compute (y1+y2)*(t1+t2) ;; split up y into y1 + y2 and compute (y1+y2)*(t1+t2)
(local.set $y1 (local.get $y)) (local.set $y1 (local.get $y))
(local.set $y1 (f64.reinterpret/i64 (i64.and (i64.reinterpret/f64 (local.get $y1)) (local.set $y1 (f64.reinterpret_i64 (i64.and (i64.reinterpret_f64 (local.get $y1))
(i64.const 0xFFFFFFFF00000000)))) (i64.const 0xFFFFFFFF00000000))))
(local.set $p_l (f64.add (f64.mul (f64.sub (local.get $y) (local.get $y1)) (local.set $p_l (f64.add (f64.mul (f64.sub (local.get $y) (local.get $y1))
(local.get $t1)) (local.get $t1))
@ -2266,9 +2266,9 @@
(local.get $t2)))) (local.get $t2))))
(local.set $p_h (f64.mul (local.get $y1) (local.get $t1))) (local.set $p_h (f64.mul (local.get $y1) (local.get $t1)))
(local.set $z (f64.add (local.get $p_l) (local.get $p_h))) (local.set $z (f64.add (local.get $p_l) (local.get $p_h)))
(local.set $j (i32.wrap/i64 (i64.shr_u (i64.reinterpret/f64 (local.get $z)) (local.set $j (i32.wrap_i64 (i64.shr_u (i64.reinterpret_f64 (local.get $z))
(i64.const 32)))) (i64.const 32))))
(local.set $i (i32.wrap/i64 (i64.reinterpret/f64 (local.get $z)))) (local.set $i (i32.wrap_i64 (i64.reinterpret_f64 (local.get $z))))
(if (i32.ge_s (local.get $j) (i32.const 0x40900000)) ;; z >= 1024 (if (i32.ge_s (local.get $j) (i32.const 0x40900000)) ;; z >= 1024
(then (if (i32.ne (i32.or (i32.sub (local.get $j) (i32.const 0x40900000)) (then (if (i32.ne (i32.or (i32.sub (local.get $j) (i32.const 0x40900000))
(local.get $i)) (local.get $i))
@ -2301,8 +2301,8 @@
(local.set $k (i32.sub (i32.shr_u (i32.and (local.get $n) (i32.const 0x7fffffff)) (local.set $k (i32.sub (i32.shr_u (i32.and (local.get $n) (i32.const 0x7fffffff))
(i32.const 20)) (i32.const 20))
(i32.const 0x3FF))) (i32.const 0x3FF)))
(local.set $t (f64.reinterpret/i64 (local.set $t (f64.reinterpret_i64
(i64.shl (i64.extend_u/i32 (i64.shl (i64.extend_i32_u
(i32.and (local.get $n) (i32.and (local.get $n)
(i32.sub (i32.mul (i32.shr_u (i32.const 0x000fffff) (i32.sub (i32.mul (i32.shr_u (i32.const 0x000fffff)
(local.get $k)) (local.get $k))
@ -2316,7 +2316,7 @@
(local.set $n (i32.mul (i32.const -1) (local.get $n)))) (local.set $n (i32.mul (i32.const -1) (local.get $n))))
(local.set $p_h (f64.sub (local.get $p_h) (local.get $t))))) (local.set $p_h (f64.sub (local.get $p_h) (local.get $t)))))
(local.set $t (f64.add (local.get $p_l) (local.get $p_h))) (local.set $t (f64.add (local.get $p_l) (local.get $p_h)))
(local.set $t (f64.reinterpret/i64 (i64.and (i64.reinterpret/f64 (local.get $t)) (local.set $t (f64.reinterpret_i64 (i64.and (i64.reinterpret_f64 (local.get $t))
(i64.const 0xFFFFFFFF00000000)))) (i64.const 0xFFFFFFFF00000000))))
(local.set $u (f64.mul (local.get $t) (global.get $lg2_h))) (local.set $u (f64.mul (local.get $t) (global.get $lg2_h)))
(local.set $v (f64.add (f64.mul (f64.sub (local.get $p_l) (f64.sub (local.get $t) (local.get $p_h))) (local.set $v (f64.add (f64.mul (f64.sub (local.get $p_l) (f64.sub (local.get $t) (local.get $p_h)))
@ -2347,14 +2347,14 @@
(f64.add (local.get $w) (f64.add (local.get $w)
(f64.mul (local.get $z) (local.get $w))))) (f64.mul (local.get $z) (local.get $w)))))
(local.set $z (f64.sub (global.get $one) (f64.sub (local.get $r) (local.get $z)))) (local.set $z (f64.sub (global.get $one) (f64.sub (local.get $r) (local.get $z))))
(local.set $j (i32.wrap/i64 (i64.shr_u (i64.reinterpret/f64 (local.get $z)) (i64.const 32)))) (local.set $j (i32.wrap_i64 (i64.shr_u (i64.reinterpret_f64 (local.get $z)) (i64.const 32))))
(local.set $j (i32.add (local.get $j) (i32.shl (local.get $n) (i32.const 20)))) (local.set $j (i32.add (local.get $j) (i32.shl (local.get $n) (i32.const 20))))
(if (i32.lt_s (i32.shr_u (local.get $j) (i32.const 20)) (i32.const 0)) (if (i32.lt_s (i32.shr_u (local.get $j) (i32.const 20)) (i32.const 0))
(then (local.set $z (call $scalbn (local.get $z) (local.get $n)))) (then (local.set $z (call $scalbn (local.get $z) (local.get $n))))
(else (local.set $z (else (local.set $z
(f64.reinterpret/i64 (f64.reinterpret_i64
(i64.add (i64.reinterpret/f64 (local.get $z)) (i64.add (i64.reinterpret_f64 (local.get $z))
(i64.shl (i64.extend_u/i32 (i32.shl (local.get $n) (i64.shl (i64.extend_i32_u (i32.shl (local.get $n)
(i32.const 20))) (i32.const 20)))
(i64.const 32))))))) (i64.const 32)))))))

Loading…
Cancel
Save