|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Arm Limited. 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 | +package compiler.vectorization; |
| 25 | + |
| 26 | +import compiler.lib.ir_framework.*; |
| 27 | + |
| 28 | +/* |
| 29 | + * @test |
| 30 | + * @bug 8297689 |
| 31 | + * @summary Test miscompilation of reverseBytes call from subword types |
| 32 | + * @library /test/lib / |
| 33 | + * @requires vm.compiler2.enabled |
| 34 | + * @run driver compiler.vectorization.TestSubwordReverseBytes |
| 35 | + */ |
| 36 | + |
| 37 | +public class TestSubwordReverseBytes { |
| 38 | + private static final int SIZE = 32000; |
| 39 | + |
| 40 | + private static int[] idx = new int[SIZE]; |
| 41 | + private static short[] rbs = new short[SIZE]; |
| 42 | + private static char[] rbc = new char[SIZE]; |
| 43 | + |
| 44 | + static { |
| 45 | + for (int i = 0; i < SIZE; i++) { |
| 46 | + idx[i] = i; |
| 47 | + } |
| 48 | + for (short s = 0; s < SIZE; s++) { |
| 49 | + rbs[s] = Short.reverseBytes(s); |
| 50 | + } |
| 51 | + for (char c = 0; c < SIZE; c++) { |
| 52 | + rbc[c] = Character.reverseBytes(c); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + @IR(failOn = {IRNode.REVERSE_BYTES_V}) |
| 58 | + public static int[] testShortReverseBytes() { |
| 59 | + int[] res = new int[SIZE]; |
| 60 | + for (int i = 0; i < SIZE; i++) { |
| 61 | + res[i] = Short.reverseBytes((short) idx[i]); |
| 62 | + } |
| 63 | + return res; |
| 64 | + } |
| 65 | + |
| 66 | + @Run(test = "testShortReverseBytes") |
| 67 | + public static void testShort() { |
| 68 | + int[] res = testShortReverseBytes(); |
| 69 | + for (int i = 0; i < SIZE; i++) { |
| 70 | + if (res[i] != rbs[i]) { |
| 71 | + throw new RuntimeException("Wrong result: expected = " + |
| 72 | + (int) rbs[i] + ", actual = " + res[i]); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + @IR(failOn = {IRNode.REVERSE_BYTES_V}) |
| 79 | + public static int[] testCharacterReverseBytes() { |
| 80 | + int[] res = new int[SIZE]; |
| 81 | + for (int i = 0; i < SIZE; i++) { |
| 82 | + res[i] = Character.reverseBytes((char) idx[i]); |
| 83 | + } |
| 84 | + return res; |
| 85 | + } |
| 86 | + |
| 87 | + @Run(test = "testCharacterReverseBytes") |
| 88 | + public static void testChar() { |
| 89 | + int[] res = testCharacterReverseBytes(); |
| 90 | + for (int i = 0; i < SIZE; i++) { |
| 91 | + if (res[i] != rbc[i]) { |
| 92 | + throw new RuntimeException("Wrong result: expected = " + |
| 93 | + (int) rbc[i] + ", actual = " + res[i]); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + public static void main(String[] args) { |
| 99 | + TestFramework.run(); |
| 100 | + } |
| 101 | +} |
| 102 | + |
0 commit comments