|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
29 | 29 |
|
30 | 30 | /** |
31 | 31 | * @test |
| 32 | + * @bug 8356549 |
32 | 33 | * @modules jdk.incubator.vector java.base/jdk.internal.vm.vector |
33 | 34 | * @run testng PreferredSpeciesTest |
34 | 35 | */ |
@@ -126,4 +127,45 @@ void testVectorShape(Class<?> c) { |
126 | 127 | Assert.assertEquals(largestSpecies.length(), maxLaneCount); |
127 | 128 | Assert.assertEquals(largestSpecies.length(), Math.max(species.length(), maxLaneCount)); |
128 | 129 | } |
| 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 | + } |
129 | 171 | } |
0 commit comments