Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fast path for memory.repeat #2104

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 38 additions & 2 deletions std/assembly/memory.ts
Expand Up @@ -46,8 +46,44 @@ export namespace memory {
// @ts-ignore: decorator
@unsafe
export function repeat(dst: usize, src: usize, srcLength: usize, count: usize): void {
var index: usize = 0;
var total = srcLength * count;
let index: usize = 0;
let total = srcLength * count;

if (ASC_SHRINK_LEVEL < 1) {
switch (<u32>srcLength) {
case 0: return;
case 1: {
memory.fill(dst, load<u8>(src), count);
return;
}
case 2: {
let srcVal = load<u16>(src);
while (index < total) {
store<u16>(dst + index, srcVal);
MaxGraey marked this conversation as resolved.
Show resolved Hide resolved
index += 2;
}
return;
}
case 4: {
let srcVal = load<u32>(src);
while (index < total) {
store<u32>(dst + index, srcVal);
index += 4;
}
return;
}
case 8: {
let srcVal = load<u64>(src);
while (index < total) {
store<u64>(dst + index, srcVal);
index += 8;
}
return;
}
default: break;
}
}

while (index < total) {
memory.copy(dst + index, src, srcLength);
index += srcLength;
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/heap.optimized.wat
Expand Up @@ -2012,7 +2012,7 @@
(func $~lib/memory/heap.reset
i32.const 1184
i32.const 1248
i32.const 109
i32.const 145
i32.const 7
call $~lib/builtins/abort
unreachable
Expand Down
2 changes: 1 addition & 1 deletion tests/compiler/heap.untouched.wat
Expand Up @@ -2886,7 +2886,7 @@
drop
i32.const 160
i32.const 224
i32.const 109
i32.const 145
i32.const 7
call $~lib/builtins/abort
unreachable
Expand Down