|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 IBM Corp. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8371187 |
| 27 | + * @summary Randomized test for lane swapping issue in LongVector reinterpretation on BE platforms |
| 28 | + * @modules jdk.incubator.vector |
| 29 | + * @run main/othervm --add-modules=jdk.incubator.vector TestLongVectorReinterpret |
| 30 | + */ |
| 31 | + |
| 32 | +import jdk.incubator.vector.*; |
| 33 | +import java.util.SplittableRandom; |
| 34 | + |
| 35 | +public class TestLongVectorReinterpret { |
| 36 | + |
| 37 | + static final VectorSpecies<Long> SPECIES = LongVector.SPECIES_128; |
| 38 | + static final SplittableRandom RAND = new SplittableRandom(42); |
| 39 | + |
| 40 | + public static void main(String[] args) { |
| 41 | + for (int iter = 0; iter < 1000; iter++) { |
| 42 | + testOnce(); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + static void testOnce() { |
| 47 | + long[] a = new long[SPECIES.length()]; |
| 48 | + long[] b = new long[SPECIES.length()]; |
| 49 | + |
| 50 | + for (int i = 0; i < a.length; i++) { |
| 51 | + a[i] = RAND.nextLong(); |
| 52 | + b[i] = RAND.nextLong(); |
| 53 | + } |
| 54 | + |
| 55 | + LongVector v1 = LongVector.fromArray(SPECIES, a, 0); |
| 56 | + LongVector v2 = LongVector.fromArray(SPECIES, b, 0); |
| 57 | + |
| 58 | + IntVector result = v2.reinterpretAsInts().add(v1.reinterpretAsInts()); |
| 59 | + |
| 60 | + int[] expected = new int[SPECIES.length() * 2]; |
| 61 | + |
| 62 | + for (int i = 0; i < a.length; i++) { |
| 63 | + int loA = (int) a[i]; |
| 64 | + int hiA = (int) (a[i] >>> 32); |
| 65 | + |
| 66 | + int loB = (int) b[i]; |
| 67 | + int hiB = (int) (b[i] >>> 32); |
| 68 | + |
| 69 | + expected[2 * i] = loA + loB; |
| 70 | + expected[2 * i + 1] = hiA + hiB; |
| 71 | + } |
| 72 | + |
| 73 | + for (int i = 0; i < expected.length; i++) { |
| 74 | + int actual = result.lane(i); |
| 75 | + if (actual != expected[i]) { |
| 76 | + throw new AssertionError( |
| 77 | + "Mismatch at lane " + i + |
| 78 | + " expected=" + expected[i] + |
| 79 | + " actual=" + actual + |
| 80 | + " vector=" + result); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments