105 a[i + 2] * H_COEFF_8.lane(2) +
106 a[i + 3] * H_COEFF_8.lane(3) +
107 a[i + 4] * H_COEFF_8.lane(4) +
108 a[i + 5] * H_COEFF_8.lane(5) +
109 a[i + 6] * H_COEFF_8.lane(6) +
110 a[i + 7] * H_COEFF_8.lane(7);
111 }
112
113 for (; i < a.length; i++) {
114 h = 31 * h + a[i];
115 }
116 return h;
117 }
118
119 static int hashCodeVector64(byte[] a) {
120 int h = 1;
121 int i = 0;
122 for (; i < (a.length & ~(BYTE_64_SPECIES.length() - 1)); i += BYTE_64_SPECIES.length()) {
123 ByteVector b = ByteVector.fromArray(BYTE_64_SPECIES, a, i);
124 IntVector x = (IntVector) b.cast(INT_256_SPECIES);
125 h = h * COEFF_31_TO_8 + x.mul(H_COEFF_8).addAll();
126 }
127
128 for (; i < a.length; i++) {
129 h = 31 * h + a[i];
130 }
131 return h;
132 }
133
134 static int hashCodeVector128(byte[] a) {
135 int h = 1;
136 int i = 0;
137 for (; i < (a.length & ~(BYTE_128_SPECIES.length() - 1)); i += BYTE_128_SPECIES.length()) {
138 ByteVector b = ByteVector.fromArray(BYTE_128_SPECIES, a, i);
139 IntVector x = (IntVector) b.cast(INT_512_SPECIES);
140 h = h * COEFF_31_TO_16 + x.mul(H_COEFF_16).addAll();
141 }
142
143 for (; i < a.length; i++) {
144 h = 31 * h + a[i];
145 }
146 return h;
147 }
148
149 static int hashCodeVector512Shift(byte[] a) {
150 return hashCodeVectorGenericShift(a,
151 BYTE_128_SPECIES,
152 BYTE_512_SPECIES,
153 INT_512_SPECIES,
154 COEFF_31_TO_16,
155 H_COEFF_16);
156 }
157
158 static int hashCodeVectorGenericShift(
159 byte[] a,
160 VectorSpecies<Byte> bytesForIntsSpecies,
161 VectorSpecies<Byte> byteSpecies, VectorSpecies<Integer> intSpecies,
162 int top_h_coeff,
163 IntVector v_h_coeff) {
164 assert bytesForIntsSpecies.length() == intSpecies.length();
165
166 int h = 1;
167 int i = 0;
168 for (; i < (a.length & ~(byteSpecies.length() - 1)); i += byteSpecies.length()) {
169 ByteVector b = ByteVector.fromArray(byteSpecies, a, i);
170
171 for (int j = 0; j < byteSpecies.length() / intSpecies.length(); j++) {
172 // Reduce the size of the byte vector and then cast to int
173 IntVector x = (IntVector)(b.reshape(bytesForIntsSpecies)).cast(intSpecies);
174
175 h = h * top_h_coeff + x.mul(v_h_coeff).addAll();
176
177 b = b.shiftEL(intSpecies.length());
178 }
179 }
180
181 for (; i < a.length; i++) {
182 h = 31 * h + a[i];
183 }
184 return h;
185 }
186
187 static final VectorSpecies<Integer> INT_512_SPECIES = IntVector.SPECIES_512;
188 static final VectorSpecies<Integer> INT_256_SPECIES = IntVector.SPECIES_256;
189 static final int COEFF_31_TO_16;
190 static final IntVector H_COEFF_16;
191
192 static final VectorSpecies<Byte> BYTE_512_SPECIES = ByteVector.SPECIES_512;
193 static final VectorSpecies<Byte> BYTE_128_SPECIES = ByteVector.SPECIES_128;
194 static final VectorSpecies<Byte> BYTE_64_SPECIES = ByteVector.SPECIES_64;
195 static final int COEFF_31_TO_8;
196 static final IntVector H_COEFF_8;
197
|
105 a[i + 2] * H_COEFF_8.lane(2) +
106 a[i + 3] * H_COEFF_8.lane(3) +
107 a[i + 4] * H_COEFF_8.lane(4) +
108 a[i + 5] * H_COEFF_8.lane(5) +
109 a[i + 6] * H_COEFF_8.lane(6) +
110 a[i + 7] * H_COEFF_8.lane(7);
111 }
112
113 for (; i < a.length; i++) {
114 h = 31 * h + a[i];
115 }
116 return h;
117 }
118
119 static int hashCodeVector64(byte[] a) {
120 int h = 1;
121 int i = 0;
122 for (; i < (a.length & ~(BYTE_64_SPECIES.length() - 1)); i += BYTE_64_SPECIES.length()) {
123 ByteVector b = ByteVector.fromArray(BYTE_64_SPECIES, a, i);
124 IntVector x = (IntVector) b.cast(INT_256_SPECIES);
125 h = h * COEFF_31_TO_8 + x.mul(H_COEFF_8).addLanes();
126 }
127
128 for (; i < a.length; i++) {
129 h = 31 * h + a[i];
130 }
131 return h;
132 }
133
134 static int hashCodeVector128(byte[] a) {
135 int h = 1;
136 int i = 0;
137 for (; i < (a.length & ~(BYTE_128_SPECIES.length() - 1)); i += BYTE_128_SPECIES.length()) {
138 ByteVector b = ByteVector.fromArray(BYTE_128_SPECIES, a, i);
139 IntVector x = (IntVector) b.cast(INT_512_SPECIES);
140 h = h * COEFF_31_TO_16 + x.mul(H_COEFF_16).addLanes();
141 }
142
143 for (; i < a.length; i++) {
144 h = 31 * h + a[i];
145 }
146 return h;
147 }
148
149 static int hashCodeVector512Shift(byte[] a) {
150 return hashCodeVectorGenericShift(a,
151 BYTE_128_SPECIES,
152 BYTE_512_SPECIES,
153 INT_512_SPECIES,
154 COEFF_31_TO_16,
155 H_COEFF_16);
156 }
157
158 static int hashCodeVectorGenericShift(
159 byte[] a,
160 VectorSpecies<Byte> bytesForIntsSpecies,
161 VectorSpecies<Byte> byteSpecies, VectorSpecies<Integer> intSpecies,
162 int top_h_coeff,
163 IntVector v_h_coeff) {
164 assert bytesForIntsSpecies.length() == intSpecies.length();
165
166 int h = 1;
167 int i = 0;
168 for (; i < (a.length & ~(byteSpecies.length() - 1)); i += byteSpecies.length()) {
169 ByteVector b = ByteVector.fromArray(byteSpecies, a, i);
170
171 for (int j = 0; j < byteSpecies.length() / intSpecies.length(); j++) {
172 // Reduce the size of the byte vector and then cast to int
173 IntVector x = (IntVector)(b.reshape(bytesForIntsSpecies)).cast(intSpecies);
174
175 h = h * top_h_coeff + x.mul(v_h_coeff).addLanes();
176
177 b = b.shiftLanesLeft(intSpecies.length());
178 }
179 }
180
181 for (; i < a.length; i++) {
182 h = 31 * h + a[i];
183 }
184 return h;
185 }
186
187 static final VectorSpecies<Integer> INT_512_SPECIES = IntVector.SPECIES_512;
188 static final VectorSpecies<Integer> INT_256_SPECIES = IntVector.SPECIES_256;
189 static final int COEFF_31_TO_16;
190 static final IntVector H_COEFF_16;
191
192 static final VectorSpecies<Byte> BYTE_512_SPECIES = ByteVector.SPECIES_512;
193 static final VectorSpecies<Byte> BYTE_128_SPECIES = ByteVector.SPECIES_128;
194 static final VectorSpecies<Byte> BYTE_64_SPECIES = ByteVector.SPECIES_64;
195 static final int COEFF_31_TO_8;
196 static final IntVector H_COEFF_8;
197
|