forked from simdjson/simdjson-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorUtils.java
More file actions
48 lines (42 loc) · 1.75 KB
/
VectorUtils.java
File metadata and controls
48 lines (42 loc) · 1.75 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
37
38
39
40
41
42
43
44
45
46
47
48
package org.simdjson;
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.VectorShape;
import jdk.incubator.vector.VectorSpecies;
class VectorUtils {
static final VectorSpecies<Integer> INT_SPECIES;
static final VectorSpecies<Byte> BYTE_SPECIES;
static {
String species = System.getProperty("org.simdjson.species", "preferred");
switch (species) {
case "preferred" -> {
BYTE_SPECIES = ByteVector.SPECIES_PREFERRED;
INT_SPECIES = IntVector.SPECIES_PREFERRED;
assertSupportForSpecies(BYTE_SPECIES);
assertSupportForSpecies(INT_SPECIES);
}
case "512" -> {
BYTE_SPECIES = ByteVector.SPECIES_512;
INT_SPECIES = IntVector.SPECIES_512;
}
case "256" -> {
BYTE_SPECIES = ByteVector.SPECIES_256;
INT_SPECIES = IntVector.SPECIES_256;
}
default -> throw new IllegalArgumentException("Unsupported vector species: " + species);
}
}
private static void assertSupportForSpecies(VectorSpecies<?> species) {
if (species.vectorShape() != VectorShape.S_256_BIT && species.vectorShape() != VectorShape.S_512_BIT) {
throw new IllegalArgumentException("Unsupported vector species: " + species);
}
}
static ByteVector repeat(byte[] array) {
int n = BYTE_SPECIES.vectorByteSize() / 4;
byte[] result = new byte[n * array.length];
for (int dst = 0; dst < result.length; dst += array.length) {
System.arraycopy(array, 0, result, dst, array.length);
}
return ByteVector.fromArray(BYTE_SPECIES, result, 0);
}
}