1
1
package org .simdjson ;
2
2
3
3
import jdk .incubator .vector .ByteVector ;
4
+ import jdk .incubator .vector .IntVector ;
5
+ import jdk .incubator .vector .VectorShape ;
4
6
import jdk .incubator .vector .VectorSpecies ;
5
- import java .lang .invoke .MethodType ;
6
7
7
8
import static jdk .incubator .vector .VectorOperators .UNSIGNED_LE ;
8
9
9
10
class StructuralIndexer {
10
11
11
- static final VectorSpecies <Byte > SPECIES ;
12
+ static final VectorSpecies <Integer > INT_SPECIES ;
13
+ static final VectorSpecies <Byte > BYTE_SPECIES ;
12
14
static final int N_CHUNKS ;
13
15
14
16
static {
15
17
String species = System .getProperty ("org.simdjson.species" , "preferred" );
16
- SPECIES = switch (species ) {
17
- case "preferred" -> ByteVector .SPECIES_PREFERRED ;
18
- case "512" -> ByteVector .SPECIES_512 ;
19
- case "256" -> ByteVector .SPECIES_256 ;
18
+ switch (species ) {
19
+ case "preferred" -> {
20
+ BYTE_SPECIES = ByteVector .SPECIES_PREFERRED ;
21
+ INT_SPECIES = IntVector .SPECIES_PREFERRED ;
22
+ }
23
+ case "512" -> {
24
+ BYTE_SPECIES = ByteVector .SPECIES_512 ;
25
+ INT_SPECIES = IntVector .SPECIES_512 ;
26
+ }
27
+ case "256" -> {
28
+ BYTE_SPECIES = ByteVector .SPECIES_256 ;
29
+ INT_SPECIES = IntVector .SPECIES_256 ;
30
+ }
20
31
default -> throw new IllegalArgumentException ("Unsupported vector species: " + species );
21
- };
22
- N_CHUNKS = 64 / SPECIES .vectorByteSize ();
23
- if (SPECIES != ByteVector .SPECIES_256 && SPECIES != ByteVector .SPECIES_512 ) {
24
- throw new IllegalArgumentException ("Unsupported vector species: " + SPECIES );
32
+ }
33
+ N_CHUNKS = 64 / BYTE_SPECIES .vectorByteSize ();
34
+ assertSupportForSpecies (BYTE_SPECIES );
35
+ assertSupportForSpecies (INT_SPECIES );
36
+ }
37
+
38
+ private static void assertSupportForSpecies (VectorSpecies <?> species ) {
39
+ if (species .vectorShape () != VectorShape .S_256_BIT && species .vectorShape () != VectorShape .S_512_BIT ) {
40
+ throw new IllegalArgumentException ("Unsupported vector species: " + species );
25
41
}
26
42
}
27
43
@@ -48,7 +64,7 @@ void step(byte[] buffer, int offset, int blockIndex) {
48
64
}
49
65
50
66
private void step1 (byte [] buffer , int offset , int blockIndex ) {
51
- ByteVector chunk0 = ByteVector .fromArray (ByteVector .SPECIES_512 , buffer , offset );
67
+ ByteVector chunk0 = ByteVector .fromArray (ByteVector .SPECIES_512 , buffer , offset );
52
68
JsonStringBlock strings = stringScanner .next (chunk0 );
53
69
JsonCharacterBlock characters = classifier .classify (chunk0 );
54
70
long unescaped = lteq (chunk0 , (byte ) 0x1F );
@@ -75,7 +91,7 @@ private void finishStep(JsonCharacterBlock characters, JsonStringBlock strings,
75
91
bitIndexes .write (blockIndex , prevStructurals );
76
92
prevStructurals = potentialStructuralStart & ~strings .stringTail ();
77
93
unescapedCharsError |= strings .nonQuoteInsideString (unescaped );
78
- }
94
+ }
79
95
80
96
private long lteq (ByteVector chunk0 , byte scalar ) {
81
97
long r = chunk0 .compare (UNSIGNED_LE , scalar ).toLong ();
0 commit comments