From 81c510336990cb3a4a0efd218aa44af278508606 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Wed, 29 Jul 2020 20:14:56 +0300 Subject: [PATCH] simplify check condision for memcpy --- std/assembly/util/memory.ts | 2 +- .../extends-baseaggregate.untouched.wat | 19 ++++++++----------- tests/compiler/infer-array.untouched.wat | 19 ++++++++----------- tests/compiler/number.untouched.wat | 19 ++++++++----------- tests/compiler/object-literal.untouched.wat | 19 ++++++++----------- tests/compiler/resolve-access.untouched.wat | 19 ++++++++----------- tests/compiler/resolve-binary.untouched.wat | 19 ++++++++----------- .../resolve-elementaccess.untouched.wat | 19 ++++++++----------- tests/compiler/resolve-ternary.untouched.wat | 19 ++++++++----------- .../retain-release-sanity.untouched.wat | 19 ++++++++----------- tests/compiler/rt/finalize.untouched.wat | 19 ++++++++----------- tests/compiler/rt/stub-realloc.untouched.wat | 19 ++++++++----------- .../compiler/std/array-literal.untouched.wat | 19 ++++++++----------- tests/compiler/std/array.untouched.wat | 19 ++++++++----------- tests/compiler/std/arraybuffer.untouched.wat | 19 ++++++++----------- tests/compiler/std/map.untouched.wat | 19 ++++++++----------- tests/compiler/std/pointer.untouched.wat | 19 ++++++++----------- tests/compiler/std/set.untouched.wat | 19 ++++++++----------- tests/compiler/std/static-array.untouched.wat | 19 ++++++++----------- tests/compiler/std/staticarray.untouched.wat | 19 ++++++++----------- .../std/string-casemapping.untouched.wat | 19 ++++++++----------- .../std/string-encoding.untouched.wat | 19 ++++++++----------- tests/compiler/std/string.untouched.wat | 19 ++++++++----------- tests/compiler/std/symbol.untouched.wat | 19 ++++++++----------- tests/compiler/std/typedarray.untouched.wat | 19 ++++++++----------- tests/compiler/wasi/trace.untouched.wat | 19 ++++++++----------- 26 files changed, 201 insertions(+), 276 deletions(-) diff --git a/std/assembly/util/memory.ts b/std/assembly/util/memory.ts index d5daa5f526..07a9bb98dd 100644 --- a/std/assembly/util/memory.ts +++ b/std/assembly/util/memory.ts @@ -146,7 +146,7 @@ export function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/s export function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c if (dest === src) return; if (ASC_SHRINK_LEVEL < 1) { - if (src + n <= dest || dest + n <= src) { + if (src - dest - n <= -(n << 1)) { memcpy(dest, src, n); return; } diff --git a/tests/compiler/extends-baseaggregate.untouched.wat b/tests/compiler/extends-baseaggregate.untouched.wat index a940f6a811..664c7a63fa 100644 --- a/tests/compiler/extends-baseaggregate.untouched.wat +++ b/tests/compiler/extends-baseaggregate.untouched.wat @@ -2658,19 +2658,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/infer-array.untouched.wat b/tests/compiler/infer-array.untouched.wat index 9ccbfba964..6ee473ce24 100644 --- a/tests/compiler/infer-array.untouched.wat +++ b/tests/compiler/infer-array.untouched.wat @@ -1192,19 +1192,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/number.untouched.wat b/tests/compiler/number.untouched.wat index 65f30e910c..1075677abd 100644 --- a/tests/compiler/number.untouched.wat +++ b/tests/compiler/number.untouched.wat @@ -2498,19 +2498,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/object-literal.untouched.wat b/tests/compiler/object-literal.untouched.wat index b44360f445..770147500f 100644 --- a/tests/compiler/object-literal.untouched.wat +++ b/tests/compiler/object-literal.untouched.wat @@ -2845,19 +2845,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/resolve-access.untouched.wat b/tests/compiler/resolve-access.untouched.wat index 5380fd4154..9de1f9f8f9 100644 --- a/tests/compiler/resolve-access.untouched.wat +++ b/tests/compiler/resolve-access.untouched.wat @@ -1192,19 +1192,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/resolve-binary.untouched.wat b/tests/compiler/resolve-binary.untouched.wat index 60a3172749..586dfd71b8 100644 --- a/tests/compiler/resolve-binary.untouched.wat +++ b/tests/compiler/resolve-binary.untouched.wat @@ -3498,19 +3498,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/resolve-elementaccess.untouched.wat b/tests/compiler/resolve-elementaccess.untouched.wat index 3faf9ef489..cd750819a0 100644 --- a/tests/compiler/resolve-elementaccess.untouched.wat +++ b/tests/compiler/resolve-elementaccess.untouched.wat @@ -2126,19 +2126,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/resolve-ternary.untouched.wat b/tests/compiler/resolve-ternary.untouched.wat index 8e7fc1c78c..6ad2258385 100644 --- a/tests/compiler/resolve-ternary.untouched.wat +++ b/tests/compiler/resolve-ternary.untouched.wat @@ -3889,19 +3889,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/retain-release-sanity.untouched.wat b/tests/compiler/retain-release-sanity.untouched.wat index 3485935621..917fefc811 100644 --- a/tests/compiler/retain-release-sanity.untouched.wat +++ b/tests/compiler/retain-release-sanity.untouched.wat @@ -2935,19 +2935,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/rt/finalize.untouched.wat b/tests/compiler/rt/finalize.untouched.wat index ffe4f20ee7..5819deea71 100644 --- a/tests/compiler/rt/finalize.untouched.wat +++ b/tests/compiler/rt/finalize.untouched.wat @@ -3278,19 +3278,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/rt/stub-realloc.untouched.wat b/tests/compiler/rt/stub-realloc.untouched.wat index 2fd94b553b..081fb46313 100644 --- a/tests/compiler/rt/stub-realloc.untouched.wat +++ b/tests/compiler/rt/stub-realloc.untouched.wat @@ -1198,19 +1198,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/array-literal.untouched.wat b/tests/compiler/std/array-literal.untouched.wat index 9f2be3362a..3e64393f57 100644 --- a/tests/compiler/std/array-literal.untouched.wat +++ b/tests/compiler/std/array-literal.untouched.wat @@ -2590,19 +2590,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 6386143d5e..ef9f2c9e29 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -3447,19 +3447,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/arraybuffer.untouched.wat b/tests/compiler/std/arraybuffer.untouched.wat index eaf6cef877..36a60407d6 100644 --- a/tests/compiler/std/arraybuffer.untouched.wat +++ b/tests/compiler/std/arraybuffer.untouched.wat @@ -2833,19 +2833,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat index 00c57c04ef..0d84e733ec 100644 --- a/tests/compiler/std/map.untouched.wat +++ b/tests/compiler/std/map.untouched.wat @@ -3433,19 +3433,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/pointer.untouched.wat b/tests/compiler/std/pointer.untouched.wat index 0ca39c67e8..7a407a2b77 100644 --- a/tests/compiler/std/pointer.untouched.wat +++ b/tests/compiler/std/pointer.untouched.wat @@ -1280,19 +1280,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/set.untouched.wat b/tests/compiler/std/set.untouched.wat index 81665a6010..b867f31859 100644 --- a/tests/compiler/std/set.untouched.wat +++ b/tests/compiler/std/set.untouched.wat @@ -3369,19 +3369,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/static-array.untouched.wat b/tests/compiler/std/static-array.untouched.wat index 8f6a22bd54..40be734cf3 100644 --- a/tests/compiler/std/static-array.untouched.wat +++ b/tests/compiler/std/static-array.untouched.wat @@ -1229,19 +1229,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/staticarray.untouched.wat b/tests/compiler/std/staticarray.untouched.wat index fb7345a2bf..e7b042d83b 100644 --- a/tests/compiler/std/staticarray.untouched.wat +++ b/tests/compiler/std/staticarray.untouched.wat @@ -2580,19 +2580,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/string-casemapping.untouched.wat b/tests/compiler/std/string-casemapping.untouched.wat index b05241b5eb..3980377e45 100644 --- a/tests/compiler/std/string-casemapping.untouched.wat +++ b/tests/compiler/std/string-casemapping.untouched.wat @@ -3005,19 +3005,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 7890591f9c..1fe5cf554d 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -2632,19 +2632,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 41b46155f4..f5b19d53cf 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -3635,19 +3635,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/symbol.untouched.wat b/tests/compiler/std/symbol.untouched.wat index b4b86bb03e..a5bff270c4 100644 --- a/tests/compiler/std/symbol.untouched.wat +++ b/tests/compiler/std/symbol.untouched.wat @@ -2817,19 +2817,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 866450965c..6c73fd6d49 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -5083,19 +5083,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4 diff --git a/tests/compiler/wasi/trace.untouched.wat b/tests/compiler/wasi/trace.untouched.wat index 3491b560ec..78bd45543a 100644 --- a/tests/compiler/wasi/trace.untouched.wat +++ b/tests/compiler/wasi/trace.untouched.wat @@ -2086,19 +2086,16 @@ i32.lt_s drop local.get $4 - local.get $3 - i32.add local.get $5 + i32.sub + local.get $3 + i32.sub + i32.const 0 + local.get $3 + i32.const 1 + i32.shl + i32.sub i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end if local.get $5 local.get $4