1 /*
   2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2020, Arm Limited. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary AArch64 SIMD codegen test for vector int
  28  * @library /test/lib /
  29  *
  30  * @build sun.hotspot.WhiteBox
  31  *        compiler.vectorization.aarch64.CodegenTestRunner
  32  *
  33  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  34  * @run main/othervm -Xbootclasspath/a:.
  35  *                   -XX:+WhiteBoxAPI
  36  *                   compiler.vectorization.aarch64.VectorIntTest
  37  *
  38  * @requires os.arch == "aarch64" & vm.debug == true &
  39  *           vm.compiler2.enabled & !vm.graal.enabled
  40  */
  41 
  42 package compiler.vectorization.aarch64;
  43 
  44 public class VectorIntTest extends CodegenTestRunner {
  45 
  46     private static final int SIZE = 5432;
  47 
  48     private int[] a = new int[SIZE];
  49     private int[] b = new int[SIZE];
  50     private int[] c = new int[SIZE];
  51 
  52     // ---------------- Arithmetic ----------------
  53     @CheckOpto(neon = "subv", sve = "sve_sub")
  54     public void vectorNeg() {
  55         for (int i = 0; i < SIZE; i++) {
  56             c[i] = -a[i];
  57         }
  58     }
  59 
  60     @CallMath
  61     @CheckOpto(neon = "abs", sve = "sve_abs")
  62     public void vectorAbs() {
  63         for (int i = 0; i < SIZE; i++) {
  64             c[i] = Math.abs(a[i]);
  65         }
  66     }
  67 
  68     @CheckOpto(neon = "addv", sve = "sve_add")
  69     public void vectorAdd() {
  70         for (int i = 0; i < SIZE; i++) {
  71             c[i] = a[i] + b[i];
  72         }
  73     }
  74 
  75     @CheckOpto(neon = "subv", sve = "sve_sub")
  76     public void vectorSub() {
  77         for (int i = 0; i < SIZE; i++) {
  78             c[i] = a[i] - b[i];
  79         }
  80     }
  81 
  82     @CheckOpto(neon = "mulv", sve = "sve_mul")
  83     public void vectorMul() {
  84         for (int i = 0; i < SIZE; i++) {
  85             c[i] = a[i] * b[i];
  86         }
  87     }
  88 
  89     @CheckOpto(neon = "mlav", sve = "sve_mla")
  90     public void vectorMulAdd() {
  91         for (int i = 0; i < SIZE; i++) {
  92             c[i] = c[i] + a[i] * b[i];
  93         }
  94     }
  95 
  96     @CheckOpto(neon = "mlsv", sve = "sve_mls")
  97     public void vectorMulSub() {
  98         for (int i = 0; i < SIZE; i++) {
  99             c[i] = c[i] - a[i] * b[i];
 100         }
 101     }
 102 
 103     // ---------------- Logic ----------------
 104     @CheckOpto(neon = "xor", sve = "sve_eor")
 105     public void vectorNot() {
 106         for (int i = 0; i < SIZE; i++) {
 107             c[i] = ~a[i];
 108         }
 109     }
 110 
 111     @CheckOpto(neon = "and", sve = "sve_and")
 112     public void vectorAnd() {
 113         for (int i = 0; i < SIZE; i++) {
 114             c[i] = a[i] & b[i];
 115         }
 116     }
 117 
 118     @CheckOpto(neon = "orr", sve = "sve_orr")
 119     public void vectorOr() {
 120         for (int i = 0; i < SIZE; i++) {
 121             c[i] = a[i] | b[i];
 122         }
 123     }
 124 
 125     @CheckOpto(neon = "xor", sve = "sve_eor")
 126     public void vectorXor() {
 127         for (int i = 0; i < SIZE; i++) {
 128             c[i] = a[i] ^ b[i];
 129         }
 130     }
 131 
 132     // ---------------- Shift ----------------
 133     @CheckOpto(neon = "shl", sve = "sve_dup|sve_lsl")
 134     public void vectorShiftLeft() {
 135         for (int i = 0; i < SIZE; i++) {
 136             c[i] = a[i] << 3;
 137         }
 138     }
 139 
 140     @CheckOpto(neon = "sshr", sve = "sve_dup|sve_asr")
 141     public void vectorSignedShiftRight() {
 142         for (int i = 0; i < SIZE; i++) {
 143             c[i] = a[i] >> 2;
 144         }
 145     }
 146 
 147     @CheckOpto(neon = "ushr", sve = "sve_dup|sve_lsr")
 148     public void vectorUnsignedShiftRight() {
 149         for (int i = 0; i < SIZE; i++) {
 150             c[i] = a[i] >>> 5;
 151         }
 152     }
 153 
 154     // ---------------- Reduction ----------------
 155     // Temporarily skip NEON reduction checks since the opto assembly of NEON
 156     // reduction instructions doesn't have the "# vector (T)" suffix.
 157     @CheckOpto(sve = "sve_sub|sve_uaddv")
 158     public int reductionAdd() {
 159         int sum = 0;
 160         for (int i = 0; i < SIZE; i++) {
 161             sum += (a[i] - b[i]);
 162         }
 163         return sum;
 164     }
 165 
 166     @CheckOpto(sve = "sve_add|sve_andv")
 167     public int reductionAnd() {
 168         int sum = -1;
 169         for (int i = 0; i < SIZE; i++) {
 170             sum &= (a[i] + b[i]);
 171         }
 172         return sum;
 173     }
 174 
 175     @CheckOpto(sve = "sve_add|sve_orv")
 176     public int reductionOr() {
 177         int sum = 0;
 178         for (int i = 0; i < SIZE; i++) {
 179             sum |= (a[i] + b[i]);
 180         }
 181         return sum;
 182     }
 183 
 184     @CheckOpto(sve = "sve_add|sve_xorv")
 185     public int reductionXor() {
 186         int sum = 0;
 187         for (int i = 0; i < SIZE; i++) {
 188             sum ^= (a[i] + b[i]);
 189         }
 190         return sum;
 191     }
 192 
 193     public static void main(String[] args) {
 194         // Delegate work to the test runner
 195         new VectorIntTest().run(args);
 196     }
 197 }
 198