Skip to content

Commit 6442250

Browse files
committed
make shifts vector static final
1 parent 5b3863e commit 6442250

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

libs/simdvec/src/main21/java/org/elasticsearch/simdvec/internal/vectorization/PanamaESVectorUtilSupport.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,21 @@ public void soarDistanceBulk(
946946
}
947947

948948
private static final VectorSpecies<Integer> INT_SPECIES_128 = IntVector.SPECIES_128;
949+
private static final IntVector SHIFTS_256;
950+
private static final IntVector HIGH_SHIFTS_128;
951+
private static final IntVector LOW_SHIFTS_128;
952+
static {
953+
final int[] shifts = new int[] { 7, 6, 5, 4, 3, 2, 1, 0 };
954+
if (VECTOR_BITSIZE == 128) {
955+
HIGH_SHIFTS_128 = IntVector.fromArray(INT_SPECIES_128, shifts, 0);
956+
LOW_SHIFTS_128 = IntVector.fromArray(INT_SPECIES_128, shifts, INT_SPECIES_128.length());
957+
SHIFTS_256 = null;
958+
} else {
959+
SHIFTS_256 = IntVector.fromArray(INT_SPECIES_256, shifts, 0);
960+
HIGH_SHIFTS_128 = null;
961+
LOW_SHIFTS_128 = null;
962+
}
963+
}
949964
private static final int[] SHIFTS = new int[] { 7, 6, 5, 4, 3, 2, 1, 0 };
950965

951966
@Override
@@ -968,10 +983,9 @@ private void packAsBinary256(int[] vector, byte[] packed) {
968983
final int limit = INT_SPECIES_256.loopBound(vector.length);
969984
int i = 0;
970985
int index = 0;
971-
IntVector shifts = IntVector.fromArray(INT_SPECIES_256, SHIFTS, 0);
972986
for (; i < limit; i += INT_SPECIES_256.length(), index++) {
973987
IntVector v = IntVector.fromArray(INT_SPECIES_256, vector, i);
974-
int result = v.lanewise(LSHL, shifts).reduceLanes(OR);
988+
int result = v.lanewise(LSHL, SHIFTS_256).reduceLanes(OR);
975989
packed[index] = (byte) result;
976990
}
977991
if (i == vector.length) {
@@ -989,13 +1003,11 @@ private void packAsBinary128(int[] vector, byte[] packed) {
9891003
final int limit = INT_SPECIES_128.loopBound(vector.length) - INT_SPECIES_128.length();
9901004
int i = 0;
9911005
int index = 0;
992-
IntVector highShifts = IntVector.fromArray(INT_SPECIES_128, SHIFTS, 0);
993-
IntVector lowShifts = IntVector.fromArray(INT_SPECIES_128, SHIFTS, INT_SPECIES_128.length());
9941006
for (; i < limit; i += 2 * INT_SPECIES_128.length(), index++) {
9951007
IntVector v = IntVector.fromArray(INT_SPECIES_128, vector, i);
996-
var v1 = v.lanewise(LSHL, highShifts);
1008+
var v1 = v.lanewise(LSHL, HIGH_SHIFTS_128);
9971009
v = IntVector.fromArray(INT_SPECIES_128, vector, i + INT_SPECIES_128.length());
998-
var v2 = v.lanewise(LSHL, lowShifts);
1010+
var v2 = v.lanewise(LSHL, LOW_SHIFTS_128);
9991011
int result = v1.lanewise(OR, v2).reduceLanes(OR);
10001012
packed[index] = (byte) result;
10011013
}

0 commit comments

Comments
 (0)