Notes on unary EQZ in compileBinary EQ

This commit is contained in:
dcodeIO 2018-01-02 23:20:57 +01:00
parent f507fc8168
commit fb2b7aa96b
4 changed files with 47 additions and 63 deletions

View File

@ -1545,6 +1545,11 @@ export class Compiler extends DiagnosticEmitter {
case Token.EQUALS_EQUALS:
case Token.EQUALS_EQUALS_EQUALS:
// NOTE that this favors correctness, in terms of emitting a binary expression, over
// checking for a possible use of unary EQZ. while the most classic of all optimizations,
// that's not what the source told us to do. for reference, `!left` emits unary EQZ.
left = this.compileExpression(expression.left, contextualType, ConversionKind.NONE);
right = this.compileExpression(expression.right, this.currentType);

View File

@ -154,18 +154,18 @@
)
)
(block
(set_local $4
(i64.shl
(get_local $4)
(i64.const 1)
)
)
(set_local $3
(i32.sub
(get_local $3)
(i32.const 1)
)
)
(set_local $4
(i64.shl
(get_local $4)
(i64.const 1)
)
)
(br $continue|0)
)
)
@ -211,18 +211,18 @@
)
)
(block
(set_local $4
(i64.shl
(get_local $4)
(i64.const 1)
)
)
(set_local $6
(i32.sub
(get_local $6)
(i32.const 1)
)
)
(set_local $4
(i64.shl
(get_local $4)
(i64.const 1)
)
)
(br $continue|1)
)
)
@ -332,18 +332,18 @@
)
)
(block
(set_local $2
(i64.shl
(get_local $2)
(i64.const 1)
)
)
(set_local $3
(i32.sub
(get_local $3)
(i32.const 1)
)
)
(set_local $2
(i64.shl
(get_local $2)
(i64.const 1)
)
)
(br $continue|3)
)
)

View File

@ -15,14 +15,16 @@ export function fmod(x: f64, y: f64): f64 {
}
if (!ex) {
for (var i = ux << 12; !(i >> 63); ex--) i <<= 1;
for (var i = ux << 12; !(i >> 63); i <<= 1)
--ex;
ux <<= -ex + 1;
} else {
ux &= -1 >> 12;
ux |= 1 << 52;
}
if (!ey) {
for (i = uy << 12; !(i >> 63); ey--) i <<= 1;
for (i = uy << 12; !(i >> 63); i <<= 1)
--ey;
uy <<= -ey + 1;
} else {
uy &= -1 >> 12;
@ -44,7 +46,8 @@ export function fmod(x: f64, y: f64): f64 {
return 0 * x;
ux = i;
}
for (; !(ux >> 52); ex--) ux <<= 1;
for (; !(ux >> 52); ux <<= 1)
--ex;
if (ex > 0) {
ux -= 1 << 52;

View File

@ -165,26 +165,18 @@
)
)
(block
(set_local $4
(i32.sub
(get_local $4)
(i32.const 1)
)
)
(set_local $9
(i64.shl
(get_local $9)
(i64.const 1)
)
)
(drop
(block (result i32)
(set_local $8
(get_local $4)
)
(set_local $4
(i32.sub
(get_local $8)
(i32.const 1)
)
)
(get_local $8)
)
)
(br $continue|0)
)
)
@ -250,26 +242,18 @@
)
)
(block
(set_local $5
(i32.sub
(get_local $5)
(i32.const 1)
)
)
(set_local $9
(i64.shl
(get_local $9)
(i64.const 1)
)
)
(drop
(block (result i32)
(set_local $8
(get_local $5)
)
(set_local $5
(i32.sub
(get_local $8)
(i32.const 1)
)
)
(get_local $8)
)
)
(br $continue|1)
)
)
@ -421,26 +405,18 @@
)
)
(block
(set_local $4
(i32.sub
(get_local $4)
(i32.const 1)
)
)
(set_local $2
(i64.shl
(get_local $2)
(i64.const 1)
)
)
(drop
(block (result i32)
(set_local $8
(get_local $4)
)
(set_local $4
(i32.sub
(get_local $8)
(i32.const 1)
)
)
(get_local $8)
)
)
(br $continue|3)
)
)