Implement bulk memory operations (#467)

This commit is contained in:
Daniel Wirtz
2019-02-07 11:40:23 +01:00
committed by GitHub
parent 831054dfd3
commit f551bc78e1
23 changed files with 331 additions and 263 deletions

View File

@ -10,18 +10,17 @@ export namespace memory {
@builtin export declare function grow(pages: i32): i32;
@inline export function fill(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset
if (isDefined(__memory_fill)) { __memory_fill(dest, c, n); return; }
memset(dest, c, n);
@builtin @inline
export function fill(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset
memset(dest, c, n); // fallback if "bulk-memory" isn't enabled
}
@inline export function copy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c
if (isDefined(__memory_copy)) { __memory_copy(dest, src, n); return; }
memmove(dest, src, n);
@builtin @inline
export function copy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c
memmove(dest, src, n); // fallback if "bulk-memory" isn't enabled
}
@inline export function compare(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c
if (isDefined(__memory_compare)) return __memory_compare(vl, vr, n);
return memcmp(vl, vr, n);
}