1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/*
* Copyright (c) 2022, 2023, 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.
*/
package compiler.vectorapi;
import compiler.lib.ir_framework.*;
import java.util.Random;
import jdk.incubator.vector.DoubleVector;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.LongVector;
import jdk.incubator.vector.VectorMask;
import jdk.incubator.vector.VectorShape;
import jdk.incubator.vector.VectorSpecies;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
/**
* @test
* @bug 8288397
* @key randomness
* @library /test/lib /
* @requires vm.cpu.features ~= ".*sve.*" & (vm.opt.MaxVectorSize == "null" | vm.opt.MaxVectorSize >= 16)
* @summary AArch64: Fix register issues in SVE backend match rules
* @modules jdk.incubator.vector
*
* @run driver compiler.vectorapi.VectorGatherScatterTest
*/
public class VectorGatherScatterTest {
private static final VectorSpecies<Double> D_SPECIES = DoubleVector.SPECIES_MAX;
private static final VectorSpecies<Long> L_SPECIES = LongVector.SPECIES_MAX;
private static final VectorSpecies<Integer> I_SPECIES =
VectorSpecies.of(int.class, VectorShape.forBitSize(L_SPECIES.vectorBitSize() / 2));
private static int LENGTH = 128;
private static final Random RD = Utils.getRandomInstance();
private static int[] ia;
private static int[] ir;
private static long[] la;
private static long[] lr;
private static double[] da;
private static double[] dr;
private static boolean[] m;
static {
ia = new int[LENGTH];
ir = new int[LENGTH];
la = new long[LENGTH];
lr = new long[LENGTH];
da = new double[LENGTH];
dr = new double[LENGTH];
m = new boolean[LENGTH];
for (int i = 0; i < LENGTH; i++) {
ia[i] = i;
la[i] = RD.nextLong(25);
da[i] = RD.nextDouble(25.0);
m[i] = i % 2 == 0;
}
}
@Test
@Warmup(10000)
@IR(counts = { IRNode.LOAD_VECTOR_GATHER, ">= 1" })
public static void testLoadGather() {
LongVector av = LongVector.fromArray(L_SPECIES, la, 0, ia, 0);
av.intoArray(lr, 0);
IntVector bv = IntVector.fromArray(I_SPECIES, ia, 0);
bv.add(0).intoArray(ir, 0);
for(int i = 0; i < I_SPECIES.length(); i++) {
Asserts.assertEquals(ia[i], ir[i]);
}
}
@Test
@Warmup(10000)
@IR(counts = { IRNode.LOAD_VECTOR_GATHER_MASKED, ">= 1" })
public static void testLoadGatherMasked() {
VectorMask<Long> mask = VectorMask.fromArray(L_SPECIES, m, 0);
// "mask" is guaranteed to be not alltrue, in case the masked
// gather load is optimized to the non-masked version.
LongVector av = LongVector.fromArray(L_SPECIES, la, 0, ia, 0, mask);
av.intoArray(lr, 0);
IntVector bv = IntVector.fromArray(I_SPECIES, ia, 0);
bv.add(0).intoArray(ir, 0);
for(int i = 0; i < I_SPECIES.length(); i++) {
Asserts.assertEquals(ia[i], ir[i]);
}
}
@Test
@Warmup(10000)
@IR(counts = { IRNode.STORE_VECTOR_SCATTER, ">= 1" })
public static void testStoreScatter() {
DoubleVector av = DoubleVector.fromArray(D_SPECIES, da, 0);
av.intoArray(dr, 0, ia, 0);
IntVector bv = IntVector.fromArray(I_SPECIES, ia, 0);
bv.add(0).intoArray(ir, 0);
for(int i = 0; i < I_SPECIES.length(); i++) {
Asserts.assertEquals(ia[i], ir[i]);
}
}
@Test
@Warmup(10000)
@IR(counts = { IRNode.STORE_VECTOR_SCATTER_MASKED, ">= 1" })
public static void testStoreScatterMasked() {
VectorMask<Double> mask = VectorMask.fromArray(D_SPECIES, m, 0);
DoubleVector av = DoubleVector.fromArray(D_SPECIES, da, 0);
// "mask" is guaranteed to be not alltrue, in case the masked
// scatter store is optimized to the non-masked version.
av.intoArray(dr, 0, ia, 0, mask);
IntVector bv = IntVector.fromArray(I_SPECIES, ia, 0);
bv.add(0).intoArray(ir, 0);
for(int i = 0; i < I_SPECIES.length(); i++) {
Asserts.assertEquals(ia[i], ir[i]);
}
}
public static void main(String[] args) {
TestFramework.runWithFlags("--add-modules=jdk.incubator.vector",
"-XX:UseSVE=1");
}
}
|