Created
August 12, 2018 06:35
-
-
Save sfpgmr/c2bf6ecce1566a2c0037a1d737fff884 to your computer and use it in GitHub Desktop.
IEEE754 float32/64のビットパターンを持つ1つ/2つの32ビット値を元にして、32/64bit floatを返すwasm関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module | |
(export "i32tof32" $i32tof32) | |
(export "i64tof64" $i64tof64) | |
;; IEE754 float32のビットパターンを持つ32ビット整数値をf32に変換する | |
(func $i32tof32 (param $i i32) (param $minus i32) (result f32) | |
(f32.reinterpret/i32 | |
(i32.xor | |
(get_local $i) | |
(get_local $minus) | |
) | |
) | |
) | |
;; IEEE754 float64のビットパターンを持つ2つの32ビット値(high,low)を元にして、64bit floatを返す | |
(func $i64tof64 (param $low i32) (param $high i32) (param $minus i32) (result f64) | |
(f64.reinterpret/i64 | |
(i64.xor | |
(i64.or | |
(i64.shl | |
(i64.extend_u(get_local $high)) | |
(i64.const 32) | |
) | |
(i64.extend_u (get_local $low)) | |
) | |
(i64.shl | |
(i64.extend_u(get_local $minus)) | |
(i64.const 32) | |
) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment