/* * Copyright (c) 2022, Arm Limited. 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @summary Vectorization test on basic byte operations * @library /test/lib / * * @build sun.hotspot.WhiteBox * compiler.vectorization.runner.VectorizationTestRunner * * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox * @run main/othervm -Xbootclasspath/a:. * -XX:+UnlockDiagnosticVMOptions * -XX:+WhiteBoxAPI * compiler.vectorization.runner.BasicByteOpTest * * @requires vm.compiler2.enabled & vm.flagless */ package compiler.vectorization.runner; public class BasicByteOpTest extends VectorizationTestRunner { private static final int SIZE = 2345; private byte[] a; private byte[] b; private byte[] c; public BasicByteOpTest() { a = new byte[SIZE]; b = new byte[SIZE]; c = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { a[i] = (byte) (-3 * i); b[i] = (byte) (i + 4); c[i] = (byte) -90; } } // ---------------- Arithmetic ---------------- @Test public byte[] vectorNeg() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) -a[i]; } return res; } @Test public byte[] vectorAbs() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) Math.abs(a[i]); } return res; } @Test public byte[] vectorAdd() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] + b[i]); } return res; } @Test public byte[] vectorSub() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] - b[i]); } return res; } @Test public byte[] vectorMul() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] * b[i]); } return res; } @Test public byte[] vectorMulAdd() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (c[i] + a[i] * b[i]); } return res; } @Test public byte[] vectorMulSub() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (c[i] - a[i] * b[i]); } return res; } // ---------------- Logic ---------------- @Test public byte[] vectorNot() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) ~a[i]; } return res; } @Test public byte[] vectorAnd() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] & b[i]); } return res; } @Test public byte[] vectorOr() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] | b[i]); } return res; } @Test public byte[] vectorXor() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] ^ b[i]); } return res; } // ---------------- Shift ---------------- @Test public byte[] vectorShiftLeft() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] << 3); } return res; } @Test public byte[] vectorSignedShiftRight() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] >> 2); } return res; } @Test // Note that unsigned shift right on subword signed integer types can // not be vectorized since the sign extension bit would be lost. public byte[] vectorUnsignedShiftRight() { byte[] res = new byte[SIZE]; for (int i = 0; i < SIZE; i++) { res[i] = (byte) (a[i] >>> 5); } return res; } }