diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-08 10:31:26 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-08 11:37:39 -0700 |
commit | e93486b7936153e21312bcc11f2c99ed9a151300 (patch) | |
tree | e70e0d070435868bf4414f80ac886bb623aef182 /src | |
parent | 282369b5430287c2397eb9e3cdd859ad12fa3937 (diff) | |
download | binaryen-e93486b7936153e21312bcc11f2c99ed9a151300.tar.gz binaryen-e93486b7936153e21312bcc11f2c99ed9a151300.tar.bz2 binaryen-e93486b7936153e21312bcc11f2c99ed9a151300.zip |
enable udivmoddi4 opts in asm2wasm
Diffstat (limited to 'src')
-rw-r--r-- | src/asm2wasm.h | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 53fa78db4..6c3fcd8cf 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -881,19 +881,17 @@ void Asm2WasmBuilder::processAsm(Ref ast) { #endif -#if 0 // enable asm2wasm i64 optimizations when browsers have consistent i64 support in wasm if (udivmoddi4.is() && getTempRet0.is()) { // generate a wasm-optimized __udivmoddi4 method, which we can do much more efficiently in wasm // we can only do this if we know getTempRet0 as well since we use it to figure out which minified global is tempRet0 // (getTempRet0 might be an import, if this is a shared module, so we can't optimize that case) - int tempRet0; + Name tempRet0; { Expression* curr = wasm.getFunction(getTempRet0)->body; if (curr->is<Block>()) curr = curr->cast<Block>()->list[0]; - curr = curr->cast<Return>()->value; - auto* load = curr->cast<Load>(); - auto* ptr = load->ptr->cast<Const>(); - tempRet0 = ptr->value.geti32() + load->offset; + if (curr->is<Return>()) curr = curr->cast<Return>()->value; + auto* get = curr->cast<GetGlobal>(); + tempRet0 = get->name; } // udivmoddi4 receives xl, xh, yl, yl, r, and // if r then *r = x % y @@ -913,13 +911,13 @@ void Asm2WasmBuilder::processAsm(Ref ast) { return builder.makeSetLocal( target, builder.makeBinary( - Or, + OrInt64, builder.makeUnary( ExtendUInt32, builder.makeGetLocal(low, i32) ), builder.makeBinary( - Shl, + ShlInt64, builder.makeUnary( ExtendUInt32, builder.makeGetLocal(high, i32) @@ -938,10 +936,11 @@ void Asm2WasmBuilder::processAsm(Ref ast) { 8, 0, 8, builder.makeGetLocal(r, i32), builder.makeBinary( - RemU, + RemUInt64, builder.makeGetLocal(x64, i64), builder.makeGetLocal(y64, i64) - ) + ), + i64 ) ) ); @@ -949,20 +948,19 @@ void Asm2WasmBuilder::processAsm(Ref ast) { builder.makeSetLocal( x64, builder.makeBinary( - DivU, + DivUInt64, builder.makeGetLocal(x64, i64), builder.makeGetLocal(y64, i64) ) ) ); body->list.push_back( - builder.makeStore( - 4, 0, 4, - builder.makeConst(Literal(int32_t(tempRet0))), + builder.makeSetGlobal( + tempRet0, builder.makeUnary( WrapInt64, builder.makeBinary( - ShrU, + ShrUInt64, builder.makeGetLocal(x64, i64), builder.makeConst(Literal(int64_t(32))) ) @@ -975,9 +973,9 @@ void Asm2WasmBuilder::processAsm(Ref ast) { builder.makeGetLocal(x64, i64) ) ); + body->finalize(); func->body = body; } -#endif assert(WasmValidator().validate(wasm)); } |