Skip to content

Commit

Permalink
feat(simd): enable new ops supported in node 14/V8 8.3
Browse files Browse the repository at this point in the history
- previously unsupported in V8 impl (f32x4.div & f32x4.sqrt ops):
  - div4_f32
  - divn4_f32
  - sqrt4_f32
  - invsqrt4_f32
  • Loading branch information
postspectacular committed May 5, 2020
1 parent 744a32b commit 5c46468
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/simd/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export * from "./addn";
export * from "./clamp";

// TODO waiting for native impl
// export * from "./div";
// export * from "./divn";
export * from "./div";
export * from "./divn";

export * from "./dot";
export * from "./madd";
Expand All @@ -25,7 +25,7 @@ export * from "./neg";
export * from "./normalize";

// TODO waiting for native impl
// export * from "./sqrt";
export * from "./sqrt";

export * from "./sub";
export * from "./subn";
Expand Down
8 changes: 2 additions & 6 deletions packages/simd/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export interface SIMD {
dot4_f32_soa(out: number, a: number, b: number, num: number, sa: number, sb: number): number;

/**
* FIXME waiting for native impl of SIMD instr
*
* {@link SIMD.sqrt4_f32}
* Also see {@link SIMD.sqrt4_f32}
*
* @param out -
* @param a -
Expand Down Expand Up @@ -163,9 +161,7 @@ export interface SIMD {
normalize4_f32_aos(out: number, a: number, num: number, norm: number, so: number, sa: number): number;

/**
* FIXME waiting for native impl of SIMD instr
*
* {@link SIMD.invsqrt4_f32}
* Also see {@link SIMD.invsqrt4_f32}
*
* @param out -
* @param a -
Expand Down
29 changes: 23 additions & 6 deletions packages/simd/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ assertEqual(res_f32(1024, 8), [10, 40, 90, 160, 250, 360, 490, 640]);
simd.muln4_f32(1024, 0, 10, 2, 4, 4);
assertEqual(res_f32(1024, 8), [10, 20, 30, 40, 50, 60, 70, 80]);
// div4_f32
// simd.div4_f32(1024, 0, 48, 2, 4, 4, 4);
// assertEqualDelta(res_f32(1024, 8), [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]);
simd.div4_f32(1024, 0, 48, 2, 4, 4, 4);
assertEqualDelta(res_f32(1024, 8), [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]);
// divn4_f32
// simd.divn4_f32(1024, 0, 10, 2, 4, 4);
// assertEqualDelta(res_f32(1024, 8), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]);
simd.divn4_f32(1024, 0, 10, 2, 4, 4);
assertEqualDelta(res_f32(1024, 8), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]);

// abs4_f32
simd.f32.set([-1, 2, -3, 4, 5, -6, 7, -8]);
Expand Down Expand Up @@ -178,21 +178,38 @@ assertEqualDelta(res_f32(1024, 4), [
1 * 1 + 2 * 2,
10 * 10 + 20 * 20,
100 * 100 + 200 * 200,
100 * 100 + 200 * 200
100 * 100 + 200 * 200,
]);
simd.mag2_f32_aos(1024, 0, 4);
assertEqualDelta(res_f32(1024, 4), [
Math.sqrt(5),
Math.sqrt(500),
Math.sqrt(50000),
Math.sqrt(50000)
Math.sqrt(50000),
]);

simd.magsq4_f32_aos(1024, 0, 2, 1, 4);
assertEqualDelta(res_f32(1024, 2), [505, 100000]);
simd.mag4_f32_aos(1024, 0, 2, 1, 4);
assertEqualDelta(res_f32(1024, 2), [Math.sqrt(505), Math.sqrt(100000)]);

// sqrt4
simd.f32.set([1, 2, 9, 16, 25, 36, 49, 64]);
simd.sqrt4_f32(1024, 0, 2, 4, 4);
assertEqualDelta(res_f32(1024, 8), [1, Math.SQRT2, 3, 4, 5, 6, 7, 8]);
// invsqrt4
simd.invsqrt4_f32(1024, 0, 2, 4, 4);
assertEqualDelta(res_f32(1024, 8), [
1,
Math.SQRT1_2,
1 / 3,
1 / 4,
1 / 5,
1 / 6,
1 / 7,
1 / 8,
]);

// mix4_f32
// mixn4_f32
// prettier-ignore
Expand Down

0 comments on commit 5c46468

Please sign in to comment.