Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions std/assembly/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ export class Array<T> {
);
}
} else {
if (ASC_SHRINK_LEVEL <= 1) {
if (isInteger<T>()) {
// @ts-ignore
if (value == <T>0 | value == <T>-1) {
if (start < end) {
memory.fill(
ptr + (<usize>start << alignof<T>()),
u8(value),
<usize>(end - start) << alignof<T>()
);
}
return this;
}
} else if (isFloat<T>()) {
// for floating non-negative zeros we can use fast memory.fill
if ((sizeof<T>() == 4 && reinterpret<u32>(f32(value)) == 0) ||
(sizeof<T>() == 8 && reinterpret<u64>(f64(value)) == 0)) {
if (start < end) {
memory.fill(
ptr + (<usize>start << alignof<T>()),
0,
<usize>(end - start) << alignof<T>()
);
}
return this;
}
}
}
for (; start < end; ++start) {
store<T>(ptr + (<usize>start << alignof<T>()), value);
}
Expand Down
28 changes: 28 additions & 0 deletions std/assembly/staticarray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ export class StaticArray<T> {
);
}
} else {
if (ASC_SHRINK_LEVEL <= 1) {
if (isInteger<T>()) {
// @ts-ignore
if (value == <T>0 | value == <T>-1) {
if (start < end) {
memory.fill(
ptr + (<usize>start << alignof<T>()),
u8(value),
<usize>(end - start) << alignof<T>()
);
}
return this;
}
} else if (isFloat<T>()) {
// for floating non-negative zeros we can use fast memory.fill
if ((sizeof<T>() == 4 && reinterpret<u32>(f32(value)) == 0) ||
(sizeof<T>() == 8 && reinterpret<u64>(f64(value)) == 0)) {
if (start < end) {
memory.fill(
ptr + (<usize>start << alignof<T>()),
0,
<usize>(end - start) << alignof<T>()
);
}
return this;
}
}
}
for (; start < end; ++start) {
store<T>(ptr + (<usize>start << alignof<T>()), value);
}
Expand Down
28 changes: 28 additions & 0 deletions std/assembly/typedarray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,34 @@ function FILL<TArray extends ArrayBufferView, T extends number>(
if (sizeof<T>() == 1) {
if (start < end) memory.fill(ptr + <usize>start, <u8>value, <usize>(end - start));
} else {
if (ASC_SHRINK_LEVEL <= 1) {
if (isInteger<T>()) {
// @ts-ignore
if (value == <T>0 | value == <T>-1) {
if (start < end) {
memory.fill(
ptr + (<usize>start << alignof<T>()),
u8(value),
<usize>(end - start) << alignof<T>()
);
}
return array;
}
} else if (isFloat<T>()) {
// for floating non-negative zeros we can use fast memory.fill
if ((sizeof<T>() == 4 && reinterpret<u32>(f32(value)) == 0) ||
(sizeof<T>() == 8 && reinterpret<u64>(f64(value)) == 0)) {
if (start < end) {
memory.fill(
ptr + (<usize>start << alignof<T>()),
0,
<usize>(end - start) << alignof<T>()
);
}
return array;
}
}
}
for (; start < end; ++start) {
store<T>(ptr + (<usize>start << alignof<T>()), value);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/std-wasi/crypto.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4920,7 +4920,7 @@
if
i32.const 448
i32.const 656
i32.const 1870
i32.const 1898
i32.const 5
call $~lib/wasi/index/abort
unreachable
Expand All @@ -4939,7 +4939,7 @@
if
i32.const 144
i32.const 656
i32.const 1875
i32.const 1903
i32.const 9
call $~lib/wasi/index/abort
unreachable
Expand All @@ -4951,7 +4951,7 @@
else
i32.const 144
i32.const 656
i32.const 1879
i32.const 1907
i32.const 7
call $~lib/wasi/index/abort
unreachable
Expand All @@ -4969,7 +4969,7 @@
if
i32.const 144
i32.const 656
i32.const 1884
i32.const 1912
i32.const 7
call $~lib/wasi/index/abort
unreachable
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/std-wasi/crypto.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -3717,7 +3717,7 @@
if
i32.const 1472
i32.const 1680
i32.const 1870
i32.const 1898
i32.const 5
call $~lib/wasi/index/abort
unreachable
Expand All @@ -3736,7 +3736,7 @@
else
i32.const 1168
i32.const 1680
i32.const 1879
i32.const 1907
i32.const 7
call $~lib/wasi/index/abort
unreachable
Expand All @@ -3751,7 +3751,7 @@
if
i32.const 1168
i32.const 1680
i32.const 1884
i32.const 1912
i32.const 7
call $~lib/wasi/index/abort
unreachable
Expand Down
Loading