Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, 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
Expand Down Expand Up @@ -208,13 +208,22 @@ static VectorShape ofSwitchKey(int sk) {
}
}

// non-public support for computing preferred shapes

/*package-private*/
static VectorShape largestShapeFor(Class<?> etype) {
/**
* Finds the largest vector shape supported by the current
* platform for the element type {@code etype}.
*
* @param etype the element type
* @return the largest vector shape supported by the platform
* for {@code etype}
* @throws IllegalArgumentException if no such vector shape exists
* for the element type or the type is not a valid {@code ETYPE}.
*/
public static VectorShape largestShapeFor(Class<?> etype) {
return VectorShape.forBitSize(getMaxVectorBitSize(etype));
}

// non-public support for computing preferred shapes

/**
* Finds the vector shape preferred by the current platform
* for all vector element types.
Expand Down
44 changes: 43 additions & 1 deletion test/jdk/jdk/incubator/vector/PreferredSpeciesTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2025, 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
Expand Down Expand Up @@ -29,6 +29,7 @@

/**
* @test
* @bug 8356549
* @modules jdk.incubator.vector java.base/jdk.internal.vm.vector
* @run testng PreferredSpeciesTest
*/
Expand Down Expand Up @@ -126,4 +127,45 @@ void testVectorShape(Class<?> c) {
Assert.assertEquals(largestSpecies.length(), maxLaneCount);
Assert.assertEquals(largestSpecies.length(), Math.max(species.length(), maxLaneCount));
}

// Testing VectorShape.largestShapeFor() for 8356549
@Test(dataProvider = "classesProvider")
void testLargestShapeFor(Class<?> c) {
final int S_64_BITS = 64;
int elemSize = 0;
VectorSpecies<?> maxVectorSpecies;
if (c == byte.class) {
elemSize = Byte.SIZE;
maxVectorSpecies = ByteVector.SPECIES_MAX;
} else if (c == short.class) {
elemSize = Short.SIZE;
maxVectorSpecies = ShortVector.SPECIES_MAX;
} else if (c == int.class) {
elemSize = Integer.SIZE;
maxVectorSpecies = IntVector.SPECIES_MAX;
} else if (c == long.class) {
elemSize = Long.SIZE;
maxVectorSpecies = LongVector.SPECIES_MAX;
} else if (c == float.class) {
elemSize = Float.SIZE;
maxVectorSpecies = FloatVector.SPECIES_MAX;
} else if (c == double.class) {
elemSize = Double.SIZE;
maxVectorSpecies = DoubleVector.SPECIES_MAX;
} else {
throw new IllegalArgumentException("Bad vector element type: " + c.getName());
}

VectorShape vs = VectorShape.largestShapeFor(c);

int maxLaneCount = VectorSupport.getMaxLaneCount(c);
int max = Math.max(maxLaneCount * elemSize, S_64_BITS);

//Assert we're using the same element when comparing shapes
Assert.assertEquals(c, maxVectorSpecies.elementType());

Assert.assertEquals(vs.vectorBitSize(), max);
Assert.assertEquals(vs.vectorBitSize(), maxVectorSpecies.vectorBitSize());

}
}