Improve Math routines; Add Mathf-specific prng (#297)

This commit is contained in:
Max Graey
2018-10-26 01:10:17 +03:00
committed by Daniel Wirtz
parent 4683599a82
commit 376afd45fc
14 changed files with 7725 additions and 9633 deletions

View File

@ -21,67 +21,64 @@
(start $start)
(func $~lib/math/NativeMath.mod (; 2 ;) (; has Stack IR ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(local $2 i64)
(local $3 i32)
(local $3 i64)
(local $4 i64)
(local $5 i64)
(local $6 i32)
(local $6 i64)
(local $7 i32)
(local $8 i32)
(local $8 i64)
(local $9 i64)
(block $folding-inner0
(set_local $3
(i32.wrap/i64
(i64.and
(i64.shr_u
(tee_local $2
(i64.reinterpret/f64
(get_local $0)
)
(i64.and
(i64.shr_u
(tee_local $2
(i64.reinterpret/f64
(get_local $0)
)
(i64.const 52)
)
(i64.const 2047)
(i64.const 52)
)
(i64.const 2047)
)
)
(set_local $6
(i32.wrap/i64
(i64.and
(i64.shr_u
(tee_local $5
(i64.reinterpret/f64
(get_local $1)
)
(i64.and
(i64.shr_u
(tee_local $5
(i64.reinterpret/f64
(get_local $1)
)
(i64.const 52)
)
(i64.const 2047)
(i64.const 52)
)
(i64.const 2047)
)
)
(set_local $8
(i32.wrap/i64
(i64.shr_u
(get_local $2)
(i64.const 63)
)
(i64.shr_u
(get_local $2)
(i64.const 63)
)
)
(if
(i32.eqz
(tee_local $7
(i64.eq
(i64.shl
(get_local $5)
(i64.const 1)
(tee_local $4
(i64.shl
(get_local $5)
(i64.const 1)
)
)
(i64.const 0)
)
)
)
(set_local $7
(f64.ne
(get_local $1)
(get_local $1)
(i64.eq
(get_local $3)
(i64.const 2047)
)
)
)
@ -90,9 +87,9 @@
(get_local $7)
)
(set_local $7
(i32.eq
(get_local $3)
(i32.const 2047)
(f64.ne
(get_local $1)
(get_local $1)
)
)
)
@ -112,26 +109,19 @@
)
(if
(i64.le_u
(i64.shl
(get_local $2)
(i64.const 1)
)
(i64.shl
(get_local $5)
(i64.const 1)
(tee_local $9
(i64.shl
(get_local $2)
(i64.const 1)
)
)
(get_local $4)
)
(block
(br_if $folding-inner0
(i64.eq
(i64.shl
(get_local $2)
(i64.const 1)
)
(i64.shl
(get_local $5)
(i64.const 1)
)
(get_local $9)
(get_local $4)
)
)
(return
@ -141,7 +131,29 @@
)
(set_local $2
(if (result i64)
(get_local $3)
(i64.eqz
(get_local $3)
)
(i64.shl
(get_local $2)
(i64.add
(i64.sub
(i64.const 0)
(tee_local $3
(i64.sub
(get_local $3)
(i64.clz
(i64.shl
(get_local $2)
(i64.const 12)
)
)
)
)
)
(i64.const 1)
)
)
(i64.or
(i64.and
(get_local $2)
@ -149,55 +161,33 @@
)
(i64.const 4503599627370496)
)
(block (result i64)
(block $break|0
(set_local $4
(i64.shl
(get_local $2)
(i64.const 12)
)
)
(loop $repeat|0
(br_if $break|0
(i32.eqz
(i64.eqz
(i64.shr_u
(get_local $4)
(i64.const 63)
)
)
)
)
(set_local $3
(i32.sub
(get_local $3)
(i32.const 1)
)
)
(set_local $4
(i64.shl
(get_local $4)
(i64.const 1)
)
)
(br $repeat|0)
)
)
(i64.shl
(get_local $2)
(i64.extend_s/i32
(i32.sub
(i32.const 1)
(get_local $3)
)
)
)
)
)
)
(set_local $5
(if (result i64)
(get_local $6)
(i64.eqz
(get_local $6)
)
(i64.shl
(get_local $5)
(i64.add
(i64.sub
(i64.const 0)
(tee_local $6
(i64.sub
(get_local $6)
(i64.clz
(i64.shl
(get_local $5)
(i64.const 12)
)
)
)
)
)
(i64.const 1)
)
)
(i64.or
(i64.and
(get_local $5)
@ -205,56 +195,12 @@
)
(i64.const 4503599627370496)
)
(block (result i64)
(block $break|1
(set_local $4
(i64.shl
(get_local $5)
(i64.const 12)
)
)
(loop $repeat|1
(br_if $break|1
(i32.eqz
(i64.eqz
(i64.shr_u
(get_local $4)
(i64.const 63)
)
)
)
)
(set_local $6
(i32.sub
(get_local $6)
(i32.const 1)
)
)
(set_local $4
(i64.shl
(get_local $4)
(i64.const 1)
)
)
(br $repeat|1)
)
)
(i64.shl
(get_local $5)
(i64.extend_s/i32
(i32.sub
(i32.const 1)
(get_local $6)
)
)
)
)
)
)
(block $break|2
(loop $repeat|2
(br_if $break|2
(i32.le_s
(block $break|0
(loop $repeat|0
(br_if $break|0
(i64.le_s
(get_local $3)
(get_local $6)
)
@ -289,12 +235,12 @@
)
)
(set_local $3
(i32.sub
(i64.sub
(get_local $3)
(i32.const 1)
(i64.const 1)
)
)
(br $repeat|2)
(br $repeat|0)
)
)
(if
@ -320,31 +266,17 @@
)
)
)
(block $break|3
(loop $repeat|3
(br_if $break|3
(i32.eqz
(i64.eqz
(i64.shr_u
(get_local $2)
(i64.const 52)
)
(set_local $2
(i64.shl
(get_local $2)
(tee_local $4
(i64.clz
(i64.shl
(get_local $2)
(i64.const 11)
)
)
)
(set_local $3
(i32.sub
(get_local $3)
(i32.const 1)
)
)
(set_local $2
(i64.shl
(get_local $2)
(i64.const 1)
)
)
(br $repeat|3)
)
)
(return
@ -352,9 +284,14 @@
(i64.or
(tee_local $2
(if (result i64)
(i32.gt_s
(get_local $3)
(i32.const 0)
(i64.gt_s
(tee_local $3
(i64.sub
(get_local $3)
(get_local $4)
)
)
(i64.const 0)
)
(i64.or
(i64.sub
@ -362,27 +299,24 @@
(i64.const 4503599627370496)
)
(i64.shl
(i64.extend_s/i32
(get_local $3)
)
(get_local $3)
(i64.const 52)
)
)
(i64.shr_u
(get_local $2)
(i64.extend_s/i32
(i32.sub
(i32.const 1)
(i64.add
(i64.sub
(i64.const 0)
(get_local $3)
)
(i64.const 1)
)
)
)
)
(i64.shl
(i64.extend_s/i32
(get_local $8)
)
(get_local $8)
(i64.const 63)
)
)
@ -467,6 +401,7 @@
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
(block $folding-inner0
(set_local $4
(i32.and
@ -494,7 +429,7 @@
(i32.const 255)
)
)
(set_local $7
(set_local $8
(i32.and
(get_local $2)
(i32.const -2147483648)
@ -504,27 +439,15 @@
(i32.eqz
(tee_local $3
(i32.eqz
(i32.shl
(get_local $5)
(i32.const 1)
(tee_local $7
(i32.shl
(get_local $5)
(i32.const 1)
)
)
)
)
)
(set_local $3
(f32.ne
(get_local $1)
(get_local $1)
)
)
)
(if
(i32.eqz
(i32.and
(get_local $3)
(i32.const 1)
)
)
(set_local $3
(i32.eq
(get_local $4)
@ -532,6 +455,17 @@
)
)
)
(if
(i32.eqz
(get_local $3)
)
(set_local $3
(f32.ne
(get_local $1)
(get_local $1)
)
)
)
(if
(i32.and
(get_local $3)
@ -551,26 +485,19 @@
)
(if
(i32.le_u
(i32.shl
(get_local $2)
(i32.const 1)
)
(i32.shl
(get_local $5)
(i32.const 1)
(tee_local $3
(i32.shl
(get_local $2)
(i32.const 1)
)
)
(get_local $7)
)
(block
(br_if $folding-inner0
(i32.eq
(i32.shl
(get_local $2)
(i32.const 1)
)
(i32.shl
(get_local $5)
(i32.const 1)
)
(get_local $3)
(get_local $7)
)
)
(return
@ -588,41 +515,20 @@
)
(i32.const 8388608)
)
(block (result i32)
(block $break|0
(set_local $3
(i32.shl
(get_local $2)
(i32.const 9)
)
)
(loop $repeat|0
(br_if $break|0
(i32.shr_u
(get_local $3)
(i32.const 31)
(i32.shl
(get_local $2)
(i32.sub
(i32.const 1)
(tee_local $4
(i32.sub
(get_local $4)
(i32.clz
(i32.shl
(get_local $2)
(i32.const 9)
)
)
)
(set_local $4
(i32.sub
(get_local $4)
(i32.const 1)
)
)
(set_local $3
(i32.shl
(get_local $3)
(i32.const 1)
)
)
(br $repeat|0)
)
)
(i32.shl
(get_local $2)
(i32.sub
(i32.const 1)
(get_local $4)
)
)
)
@ -638,49 +544,28 @@
)
(i32.const 8388608)
)
(block (result i32)
(block $break|1
(set_local $3
(i32.shl
(get_local $5)
(i32.const 9)
)
)
(loop $repeat|1
(br_if $break|1
(i32.shr_u
(get_local $3)
(i32.const 31)
(i32.shl
(get_local $5)
(i32.sub
(i32.const 1)
(tee_local $6
(i32.sub
(get_local $6)
(i32.clz
(i32.shl
(get_local $5)
(i32.const 9)
)
)
)
(set_local $6
(i32.sub
(get_local $6)
(i32.const 1)
)
)
(set_local $3
(i32.shl
(get_local $3)
(i32.const 1)
)
)
(br $repeat|1)
)
)
(i32.shl
(get_local $5)
(i32.sub
(i32.const 1)
(get_local $6)
)
)
)
)
)
(block $break|2
(loop $repeat|2
(br_if $break|2
(block $break|0
(loop $repeat|0
(br_if $break|0
(i32.le_s
(get_local $4)
(get_local $6)
@ -721,7 +606,7 @@
(i32.const 1)
)
)
(br $repeat|2)
(br $repeat|0)
)
)
(if
@ -747,27 +632,17 @@
)
)
)
(block $break|3
(loop $repeat|3
(br_if $break|3
(i32.shr_u
(get_local $2)
(i32.const 23)
(set_local $2
(i32.shl
(get_local $2)
(tee_local $3
(i32.clz
(i32.shl
(get_local $2)
(i32.const 8)
)
)
)
(set_local $4
(i32.sub
(get_local $4)
(i32.const 1)
)
)
(set_local $2
(i32.shl
(get_local $2)
(i32.const 1)
)
)
(br $repeat|3)
)
)
(return
@ -776,7 +651,12 @@
(tee_local $2
(if (result i32)
(i32.gt_s
(get_local $4)
(tee_local $4
(i32.sub
(get_local $4)
(get_local $3)
)
)
(i32.const 0)
)
(i32.or
@ -798,7 +678,7 @@
)
)
)
(get_local $7)
(get_local $8)
)
)
)