< prev index next >

test/jdk/jdk/incubator/vector/ByteMaxVectorLoadStoreTests.java

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level


  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
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @modules jdk.incubator.vector
  27  * @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
  28  *      ByteMaxVectorLoadStoreTests
  29  *
  30  */
  31 
  32 import jdk.incubator.vector.Vector.Shape;
  33 import jdk.incubator.vector.Vector.Species;

  34 import jdk.incubator.vector.Vector;
  35 
  36 import jdk.incubator.vector.ByteVector;
  37 
  38 import org.testng.Assert;
  39 import org.testng.annotations.DataProvider;
  40 import org.testng.annotations.Test;
  41 
  42 import java.lang.invoke.MethodHandles;
  43 import java.lang.invoke.VarHandle;
  44 import java.nio.ByteBuffer;
  45 import java.nio.ByteOrder;
  46 import java.util.List;
  47 import java.util.function.IntFunction;
  48 
  49 @Test
  50 public class ByteMaxVectorLoadStoreTests extends AbstractVectorTest {
  51     static final Species<Byte> SPECIES =
  52                 ByteVector.SPECIES_MAX;
  53 
  54     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
  55 
  56     static Shape getMaxBit() {
  57         return Shape.S_Max_BIT;
  58     }
  59 
  60     static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask) {
  61         int i = 0;
  62         try {
  63             for (; i < a.length; i++) {
  64                 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i]);
  65             }
  66         } catch (AssertionError e) {
  67             Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i], "at index #" + i);
  68         }
  69     }
  70 
  71     static void assertArraysEquals(byte[] a, byte[] r, int[] im) {
  72         int i = 0;
  73         try {
  74             for (; i < a.length; i++) {
  75                 Assert.assertEquals(a[im[i]], r[i]);
  76             }
  77         } catch (AssertionError e) {


 188     @Test(dataProvider = "byteProvider")
 189     static void loadStoreArray(IntFunction<byte[]> fa) {
 190         byte[] a = fa.apply(SPECIES.length());
 191         byte[] r = new byte[a.length];
 192 
 193         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 194             for (int i = 0; i < a.length; i += SPECIES.length()) {
 195                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 196                 av.intoArray(r, i);
 197             }
 198         }
 199         Assert.assertEquals(a, r);
 200     }
 201 
 202     @Test(dataProvider = "byteMaskProvider")
 203     static void loadStoreMaskArray(IntFunction<byte[]> fa,
 204                                    IntFunction<boolean[]> fm) {
 205         byte[] a = fa.apply(SPECIES.length());
 206         byte[] r = new byte[a.length];
 207         boolean[] mask = fm.apply(SPECIES.length());
 208         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 209 
 210         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 211             for (int i = 0; i < a.length; i += SPECIES.length()) {
 212                 ByteVector av = ByteVector.fromArray(SPECIES, a, i, vmask);
 213                 av.intoArray(r, i);
 214             }
 215         }
 216         assertArraysEquals(a, r, mask);
 217 
 218         r = new byte[a.length];
 219         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 220             for (int i = 0; i < a.length; i += SPECIES.length()) {
 221                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 222                 av.intoArray(r, i, vmask);
 223             }
 224         }
 225 
 226         assertArraysEquals(a, r, mask);
 227     }
 228 


 262         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 263             for (int i = 0; i < l; i += s) {
 264                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
 265                 av.intoByteBuffer(r, i);
 266             }
 267         }
 268         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 269         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 270         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 271         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 272         Assert.assertEquals(a, r, "Buffers not equal");
 273     }
 274 
 275     @Test(dataProvider = "byteByteBufferMaskProvider")
 276     static void loadStoreByteBufferMask(IntFunction<byte[]> fa,
 277                                         IntFunction<ByteBuffer> fb,
 278                                         IntFunction<boolean[]> fm) {
 279         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
 280         ByteBuffer r = fb.apply(a.limit());
 281         boolean[] mask = fm.apply(SPECIES.length());
 282         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 283 
 284         int l = a.limit();
 285         int s = SPECIES.length() * SPECIES.elementSize() / 8;
 286 
 287         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 288             for (int i = 0; i < l; i += s) {
 289                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
 290                 av.intoByteBuffer(r, i);
 291             }
 292         }
 293         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 294         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 295         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 296         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 297         assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
 298 
 299         a = toBuffer(fa.apply(SPECIES.length()), fb);
 300         r = fb.apply(a.limit());
 301         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 302             for (int i = 0; i < l; i += s) {
 303                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
 304                 av.intoByteBuffer(r, i, vmask);
 305             }
 306         }
 307         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 308         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 309         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 310         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 311         assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
 312     }
 313 
 314     @Test(dataProvider = "byteByteBufferMaskProvider")
 315     static void loadReadOnlyStoreByteBufferMask(IntFunction<byte[]> fa,
 316                                                 IntFunction<ByteBuffer> fb,
 317                                                 IntFunction<boolean[]> fm) {
 318         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
 319         a = a.asReadOnlyBuffer().order(a.order());
 320         ByteBuffer r = fb.apply(a.limit());
 321         boolean[] mask = fm.apply(SPECIES.length());
 322         Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
 323 
 324         int l = a.limit();
 325         int s = SPECIES.length() * SPECIES.elementSize() / 8;
 326 
 327         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 328             for (int i = 0; i < l; i += s) {
 329                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
 330                 av.intoByteBuffer(r, i);
 331             }
 332         }
 333         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 334         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 335         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 336         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 337         assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
 338     }
 339 }


  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
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @modules jdk.incubator.vector
  27  * @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
  28  *      ByteMaxVectorLoadStoreTests
  29  *
  30  */
  31 
  32 import jdk.incubator.vector.VectorShape;
  33 import jdk.incubator.vector.VectorSpecies;
  34 import jdk.incubator.vector.VectorMask;
  35 import jdk.incubator.vector.Vector;
  36 
  37 import jdk.incubator.vector.ByteVector;
  38 
  39 import org.testng.Assert;
  40 import org.testng.annotations.DataProvider;
  41 import org.testng.annotations.Test;
  42 
  43 import java.lang.invoke.MethodHandles;
  44 import java.lang.invoke.VarHandle;
  45 import java.nio.ByteBuffer;
  46 import java.nio.ByteOrder;
  47 import java.util.List;
  48 import java.util.function.IntFunction;
  49 
  50 @Test
  51 public class ByteMaxVectorLoadStoreTests extends AbstractVectorTest {
  52     static final VectorSpecies<Byte> SPECIES =
  53                 ByteVector.SPECIES_MAX;
  54 
  55     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
  56 
  57     static VectorShape getMaxBit() {
  58         return VectorShape.S_Max_BIT;
  59     }
  60 
  61     static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask) {
  62         int i = 0;
  63         try {
  64             for (; i < a.length; i++) {
  65                 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i]);
  66             }
  67         } catch (AssertionError e) {
  68             Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i], "at index #" + i);
  69         }
  70     }
  71 
  72     static void assertArraysEquals(byte[] a, byte[] r, int[] im) {
  73         int i = 0;
  74         try {
  75             for (; i < a.length; i++) {
  76                 Assert.assertEquals(a[im[i]], r[i]);
  77             }
  78         } catch (AssertionError e) {


 189     @Test(dataProvider = "byteProvider")
 190     static void loadStoreArray(IntFunction<byte[]> fa) {
 191         byte[] a = fa.apply(SPECIES.length());
 192         byte[] r = new byte[a.length];
 193 
 194         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 195             for (int i = 0; i < a.length; i += SPECIES.length()) {
 196                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 197                 av.intoArray(r, i);
 198             }
 199         }
 200         Assert.assertEquals(a, r);
 201     }
 202 
 203     @Test(dataProvider = "byteMaskProvider")
 204     static void loadStoreMaskArray(IntFunction<byte[]> fa,
 205                                    IntFunction<boolean[]> fm) {
 206         byte[] a = fa.apply(SPECIES.length());
 207         byte[] r = new byte[a.length];
 208         boolean[] mask = fm.apply(SPECIES.length());
 209         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 210 
 211         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 212             for (int i = 0; i < a.length; i += SPECIES.length()) {
 213                 ByteVector av = ByteVector.fromArray(SPECIES, a, i, vmask);
 214                 av.intoArray(r, i);
 215             }
 216         }
 217         assertArraysEquals(a, r, mask);
 218 
 219         r = new byte[a.length];
 220         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 221             for (int i = 0; i < a.length; i += SPECIES.length()) {
 222                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
 223                 av.intoArray(r, i, vmask);
 224             }
 225         }
 226 
 227         assertArraysEquals(a, r, mask);
 228     }
 229 


 263         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 264             for (int i = 0; i < l; i += s) {
 265                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
 266                 av.intoByteBuffer(r, i);
 267             }
 268         }
 269         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 270         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 271         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 272         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 273         Assert.assertEquals(a, r, "Buffers not equal");
 274     }
 275 
 276     @Test(dataProvider = "byteByteBufferMaskProvider")
 277     static void loadStoreByteBufferMask(IntFunction<byte[]> fa,
 278                                         IntFunction<ByteBuffer> fb,
 279                                         IntFunction<boolean[]> fm) {
 280         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
 281         ByteBuffer r = fb.apply(a.limit());
 282         boolean[] mask = fm.apply(SPECIES.length());
 283         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 284 
 285         int l = a.limit();
 286         int s = SPECIES.length() * SPECIES.elementSize() / 8;
 287 
 288         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 289             for (int i = 0; i < l; i += s) {
 290                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
 291                 av.intoByteBuffer(r, i);
 292             }
 293         }
 294         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 295         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 296         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 297         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 298         assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
 299 
 300         a = toBuffer(fa.apply(SPECIES.length()), fb);
 301         r = fb.apply(a.limit());
 302         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 303             for (int i = 0; i < l; i += s) {
 304                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
 305                 av.intoByteBuffer(r, i, vmask);
 306             }
 307         }
 308         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 309         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 310         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 311         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 312         assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
 313     }
 314 
 315     @Test(dataProvider = "byteByteBufferMaskProvider")
 316     static void loadReadOnlyStoreByteBufferMask(IntFunction<byte[]> fa,
 317                                                 IntFunction<ByteBuffer> fb,
 318                                                 IntFunction<boolean[]> fm) {
 319         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
 320         a = a.asReadOnlyBuffer().order(a.order());
 321         ByteBuffer r = fb.apply(a.limit());
 322         boolean[] mask = fm.apply(SPECIES.length());
 323         VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
 324 
 325         int l = a.limit();
 326         int s = SPECIES.length() * SPECIES.elementSize() / 8;
 327 
 328         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 329             for (int i = 0; i < l; i += s) {
 330                 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
 331                 av.intoByteBuffer(r, i);
 332             }
 333         }
 334         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
 335         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
 336         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
 337         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
 338         assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
 339     }
 340 }
< prev index next >