-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathS0019_SIMDVector.java
More file actions
36 lines (30 loc) · 1.03 KB
/
S0019_SIMDVector.java
File metadata and controls
36 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.VectorSpecies;
//--source 21 --add-modules jdk.incubator.vector --enable-preview
interface S0174_SIMDVector {
VectorSpecies<Float> SPECIES = FloatVector.SPECIES_PREFERRED;
static void vectorCalculation(float[] a, float[] b, float[] c) {
int upperBound = SPECIES.loopBound(a.length);
for (int i = 0; i < upperBound; i += SPECIES.length()) {
var va = FloatVector.fromArray(SPECIES, a, i);
var vb = FloatVector.fromArray(SPECIES, b, i);
var vc = va.mul(vb).neg();
vc.intoArray(c, i);
}
}
static void calculation(float[] a, float[] b, float[] c) {
for (int i = 0; i < a.length; i++) {
c[i] = (a[i] * b[i]) * -1.0f;
}
}
// --add-modules jdk.incubator.vector
static void main(String... args) {
float[] a = { 1.0f, 2.0f, 3.0f, 4.0f };
float[] b = { 5.0f, 6.0f, 7.0f, 8.0f };
float[] result = new float[a.length];
calculation(a, b, result);
for (var f : result) {
System.out.println(f);
}
}
}