@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,16 @@
* @run testng PreferredSpeciesTest
*/
/**
* @test
* @bug 8262096
* @requires vm.compiler2.enabled
* @summary Test the initialization of vector shapes
* @modules jdk.incubator.vector java.base/jdk.internal.vm.vector
* @run testng/othervm -XX:MaxVectorSize=8 PreferredSpeciesTest
* @run testng/othervm -XX:MaxVectorSize=4 PreferredSpeciesTest
*/
public class PreferredSpeciesTest {
@ DataProvider
public static Object [][] classesProvider () {
@@ -49,26 +59,35 @@ public static Object[][] classesProvider() {
@ Test (dataProvider = "classesProvider" )
void testVectorLength (Class <?> c ) {
VectorSpecies <?> species = null ;
int elemSize = 0 ;
if (c == byte .class ) {
species = ByteVector .SPECIES_PREFERRED ;
elemSize = Byte .SIZE ;
} else if (c == short .class ) {
species = ShortVector .SPECIES_PREFERRED ;
elemSize = Short .SIZE ;
} else if (c == int .class ) {
species = IntVector .SPECIES_PREFERRED ;
elemSize = Integer .SIZE ;
} else if (c == long .class ) {
species = LongVector .SPECIES_PREFERRED ;
elemSize = Long .SIZE ;
} else if (c == float .class ) {
species = FloatVector .SPECIES_PREFERRED ;
elemSize = Float .SIZE ;
} else if (c == double .class ) {
species = DoubleVector .SPECIES_PREFERRED ;
elemSize = Double .SIZE ;
} else {
throw new IllegalArgumentException ("Bad vector element type: " + c .getName ());
}
VectorShape shape = VectorShape .preferredShape ();
System .out .println ("class = " +c +"; preferred shape" +shape +"; preferred species = " +species +"; maxSize=" +VectorSupport .getMaxLaneCount (c ));
int maxLaneCount = Math .max (VectorSupport .getMaxLaneCount (c ), 64 / elemSize );
System .out .println ("class = " +c +"; preferred shape" +shape +"; preferred species = " +species +"; maxSize=" +maxLaneCount );
Assert .assertEquals (species .vectorShape (), shape );
Assert .assertEquals (species .length (), Math .min (species .length (), VectorSupport . getMaxLaneCount ( c ) ));
Assert .assertEquals (species .length (), Math .min (species .length (), maxLaneCount ));
}
@ Test (dataProvider = "classesProvider" )
@@ -96,12 +115,15 @@ void testVectorShape(Class<?> c) {
} else {
throw new IllegalArgumentException ("Bad vector element type: " + c .getName ());
}
int maxLaneCount = Math .max (VectorSupport .getMaxLaneCount (c ), 64 / elemSize );
VectorSpecies largestSpecies = VectorSpecies .ofLargestShape (c );
VectorShape largestShape = VectorShape .forBitSize (VectorSupport . getMaxLaneCount ( c ) * elemSize );
VectorShape largestShape = VectorShape .forBitSize (maxLaneCount * elemSize );
System .out .println ("class = " +c +"; largest species = " +largestSpecies +"; maxSize=" +VectorSupport . getMaxLaneCount ( c ) );
System .out .println ("class = " +c +"; largest species = " +largestSpecies +"; maxSize=" +maxLaneCount );
Assert .assertEquals (largestSpecies .vectorShape (), largestShape );
Assert .assertEquals (largestSpecies .length (), VectorSupport . getMaxLaneCount ( c ) );
Assert .assertEquals (largestSpecies .length (), Math .max (species .length (), VectorSupport . getMaxLaneCount ( c ) ));
Assert .assertEquals (largestSpecies .length (), maxLaneCount );
Assert .assertEquals (largestSpecies .length (), Math .max (species .length (), maxLaneCount ));
}
}