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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
/*
* Copyright (c) 2021, Oracle and/or its affiliates. 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 java.util.Random;
import jdk.incubator.vector.VectorSpecies;
import jdk.incubator.vector.ByteVector;
import jdk.incubator.vector.DoubleVector;
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.LongVector;
import jdk.incubator.vector.ShortVector;
import jdk.incubator.vector.VectorMask;
import jdk.test.lib.Utils;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* @test
* @bug 8274569
* @key randomness
* @library /test/lib
* @summary Tests X86 backend related incorrectness issues in legacy storemask patterns
* @modules jdk.incubator.vector
*
* @run testng/othervm -XX:-TieredCompilation -XX:CompileThreshold=100 compiler.vectorapi.VectorMaskLoadStoreTest
*/
/**
* @test
* @bug 8278584
* @library /test/lib
* @summary Test the codegen for C2's VectorLongToMaskNode
* "-XX:DisableIntrinsic=_VectorMaskOp" is required to break "VectorMaskToLong (VectorLongToMask l) ==> l" opt.
* This is because when _VectorMaskOp is disabled, VectorMaskToLong won't be generated.
* @modules jdk.incubator.vector
*
* @run testng/othervm -XX:-TieredCompilation -XX:CompileThreshold=100 -XX:+UnlockDiagnosticVMOptions
* -XX:DisableIntrinsic=_VectorMaskOp compiler.vectorapi.VectorMaskLoadStoreTest
*/
public class VectorMaskLoadStoreTest{
private static final int NUM_ITER = 5000;
private static final Random rd = Utils.getRandomInstance();
public static void testByte64(long val) {
VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_64;
VectorMask<Byte> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFL);
}
public static void testByte128(long val) {
VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_128;
VectorMask<Byte> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFFFL);
}
public static void testByte256(long val) {
VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_256;
VectorMask<Byte> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFFFFFFFL);
}
public static void testByte512(long val) {
VectorSpecies<Byte> SPECIES = ByteVector.SPECIES_512;
VectorMask<Byte> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & -1L);
}
public static void testShort64(long val) {
VectorSpecies<Short> SPECIES = ShortVector.SPECIES_64;
VectorMask<Short> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFL);
}
public static void testShort128(long val) {
VectorSpecies<Short> SPECIES = ShortVector.SPECIES_128;
VectorMask<Short> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFL);
}
public static void testShort256(long val) {
VectorSpecies<Short> SPECIES = ShortVector.SPECIES_256;
VectorMask<Short> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFFFL);
}
public static void testShort512(long val) {
VectorSpecies<Short> SPECIES = ShortVector.SPECIES_512;
VectorMask<Short> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFFFFFFFL);
}
public static void testInteger64(long val) {
VectorSpecies<Integer> SPECIES = IntVector.SPECIES_64;
VectorMask<Integer> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0x3L);
}
public static void testInteger128(long val) {
VectorSpecies<Integer> SPECIES = IntVector.SPECIES_128;
VectorMask<Integer> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFL);
}
public static void testInteger256(long val) {
VectorSpecies<Integer> SPECIES = IntVector.SPECIES_256;
VectorMask<Integer> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFL);
}
public static void testInteger512(long val) {
VectorSpecies<Integer> SPECIES = IntVector.SPECIES_512;
VectorMask<Integer> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFFFL);
}
public static void testLong64(long val) {
VectorSpecies<Long> SPECIES = LongVector.SPECIES_64;
VectorMask<Long> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0x1L);
}
public static void testLong128(long val) {
VectorSpecies<Long> SPECIES = LongVector.SPECIES_128;
VectorMask<Long> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0x3L);
}
public static void testLong256(long val) {
VectorSpecies<Long> SPECIES = LongVector.SPECIES_256;
VectorMask<Long> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFL);
}
public static void testLong512(long val) {
VectorSpecies<Long> SPECIES = LongVector.SPECIES_512;
VectorMask<Long> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFL);
}
public static void testFloat64(long val) {
VectorSpecies<Float> SPECIES = FloatVector.SPECIES_64;
VectorMask<Float> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0x3L);
}
public static void testFloat128(long val) {
VectorSpecies<Float> SPECIES = FloatVector.SPECIES_128;
VectorMask<Float> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFL);
}
public static void testFloat256(long val) {
VectorSpecies<Float> SPECIES = FloatVector.SPECIES_256;
VectorMask<Float> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFL);
}
public static void testFloat512(long val) {
VectorSpecies<Float> SPECIES = FloatVector.SPECIES_512;
VectorMask<Float> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFFFL);
}
public static void testDouble64(long val) {
VectorSpecies<Double> SPECIES = DoubleVector.SPECIES_64;
VectorMask<Double> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0x1L);
}
public static void testDouble128(long val) {
VectorSpecies<Double> SPECIES = DoubleVector.SPECIES_128;
VectorMask<Double> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0x3L);
}
public static void testDouble256(long val) {
VectorSpecies<Double> SPECIES = DoubleVector.SPECIES_256;
VectorMask<Double> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFL);
}
public static void testDouble512(long val) {
VectorSpecies<Double> SPECIES = DoubleVector.SPECIES_512;
VectorMask<Double> mask = VectorMask.fromLong(SPECIES, val);
Assert.assertEquals(mask.toLong(), val & 0xFFL);
}
@Test
public static void testMaskCast() {
long [] vals = {-1L, 0, rd.nextLong(), rd.nextLong()};
for(int i = 0; i < vals.length; i++) {
long val = vals[i];
for (int ctr = 0; ctr < NUM_ITER; ctr++) {
testByte64(val);
testByte128(val);
testByte256(val);
testByte512(val);
testShort64(val);
testShort128(val);
testShort256(val);
testShort512(val);
testInteger64(val);
testInteger128(val);
testInteger256(val);
testInteger512(val);
testLong64(val);
testLong128(val);
testLong256(val);
testLong512(val);
testFloat64(val);
testFloat128(val);
testFloat256(val);
testFloat512(val);
testDouble64(val);
testDouble128(val);
testDouble256(val);
testDouble512(val);
}
}
}
}
|