From becfa3ee4214bb4e6fbe1dbdbf6c3756c548d82b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 25 May 2018 10:54:05 -0500 Subject: wasm2asm: Finish i64 lowering operations (#1563) * wasm2asm: Finish i64 lowering operations This commit finishes out lowering i64 operations to JS with implementations of division and remainder for JS. The primary change here is to have these compiled from Rust to wasm and then have them "linked in" via intrinsics. The `RemoveNonJSOps` pass has been updated to include some of what `I64ToI32Lowering` was previously doing, basically replacing some instructions with calls to intrinsics. The intrinsics are now all tracked in one location. Hopefully the intrinsics don't need to be regenerated too much, but for posterity the source currently [lives in a gist][gist], although I suspect that gist won't continue to compile and work as-is for all of time. [gist]: https://gist.github.com/alexcrichton/e7ea67bcdd17ce4b6254e66f77165690 --- test/wasm2asm/conversions-modified.2asm.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'test/wasm2asm/conversions-modified.2asm.js') diff --git a/test/wasm2asm/conversions-modified.2asm.js b/test/wasm2asm/conversions-modified.2asm.js index b4613c407..a8ec0b104 100644 --- a/test/wasm2asm/conversions-modified.2asm.js +++ b/test/wasm2asm/conversions-modified.2asm.js @@ -20,24 +20,22 @@ function asmFunc(global, env, buffer) { var i64toi32_i32$HIGH_BITS = 0; function $0(x) { x = x | 0; - var i64toi32_i32$1 = 0, i64toi32_i32$0 = 0, wasm2asm_i32$0 = 0; + var i64toi32_i32$1 = 0, i64toi32_i32$0 = 0; i64toi32_i32$1 = x; i64toi32_i32$0 = i64toi32_i32$1 >> 31 | 0; i64toi32_i32$0 = i64toi32_i32$0; i64toi32_i32$1 = i64toi32_i32$1; i64toi32_i32$HIGH_BITS = i64toi32_i32$0; return i64toi32_i32$1 | 0; - return wasm2asm_i32$0 | 0; } function $1(x) { x = x | 0; - var i64toi32_i32$0 = 0, wasm2asm_i32$0 = 0; + var i64toi32_i32$0 = 0; i64toi32_i32$0 = 0; i64toi32_i32$0 = i64toi32_i32$0; i64toi32_i32$HIGH_BITS = i64toi32_i32$0; return x | 0; - return wasm2asm_i32$0 | 0; } function $2(x, x$hi) { @@ -68,7 +66,7 @@ function asmFunc(global, env, buffer) { function $7(x) { x = Math_fround(x); - var i64toi32_i32$0 = Math_fround(0), i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0, wasm2asm_i32$0 = 0; + var i64toi32_i32$0 = Math_fround(0), i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0; i64toi32_i32$0 = x; if (Math_fround(Math_abs(i64toi32_i32$0)) >= Math_fround(1.0)) { if (i64toi32_i32$0 > Math_fround(0.0)) $4 = ~~Math_fround(Math_min(Math_fround(Math_floor(Math_fround(i64toi32_i32$0 / Math_fround(4294967296.0)))), Math_fround(Math_fround(4294967296.0) - Math_fround(1.0)))) >>> 0; else $4 = ~~Math_fround(Math_ceil(Math_fround(Math_fround(i64toi32_i32$0 - Math_fround(~~i64toi32_i32$0 >>> 0 >>> 0)) / Math_fround(4294967296.0)))) >>> 0; @@ -79,12 +77,11 @@ function asmFunc(global, env, buffer) { i64toi32_i32$2 = ~~i64toi32_i32$0 >>> 0; i64toi32_i32$HIGH_BITS = i64toi32_i32$1; return i64toi32_i32$2 | 0; - return wasm2asm_i32$0 | 0; } function $8(x) { x = Math_fround(x); - var i64toi32_i32$0 = Math_fround(0), i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0, wasm2asm_i32$0 = 0; + var i64toi32_i32$0 = Math_fround(0), i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0; i64toi32_i32$0 = x; if (Math_fround(Math_abs(i64toi32_i32$0)) >= Math_fround(1.0)) { if (i64toi32_i32$0 > Math_fround(0.0)) $4 = ~~Math_fround(Math_min(Math_fround(Math_floor(Math_fround(i64toi32_i32$0 / Math_fround(4294967296.0)))), Math_fround(Math_fround(4294967296.0) - Math_fround(1.0)))) >>> 0; else $4 = ~~Math_fround(Math_ceil(Math_fround(Math_fround(i64toi32_i32$0 - Math_fround(~~i64toi32_i32$0 >>> 0 >>> 0)) / Math_fround(4294967296.0)))) >>> 0; @@ -95,12 +92,11 @@ function asmFunc(global, env, buffer) { i64toi32_i32$2 = ~~i64toi32_i32$0 >>> 0; i64toi32_i32$HIGH_BITS = i64toi32_i32$1; return i64toi32_i32$2 | 0; - return wasm2asm_i32$0 | 0; } function $9(x) { x = +x; - var i64toi32_i32$0 = 0.0, i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0, wasm2asm_i32$0 = 0; + var i64toi32_i32$0 = 0.0, i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0; i64toi32_i32$0 = x; if (Math_abs(i64toi32_i32$0) >= 1.0) { if (i64toi32_i32$0 > 0.0) $4 = ~~Math_min(Math_floor(i64toi32_i32$0 / 4294967296.0), 4294967296.0 - 1.0) >>> 0; else $4 = ~~Math_ceil((i64toi32_i32$0 - +(~~i64toi32_i32$0 >>> 0 >>> 0)) / 4294967296.0) >>> 0; @@ -111,12 +107,11 @@ function asmFunc(global, env, buffer) { i64toi32_i32$2 = ~~i64toi32_i32$0 >>> 0; i64toi32_i32$HIGH_BITS = i64toi32_i32$1; return i64toi32_i32$2 | 0; - return wasm2asm_i32$0 | 0; } function $10(x) { x = +x; - var i64toi32_i32$0 = 0.0, i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0, wasm2asm_i32$0 = 0; + var i64toi32_i32$0 = 0.0, i64toi32_i32$1 = 0, $4 = 0, $5 = 0, i64toi32_i32$2 = 0; i64toi32_i32$0 = x; if (Math_abs(i64toi32_i32$0) >= 1.0) { if (i64toi32_i32$0 > 0.0) $4 = ~~Math_min(Math_floor(i64toi32_i32$0 / 4294967296.0), 4294967296.0 - 1.0) >>> 0; else $4 = ~~Math_ceil((i64toi32_i32$0 - +(~~i64toi32_i32$0 >>> 0 >>> 0)) / 4294967296.0) >>> 0; @@ -127,7 +122,6 @@ function asmFunc(global, env, buffer) { i64toi32_i32$2 = ~~i64toi32_i32$0 >>> 0; i64toi32_i32$HIGH_BITS = i64toi32_i32$1; return i64toi32_i32$2 | 0; - return wasm2asm_i32$0 | 0; } function $11(x) { @@ -219,14 +213,13 @@ function asmFunc(global, env, buffer) { function $24(x) { x = +x; - var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, wasm2asm_i32$0 = 0; + var i64toi32_i32$0 = 0, i64toi32_i32$1 = 0; HEAPF64[0 >> 3] = x; i64toi32_i32$0 = HEAP32[(0 + 4 | 0) >> 2] | 0; i64toi32_i32$0 = i64toi32_i32$0; i64toi32_i32$1 = HEAP32[0 >> 2] | 0; i64toi32_i32$HIGH_BITS = i64toi32_i32$0; return i64toi32_i32$1 | 0; - return wasm2asm_i32$0 | 0; } return { -- cgit v1.2.3