@@ -43,8 +43,7 @@ final class VectorUtilPanamaProvider implements VectorUtilProvider {
43
43
* <p>it could be that it has only AVX1 and integer vectors are fast. it could also be that it has
44
44
* no AVX and integer vectors are extremely slow. don't use integer vectors to avoid landmines.
45
45
*/
46
- private static final boolean IS_AMD64_WITHOUT_AVX2 =
47
- Constants .OS_ARCH .equals ("amd64" ) && INT_SPECIES_PREF_BIT_SIZE < 256 ;
46
+ private final boolean hasFastIntegerVectors ;
48
47
49
48
static {
50
49
if (INT_SPECIES_PREF_BIT_SIZE >= 256 ) {
@@ -67,8 +66,8 @@ private static <T> T doPrivileged(PrivilegedAction<T> action) {
67
66
return AccessController .doPrivileged (action );
68
67
}
69
68
70
- VectorUtilPanamaProvider () {
71
- if (INT_SPECIES_PREF_BIT_SIZE < 128 ) {
69
+ VectorUtilPanamaProvider (boolean testMode ) {
70
+ if (! testMode && INT_SPECIES_PREF_BIT_SIZE < 128 ) {
72
71
throw new UnsupportedOperationException (
73
72
"Vector bit size is less than 128: " + INT_SPECIES_PREF_BIT_SIZE );
74
73
}
@@ -83,9 +82,16 @@ private static <T> T doPrivileged(PrivilegedAction<T> action) {
83
82
"We hit initialization failure described in JDK-8309727: " + se );
84
83
}
85
84
85
+ // check if the system is x86 and less than 256-bit vectors:
86
+ var isAMD64withoutAVX2 = Constants .OS_ARCH .equals ("amd64" ) && INT_SPECIES_PREF_BIT_SIZE < 256 ;
87
+ this .hasFastIntegerVectors = testMode || false == isAMD64withoutAVX2 ;
88
+
86
89
var log = Logger .getLogger (getClass ().getName ());
87
90
log .info (
88
- "Java vector incubator API enabled; uses preferredBitSize=" + INT_SPECIES_PREF_BIT_SIZE );
91
+ "Java vector incubator API enabled"
92
+ + (testMode ? " (test mode)" : "" )
93
+ + "; uses preferredBitSize="
94
+ + INT_SPECIES_PREF_BIT_SIZE );
89
95
}
90
96
91
97
@ Override
@@ -295,7 +301,7 @@ public int dotProduct(byte[] a, byte[] b) {
295
301
int res = 0 ;
296
302
// only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit
297
303
// vectors (256-bit on intel to dodge performance landmines)
298
- if (a .length >= 16 && IS_AMD64_WITHOUT_AVX2 == false ) {
304
+ if (a .length >= 16 && hasFastIntegerVectors ) {
299
305
// compute vectorized dot product consistent with VPDPBUSD instruction
300
306
if (INT_SPECIES_PREF_BIT_SIZE >= 256 ) {
301
307
// optimized 256/512 bit implementation, processes 8/16 bytes at a time
@@ -352,7 +358,7 @@ public float cosine(byte[] a, byte[] b) {
352
358
int norm2 = 0 ;
353
359
// only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit
354
360
// vectors (256-bit on intel to dodge performance landmines)
355
- if (a .length >= 16 && IS_AMD64_WITHOUT_AVX2 == false ) {
361
+ if (a .length >= 16 && hasFastIntegerVectors ) {
356
362
if (INT_SPECIES_PREF_BIT_SIZE >= 256 ) {
357
363
// optimized 256/512 bit implementation, processes 8/16 bytes at a time
358
364
int upperBound = PREF_BYTE_SPECIES .loopBound (a .length );
@@ -442,7 +448,7 @@ public int squareDistance(byte[] a, byte[] b) {
442
448
int res = 0 ;
443
449
// only vectorize if we'll at least enter the loop a single time, and we have at least 128-bit
444
450
// vectors (256-bit on intel to dodge performance landmines)
445
- if (a .length >= 16 && IS_AMD64_WITHOUT_AVX2 == false ) {
451
+ if (a .length >= 16 && hasFastIntegerVectors ) {
446
452
if (INT_SPECIES_PREF_BIT_SIZE >= 256 ) {
447
453
// optimized 256/512 bit implementation, processes 8/16 bytes at a time
448
454
int upperBound = PREF_BYTE_SPECIES .loopBound (a .length );
0 commit comments