Skip to content

Commit 09301c1

Browse files
author
Ian Graves
committed
8356634: VectorShape#largestShapeFor should have public access
Reviewed-by: psandoz
1 parent abbffc0 commit 09301c1

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorShape.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -208,13 +208,22 @@ static VectorShape ofSwitchKey(int sk) {
208208
}
209209
}
210210

211-
// non-public support for computing preferred shapes
212-
213-
/*package-private*/
214-
static VectorShape largestShapeFor(Class<?> etype) {
211+
/**
212+
* Finds the largest vector shape supported by the current
213+
* platform for the element type {@code etype}.
214+
*
215+
* @param etype the element type
216+
* @return the largest vector shape supported by the platform
217+
* for {@code etype}
218+
* @throws IllegalArgumentException if no such vector shape exists
219+
* for the element type or the type is not a valid {@code ETYPE}.
220+
*/
221+
public static VectorShape largestShapeFor(Class<?> etype) {
215222
return VectorShape.forBitSize(getMaxVectorBitSize(etype));
216223
}
217224

225+
// non-public support for computing preferred shapes
226+
218227
/**
219228
* Finds the vector shape preferred by the current platform
220229
* for all vector element types.

test/jdk/jdk/incubator/vector/PreferredSpeciesTest.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* @test
32+
* @bug 8356549
3233
* @modules jdk.incubator.vector java.base/jdk.internal.vm.vector
3334
* @run testng PreferredSpeciesTest
3435
*/
@@ -126,4 +127,45 @@ void testVectorShape(Class<?> c) {
126127
Assert.assertEquals(largestSpecies.length(), maxLaneCount);
127128
Assert.assertEquals(largestSpecies.length(), Math.max(species.length(), maxLaneCount));
128129
}
130+
131+
// Testing VectorShape.largestShapeFor() for 8356549
132+
@Test(dataProvider = "classesProvider")
133+
void testLargestShapeFor(Class<?> c) {
134+
final int S_64_BITS = 64;
135+
int elemSize = 0;
136+
VectorSpecies<?> maxVectorSpecies;
137+
if (c == byte.class) {
138+
elemSize = Byte.SIZE;
139+
maxVectorSpecies = ByteVector.SPECIES_MAX;
140+
} else if (c == short.class) {
141+
elemSize = Short.SIZE;
142+
maxVectorSpecies = ShortVector.SPECIES_MAX;
143+
} else if (c == int.class) {
144+
elemSize = Integer.SIZE;
145+
maxVectorSpecies = IntVector.SPECIES_MAX;
146+
} else if (c == long.class) {
147+
elemSize = Long.SIZE;
148+
maxVectorSpecies = LongVector.SPECIES_MAX;
149+
} else if (c == float.class) {
150+
elemSize = Float.SIZE;
151+
maxVectorSpecies = FloatVector.SPECIES_MAX;
152+
} else if (c == double.class) {
153+
elemSize = Double.SIZE;
154+
maxVectorSpecies = DoubleVector.SPECIES_MAX;
155+
} else {
156+
throw new IllegalArgumentException("Bad vector element type: " + c.getName());
157+
}
158+
159+
VectorShape vs = VectorShape.largestShapeFor(c);
160+
161+
int maxLaneCount = VectorSupport.getMaxLaneCount(c);
162+
int max = Math.max(maxLaneCount * elemSize, S_64_BITS);
163+
164+
//Assert we're using the same element when comparing shapes
165+
Assert.assertEquals(c, maxVectorSpecies.elementType());
166+
167+
Assert.assertEquals(vs.vectorBitSize(), max);
168+
Assert.assertEquals(vs.vectorBitSize(), maxVectorSpecies.vectorBitSize());
169+
170+
}
129171
}

0 commit comments

Comments
 (0)