From 2d22cb07a302de20c29714bf328b41cb7e6efdaf Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 23 Dec 2019 00:18:29 +0200 Subject: [PATCH 01/17] optimize UTF8.decodeUnsafe --- std/assembly/string.ts | 54 +++--- .../std/string-encoding.optimized.wat | 168 ++++++++---------- .../std/string-encoding.untouched.wat | 146 +++++++-------- 3 files changed, 169 insertions(+), 199 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index c233821dcd..3b4c0b02fc 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -703,36 +703,34 @@ export namespace String { var str = __alloc(len << 1, idof()); // max is one u16 char per u8 byte var strOff = str; while (bufOff < bufEnd) { - let cp = load(bufOff++); - if (cp < 128) { - if (nullTerminated && !cp) break; - store(strOff, cp); - strOff += 2; - } else if (cp > 191 && cp < 224) { - if (bufEnd - bufOff < 1) break; - store(strOff, (cp & 31) << 6 | load(bufOff++) & 63); - strOff += 2; - } else if (cp > 239 && cp < 365) { - if (bufEnd - bufOff < 3) break; - cp = ( - (cp & 7) << 18 | - (load(bufOff) & 63) << 12 | - (load(bufOff, 1) & 63) << 6 | - load(bufOff, 2) & 63 - ) - 0x10000; - bufOff += 3; - store(strOff, 0xD800 | (cp >> 10)); - store(strOff, 0xDC00 | (cp & 1023), 2); - strOff += 4; + let u0 = load(bufOff++); + if (!(u0 & 128)) { + if (nullTerminated && !u0) break; + store(strOff, u0); } else { - if (bufEnd - bufOff < 2) break; - store(strOff, - (cp & 15) << 12 | - (load(bufOff) & 63) << 6 | - load(bufOff, 1) & 63 - ); - bufOff += 2; strOff += 2; + let u1 = load(bufOff++) & 63; + if ((u0 & 224) == 192) { + if (bufEnd - bufOff < 1) break; + store(strOff, (u0 & 31) << 6 | u1); + } else { + let u2 = load(bufOff++) & 63; + if ((u0 & 240) == 224) { + u0 = (u0 & 15) << 12 | u1 << 6 | u2; + } else { + if (bufEnd - bufOff < 1) break; + u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | load(bufOff++) & 63; + } + if (u0 < 0x10000) { + store(strOff, u0); + } else { + u0 -= 0x10000; + store(strOff, 0xD800 | u0 >> 10, 0); + store(strOff, 0xDC00 | (u0 & 1023), 2); + strOff += 2; + } + } } + strOff += 2; } return changetype(__realloc(str, strOff - str)); // retains } diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index a429d6897d..bce63120c1 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3078,6 +3078,8 @@ (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) + (local $8 i32) local.get $0 local.get $1 i32.add @@ -3097,7 +3099,7 @@ i32.shl i32.const 1 call $~lib/rt/tlsf/__alloc - local.tee $6 + local.tee $7 local.set $3 loop $continue|0 block $break|0 @@ -3114,30 +3116,23 @@ i32.load8_u local.tee $4 i32.const 128 - i32.lt_u + i32.and if - local.get $4 - i32.eqz - i32.const 0 - local.get $2 - select - br_if $break|0 - local.get $3 - local.get $4 - i32.store16 - local.get $3 - i32.const 2 + local.get $0 + local.tee $1 + i32.const 1 i32.add - local.set $3 - else + local.set $0 + local.get $1 + i32.load8_u + i32.const 63 + i32.and + local.set $6 local.get $4 i32.const 224 - i32.lt_u - i32.const 0 - local.get $4 - i32.const 191 - i32.gt_u - select + i32.and + i32.const 192 + i32.eq if local.get $5 local.get $0 @@ -3145,46 +3140,57 @@ i32.const 1 i32.lt_u br_if $break|0 + local.get $3 + local.get $4 + i32.const 31 + i32.and + i32.const 6 + i32.shl + local.get $6 + i32.or + i32.store16 + else local.get $0 local.tee $1 i32.const 1 i32.add local.set $0 - local.get $3 local.get $1 i32.load8_u i32.const 63 i32.and + local.set $8 local.get $4 - i32.const 31 + i32.const 240 i32.and - i32.const 6 - i32.shl - i32.or - i32.store16 - local.get $3 - i32.const 2 - i32.add - local.set $3 - else - local.get $4 - i32.const 365 - i32.lt_u - i32.const 0 - local.get $4 - i32.const 239 - i32.gt_u - select + i32.const 224 + i32.eq if (result i32) + local.get $4 + i32.const 15 + i32.and + i32.const 12 + i32.shl + local.get $6 + i32.const 6 + i32.shl + i32.or + local.get $8 + i32.or + else local.get $5 local.get $0 i32.sub - i32.const 3 + i32.const 1 i32.lt_u br_if $break|0 - local.get $3 local.get $0 - i32.load8_u offset=2 + local.tee $1 + i32.const 1 + i32.add + local.set $0 + local.get $1 + i32.load8_u i32.const 63 i32.and local.get $4 @@ -3192,21 +3198,26 @@ i32.and i32.const 18 i32.shl - local.get $0 - i32.load8_u - i32.const 63 - i32.and + local.get $6 i32.const 12 i32.shl i32.or - local.get $0 - i32.load8_u offset=1 - i32.const 63 - i32.and + local.get $8 i32.const 6 i32.shl i32.or i32.or + end + local.tee $1 + i32.const 65536 + i32.lt_u + if + local.get $3 + local.get $1 + i32.store16 + else + local.get $3 + local.get $1 i32.const 65536 i32.sub local.tee $1 @@ -3223,55 +3234,32 @@ i32.or i32.store16 offset=2 local.get $3 - i32.const 4 - i32.add - local.set $3 - local.get $0 - i32.const 3 - i32.add - else - local.get $5 - local.get $0 - i32.sub - i32.const 2 - i32.lt_u - br_if $break|0 - local.get $3 - local.get $0 - i32.load8_u offset=1 - i32.const 63 - i32.and - local.get $4 - i32.const 15 - i32.and - i32.const 12 - i32.shl - local.get $0 - i32.load8_u - i32.const 63 - i32.and - i32.const 6 - i32.shl - i32.or - i32.or - i32.store16 - local.get $3 i32.const 2 i32.add local.set $3 - local.get $0 - i32.const 2 - i32.add end - local.set $0 end + else + local.get $4 + i32.eqz + i32.const 0 + local.get $2 + select + br_if $break|0 + local.get $3 + local.get $4 + i32.store16 end + local.get $3 + i32.const 2 + i32.add + local.set $3 br $continue|0 end end - local.get $6 + local.get $7 local.get $3 - local.get $6 + local.get $7 i32.sub call $~lib/rt/tlsf/__realloc call $~lib/rt/pure/__retain diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 161edf2301..a02166682e 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4839,6 +4839,8 @@ (local $6 i32) (local $7 i32) (local $8 i32) + (local $9 i32) + (local $10 i32) local.get $0 local.set $3 local.get $0 @@ -4882,7 +4884,8 @@ local.set $7 local.get $7 i32.const 128 - i32.lt_u + i32.and + i32.eqz if local.get $2 if (result i32) @@ -4897,21 +4900,22 @@ local.get $6 local.get $7 i32.store16 - local.get $6 - i32.const 2 - i32.add - local.set $6 else + local.get $3 + local.tee $8 + i32.const 1 + i32.add + local.set $3 + local.get $8 + i32.load8_u + i32.const 63 + i32.and + local.set $8 local.get $7 - i32.const 191 - i32.gt_u - if (result i32) - local.get $7 - i32.const 224 - i32.lt_u - else - i32.const 0 - end + i32.const 224 + i32.and + i32.const 192 + i32.eq if local.get $4 local.get $3 @@ -4927,37 +4931,43 @@ i32.and i32.const 6 i32.shl + local.get $8 + i32.or + i32.store16 + else local.get $3 - local.tee $8 + local.tee $9 i32.const 1 i32.add local.set $3 - local.get $8 + local.get $9 i32.load8_u i32.const 63 i32.and - i32.or - i32.store16 - local.get $6 - i32.const 2 - i32.add - local.set $6 - else + local.set $9 local.get $7 - i32.const 239 - i32.gt_u - if (result i32) + i32.const 240 + i32.and + i32.const 224 + i32.eq + if local.get $7 - i32.const 365 - i32.lt_u + i32.const 15 + i32.and + i32.const 12 + i32.shl + local.get $8 + i32.const 6 + i32.shl + i32.or + local.get $9 + i32.or + local.set $7 else - i32.const 0 - end - if local.get $4 local.get $3 i32.sub - i32.const 3 + i32.const 1 i32.lt_u if br $break|0 @@ -4967,32 +4977,38 @@ i32.and i32.const 18 i32.shl - local.get $3 - i32.load8_u - i32.const 63 - i32.and + local.get $8 i32.const 12 i32.shl i32.or - local.get $3 - i32.load8_u offset=1 - i32.const 63 - i32.and + local.get $9 i32.const 6 i32.shl i32.or local.get $3 - i32.load8_u offset=2 + local.tee $10 + i32.const 1 + i32.add + local.set $3 + local.get $10 + i32.load8_u i32.const 63 i32.and i32.or + local.set $7 + end + local.get $7 + i32.const 65536 + i32.lt_u + if + local.get $6 + local.get $7 + i32.store16 + else + local.get $7 i32.const 65536 i32.sub local.set $7 - local.get $3 - i32.const 3 - i32.add - local.set $3 local.get $6 i32.const 55296 local.get $7 @@ -5008,48 +5024,16 @@ i32.or i32.store16 offset=2 local.get $6 - i32.const 4 - i32.add - local.set $6 - else - local.get $4 - local.get $3 - i32.sub - i32.const 2 - i32.lt_u - if - br $break|0 - end - local.get $6 - local.get $7 - i32.const 15 - i32.and - i32.const 12 - i32.shl - local.get $3 - i32.load8_u - i32.const 63 - i32.and - i32.const 6 - i32.shl - i32.or - local.get $3 - i32.load8_u offset=1 - i32.const 63 - i32.and - i32.or - i32.store16 - local.get $3 - i32.const 2 - i32.add - local.set $3 - local.get $6 i32.const 2 i32.add local.set $6 end end end + local.get $6 + i32.const 2 + i32.add + local.set $6 br $continue|0 end unreachable From 9fd51cea5bf3a091aa21a91ce6d8e71c3b321e78 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 23 Dec 2019 00:22:25 +0200 Subject: [PATCH 02/17] add guard --- std/assembly/string.ts | 1 + tests/compiler/std/string-encoding.optimized.wat | 6 ++++++ tests/compiler/std/string-encoding.untouched.wat | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 3b4c0b02fc..ba18f40829 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -708,6 +708,7 @@ export namespace String { if (nullTerminated && !u0) break; store(strOff, u0); } else { + if (bufEnd - bufOff < 1) break; let u1 = load(bufOff++) & 63; if ((u0 & 224) == 192) { if (bufEnd - bufOff < 1) break; diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index bce63120c1..d9a3c71cb0 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3118,6 +3118,12 @@ i32.const 128 i32.and if + local.get $5 + local.get $0 + i32.sub + i32.const 1 + i32.lt_u + br_if $break|0 local.get $0 local.tee $1 i32.const 1 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index a02166682e..786e4c84e2 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4901,6 +4901,14 @@ local.get $7 i32.store16 else + local.get $4 + local.get $3 + i32.sub + i32.const 1 + i32.lt_u + if + br $break|0 + end local.get $3 local.tee $8 i32.const 1 From 6e31949446376883a1bcc3f9bdedbe9e967ba48a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 23 Dec 2019 00:23:51 +0200 Subject: [PATCH 03/17] fix --- std/assembly/string.ts | 2 +- tests/compiler/std/string-encoding.optimized.wat | 12 ++++++------ tests/compiler/std/string-encoding.untouched.wat | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index ba18f40829..31a3cb8beb 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -711,9 +711,9 @@ export namespace String { if (bufEnd - bufOff < 1) break; let u1 = load(bufOff++) & 63; if ((u0 & 224) == 192) { - if (bufEnd - bufOff < 1) break; store(strOff, (u0 & 31) << 6 | u1); } else { + if (bufEnd - bufOff < 1) break; let u2 = load(bufOff++) & 63; if ((u0 & 240) == 224) { u0 = (u0 & 15) << 12 | u1 << 6 | u2; diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index d9a3c71cb0..0e2f7f6948 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3140,12 +3140,6 @@ i32.const 192 i32.eq if - local.get $5 - local.get $0 - i32.sub - i32.const 1 - i32.lt_u - br_if $break|0 local.get $3 local.get $4 i32.const 31 @@ -3156,6 +3150,12 @@ i32.or i32.store16 else + local.get $5 + local.get $0 + i32.sub + i32.const 1 + i32.lt_u + br_if $break|0 local.get $0 local.tee $1 i32.const 1 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 786e4c84e2..adbdb2c1d6 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4925,14 +4925,6 @@ i32.const 192 i32.eq if - local.get $4 - local.get $3 - i32.sub - i32.const 1 - i32.lt_u - if - br $break|0 - end local.get $6 local.get $7 i32.const 31 @@ -4943,6 +4935,14 @@ i32.or i32.store16 else + local.get $4 + local.get $3 + i32.sub + i32.const 1 + i32.lt_u + if + br $break|0 + end local.get $3 local.tee $9 i32.const 1 From 88c9bd69570305a0d778391f8d20f986ae060681 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 23 Dec 2019 00:46:35 +0200 Subject: [PATCH 04/17] opt store --- std/assembly/string.ts | 5 +++-- .../compiler/std/string-encoding.optimized.wat | 7 ++++--- .../compiler/std/string-encoding.untouched.wat | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 31a3cb8beb..f89d7c73ca 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -725,8 +725,9 @@ export namespace String { store(strOff, u0); } else { u0 -= 0x10000; - store(strOff, 0xD800 | u0 >> 10, 0); - store(strOff, 0xDC00 | (u0 & 1023), 2); + let lo = u0 >> 10 | 0xD800; + let hi = (u0 & 0x03FF) | 0xDC00; + store(strOff, lo | (hi << 16)); strOff += 2; } } diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 0e2f7f6948..3d7496459f 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3231,14 +3231,15 @@ i32.shr_u i32.const 55296 i32.or - i32.store16 - local.get $3 local.get $1 i32.const 1023 i32.and i32.const 56320 i32.or - i32.store16 offset=2 + i32.const 16 + i32.shl + i32.or + i32.store local.get $3 i32.const 2 i32.add diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index adbdb2c1d6..265b2655b0 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4841,6 +4841,7 @@ (local $8 i32) (local $9 i32) (local $10 i32) + (local $11 i32) local.get $0 local.set $3 local.get $0 @@ -5017,20 +5018,25 @@ i32.const 65536 i32.sub local.set $7 - local.get $6 - i32.const 55296 local.get $7 i32.const 10 i32.shr_u + i32.const 55296 i32.or - i32.store16 - local.get $6 - i32.const 56320 + local.set $10 local.get $7 i32.const 1023 i32.and + i32.const 56320 i32.or - i32.store16 offset=2 + local.set $11 + local.get $6 + local.get $10 + local.get $11 + i32.const 16 + i32.shl + i32.or + i32.store local.get $6 i32.const 2 i32.add From 17949a6829d5912e2f64d1ed78d7887995801c88 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 23 Dec 2019 00:53:09 +0200 Subject: [PATCH 05/17] simplify guard checks --- std/assembly/string.ts | 6 +++--- .../compiler/std/string-encoding.optimized.wat | 18 ++++++------------ .../compiler/std/string-encoding.untouched.wat | 12 +++--------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index f89d7c73ca..880b03f385 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -708,17 +708,17 @@ export namespace String { if (nullTerminated && !u0) break; store(strOff, u0); } else { - if (bufEnd - bufOff < 1) break; + if (bufEnd == bufOff) break; let u1 = load(bufOff++) & 63; if ((u0 & 224) == 192) { store(strOff, (u0 & 31) << 6 | u1); } else { - if (bufEnd - bufOff < 1) break; + if (bufEnd == bufOff) break; let u2 = load(bufOff++) & 63; if ((u0 & 240) == 224) { u0 = (u0 & 15) << 12 | u1 << 6 | u2; } else { - if (bufEnd - bufOff < 1) break; + if (bufEnd == bufOff) break; u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | load(bufOff++) & 63; } if (u0 < 0x10000) { diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 3d7496459f..8d94c9a1ff 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3118,11 +3118,9 @@ i32.const 128 i32.and if - local.get $5 local.get $0 - i32.sub - i32.const 1 - i32.lt_u + local.get $5 + i32.eq br_if $break|0 local.get $0 local.tee $1 @@ -3150,11 +3148,9 @@ i32.or i32.store16 else - local.get $5 local.get $0 - i32.sub - i32.const 1 - i32.lt_u + local.get $5 + i32.eq br_if $break|0 local.get $0 local.tee $1 @@ -3184,11 +3180,9 @@ local.get $8 i32.or else - local.get $5 local.get $0 - i32.sub - i32.const 1 - i32.lt_u + local.get $5 + i32.eq br_if $break|0 local.get $0 local.tee $1 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 265b2655b0..77dcbe5a93 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4904,9 +4904,7 @@ else local.get $4 local.get $3 - i32.sub - i32.const 1 - i32.lt_u + i32.eq if br $break|0 end @@ -4938,9 +4936,7 @@ else local.get $4 local.get $3 - i32.sub - i32.const 1 - i32.lt_u + i32.eq if br $break|0 end @@ -4975,9 +4971,7 @@ else local.get $4 local.get $3 - i32.sub - i32.const 1 - i32.lt_u + i32.eq if br $break|0 end From dcb025c9a4a03a10639b69db8b3b0b2567e9df8a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 23 Dec 2019 00:58:54 +0200 Subject: [PATCH 06/17] reafctor --- std/assembly/string.ts | 9 +- .../std/string-encoding.optimized.wat | 106 +++++++++--------- .../std/string-encoding.untouched.wat | 34 +++--- 3 files changed, 72 insertions(+), 77 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 880b03f385..b246c0724d 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -703,23 +703,24 @@ export namespace String { var str = __alloc(len << 1, idof()); // max is one u16 char per u8 byte var strOff = str; while (bufOff < bufEnd) { - let u0 = load(bufOff++); + let u0 = load(bufOff); ++bufOff; if (!(u0 & 128)) { if (nullTerminated && !u0) break; store(strOff, u0); } else { if (bufEnd == bufOff) break; - let u1 = load(bufOff++) & 63; + let u1 = load(bufOff) & 63; ++bufOff; if ((u0 & 224) == 192) { store(strOff, (u0 & 31) << 6 | u1); } else { if (bufEnd == bufOff) break; - let u2 = load(bufOff++) & 63; + let u2 = load(bufOff) & 63; ++bufOff; if ((u0 & 240) == 224) { u0 = (u0 & 15) << 12 | u1 << 6 | u2; } else { if (bufEnd == bufOff) break; - u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | load(bufOff++) & 63; + u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | load(bufOff) & 63; + ++bufOff; } if (u0 < 0x10000) { store(strOff, u0); diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 8d94c9a1ff..04c37f4ee5 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3079,11 +3079,10 @@ (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) local.get $0 local.get $1 i32.add - local.tee $5 + local.tee $4 local.get $0 i32.lt_u if @@ -3099,133 +3098,132 @@ i32.shl i32.const 1 call $~lib/rt/tlsf/__alloc - local.tee $7 - local.set $3 + local.tee $6 + local.set $1 loop $continue|0 block $break|0 local.get $0 - local.get $5 + local.get $4 i32.ge_u br_if $break|0 local.get $0 - local.tee $1 + i32.load8_u + local.set $3 + local.get $0 i32.const 1 i32.add local.set $0 - local.get $1 - i32.load8_u - local.tee $4 + local.get $3 i32.const 128 i32.and if local.get $0 - local.get $5 + local.get $4 i32.eq br_if $break|0 local.get $0 - local.tee $1 - i32.const 1 - i32.add - local.set $0 - local.get $1 i32.load8_u i32.const 63 i32.and - local.set $6 - local.get $4 + local.set $5 + local.get $0 + i32.const 1 + i32.add + local.set $0 + local.get $3 i32.const 224 i32.and i32.const 192 i32.eq if + local.get $1 local.get $3 - local.get $4 i32.const 31 i32.and i32.const 6 i32.shl - local.get $6 + local.get $5 i32.or i32.store16 else local.get $0 - local.get $5 + local.get $4 i32.eq br_if $break|0 local.get $0 - local.tee $1 - i32.const 1 - i32.add - local.set $0 - local.get $1 i32.load8_u i32.const 63 i32.and - local.set $8 - local.get $4 + local.set $7 + local.get $0 + i32.const 1 + i32.add + local.set $0 + local.get $3 i32.const 240 i32.and i32.const 224 i32.eq - if (result i32) - local.get $4 + if + local.get $3 i32.const 15 i32.and i32.const 12 i32.shl - local.get $6 + local.get $5 i32.const 6 i32.shl i32.or - local.get $8 + local.get $7 i32.or + local.set $3 else local.get $0 - local.get $5 + local.get $4 i32.eq br_if $break|0 local.get $0 - local.tee $1 - i32.const 1 - i32.add - local.set $0 - local.get $1 i32.load8_u i32.const 63 i32.and - local.get $4 + local.get $3 i32.const 7 i32.and i32.const 18 i32.shl - local.get $6 + local.get $5 i32.const 12 i32.shl i32.or - local.get $8 + local.get $7 i32.const 6 i32.shl i32.or i32.or + local.set $3 + local.get $0 + i32.const 1 + i32.add + local.set $0 end - local.tee $1 + local.get $3 i32.const 65536 i32.lt_u if - local.get $3 local.get $1 + local.get $3 i32.store16 else - local.get $3 local.get $1 + local.get $3 i32.const 65536 i32.sub - local.tee $1 + local.tee $3 i32.const 10 i32.shr_u i32.const 55296 i32.or - local.get $1 + local.get $3 i32.const 1023 i32.and i32.const 56320 @@ -3234,33 +3232,33 @@ i32.shl i32.or i32.store - local.get $3 + local.get $1 i32.const 2 i32.add - local.set $3 + local.set $1 end end else - local.get $4 + local.get $3 i32.eqz i32.const 0 local.get $2 select br_if $break|0 + local.get $1 local.get $3 - local.get $4 i32.store16 end - local.get $3 + local.get $1 i32.const 2 i32.add - local.set $3 + local.set $1 br $continue|0 end end - local.get $7 - local.get $3 - local.get $7 + local.get $6 + local.get $1 + local.get $6 i32.sub call $~lib/rt/tlsf/__realloc call $~lib/rt/pure/__retain diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 77dcbe5a93..5eaa71a407 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4876,14 +4876,13 @@ i32.eqz br_if $break|0 local.get $3 - local.tee $7 + i32.load8_u + local.set $7 + local.get $3 i32.const 1 i32.add local.set $3 local.get $7 - i32.load8_u - local.set $7 - local.get $7 i32.const 128 i32.and i32.eqz @@ -4909,15 +4908,14 @@ br $break|0 end local.get $3 - local.tee $8 - i32.const 1 - i32.add - local.set $3 - local.get $8 i32.load8_u i32.const 63 i32.and local.set $8 + local.get $3 + i32.const 1 + i32.add + local.set $3 local.get $7 i32.const 224 i32.and @@ -4941,15 +4939,14 @@ br $break|0 end local.get $3 - local.tee $9 - i32.const 1 - i32.add - local.set $3 - local.get $9 i32.load8_u i32.const 63 i32.and local.set $9 + local.get $3 + i32.const 1 + i32.add + local.set $3 local.get $7 i32.const 240 i32.and @@ -4989,16 +4986,15 @@ i32.shl i32.or local.get $3 - local.tee $10 - i32.const 1 - i32.add - local.set $3 - local.get $10 i32.load8_u i32.const 63 i32.and i32.or local.set $7 + local.get $3 + i32.const 1 + i32.add + local.set $3 end local.get $7 i32.const 65536 From 642b90a22741aea745668eb6c49764a424aecd87 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 23 Dec 2019 04:52:55 +0200 Subject: [PATCH 07/17] switch to binary logic --- std/assembly/string.ts | 6 +++-- .../std/string-encoding.optimized.wat | 12 ++++------ .../std/string-encoding.untouched.wat | 24 +++++++------------ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index b246c0724d..8a145720c9 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -654,7 +654,8 @@ export namespace String { while (strOff < strEnd) { let c1 = load(strOff); if (c1 < 128) { - if (nullTerminated && !c1) break; + // @ts-ignore: cast + if (nullTerminated & !c1) break; store(bufOff, c1); bufOff += 1; strOff += 2; } else if (c1 < 2048) { @@ -705,7 +706,8 @@ export namespace String { while (bufOff < bufEnd) { let u0 = load(bufOff); ++bufOff; if (!(u0 & 128)) { - if (nullTerminated && !u0) break; + // @ts-ignore: cast + if (nullTerminated & !u0) break; store(strOff, u0); } else { if (bufEnd == bufOff) break; diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 04c37f4ee5..e04d0bea08 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -2593,9 +2593,8 @@ if local.get $3 i32.eqz - i32.const 0 local.get $1 - select + i32.and br_if $break|0 local.get $2 local.get $3 @@ -2747,7 +2746,7 @@ if i32.const 0 i32.const 480 - i32.const 684 + i32.const 685 i32.const 8 call $~lib/builtins/abort unreachable @@ -2770,7 +2769,7 @@ if i32.const 0 i32.const 480 - i32.const 688 + i32.const 689 i32.const 8 call $~lib/builtins/abort unreachable @@ -3088,7 +3087,7 @@ if i32.const 0 i32.const 480 - i32.const 702 + i32.const 703 i32.const 6 call $~lib/builtins/abort unreachable @@ -3241,9 +3240,8 @@ else local.get $3 i32.eqz - i32.const 0 local.get $2 - select + i32.and br_if $break|0 local.get $1 local.get $3 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 5eaa71a407..b050d30eae 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4299,12 +4299,9 @@ i32.lt_u if local.get $1 - if (result i32) - local.get $6 - i32.eqz - else - i32.const 0 - end + local.get $6 + i32.eqz + i32.and if br $break|0 end @@ -4472,7 +4469,7 @@ if i32.const 0 i32.const 480 - i32.const 684 + i32.const 685 i32.const 8 call $~lib/builtins/abort unreachable @@ -4496,7 +4493,7 @@ if i32.const 0 i32.const 480 - i32.const 688 + i32.const 689 i32.const 8 call $~lib/builtins/abort unreachable @@ -4855,7 +4852,7 @@ if i32.const 0 i32.const 480 - i32.const 702 + i32.const 703 i32.const 6 call $~lib/builtins/abort unreachable @@ -4888,12 +4885,9 @@ i32.eqz if local.get $2 - if (result i32) - local.get $7 - i32.eqz - else - i32.const 0 - end + local.get $7 + i32.eqz + i32.and if br $break|0 end From 835a0811c07e3c8de80b62d9ed36147f93a53d30 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Tue, 24 Dec 2019 14:27:44 +0200 Subject: [PATCH 08/17] optimize utf len calc --- std/assembly/string.ts | 16 +++--- .../std/string-encoding.optimized.wat | 34 ++++++------- .../std/string-encoding.untouched.wat | 50 +++++++------------ 3 files changed, 40 insertions(+), 60 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 8a145720c9..0e24d93a98 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -625,23 +625,25 @@ export namespace String { export function byteLength(str: string, nullTerminated: bool = false): i32 { var strOff = changetype(str); var strEnd = strOff + changetype(changetype(str) - BLOCK_OVERHEAD).rtSize; - var bufLen = nullTerminated ? 1 : 0; + var bufLen = nullTerminated; while (strOff < strEnd) { let c1 = load(strOff); if (c1 < 128) { - if (nullTerminated && !c1) break; - bufLen += 1; strOff += 2; + // @ts-ignore: cast + if (nullTerminated & !c1) break; + bufLen += 1; } else if (c1 < 2048) { - bufLen += 2; strOff += 2; + bufLen += 2; } else { if ((c1 & 0xFC00) == 0xD800 && strOff + 2 < strEnd) { if ((load(strOff, 2) & 0xFC00) == 0xDC00) { - strOff += 4; bufLen += 4; + bufLen += 4; strOff += 4; continue; } } - strOff += 2; bufLen += 3; + bufLen += 3; } + strOff += 2; } return bufLen; } @@ -748,7 +750,7 @@ export namespace String { } export function encode(str: string): ArrayBuffer { - var size = changetype(changetype(str) - BLOCK_OVERHEAD).rtSize; + var size = UTF16.byteLength(str); var buf = __alloc(size, idof()); memory.copy(buf, changetype(str), size); return changetype(buf); // retains diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index e04d0bea08..97b4a660e9 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -1793,9 +1793,7 @@ (local $1 i32) (local $2 i32) local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 + call $~lib/string/String.UTF16.byteLength local.tee $1 i32.const 0 call $~lib/rt/tlsf/__alloc @@ -2290,10 +2288,9 @@ local.get $0 i32.add local.set $4 - i32.const 1 - i32.const 0 local.get $1 - select + i32.const 0 + i32.ne local.set $2 loop $continue|0 block $break|0 @@ -2306,26 +2303,23 @@ local.tee $3 i32.const 128 i32.lt_u - if + if (result i32) local.get $3 i32.eqz - i32.const 0 local.get $1 - select + i32.and br_if $break|0 local.get $2 i32.const 1 i32.add - local.set $2 else local.get $3 i32.const 2048 i32.lt_u - if + if (result i32) local.get $2 i32.const 2 i32.add - local.set $2 else local.get $0 i32.const 2 @@ -2347,23 +2341,23 @@ i32.const 56320 i32.eq if - local.get $0 - i32.const 4 - i32.add - local.set $0 local.get $2 i32.const 4 i32.add local.set $2 + local.get $0 + i32.const 4 + i32.add + local.set $0 br $continue|0 end end local.get $2 i32.const 3 i32.add - local.set $2 end end + local.set $2 local.get $0 i32.const 2 i32.add @@ -2746,7 +2740,7 @@ if i32.const 0 i32.const 480 - i32.const 685 + i32.const 687 i32.const 8 call $~lib/builtins/abort unreachable @@ -2769,7 +2763,7 @@ if i32.const 0 i32.const 480 - i32.const 689 + i32.const 691 i32.const 8 call $~lib/builtins/abort unreachable @@ -3087,7 +3081,7 @@ if i32.const 0 i32.const 480 - i32.const 703 + i32.const 705 i32.const 6 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index b050d30eae..1ebfcbbd8b 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -3314,9 +3314,7 @@ call $~lib/rt/pure/__retain local.set $0 local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 + call $~lib/string/String.UTF16.byteLength local.set $1 local.get $1 i32.const 0 @@ -3944,11 +3942,8 @@ i32.add local.set $3 local.get $1 - if (result i32) - i32.const 1 - else - i32.const 0 - end + i32.const 0 + i32.ne local.set $4 block $break|0 loop $continue|0 @@ -3965,12 +3960,9 @@ i32.lt_u if local.get $1 - if (result i32) - local.get $5 - i32.eqz - else - i32.const 0 - end + local.get $5 + i32.eqz + i32.and if br $break|0 end @@ -3978,10 +3970,6 @@ i32.const 1 i32.add local.set $4 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $5 i32.const 2048 @@ -3991,10 +3979,6 @@ i32.const 2 i32.add local.set $4 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $5 i32.const 64512 @@ -4018,27 +4002,27 @@ i32.const 56320 i32.eq if - local.get $2 - i32.const 4 - i32.add - local.set $2 local.get $4 i32.const 4 i32.add local.set $4 + local.get $2 + i32.const 4 + i32.add + local.set $2 br $continue|0 end end - local.get $2 - i32.const 2 - i32.add - local.set $2 local.get $4 i32.const 3 i32.add local.set $4 end end + local.get $2 + i32.const 2 + i32.add + local.set $2 br $continue|0 end unreachable @@ -4469,7 +4453,7 @@ if i32.const 0 i32.const 480 - i32.const 685 + i32.const 687 i32.const 8 call $~lib/builtins/abort unreachable @@ -4493,7 +4477,7 @@ if i32.const 0 i32.const 480 - i32.const 689 + i32.const 691 i32.const 8 call $~lib/builtins/abort unreachable @@ -4852,7 +4836,7 @@ if i32.const 0 i32.const 480 - i32.const 703 + i32.const 705 i32.const 6 call $~lib/builtins/abort unreachable From c6900316597ba807101d4f144866121ca5abbfee Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 1 Jan 2020 16:29:32 +0200 Subject: [PATCH 09/17] rebuild --- .../std/string-encoding.optimized.wat | 66 +++++++++---------- .../std/string-encoding.untouched.wat | 6 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index bd895da70d..736026f308 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -1766,7 +1766,13 @@ call $~lib/rt/pure/decrement end ) - (func $~lib/string/String.UTF16.encode (; 30 ;) (param $0 i32) (result i32) + (func $~lib/string/String.UTF16.byteLength (; 30 ;) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + ) + (func $~lib/string/String.UTF16.encode (; 31 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) local.get $0 @@ -1781,12 +1787,6 @@ local.get $2 call $~lib/rt/pure/__retain ) - (func $~lib/arraybuffer/ArrayBuffer#get:byteLength (; 31 ;) (param $0 i32) (result i32) - local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 - ) (func $std/string-encoding/testUTF16Encode (; 32 ;) (local $0 i32) (local $1 i32) @@ -1794,7 +1794,7 @@ call $~lib/string/String.UTF16.encode local.tee $1 local.tee $0 - call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/string/String.UTF16.byteLength i32.const 12 i32.ne if @@ -1966,7 +1966,7 @@ (func $~lib/string/String.UTF16.decode (; 34 ;) (param $0 i32) (result i32) local.get $0 local.get $0 - call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/string/String.UTF16.byteLength call $~lib/string/String.UTF16.decodeUnsafe ) (func $~lib/string/String#get:length (; 35 ;) (param $0 i32) (result i32) @@ -2127,8 +2127,8 @@ i32.const 32 call $~lib/string/String.UTF16.encode local.set $0 - i32.const 28 - i32.load + i32.const 32 + call $~lib/string/String.UTF16.byteLength local.set $1 local.get $0 i32.const 0 @@ -2148,7 +2148,7 @@ local.get $0 local.get $1 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $1 + local.tee $3 i32.const 32 call $~lib/string/String.__eq i32.eqz @@ -2163,7 +2163,7 @@ local.get $0 i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $3 + local.tee $4 i32.const 416 call $~lib/string/String.__eq i32.eqz @@ -2180,7 +2180,7 @@ i32.add i32.const 2 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $4 + local.tee $5 i32.const 448 call $~lib/string/String.__eq i32.eqz @@ -2197,7 +2197,7 @@ i32.add i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $5 + local.tee $6 i32.const 480 call $~lib/string/String.__eq i32.eqz @@ -2214,7 +2214,7 @@ i32.add i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $6 + local.tee $7 i32.const 512 call $~lib/string/String.__eq i32.eqz @@ -2231,7 +2231,7 @@ i32.add i32.const 0 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $7 + local.tee $1 i32.const 400 call $~lib/string/String.__eq i32.eqz @@ -2245,8 +2245,6 @@ end local.get $2 call $~lib/rt/pure/__release - local.get $1 - call $~lib/rt/pure/__release local.get $3 call $~lib/rt/pure/__release local.get $4 @@ -2257,6 +2255,8 @@ call $~lib/rt/pure/__release local.get $7 call $~lib/rt/pure/__release + local.get $1 + call $~lib/rt/pure/__release local.get $0 call $~lib/rt/pure/__release ) @@ -2287,9 +2287,9 @@ i32.const 128 i32.lt_u if (result i32) + local.get $1 local.get $3 i32.eqz - local.get $1 i32.and br_if $break|0 local.get $2 @@ -2563,9 +2563,9 @@ i32.const 128 i32.lt_u if + local.get $1 local.get $3 i32.eqz - local.get $1 i32.and br_if $break|0 local.get $2 @@ -2718,7 +2718,7 @@ if i32.const 0 i32.const 544 - i32.const 684 + i32.const 687 i32.const 8 call $~lib/builtins/abort unreachable @@ -2741,7 +2741,7 @@ if i32.const 0 i32.const 544 - i32.const 688 + i32.const 691 i32.const 8 call $~lib/builtins/abort unreachable @@ -2758,7 +2758,7 @@ call $~lib/string/String.UTF8.encode local.tee $1 local.tee $0 - call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/string/String.UTF16.byteLength i32.const 10 i32.ne if @@ -2900,7 +2900,7 @@ call $~lib/string/String.UTF8.encode local.tee $1 local.tee $0 - call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/string/String.UTF16.byteLength i32.const 11 i32.ne if @@ -3059,7 +3059,7 @@ if i32.const 0 i32.const 544 - i32.const 702 + i32.const 705 i32.const 6 call $~lib/builtins/abort unreachable @@ -3108,12 +3108,12 @@ i32.eq if local.get $1 + local.get $5 local.get $3 i32.const 31 i32.and i32.const 6 i32.shl - local.get $5 i32.or i32.store16 else @@ -3136,6 +3136,7 @@ i32.const 224 i32.eq if + local.get $7 local.get $3 i32.const 15 i32.and @@ -3145,7 +3146,6 @@ i32.const 6 i32.shl i32.or - local.get $7 i32.or local.set $3 else @@ -3210,9 +3210,9 @@ end end else + local.get $2 local.get $3 i32.eqz - local.get $2 i32.and br_if $break|0 local.get $1 @@ -3236,7 +3236,7 @@ (func $~lib/string/String.UTF8.decode (; 48 ;) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $0 - call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/string/String.UTF16.byteLength local.get $1 call $~lib/string/String.UTF8.decodeUnsafe ) @@ -3308,7 +3308,7 @@ i32.const 1 call $~lib/string/String.UTF8.encode local.tee $0 - call $~lib/arraybuffer/ArrayBuffer#get:byteLength + call $~lib/string/String.UTF16.byteLength i32.const 4 i32.ne if @@ -3623,8 +3623,8 @@ call $~lib/rt/pure/__release ) (func $start:std/string-encoding (; 53 ;) - i32.const 28 - i32.load + i32.const 32 + call $~lib/string/String.UTF16.byteLength i32.const 12 i32.ne if diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 8dccd93ca6..eab0f3d14e 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4434,7 +4434,7 @@ if i32.const 0 i32.const 544 - i32.const 684 + i32.const 687 i32.const 8 call $~lib/builtins/abort unreachable @@ -4458,7 +4458,7 @@ if i32.const 0 i32.const 544 - i32.const 688 + i32.const 691 i32.const 8 call $~lib/builtins/abort unreachable @@ -4817,7 +4817,7 @@ if i32.const 0 i32.const 544 - i32.const 702 + i32.const 705 i32.const 6 call $~lib/builtins/abort unreachable From cb6bb7fdaafcecfd3d3733902b789010d69e9025 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Fri, 10 Jan 2020 17:09:49 +0200 Subject: [PATCH 10/17] rebuild --- .../std/string-encoding.optimized.wat | 42 ++++++++++--------- .../std/string-encoding.untouched.wat | 6 +-- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 4efb6b7688..f0bc7ff6f2 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -2123,14 +2123,15 @@ (local $7 i32) i32.const 32 call $~lib/string/String.UTF16.encode - local.set $0 + local.set $2 i32.const 32 call $~lib/string/String.UTF16.byteLength local.set $1 - local.get $0 + local.get $2 + local.tee $0 i32.const 0 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $2 + local.tee $3 i32.const 400 call $~lib/string/String.__eq i32.eqz @@ -2145,7 +2146,7 @@ local.get $0 local.get $1 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $3 + local.tee $4 i32.const 32 call $~lib/string/String.__eq i32.eqz @@ -2160,7 +2161,7 @@ local.get $0 i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $4 + local.tee $5 i32.const 416 call $~lib/string/String.__eq i32.eqz @@ -2177,7 +2178,7 @@ i32.add i32.const 2 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $5 + local.tee $6 i32.const 448 call $~lib/string/String.__eq i32.eqz @@ -2194,7 +2195,7 @@ i32.add i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $6 + local.tee $7 i32.const 480 call $~lib/string/String.__eq i32.eqz @@ -2211,7 +2212,7 @@ i32.add i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $7 + local.tee $1 i32.const 512 call $~lib/string/String.__eq i32.eqz @@ -2228,7 +2229,7 @@ i32.add i32.const 0 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $1 + local.tee $0 i32.const 400 call $~lib/string/String.__eq i32.eqz @@ -2240,8 +2241,6 @@ call $~lib/builtins/abort unreachable end - local.get $2 - call $~lib/rt/pure/__release local.get $3 call $~lib/rt/pure/__release local.get $4 @@ -2256,6 +2255,8 @@ call $~lib/rt/pure/__release local.get $0 call $~lib/rt/pure/__release + local.get $2 + call $~lib/rt/pure/__release ) (func $~lib/string/String.UTF8.byteLength (; 40 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) @@ -2715,7 +2716,7 @@ if i32.const 0 i32.const 544 - i32.const 696 + i32.const 699 i32.const 8 call $~lib/builtins/abort unreachable @@ -2738,7 +2739,7 @@ if i32.const 0 i32.const 544 - i32.const 700 + i32.const 703 i32.const 8 call $~lib/builtins/abort unreachable @@ -3056,7 +3057,7 @@ if i32.const 0 i32.const 544 - i32.const 714 + i32.const 717 i32.const 6 call $~lib/builtins/abort unreachable @@ -3620,9 +3621,9 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $start (; 53 ;) - i32.const 28 - i32.load + (func $start:std/string-encoding (; 53 ;) + i32.const 32 + call $~lib/string/String.UTF16.byteLength i32.const 12 i32.ne if @@ -3647,7 +3648,10 @@ i32.const 13808 call $std/string-encoding/testLarge ) - (func $~lib/rt/pure/__visit (; 54 ;) (param $0 i32) (param $1 i32) + (func $start (; 54 ;) + call $start:std/string-encoding + ) + (func $~lib/rt/pure/__visit (; 55 ;) (param $0 i32) (param $1 i32) local.get $0 i32.const 21196 i32.lt_u @@ -3750,7 +3754,7 @@ unreachable end ) - (func $~lib/rt/__visit_members (; 55 ;) (param $0 i32) (param $1 i32) + (func $~lib/rt/__visit_members (; 56 ;) (param $0 i32) (param $1 i32) block $switch$1$default block $switch$1$case$4 block $switch$1$case$2 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 5efb15943d..591f95f7b3 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4434,7 +4434,7 @@ if i32.const 0 i32.const 544 - i32.const 696 + i32.const 699 i32.const 8 call $~lib/builtins/abort unreachable @@ -4458,7 +4458,7 @@ if i32.const 0 i32.const 544 - i32.const 700 + i32.const 703 i32.const 8 call $~lib/builtins/abort unreachable @@ -4817,7 +4817,7 @@ if i32.const 0 i32.const 544 - i32.const 714 + i32.const 717 i32.const 6 call $~lib/builtins/abort unreachable From 187340a747db58eb8c8fce8faf137e4e06ee625b Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Fri, 10 Jan 2020 20:31:05 +0200 Subject: [PATCH 11/17] update encode --- std/assembly/string.ts | 9 +++--- .../std/string-encoding.optimized.wat | 22 +++++++------- .../std/string-encoding.untouched.wat | 30 +++++++------------ 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index a9a9e6d5bd..0e017ac976 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -671,11 +671,11 @@ export namespace String { // @ts-ignore: cast if (nullTerminated & !c1) break; store(bufOff, c1); - bufOff += 1; strOff += 2; + bufOff += 1; } else if (c1 < 2048) { store(bufOff, c1 >> 6 | 192); store(bufOff, c1 & 63 | 128, 1); - bufOff += 2; strOff += 2; + bufOff += 2; } else { if ((c1 & 0xFC00) == 0xD800 && strOff + 2 < strEnd) { let c2 = load(strOff, 2); @@ -685,15 +685,16 @@ export namespace String { store(bufOff, c1 >> 12 & 63 | 128, 1); store(bufOff, c1 >> 6 & 63 | 128, 2); store(bufOff, c1 & 63 | 128, 3); - strOff += 4; bufOff += 4; + bufOff += 4; strOff += 4; continue; } } store(bufOff, c1 >> 12 | 224); store(bufOff, c1 >> 6 & 63 | 128, 1); store(bufOff, c1 & 63 | 128, 2); - strOff += 2; bufOff += 3; + bufOff += 3; } + strOff += 2; } if (nullTerminated) { assert(strOff <= strEnd); diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index f0bc7ff6f2..1c64b46d1b 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -2560,7 +2560,7 @@ local.tee $3 i32.const 128 i32.lt_u - if + if (result i32) local.get $1 local.get $3 i32.eqz @@ -2572,12 +2572,11 @@ local.get $2 i32.const 1 i32.add - local.set $2 else local.get $3 i32.const 2048 i32.lt_u - if + if (result i32) local.get $2 local.get $3 i32.const 6 @@ -2595,7 +2594,6 @@ local.get $2 i32.const 2 i32.add - local.set $2 else local.get $0 i32.const 2 @@ -2661,14 +2659,14 @@ i32.const 128 i32.or i32.store8 offset=3 - local.get $0 - i32.const 4 - i32.add - local.set $0 local.get $2 i32.const 4 i32.add local.set $2 + local.get $0 + i32.const 4 + i32.add + local.set $0 br $continue|0 end end @@ -2698,9 +2696,9 @@ local.get $2 i32.const 3 i32.add - local.set $2 end end + local.set $2 local.get $0 i32.const 2 i32.add @@ -2716,7 +2714,7 @@ if i32.const 0 i32.const 544 - i32.const 699 + i32.const 700 i32.const 8 call $~lib/builtins/abort unreachable @@ -2739,7 +2737,7 @@ if i32.const 0 i32.const 544 - i32.const 703 + i32.const 704 i32.const 8 call $~lib/builtins/abort unreachable @@ -3057,7 +3055,7 @@ if i32.const 0 i32.const 544 - i32.const 717 + i32.const 718 i32.const 6 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 591f95f7b3..6fe4fb2d40 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4277,10 +4277,6 @@ i32.const 1 i32.add local.set $5 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $6 i32.const 2048 @@ -4304,10 +4300,6 @@ i32.const 2 i32.add local.set $5 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $6 i32.const 64512 @@ -4377,14 +4369,14 @@ i32.const 128 i32.or i32.store8 offset=3 - local.get $2 - i32.const 4 - i32.add - local.set $2 local.get $5 i32.const 4 i32.add local.set $5 + local.get $2 + i32.const 4 + i32.add + local.set $2 br $continue|0 end end @@ -4411,16 +4403,16 @@ i32.const 128 i32.or i32.store8 offset=2 - local.get $2 - i32.const 2 - i32.add - local.set $2 local.get $5 i32.const 3 i32.add local.set $5 end end + local.get $2 + i32.const 2 + i32.add + local.set $2 br $continue|0 end unreachable @@ -4434,7 +4426,7 @@ if i32.const 0 i32.const 544 - i32.const 699 + i32.const 700 i32.const 8 call $~lib/builtins/abort unreachable @@ -4458,7 +4450,7 @@ if i32.const 0 i32.const 544 - i32.const 703 + i32.const 704 i32.const 8 call $~lib/builtins/abort unreachable @@ -4817,7 +4809,7 @@ if i32.const 0 i32.const 544 - i32.const 717 + i32.const 718 i32.const 6 call $~lib/builtins/abort unreachable From a9968cbb5a270c5697c3842d3c63313c4912828a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 11 Jan 2020 22:00:09 +0200 Subject: [PATCH 12/17] rebuild --- .../std/string-encoding.optimized.wat | 244 ++++++++--------- .../std/string-encoding.untouched.wat | 248 ++++++++---------- 2 files changed, 222 insertions(+), 270 deletions(-) diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 7f97c9b75b..4dd99a0bd4 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -2280,12 +2280,11 @@ local.tee $3 i32.const 128 i32.lt_u - if + if (result i32) + local.get $1 local.get $3 i32.eqz - i32.const 0 - local.get $1 - select + i32.and br_if $while-break|0 local.get $2 i32.const 1 @@ -2294,11 +2293,10 @@ local.get $3 i32.const 2048 i32.lt_u - if + if (result i32) local.get $2 i32.const 2 i32.add - local.set $2 else local.get $0 i32.const 2 @@ -2320,23 +2318,23 @@ i32.const 56320 i32.eq if - local.get $0 - i32.const 4 - i32.add - local.set $0 local.get $2 i32.const 4 i32.add local.set $2 + local.get $0 + i32.const 4 + i32.add + local.set $0 br $while-continue|0 end end local.get $2 i32.const 3 i32.add - local.set $2 end end + local.set $2 local.get $0 i32.const 2 i32.add @@ -2559,12 +2557,11 @@ local.tee $3 i32.const 128 i32.lt_u - if + if (result i32) + local.get $1 local.get $3 i32.eqz - i32.const 0 - local.get $1 - select + i32.and br_if $while-break|0 local.get $2 local.get $3 @@ -2576,7 +2573,7 @@ local.get $3 i32.const 2048 i32.lt_u - if + if (result i32) local.get $2 local.get $3 i32.const 6 @@ -2594,7 +2591,6 @@ local.get $2 i32.const 2 i32.add - local.set $2 else local.get $0 i32.const 2 @@ -2660,14 +2656,14 @@ i32.const 128 i32.or i32.store8 offset=3 - local.get $0 - i32.const 4 - i32.add - local.set $0 local.get $2 i32.const 4 i32.add local.set $2 + local.get $0 + i32.const 4 + i32.add + local.set $0 br $while-continue|0 end end @@ -2697,9 +2693,9 @@ local.get $2 i32.const 3 i32.add - local.set $2 end end + local.set $2 local.get $0 i32.const 2 i32.add @@ -3068,177 +3064,159 @@ i32.const 1 call $~lib/rt/tlsf/__alloc local.tee $6 - local.set $3 + local.set $1 loop $while-continue|0 local.get $0 - local.get $5 + local.get $4 i32.lt_u if block $while-break|0 local.get $0 - local.tee $1 + i32.load8_u + local.set $3 + local.get $0 i32.const 1 i32.add local.set $0 - local.get $1 - i32.load8_u - local.tee $4 + local.get $3 i32.const 128 - i32.lt_u + i32.and if + local.get $0 local.get $4 - i32.eqz - i32.const 0 - local.get $2 - select + i32.eq br_if $while-break|0 - local.get $3 - local.get $4 - i32.store16 - else local.get $0 - local.get $4 + i32.load8_u + i32.const 63 + i32.and + local.set $5 + local.get $0 + i32.const 1 + i32.add + local.set $0 + local.get $3 i32.const 224 - i32.lt_u - i32.const 0 - local.get $4 - i32.const 191 - i32.gt_u - select + i32.and + i32.const 192 + i32.eq if + local.get $1 local.get $5 + local.get $3 + i32.const 31 + i32.and i32.const 6 i32.shl i32.or - i32.or - local.set $3 + i32.store16 else local.get $0 - i32.sub - i32.const 1 - i32.lt_u + local.get $4 + i32.eq br_if $while-break|0 local.get $0 - local.tee $1 + i32.load8_u + i32.const 63 + i32.and + local.set $7 + local.get $0 i32.const 1 i32.add local.set $0 local.get $3 - local.get $1 - i32.load8_u - i32.const 63 - i32.and - local.get $4 - i32.const 31 + i32.const 240 i32.and - i32.const 6 - i32.shl - i32.or - i32.store16 - local.get $3 - i32.const 2 - i32.add - local.set $3 - else - local.get $4 - i32.const 365 - i32.lt_u - i32.const 0 - local.get $4 - i32.const 239 - i32.gt_u - select - if (result i32) + i32.const 224 + i32.eq + if + local.get $7 + local.get $3 + i32.const 15 + i32.and + i32.const 12 + i32.shl local.get $5 + i32.const 6 + i32.shl + i32.or + i32.or + local.set $3 + else local.get $0 - i32.sub - i32.const 3 - i32.lt_u + local.get $4 + i32.eq br_if $while-break|0 - local.get $3 local.get $0 - i32.load8_u offset=2 + i32.load8_u i32.const 63 i32.and - local.get $4 + local.get $3 i32.const 7 i32.and i32.const 18 i32.shl - local.get $0 - i32.load8_u - i32.const 63 - i32.and + local.get $5 i32.const 12 i32.shl i32.or - local.get $0 - i32.load8_u offset=1 - i32.const 63 - i32.and + local.get $7 i32.const 6 i32.shl i32.or i32.or + local.set $3 + local.get $0 + i32.const 1 + i32.add + local.set $0 + end + local.get $3 + i32.const 65536 + i32.lt_u + if + local.get $1 + local.get $3 + i32.store16 + else + local.get $1 + local.get $3 i32.const 65536 i32.sub - local.tee $1 + local.tee $3 i32.const 10 i32.shr_u i32.const 55296 i32.or - i32.store16 local.get $3 - local.get $1 i32.const 1023 i32.and i32.const 56320 i32.or - i32.store16 offset=2 - local.get $3 - i32.const 4 - i32.add - local.set $3 - local.get $0 - i32.const 3 - i32.add - else - local.get $5 - local.get $0 - i32.sub - i32.const 2 - i32.lt_u - br_if $while-break|0 - local.get $3 - local.get $0 - i32.load8_u offset=1 - i32.const 63 - i32.and - local.get $4 - i32.const 15 - i32.and - i32.const 12 - i32.shl - local.get $0 - i32.load8_u - i32.const 63 - i32.and - i32.const 6 + i32.const 16 i32.shl i32.or - i32.or - i32.store16 - local.get $3 - i32.const 2 - i32.add - local.set $3 - local.get $0 + i32.store + local.get $1 i32.const 2 i32.add + local.set $1 end - local.set $0 end + else + local.get $2 + local.get $3 + i32.eqz + i32.and + br_if $while-break|0 + local.get $1 + local.get $3 + i32.store16 end + local.get $1 + i32.const 2 + i32.add + local.set $1 br $while-continue|0 end end @@ -3640,9 +3618,9 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $~start (; 53 ;) - i32.const 28 - i32.load + (func $start:std/string-encoding (; 53 ;) + i32.const 32 + call $~lib/string/String.UTF16.byteLength i32.const 12 i32.ne if @@ -3667,7 +3645,7 @@ i32.const 13808 call $std/string-encoding/testLarge ) - (func $start (; 54 ;) + (func $~start (; 54 ;) call $start:std/string-encoding ) (func $~lib/rt/pure/__visit (; 55 ;) (param $0 i32) (param $1 i32) diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 5c8ca881e9..91120454f6 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -3939,12 +3939,9 @@ i32.lt_u if local.get $1 - if (result i32) - local.get $6 - i32.eqz - else - i32.const 0 - end + local.get $6 + i32.eqz + i32.and if br $while-break|0 end @@ -3961,10 +3958,6 @@ i32.const 2 i32.add local.set $4 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $6 i32.const 64512 @@ -3988,27 +3981,27 @@ i32.const 56320 i32.eq if - local.get $2 - i32.const 4 - i32.add - local.set $2 local.get $4 i32.const 4 i32.add local.set $4 + local.get $2 + i32.const 4 + i32.add + local.set $2 br $while-continue|0 end end - local.get $2 - i32.const 2 - i32.add - local.set $2 local.get $4 i32.const 3 i32.add local.set $4 end end + local.get $2 + i32.const 2 + i32.add + local.set $2 br $while-continue|0 end end @@ -4266,12 +4259,9 @@ i32.lt_u if local.get $1 - if (result i32) - local.get $7 - i32.eqz - else - i32.const 0 - end + local.get $7 + i32.eqz + i32.and if br $while-break|0 end @@ -4305,10 +4295,6 @@ i32.const 2 i32.add local.set $5 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $7 i32.const 64512 @@ -4378,14 +4364,14 @@ i32.const 128 i32.or i32.store8 offset=3 - local.get $2 - i32.const 4 - i32.add - local.set $2 local.get $5 i32.const 4 i32.add local.set $5 + local.get $2 + i32.const 4 + i32.add + local.set $2 br $while-continue|0 end end @@ -4412,16 +4398,16 @@ i32.const 128 i32.or i32.store8 offset=2 - local.get $2 - i32.const 2 - i32.add - local.set $2 local.get $5 i32.const 3 i32.add local.set $5 end end + local.get $2 + i32.const 2 + i32.add + local.set $2 br $while-continue|0 end end @@ -4803,6 +4789,9 @@ (local $7 i32) (local $8 i32) (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 i32) local.get $0 local.set $3 local.get $0 @@ -4838,89 +4827,96 @@ local.get $7 if local.get $3 - local.tee $8 + i32.load8_u + local.set $8 + local.get $3 i32.const 1 i32.add local.set $3 local.get $8 - i32.load8_u - local.set $8 - local.get $8 i32.const 128 - i32.lt_u + i32.and + i32.eqz if local.get $2 - if (result i32) - local.get $8 - i32.eqz - else - i32.const 0 - end + local.get $8 + i32.eqz + i32.and if br $while-break|0 end local.get $6 local.get $8 i32.store16 - local.get $6 - i32.const 2 - i32.add - local.set $6 else + local.get $4 + local.get $3 + i32.eq + if + br $while-break|0 + end + local.get $3 + i32.load8_u + i32.const 63 + i32.and + local.set $9 + local.get $3 + i32.const 1 + i32.add + local.set $3 local.get $8 - i32.const 191 - i32.gt_u - if (result i32) + i32.const 224 + i32.and + i32.const 192 + i32.eq + if + local.get $6 local.get $8 - i32.const 224 - i32.lt_u + i32.const 31 + i32.and + i32.const 6 + i32.shl + local.get $9 + i32.or + i32.store16 else local.get $4 local.get $3 - i32.sub - i32.const 1 - i32.lt_u + i32.eq if br $while-break|0 end - local.get $6 - local.get $8 - i32.const 31 - i32.and - i32.const 6 - i32.shl local.get $3 - local.tee $9 - i32.const 1 - i32.add - local.set $3 - local.get $9 i32.load8_u i32.const 63 i32.and - i32.or - i32.store16 - local.get $6 - i32.const 2 + local.set $10 + local.get $3 + i32.const 1 i32.add - local.set $6 - else + local.set $3 local.get $8 - i32.const 239 - i32.gt_u - if (result i32) + i32.const 240 + i32.and + i32.const 224 + i32.eq + if local.get $8 - i32.const 365 - i32.lt_u + i32.const 15 + i32.and + i32.const 12 + i32.shl + local.get $9 + i32.const 6 + i32.shl + i32.or + local.get $10 + i32.or + local.set $8 else - i32.const 0 - end - if local.get $4 local.get $3 - i32.sub - i32.const 3 - i32.lt_u + i32.eq if br $while-break|0 end @@ -4929,82 +4925,56 @@ i32.and i32.const 18 i32.shl - local.get $3 - i32.load8_u - i32.const 63 - i32.and + local.get $9 i32.const 12 i32.shl i32.or - local.get $3 - i32.load8_u offset=1 - i32.const 63 - i32.and + local.get $10 i32.const 6 i32.shl i32.or local.get $3 - i32.load8_u offset=2 + i32.load8_u i32.const 63 i32.and i32.or - i32.const 65536 - i32.sub local.set $8 local.get $3 - i32.const 3 + i32.const 1 i32.add local.set $3 + end + local.get $8 + i32.const 65536 + i32.lt_u + if local.get $6 - i32.const 55296 + local.get $8 + i32.store16 + else + local.get $8 + i32.const 65536 + i32.sub + local.set $8 local.get $8 i32.const 10 i32.shr_u + i32.const 55296 i32.or - i32.store16 - local.get $6 - i32.const 56320 + local.set $11 local.get $8 i32.const 1023 i32.and + i32.const 56320 i32.or - i32.store16 offset=2 + local.set $12 local.get $6 - i32.const 4 - i32.add - local.set $6 - else - local.get $4 - local.get $3 - i32.sub - i32.const 2 - i32.lt_u - if - br $while-break|0 - end - local.get $6 - local.get $8 - i32.const 15 - i32.and - i32.const 12 - i32.shl - local.get $3 - i32.load8_u - i32.const 63 - i32.and - i32.const 6 + local.get $11 + local.get $12 + i32.const 16 i32.shl i32.or - local.get $3 - i32.load8_u offset=1 - i32.const 63 - i32.and - i32.or - i32.store16 - local.get $3 - i32.const 2 - i32.add - local.set $3 + i32.store local.get $6 i32.const 2 i32.add @@ -5012,6 +4982,10 @@ end end end + local.get $6 + i32.const 2 + i32.add + local.set $6 br $while-continue|0 end end From 6977e7618c1c7bea67a8bdee59da6281665953ab Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 20 Jan 2020 04:23:34 +0200 Subject: [PATCH 13/17] rebuild --- .../std/string-encoding.optimized.wat | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 9eb93febea..8baa1156f7 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -1,6 +1,6 @@ (module - (type $i32_=>_none (func (param i32))) (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) (type $i32_=>_i32 (func (param i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $i32_i32_=>_none (func (param i32 i32))) @@ -1772,15 +1772,13 @@ call $~lib/rt/pure/decrement end ) - (func $~lib/string/String.UTF16.encode (; 31 ;) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) + (func $~lib/string/String.UTF16.byteLength (; 31 ;) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub i32.load offset=12 ) - (func $~lib/string/String.UTF16.encode (; 31 ;) (param $0 i32) (result i32) + (func $~lib/string/String.UTF16.encode (; 32 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) local.get $0 @@ -1795,12 +1793,6 @@ local.get $2 call $~lib/rt/pure/__retain ) - (func $~lib/arraybuffer/ArrayBuffer#get:byteLength (; 32 ;) (param $0 i32) (result i32) - local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 - ) (func $std/string-encoding/testUTF16Encode (; 33 ;) (local $0 i32) (local $1 i32) @@ -3594,9 +3586,9 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $~start (; 54 ;) - i32.const 28 - i32.load + (func $start:std/string-encoding (; 54 ;) + i32.const 32 + call $~lib/string/String.UTF16.byteLength i32.const 12 i32.ne if @@ -3621,7 +3613,10 @@ i32.const 13808 call $std/string-encoding/testLarge ) - (func $~lib/rt/pure/__visit (; 55 ;) (param $0 i32) (param $1 i32) + (func $~start (; 55 ;) + call $start:std/string-encoding + ) + (func $~lib/rt/pure/__visit (; 56 ;) (param $0 i32) (param $1 i32) local.get $0 i32.const 21196 i32.lt_u @@ -3724,7 +3719,7 @@ unreachable end ) - (func $~lib/rt/__visit_members (; 56 ;) (param $0 i32) (param $1 i32) + (func $~lib/rt/__visit_members (; 57 ;) (param $0 i32) (param $1 i32) block $switch$1$default block $switch$1$case$4 block $switch$1$case$2 From 77e95a7fdf71e76a0b99fa90cbcae4476f38d2c3 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 23 Jan 2020 21:17:44 +0200 Subject: [PATCH 14/17] rebuild --- .../std/string-encoding.optimized.wat | 46 +++++++++---------- .../std/string-encoding.untouched.wat | 28 ++++------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 4480eb3753..36361fbe5b 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -2428,10 +2428,6 @@ local.get $0 local.get $2 i32.store8 - local.get $3 - i32.const 2 - i32.add - local.set $3 local.get $0 i32.const 1 i32.add @@ -2454,10 +2450,6 @@ i32.const 128 i32.or i32.store8 offset=1 - local.get $3 - i32.const 2 - i32.add - local.set $3 local.get $0 i32.const 2 i32.add @@ -2526,14 +2518,14 @@ i32.const 128 i32.or i32.store8 offset=3 - local.get $3 - i32.const 4 - i32.add - local.set $3 local.get $0 i32.const 4 i32.add local.set $0 + local.get $3 + i32.const 4 + i32.add + local.set $3 br $while-continue|0 end end @@ -2560,16 +2552,16 @@ i32.const 128 i32.or i32.store8 offset=2 - local.get $3 - i32.const 2 - i32.add - local.set $3 local.get $0 i32.const 3 i32.add end end local.set $0 + local.get $3 + i32.const 2 + i32.add + local.set $3 br $while-continue|0 end end @@ -2579,7 +2571,7 @@ if i32.const 0 i32.const 544 - i32.const 696 + i32.const 699 i32.const 6 call $~lib/builtins/abort unreachable @@ -2995,16 +2987,17 @@ (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) local.get $0 local.get $1 i32.add - local.tee $5 + local.tee $4 local.get $0 i32.lt_u if i32.const 0 i32.const 544 - i32.const 712 + i32.const 715 i32.const 6 call $~lib/builtins/abort unreachable @@ -3175,7 +3168,7 @@ call $~lib/rt/tlsf/maybeInitialize local.get $6 call $~lib/rt/tlsf/checkUsedBlock - local.get $3 + local.get $1 local.get $6 i32.sub call $~lib/rt/tlsf/reallocateBlock @@ -3573,9 +3566,9 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $~start (; 53 ;) - i32.const 28 - i32.load + (func $start:std/string-encoding (; 53 ;) + i32.const 32 + call $~lib/string/String.UTF16.byteLength i32.const 12 i32.ne if @@ -3600,7 +3593,10 @@ i32.const 13808 call $std/string-encoding/testLarge ) - (func $~lib/rt/pure/__visit (; 54 ;) (param $0 i32) (param $1 i32) + (func $~start (; 54 ;) + call $start:std/string-encoding + ) + (func $~lib/rt/pure/__visit (; 55 ;) (param $0 i32) (param $1 i32) local.get $0 i32.const 21196 i32.lt_u @@ -3703,7 +3699,7 @@ unreachable end ) - (func $~lib/rt/__visit_members (; 55 ;) (param $0 i32) (param $1 i32) + (func $~lib/rt/__visit_members (; 56 ;) (param $0 i32) (param $1 i32) block $switch$1$default block $switch$1$case$4 block $switch$1$case$2 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index f5fa48061c..b4cb9f0f13 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4114,10 +4114,6 @@ i32.const 1 i32.add local.set $7 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $9 i32.const 2048 @@ -4141,10 +4137,6 @@ i32.const 2 i32.add local.set $7 - local.get $2 - i32.const 2 - i32.add - local.set $2 else local.get $9 i32.const 64512 @@ -4214,14 +4206,14 @@ i32.const 128 i32.or i32.store8 offset=3 - local.get $2 - i32.const 4 - i32.add - local.set $2 local.get $7 i32.const 4 i32.add local.set $7 + local.get $2 + i32.const 4 + i32.add + local.set $2 br $while-continue|0 end end @@ -4248,16 +4240,16 @@ i32.const 128 i32.or i32.store8 offset=2 - local.get $2 - i32.const 2 - i32.add - local.set $2 local.get $7 i32.const 3 i32.add local.set $7 end end + local.get $2 + i32.const 2 + i32.add + local.set $2 br $while-continue|0 end end @@ -4268,7 +4260,7 @@ if i32.const 0 i32.const 544 - i32.const 696 + i32.const 699 i32.const 6 call $~lib/builtins/abort unreachable @@ -4761,7 +4753,7 @@ if i32.const 0 i32.const 544 - i32.const 712 + i32.const 715 i32.const 6 call $~lib/builtins/abort unreachable From 016c2c547cf05e24e70be1dff781df99c84673b4 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Fri, 24 Jan 2020 21:05:20 +0200 Subject: [PATCH 15/17] improve UTF8.encode --- std/assembly/string.ts | 22 +++--- .../std/string-encoding.optimized.wat | 65 +++++++++-------- .../std/string-encoding.untouched.wat | 71 +++++++++++++------ 3 files changed, 98 insertions(+), 60 deletions(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 4cb639ec22..9547ac4c43 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -673,25 +673,29 @@ export namespace String { store(bufOff, c1); bufOff += 1; } else if (c1 < 2048) { - store(bufOff, c1 >> 6 | 192); - store(bufOff, c1 & 63 | 128, 1); + let b0 = c1 >> 6 | 192; + let b1 = c1 & 63 | 128; + store(bufOff, b1 << 8 | b0); bufOff += 2; } else { if ((c1 & 0xFC00) == 0xD800 && strOff + 2 < strEnd) { let c2 = load(strOff, 2); if ((c2 & 0xFC00) == 0xDC00) { c1 = 0x10000 + ((c1 & 0x03FF) << 10) | (c2 & 0x03FF); - store(bufOff, c1 >> 18 | 240); - store(bufOff, c1 >> 12 & 63 | 128, 1); - store(bufOff, c1 >> 6 & 63 | 128, 2); - store(bufOff, c1 & 63 | 128, 3); + let b0 = c1 >> 18 | 240; + let b1 = c1 >> 12 & 63 | 128; + let b2 = c1 >> 6 & 63 | 128; + let b3 = c1 & 63 | 128; + store(bufOff, b3 << 24 | b2 << 16 | b1 << 8 | b0); bufOff += 4; strOff += 4; continue; } } - store(bufOff, c1 >> 12 | 224); - store(bufOff, c1 >> 6 & 63 | 128, 1); - store(bufOff, c1 & 63 | 128, 2); + let b0 = c1 >> 12 | 224; + let b1 = c1 >> 6 & 63 | 128; + let b2 = c1 & 63 | 128; + store(bufOff, b1 << 8 | b0); + store(bufOff, b2, 2); bufOff += 3; } strOff += 2; diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 36361fbe5b..308b986a57 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -2396,7 +2396,7 @@ i32.sub i32.load offset=12 i32.add - local.set $5 + local.set $6 local.get $0 local.get $1 call $~lib/string/String.UTF8.byteLength @@ -2411,12 +2411,12 @@ i32.const 0 i32.ne i32.sub - local.set $6 + local.set $7 local.get $4 local.set $0 loop $while-continue|0 local.get $0 - local.get $6 + local.get $7 i32.lt_u if local.get $3 @@ -2442,14 +2442,15 @@ i32.shr_u i32.const 192 i32.or - i32.store8 - local.get $0 local.get $2 i32.const 63 i32.and i32.const 128 i32.or - i32.store8 offset=1 + i32.const 8 + i32.shl + i32.or + i32.store16 local.get $0 i32.const 2 i32.add @@ -2457,7 +2458,7 @@ local.get $3 i32.const 2 i32.add - local.get $5 + local.get $6 i32.lt_u i32.const 0 local.get $2 @@ -2469,13 +2470,12 @@ if local.get $3 i32.load16_u offset=2 - local.tee $7 + local.tee $5 i32.const 64512 i32.and i32.const 56320 i32.eq if - local.get $0 local.get $2 i32.const 1023 i32.and @@ -2483,41 +2483,47 @@ i32.shl i32.const 65536 i32.add - local.get $7 + local.get $5 i32.const 1023 i32.and i32.or local.tee $2 - i32.const 18 - i32.shr_u - i32.const 240 - i32.or - i32.store8 - local.get $0 - local.get $2 - i32.const 12 - i32.shr_u i32.const 63 i32.and i32.const 128 i32.or - i32.store8 offset=1 + local.set $5 local.get $0 local.get $2 + i32.const 18 + i32.shr_u + i32.const 240 + i32.or + local.get $5 + i32.const 24 + i32.shl + local.get $2 i32.const 6 i32.shr_u i32.const 63 i32.and i32.const 128 i32.or - i32.store8 offset=2 - local.get $0 + i32.const 16 + i32.shl + i32.or local.get $2 + i32.const 12 + i32.shr_u i32.const 63 i32.and i32.const 128 i32.or - i32.store8 offset=3 + i32.const 8 + i32.shl + i32.or + i32.or + i32.store local.get $0 i32.const 4 i32.add @@ -2535,8 +2541,6 @@ i32.shr_u i32.const 224 i32.or - i32.store8 - local.get $0 local.get $2 i32.const 6 i32.shr_u @@ -2544,7 +2548,10 @@ i32.and i32.const 128 i32.or - i32.store8 offset=1 + i32.const 8 + i32.shl + i32.or + i32.store16 local.get $0 local.get $2 i32.const 63 @@ -2566,12 +2573,12 @@ end end local.get $3 - local.get $5 + local.get $6 i32.gt_u if i32.const 0 i32.const 544 - i32.const 699 + i32.const 703 i32.const 6 call $~lib/builtins/abort unreachable @@ -2997,7 +3004,7 @@ if i32.const 0 i32.const 544 - i32.const 715 + i32.const 719 i32.const 6 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index b4cb9f0f13..f9b37ae3b3 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -4063,6 +4063,10 @@ (local $8 i32) (local $9 i32) (local $10 i32) + (local $11 i32) + (local $12 i32) + (local $13 i32) + (local $14 i32) local.get $0 call $~lib/rt/pure/__retain local.set $0 @@ -4119,20 +4123,25 @@ i32.const 2048 i32.lt_u if - local.get $7 local.get $9 i32.const 6 i32.shr_u i32.const 192 i32.or - i32.store8 - local.get $7 + local.set $10 local.get $9 i32.const 63 i32.and i32.const 128 i32.or - i32.store8 offset=1 + local.set $11 + local.get $7 + local.get $11 + i32.const 8 + i32.shl + local.get $10 + i32.or + i32.store16 local.get $7 i32.const 2 i32.add @@ -4155,8 +4164,8 @@ if local.get $2 i32.load16_u offset=2 - local.set $10 - local.get $10 + local.set $11 + local.get $11 i32.const 64512 i32.and i32.const 56320 @@ -4169,19 +4178,17 @@ i32.const 10 i32.shl i32.add - local.get $10 + local.get $11 i32.const 1023 i32.and i32.or local.set $9 - local.get $7 local.get $9 i32.const 18 i32.shr_u i32.const 240 i32.or - i32.store8 - local.get $7 + local.set $10 local.get $9 i32.const 12 i32.shr_u @@ -4189,8 +4196,7 @@ i32.and i32.const 128 i32.or - i32.store8 offset=1 - local.get $7 + local.set $12 local.get $9 i32.const 6 i32.shr_u @@ -4198,14 +4204,28 @@ i32.and i32.const 128 i32.or - i32.store8 offset=2 - local.get $7 + local.set $13 local.get $9 i32.const 63 i32.and i32.const 128 i32.or - i32.store8 offset=3 + local.set $14 + local.get $7 + local.get $14 + i32.const 24 + i32.shl + local.get $13 + i32.const 16 + i32.shl + i32.or + local.get $12 + i32.const 8 + i32.shl + i32.or + local.get $10 + i32.or + i32.store local.get $7 i32.const 4 i32.add @@ -4217,14 +4237,12 @@ br $while-continue|0 end end - local.get $7 local.get $9 i32.const 12 i32.shr_u i32.const 224 i32.or - i32.store8 - local.get $7 + local.set $11 local.get $9 i32.const 6 i32.shr_u @@ -4232,13 +4250,22 @@ i32.and i32.const 128 i32.or - i32.store8 offset=1 - local.get $7 + local.set $14 local.get $9 i32.const 63 i32.and i32.const 128 i32.or + local.set $13 + local.get $7 + local.get $14 + i32.const 8 + i32.shl + local.get $11 + i32.or + i32.store16 + local.get $7 + local.get $13 i32.store8 offset=2 local.get $7 i32.const 3 @@ -4260,7 +4287,7 @@ if i32.const 0 i32.const 544 - i32.const 699 + i32.const 703 i32.const 6 call $~lib/builtins/abort unreachable @@ -4753,7 +4780,7 @@ if i32.const 0 i32.const 544 - i32.const 715 + i32.const 719 i32.const 6 call $~lib/builtins/abort unreachable From 3e3babb2ffcbbf4d0d466a74386c6ec1543d0720 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Fri, 24 Jan 2020 21:59:58 +0200 Subject: [PATCH 16/17] refactor --- std/assembly/string.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 9547ac4c43..7e158e25e8 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -671,7 +671,7 @@ export namespace String { let c1 = load(strOff); if (c1 < 128) { store(bufOff, c1); - bufOff += 1; + bufOff++; } else if (c1 < 2048) { let b0 = c1 >> 6 | 192; let b1 = c1 & 63 | 128; From 9f7cd5cf4bb42721fbb2b2ef2db89ac775292929 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Sat, 25 Jan 2020 16:59:49 +0200 Subject: [PATCH 17/17] rebuild --- .../std/string-encoding.optimized.wat | 73 +++++++++---------- .../std/string-encoding.untouched.wat | 8 +- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 5113e06563..cb8ad9bd81 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -99,7 +99,13 @@ call $~lib/rt/pure/decrement end ) - (func $~lib/rt/tlsf/removeBlock (; 9 ;) (param $0 i32) (param $1 i32) + (func $~lib/string/String.UTF16.byteLength (; 9 ;) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + ) + (func $~lib/rt/tlsf/removeBlock (; 10 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -265,7 +271,7 @@ end end ) - (func $~lib/rt/tlsf/insertBlock (; 10 ;) (param $0 i32) (param $1 i32) + (func $~lib/rt/tlsf/insertBlock (; 11 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -548,7 +554,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 11 ;) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 12 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -662,7 +668,7 @@ local.get $1 call $~lib/rt/tlsf/insertBlock ) - (func $~lib/rt/tlsf/maybeInitialize (; 12 ;) (result i32) + (func $~lib/rt/tlsf/maybeInitialize (; 13 ;) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -749,7 +755,7 @@ end local.get $0 ) - (func $~lib/rt/tlsf/prepareSize (; 13 ;) (param $0 i32) (result i32) + (func $~lib/rt/tlsf/prepareSize (; 14 ;) (param $0 i32) (result i32) local.get $0 i32.const 1073741808 i32.ge_u @@ -773,7 +779,7 @@ i32.gt_u select ) - (func $~lib/rt/tlsf/searchBlock (; 14 ;) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/tlsf/searchBlock (; 15 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $1 i32.const 256 @@ -904,7 +910,7 @@ end end ) - (func $~lib/rt/tlsf/growMemory (; 15 ;) (param $0 i32) (param $1 i32) + (func $~lib/rt/tlsf/growMemory (; 16 ;) (param $0 i32) (param $1 i32) (local $2 i32) memory.size local.tee $2 @@ -966,7 +972,7 @@ i32.shl call $~lib/rt/tlsf/addMemory ) - (func $~lib/rt/tlsf/prepareBlock (; 16 ;) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/prepareBlock (; 17 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $1 @@ -1042,7 +1048,7 @@ i32.store end ) - (func $~lib/rt/tlsf/allocateBlock (; 17 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/rt/tlsf/allocateBlock (; 18 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) global.get $~lib/rt/tlsf/collectLock @@ -1124,7 +1130,7 @@ call $~lib/rt/rtrace/onalloc local.get $3 ) - (func $~lib/rt/tlsf/__alloc (; 18 ;) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/tlsf/__alloc (; 19 ;) (param $0 i32) (param $1 i32) (result i32) call $~lib/rt/tlsf/maybeInitialize local.get $0 local.get $1 @@ -1132,7 +1138,7 @@ i32.const 16 i32.add ) - (func $~lib/memory/memory.copy (; 19 ;) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/memory.copy (; 20 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) block $~lib/util/memory/memmove|inlined.0 @@ -1305,15 +1311,7 @@ end end ) - (func $~lib/string/String.UTF16.encode (; 20 ;) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 - ) - (func $~lib/string/String.UTF16.encode (; 32 ;) (param $0 i32) (result i32) + (func $~lib/string/String.UTF16.encode (; 21 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) local.get $0 @@ -1328,12 +1326,6 @@ local.get $2 call $~lib/rt/pure/__retain ) - (func $~lib/arraybuffer/ArrayBuffer#get:byteLength (; 21 ;) (param $0 i32) (result i32) - local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 - ) (func $std/string-encoding/testUTF16Encode (; 22 ;) (local $0 i32) (local $1 i32) @@ -1677,7 +1669,7 @@ local.tee $0 i32.const 0 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $2 + local.tee $3 i32.const 288 call $~lib/string/String.__eq i32.eqz @@ -1707,7 +1699,7 @@ local.get $0 i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $4 + local.tee $5 i32.const 304 call $~lib/string/String.__eq i32.eqz @@ -1724,7 +1716,7 @@ i32.add i32.const 2 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $5 + local.tee $6 i32.const 336 call $~lib/string/String.__eq i32.eqz @@ -1741,7 +1733,7 @@ i32.add i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $6 + local.tee $7 i32.const 368 call $~lib/string/String.__eq i32.eqz @@ -1758,7 +1750,7 @@ i32.add i32.const 4 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $7 + local.tee $1 i32.const 400 call $~lib/string/String.__eq i32.eqz @@ -1775,7 +1767,7 @@ i32.add i32.const 0 call $~lib/string/String.UTF16.decodeUnsafe - local.tee $1 + local.tee $0 i32.const 288 call $~lib/string/String.__eq i32.eqz @@ -2119,7 +2111,7 @@ if i32.const 0 i32.const 432 - i32.const 696 + i32.const 703 i32.const 6 call $~lib/builtins/abort unreachable @@ -2600,7 +2592,7 @@ if i32.const 0 i32.const 432 - i32.const 712 + i32.const 719 i32.const 6 call $~lib/builtins/abort unreachable @@ -3169,9 +3161,9 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $~start (; 44 ;) - i32.const 28 - i32.load + (func $start:std/string-encoding (; 44 ;) + i32.const 32 + call $~lib/string/String.UTF16.byteLength i32.const 12 i32.ne if @@ -3196,7 +3188,10 @@ i32.const 13696 call $std/string-encoding/testLarge ) - (func $~lib/rt/pure/decrement (; 45 ;) (param $0 i32) + (func $~start (; 45 ;) + call $start:std/string-encoding + ) + (func $~lib/rt/pure/decrement (; 46 ;) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 @@ -3264,7 +3259,7 @@ i32.store offset=4 end ) - (func $~lib/rt/__visit_members (; 46 ;) (param $0 i32) + (func $~lib/rt/__visit_members (; 47 ;) (param $0 i32) block $switch$1$default block $switch$1$case$4 block $switch$1$case$2 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 70bd8814b0..f01ce1e805 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -2758,9 +2758,7 @@ call $~lib/rt/pure/__retain local.set $0 local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 + call $~lib/string/String.UTF16.byteLength local.set $1 local.get $1 i32.const 0 @@ -3747,7 +3745,7 @@ if i32.const 0 i32.const 432 - i32.const 696 + i32.const 703 i32.const 6 call $~lib/builtins/abort unreachable @@ -4302,7 +4300,7 @@ if i32.const 0 i32.const 432 - i32.const 712 + i32.const 719 i32.const 6 call $~lib/builtins/abort unreachable