11package org .simdjson ;
22
33import jdk .incubator .vector .ByteVector ;
4+ import jdk .incubator .vector .IntVector ;
5+ import jdk .incubator .vector .VectorShape ;
46import jdk .incubator .vector .VectorSpecies ;
5- import java .lang .invoke .MethodType ;
67
78import static jdk .incubator .vector .VectorOperators .UNSIGNED_LE ;
89
910class StructuralIndexer {
1011
11- static final VectorSpecies <Byte > SPECIES ;
12+ static final VectorSpecies <Integer > INT_SPECIES ;
13+ static final VectorSpecies <Byte > BYTE_SPECIES ;
1214 static final int N_CHUNKS ;
1315
1416 static {
1517 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+ }
2031 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 );
2541 }
2642 }
2743
@@ -48,7 +64,7 @@ void step(byte[] buffer, int offset, int blockIndex) {
4864 }
4965
5066 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 );
5268 JsonStringBlock strings = stringScanner .next (chunk0 );
5369 JsonCharacterBlock characters = classifier .classify (chunk0 );
5470 long unescaped = lteq (chunk0 , (byte ) 0x1F );
@@ -75,7 +91,7 @@ private void finishStep(JsonCharacterBlock characters, JsonStringBlock strings,
7591 bitIndexes .write (blockIndex , prevStructurals );
7692 prevStructurals = potentialStructuralStart & ~strings .stringTail ();
7793 unescapedCharsError |= strings .nonQuoteInsideString (unescaped );
78- }
94+ }
7995
8096 private long lteq (ByteVector chunk0 , byte scalar ) {
8197 long r = chunk0 .compare (UNSIGNED_LE , scalar ).toLong ();
0 commit comments