-
-
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.
feat(simd): add hadd* inline fns, update dot, normalize, mulv, sum
- Loading branch information
1 parent
0e0dfde
commit a1011ea
Showing
8 changed files
with
99 additions
and
43 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
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,29 @@ | ||
/** | ||
* Pairwise horizontal sum of `v`: | ||
* | ||
* ``` | ||
* [a, b, c, d] => [a+b, a+b, c+d, c+d] | ||
* ``` | ||
* | ||
* @param v | ||
*/ | ||
// @ts-ignore: decorator | ||
@inline | ||
export function hadd2_f32(v: v128): v128 { | ||
return f32x4.add(v, v128.shuffle<f32>(v, v, 1, 0, 3, 2)); | ||
} | ||
|
||
/** | ||
* Full horizontal sum of `v`: | ||
* | ||
* ``` | ||
* [a, b, c, d] => a + c + b + d | ||
* ``` | ||
* @param v | ||
*/ | ||
// @ts-ignore: decorator | ||
@inline | ||
export function hadd4_f32(v: v128): f32 { | ||
v = f32x4.add(v, v128.shuffle<f32>(v, v, 2, 3, 0, 1)); | ||
return f32x4.extract_lane(v, 0) + f32x4.extract_lane(v, 1); | ||
} |
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
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
export function sum4_f32(a: usize, num: usize, sa: usize): f64 { | ||
import { hadd4_f32 } from "./hadd"; | ||
|
||
export function sum4_f32(a: usize, num: usize, sa: usize): f32 { | ||
sa <<= 2; | ||
let acc = f32x4.splat(0); | ||
for (; num-- > 0; ) { | ||
acc = f32x4.add(acc, v128.load(a)); | ||
a += sa; | ||
} | ||
acc = f32x4.add(acc, v128.shuffle<f32>(acc, acc, 2, 3, 0, 1)); | ||
return f32x4.extract_lane(acc, 0) + f32x4.extract_lane(acc, 1); | ||
return hadd4_f32(acc); | ||
} |
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