-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(simd): extract SIMD API, update readme
- Loading branch information
1 parent
d266fec
commit 8b7287e
Showing
3 changed files
with
214 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
export interface SIMD { | ||
/** | ||
* WASM memory instance given to `init()`. | ||
*/ | ||
memory: WebAssembly.Memory; | ||
/** | ||
* Float64 view of WASM memory. | ||
*/ | ||
f64: Float64Array; | ||
/** | ||
* Float32 view of WASM memory. | ||
*/ | ||
f32: Float32Array; | ||
/** | ||
* Uint32 view of WASM memory. | ||
*/ | ||
u32: Uint32Array; | ||
/** | ||
* Int32 view of WASM memory. | ||
*/ | ||
i32: Int32Array; | ||
/** | ||
* Uint16 of WASM memory. | ||
*/ | ||
u16: Uint16Array; | ||
/** | ||
* Int16 view of WASM memory. | ||
*/ | ||
i16: Int16Array; | ||
/** | ||
* Uint8 view of WASM memory. | ||
*/ | ||
u8: Uint8Array; | ||
/** | ||
* Int8 view of WASM memory. | ||
*/ | ||
i8: Int8Array; | ||
|
||
/** | ||
* Takes two densely packed vec2 AOS buffers `a` and `b`, computes | ||
* their 2D dot products and stores results in `out`. Computes two | ||
* results per iteration, hence `num` must be an even number or else | ||
* the last vector will not be processed. `so` should be 1 for | ||
* packed result buffer. | ||
* | ||
* `a` & `b` should be aligned to 16, `out` to multiples of 4. | ||
* | ||
* @param out | ||
* @param a | ||
* @param b | ||
* @param num | ||
* @param so | ||
*/ | ||
// prettier-ignore | ||
dot2_f32_aos(out: number, a: number, b: number, num: number, so: number): number; | ||
|
||
/** | ||
* Takes two vec4 AOS buffers, computes their dot products and | ||
* stores results in `out`. `so` should be 1 for packed result | ||
* buffer. `sa` and `sb` indicate the stride lengths (in floats) | ||
* between each vector in each respective buffer and should be a | ||
* multiple of 4. | ||
* | ||
* @param out | ||
* @param a | ||
* @param b | ||
* @param num | ||
* @param so | ||
* @param sa | ||
* @param sb | ||
*/ | ||
// prettier-ignore | ||
dot4_f32_aos(out: number, a: number, b: number, num: number, so: number, sa: number, sb: number): number; | ||
|
||
/** | ||
* Takes two vec4 SOA buffers and computes their 4D dot products and | ||
* writes results to `out`. `sa` and `sb` indicate the element | ||
* stride size (in floats) of the respective vectors (should be | ||
* multiple of 4). The results are always stored in a packed layout. | ||
* Processes 4 vectors per iteration, hence `num` should be a | ||
* multiple of 4 too. | ||
* | ||
* @param out | ||
* @param a | ||
* @param b | ||
* @param num | ||
* @param sa | ||
* @param sb | ||
*/ | ||
// prettier-ignore | ||
dot4_f32_soa(out: number, a: number, b: number, num: number, sa: number, sb: number): number; | ||
|
||
/** | ||
* Takes three vec4 buffers, computes componentwise `a * b + c` and | ||
* stores results in `out`. Both AOS / SOA layouts are supported, as | ||
* long as all buffers are using the same layout. | ||
* | ||
* All strides must by multiples of 4. All pointers should be | ||
* aligned to multiples of 16. Returns `out` pointer. | ||
* | ||
* @param out | ||
* @param a | ||
* @param b | ||
* @param c | ||
* @param num number of vec4 | ||
* @param so out element stride | ||
* @param sa A element stride | ||
* @param sb B element stride | ||
* @param sc C element stride | ||
*/ | ||
// prettier-ignore | ||
madd4_f32(out: number, a: number, b: number, c: number, num: number, so: number, sa: number, sb: number, sc: number): number; | ||
|
||
// prettier-ignore | ||
maddn4_f32(out: number, a: number, b: number, c: number, num: number, so: number, sa: number, sc: number): number; | ||
|
||
// prettier-ignore | ||
mul_m23v2_aos(out: number, mat: number, vec: number, num: number, so: number, sv: number): number; | ||
|
||
mul_m23v2_aos_single(out: number, mat: number, vec: number): number; | ||
|
||
// prettier-ignore | ||
mul_m44v4_aos(out: number, mat: number, vec: number, num: number, so: number, sv: number): number; | ||
|
||
mul_m44v4_aos_single(out: number, mat: number, vec: number): number; | ||
} |
Oops, something went wrong.