< prev index next >

test/jdk/jdk/incubator/vector/Double128VectorLoadStoreTests.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2018, 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.
--- 1,7 ---
  /*
!  * Copyright (c) 2018, 2022, 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.

*** 28,23 ***
   *
   */
  
  // -- This file was mechanically generated: Do not edit! -- //
  
  import jdk.incubator.vector.DoubleVector;
  import jdk.incubator.vector.VectorMask;
  import jdk.incubator.vector.VectorSpecies;
  import jdk.incubator.vector.VectorShuffle;
  import jdk.internal.vm.annotation.DontInline;
  import org.testng.Assert;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;
  
- import java.nio.ByteBuffer;
- import java.nio.DoubleBuffer;
  import java.nio.ByteOrder;
- import java.nio.ReadOnlyBufferException;
  import java.util.List;
  import java.util.function.*;
  
  @Test
  public class Double128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {
--- 28,23 ---
   *
   */
  
  // -- This file was mechanically generated: Do not edit! -- //
  
+ import jdk.incubator.foreign.MemorySegment;
+ import jdk.incubator.foreign.ResourceScope;
+ import jdk.incubator.foreign.ValueLayout;
  import jdk.incubator.vector.DoubleVector;
  import jdk.incubator.vector.VectorMask;
  import jdk.incubator.vector.VectorSpecies;
  import jdk.incubator.vector.VectorShuffle;
  import jdk.internal.vm.annotation.DontInline;
  import org.testng.Assert;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;
  
  import java.nio.ByteOrder;
  import java.util.List;
  import java.util.function.*;
  
  @Test
  public class Double128VectorLoadStoreTests extends AbstractVectorLoadStoreTest {

*** 65,21 ***
          } catch (AssertionError e) {
              Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? a[i] : (double) 0, "at index #" + i);
          }
      }
  
-     static void assertArraysEquals(byte[] r, byte[] a, boolean[] mask) {
-         int i = 0;
-         try {
-             for (; i < a.length; i++) {
-                 Assert.assertEquals(r[i], mask[(i*8/SPECIES.elementSize()) % SPECIES.length()] ? a[i] : (byte) 0);
-             }
-         } catch (AssertionError e) {
-             Assert.assertEquals(r[i], mask[(i*8/SPECIES.elementSize()) % SPECIES.length()] ? a[i] : (byte) 0, "at index #" + i);
-         }
-     }
- 
      static final List<IntFunction<double[]>> DOUBLE_GENERATORS = List.of(
              withToString("double[i * 5]", (int s) -> {
                  return fill(s * BUFFER_REPS,
                              i -> (double)(i * 5));
              }),
--- 65,10 ---

*** 115,11 ***
              withToString("l + speciesl + 1", (int l) -> {
                  return l + SPECIES.length() + 1;
              })
      );
  
!     // Relative to byte[] array.length or ByteBuffer.limit()
      static final List<IntFunction<Integer>> BYTE_INDEX_GENERATORS = List.of(
              withToString("-1", (int l) -> {
                  return -1;
              }),
              withToString("l", (int l) -> {
--- 104,11 ---
              withToString("l + speciesl + 1", (int l) -> {
                  return l + SPECIES.length() + 1;
              })
      );
  
!     // Relative to byte[] array.length or MemorySegment.byteSize()
      static final List<IntFunction<Integer>> BYTE_INDEX_GENERATORS = List.of(
              withToString("-1", (int l) -> {
                  return -1;
              }),
              withToString("l", (int l) -> {

*** 186,49 ***
                  })).
                  toArray(Object[][]::new);
      }
  
      @DataProvider
!     public Object[][] doubleByteBufferProvider() {
          return DOUBLE_GENERATORS.stream().
!                 flatMap(fa -> BYTE_BUFFER_GENERATORS.stream().
                          flatMap(fb -> BYTE_ORDER_VALUES.stream().map(bo -> {
                              return new Object[]{fa, fb, bo};
                          }))).
                  toArray(Object[][]::new);
      }
  
      @DataProvider
!     public Object[][] doubleByteBufferMaskProvider() {
          return BOOLEAN_MASK_GENERATORS.stream().
                  flatMap(fm -> DOUBLE_GENERATORS.stream().
!                         flatMap(fa -> BYTE_BUFFER_GENERATORS.stream().
                                  flatMap(fb -> BYTE_ORDER_VALUES.stream().map(bo -> {
                              return new Object[]{fa, fb, fm, bo};
                          })))).
                  toArray(Object[][]::new);
      }
  
-     @DataProvider
-     public Object[][] doubleByteArrayProvider() {
-         return DOUBLE_GENERATORS.stream().
-                 flatMap(fa -> BYTE_ORDER_VALUES.stream().map(bo -> {
-                     return new Object[]{fa, bo};
-                 })).
-                 toArray(Object[][]::new);
-     }
- 
-     @DataProvider
-     public Object[][] doubleByteArrayMaskProvider() {
-         return BOOLEAN_MASK_GENERATORS.stream().
-                 flatMap(fm -> DOUBLE_GENERATORS.stream().
-                     flatMap(fa -> BYTE_ORDER_VALUES.stream().map(bo -> {
-                         return new Object[]{fa, fm, bo};
-                     }))).
-                 toArray(Object[][]::new);
-     }
- 
      @DataProvider
      public Object[][] doubleByteProviderForIOOBE() {
          var f = DOUBLE_GENERATORS.get(0);
          return BYTE_INDEX_GENERATORS.stream().map(fi -> {
                      return new Object[] {f, fi};
--- 175,30 ---
                  })).
                  toArray(Object[][]::new);
      }
  
      @DataProvider
!     public Object[][] doubleMemorySegmentProvider() {
          return DOUBLE_GENERATORS.stream().
!                 flatMap(fa -> MEMORY_SEGMENT_GENERATORS.stream().
                          flatMap(fb -> BYTE_ORDER_VALUES.stream().map(bo -> {
                              return new Object[]{fa, fb, bo};
                          }))).
                  toArray(Object[][]::new);
      }
  
      @DataProvider
!     public Object[][] doubleMemorySegmentMaskProvider() {
          return BOOLEAN_MASK_GENERATORS.stream().
                  flatMap(fm -> DOUBLE_GENERATORS.stream().
!                         flatMap(fa -> MEMORY_SEGMENT_GENERATORS.stream().
                                  flatMap(fb -> BYTE_ORDER_VALUES.stream().map(bo -> {
                              return new Object[]{fa, fb, fm, bo};
                          })))).
                  toArray(Object[][]::new);
      }
  
      @DataProvider
      public Object[][] doubleByteProviderForIOOBE() {
          var f = DOUBLE_GENERATORS.get(0);
          return BYTE_INDEX_GENERATORS.stream().map(fi -> {
                      return new Object[] {f, fi};

*** 244,32 ***
                      return new Object[] {f, fi, fm};
                  })).
                  toArray(Object[][]::new);
      }
  
!     static ByteBuffer toBuffer(double[] a, IntFunction<ByteBuffer> fb) {
!         ByteBuffer bb = fb.apply(a.length * SPECIES.elementSize() / 8);
!         for (double v : a) {
!             bb.putDouble(v);
          }
!         return bb.clear();
      }
  
!     static double[] bufferToArray(ByteBuffer bb) {
!         DoubleBuffer db = bb.asDoubleBuffer();
-         double[] d = new double[db.capacity()];
-         db.get(0, d);
-         return d;
-     }
- 
-     static byte[] toByteArray(double[] a, IntFunction<byte[]> fb, ByteOrder bo) {
-         byte[] b = fb.apply(a.length * SPECIES.elementSize() / 8);
-         DoubleBuffer bb = ByteBuffer.wrap(b, 0, b.length).order(bo).asDoubleBuffer();
-         for (double v : a) {
-             bb.put(v);
-         }
-         return b;
      }
  
  
      interface ToDoubleF {
          double apply(int i);
--- 214,20 ---
                      return new Object[] {f, fi, fm};
                  })).
                  toArray(Object[][]::new);
      }
  
!     static MemorySegment toSegment(double[] a, IntFunction<MemorySegment> fb) {
!         MemorySegment ms = fb.apply(a.length * SPECIES.elementSize() / 8);
!         for (int i = 0; i < a.length; i++) {
!             ms.set(ValueLayout.JAVA_DOUBLE, i * SPECIES.elementSize() / 8 , a[i]);
          }
!         return ms;
      }
  
!     static double[] segmentToArray(MemorySegment ms) {
!         return ms.toArray(ValueLayout.JAVA_DOUBLE);
      }
  
  
      interface ToDoubleF {
          double apply(int i);

*** 305,50 ***
      static void intoArray(DoubleVector v, double[] a, int i, VectorMask<Double> m) {
          v.intoArray(a, i, m);
      }
  
      @DontInline
!     static DoubleVector fromByteArray(byte[] a, int i, ByteOrder bo) {
!         return DoubleVector.fromByteArray(SPECIES, a, i, bo);
-     }
- 
-     @DontInline
-     static DoubleVector fromByteArray(byte[] a, int i, ByteOrder bo, VectorMask<Double> m) {
-         return DoubleVector.fromByteArray(SPECIES, a, i, bo, m);
-     }
- 
-     @DontInline
-     static void intoByteArray(DoubleVector v, byte[] a, int i, ByteOrder bo) {
-         v.intoByteArray(a, i, bo);
-     }
- 
-     @DontInline
-     static void intoByteArray(DoubleVector v, byte[] a, int i, ByteOrder bo, VectorMask<Double> m) {
-         v.intoByteArray(a, i, bo, m);
-     }
- 
-     @DontInline
-     static DoubleVector fromByteBuffer(ByteBuffer a, int i, ByteOrder bo) {
-         return DoubleVector.fromByteBuffer(SPECIES, a, i, bo);
      }
  
      @DontInline
!     static DoubleVector fromByteBuffer(ByteBuffer a, int i, ByteOrder bo, VectorMask<Double> m) {
!         return DoubleVector.fromByteBuffer(SPECIES, a, i, bo, m);
      }
  
      @DontInline
!     static void intoByteBuffer(DoubleVector v, ByteBuffer a, int i, ByteOrder bo) {
!         v.intoByteBuffer(a, i, bo);
      }
  
      @DontInline
!     static void intoByteBuffer(DoubleVector v, ByteBuffer a, int i, ByteOrder bo, VectorMask<Double> m) {
!         v.intoByteBuffer(a, i, bo, m);
      }
  
- 
      @Test(dataProvider = "doubleProvider")
      static void loadStoreArray(IntFunction<double[]> fa) {
          double[] a = fa.apply(SPECIES.length());
          double[] r = new double[a.length];
  
--- 263,29 ---
      static void intoArray(DoubleVector v, double[] a, int i, VectorMask<Double> m) {
          v.intoArray(a, i, m);
      }
  
      @DontInline
!     static DoubleVector fromMemorySegment(MemorySegment a, int i, ByteOrder bo) {
!         return DoubleVector.fromMemorySegment(SPECIES, a, i, bo);
      }
  
      @DontInline
!     static DoubleVector fromMemorySegment(MemorySegment a, int i, ByteOrder bo, VectorMask<Double> m) {
!         return DoubleVector.fromMemorySegment(SPECIES, a, i, bo, m);
      }
  
      @DontInline
!     static void intoMemorySegment(DoubleVector v, MemorySegment a, int i, ByteOrder bo) {
!         v.intoMemorySegment(a, i, bo);
      }
  
      @DontInline
!     static void intoMemorySegment(DoubleVector v, MemorySegment a, int i, ByteOrder bo, VectorMask<Double> m) {
!         v.intoMemorySegment(a, i, bo, m);
      }
  
      @Test(dataProvider = "doubleProvider")
      static void loadStoreArray(IntFunction<double[]> fa) {
          double[] a = fa.apply(SPECIES.length());
          double[] r = new double[a.length];
  

*** 515,52 ***
          }
          Assert.assertEquals(r, mask);
      }
  
  
!     @Test(dataProvider = "doubleByteBufferProvider")
!     static void loadStoreByteBuffer(IntFunction<double[]> fa,
!                                     IntFunction<ByteBuffer> fb,
!                                     ByteOrder bo) {
!         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
!         ByteBuffer r = fb.apply(a.limit());
  
!         int l = a.limit();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromByteBuffer(SPECIES, a, i, bo);
!                 av.intoByteBuffer(r, i, bo);
              }
          }
!         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
!         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
-         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
-         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
-         Assert.assertEquals(r, a, "Buffers not equal");
      }
  
      @Test(dataProvider = "doubleByteProviderForIOOBE")
!     static void loadByteBufferIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi) {
!         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), ByteBuffer::allocateDirect);
!         ByteBuffer r = ByteBuffer.allocateDirect(a.limit());
  
!         int l = a.limit();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = fromByteBuffer(a, i, ByteOrder.nativeOrder());
!                 av.intoByteBuffer(r, i, ByteOrder.nativeOrder());
              }
          }
  
!         int index = fi.apply(a.limit());
!         boolean shouldFail = isIndexOutOfBounds(SPECIES.vectorByteSize(), index, a.limit());
          try {
!             fromByteBuffer(a, index, ByteOrder.nativeOrder());
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {
--- 452,49 ---
          }
          Assert.assertEquals(r, mask);
      }
  
  
!     @Test(dataProvider = "doubleMemorySegmentProvider")
!     static void loadStoreMemorySegment(IntFunction<double[]> fa,
!                                        IntFunction<MemorySegment> fb,
!                                        ByteOrder bo) {
!         MemorySegment a = toSegment(fa.apply(SPECIES.length()), fb);
!         MemorySegment r = fb.apply((int) a.byteSize());
  
!         int l = (int) a.byteSize();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromMemorySegment(SPECIES, a, i, bo);
!                 av.intoMemorySegment(r, i, bo);
              }
          }
!         long m = r.mismatch(a);
!         Assert.assertEquals(m, -1, "Segments not equal");
      }
  
      @Test(dataProvider = "doubleByteProviderForIOOBE")
!     static void loadMemorySegmentIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi) {
!         MemorySegment a = toSegment(fa.apply(SPECIES.length()), i -> MemorySegment.allocateNative(i, ResourceScope.newImplicitScope()));
!         MemorySegment r = MemorySegment.allocateNative(a.byteSize(), ResourceScope.newImplicitScope());
  
!         int l = (int) a.byteSize();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = fromMemorySegment(a, i, ByteOrder.nativeOrder());
!                 av.intoMemorySegment(r, i, ByteOrder.nativeOrder());
              }
          }
  
!         int index = fi.apply((int) a.byteSize());
!         boolean shouldFail = isIndexOutOfBounds(SPECIES.vectorByteSize(), index, (int) a.byteSize());
          try {
!             fromMemorySegment(a, index, ByteOrder.nativeOrder());
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {

*** 568,103 ***
              }
          }
      }
  
      @Test(dataProvider = "doubleByteProviderForIOOBE")
!     static void storeByteBufferIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi) {
!         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), ByteBuffer::allocateDirect);
!         ByteBuffer r = ByteBuffer.allocateDirect(a.limit());
  
!         int l = a.limit();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromByteBuffer(SPECIES, a, i, ByteOrder.nativeOrder());
!                 intoByteBuffer(av, r, i, ByteOrder.nativeOrder());
              }
          }
  
!         int index = fi.apply(a.limit());
!         boolean shouldFail = isIndexOutOfBounds(SPECIES.vectorByteSize(), index, a.limit());
          try {
!             DoubleVector av = DoubleVector.fromByteBuffer(SPECIES, a, 0, ByteOrder.nativeOrder());
!             intoByteBuffer(av, r, index, ByteOrder.nativeOrder());
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {
                  Assert.fail("Unexpected IndexOutOfBoundsException");
              }
          }
      }
  
! 
!     @Test(dataProvider = "doubleByteBufferMaskProvider")
!     static void loadStoreByteBufferMask(IntFunction<double[]> fa,
!                                         IntFunction<ByteBuffer> fb,
!                                         IntFunction<boolean[]> fm,
-                                         ByteOrder bo) {
          double[] _a = fa.apply(SPECIES.length());
!         ByteBuffer a = toBuffer(_a, fb);
!         ByteBuffer r = fb.apply(a.limit());
          boolean[] mask = fm.apply(SPECIES.length());
          VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
  
!         int l = a.limit();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromByteBuffer(SPECIES, a, i, bo, vmask);
!                 av.intoByteBuffer(r, i, bo);
              }
          }
!         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
-         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
-         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
-         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
-         assertArraysEquals(bufferToArray(r), _a, mask);
  
  
!         r = fb.apply(a.limit());
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromByteBuffer(SPECIES, a, i, bo);
!                 av.intoByteBuffer(r, i, bo, vmask);
              }
          }
!         Assert.assertEquals(a.position(), 0, "Input buffer position changed");
-         Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
-         Assert.assertEquals(r.position(), 0, "Result buffer position changed");
-         Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
-         assertArraysEquals(bufferToArray(r), _a, mask);
      }
  
      @Test(dataProvider = "doubleByteMaskProviderForIOOBE")
!     static void loadByteBufferMaskIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi, IntFunction<boolean[]> fm) {
!         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), ByteBuffer::allocateDirect);
!         ByteBuffer r = ByteBuffer.allocateDirect(a.limit());
          boolean[] mask = fm.apply(SPECIES.length());
          VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
  
!         int l = a.limit();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = fromByteBuffer(a, i, ByteOrder.nativeOrder(), vmask);
!                 av.intoByteBuffer(r, i, ByteOrder.nativeOrder());
              }
          }
  
!         int index = fi.apply(a.limit());
!         boolean shouldFail = isIndexOutOfBoundsForMask(mask, index, a.limit(), SPECIES.elementSize() / 8);
          try {
!             fromByteBuffer(a, index, ByteOrder.nativeOrder(), vmask);
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {
--- 502,94 ---
              }
          }
      }
  
      @Test(dataProvider = "doubleByteProviderForIOOBE")
!     static void storeMemorySegmentIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi) {
!         MemorySegment a = toSegment(fa.apply(SPECIES.length()), i -> MemorySegment.allocateNative(i, ResourceScope.newImplicitScope()));
!         MemorySegment r = MemorySegment.allocateNative(a.byteSize(), ResourceScope.newImplicitScope());
  
!         int l = (int) a.byteSize();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromMemorySegment(SPECIES, a, i, ByteOrder.nativeOrder());
!                 intoMemorySegment(av, r, i, ByteOrder.nativeOrder());
              }
          }
  
!         int index = fi.apply((int) a.byteSize());
!         boolean shouldFail = isIndexOutOfBounds(SPECIES.vectorByteSize(), index, (int) a.byteSize());
          try {
!             DoubleVector av = DoubleVector.fromMemorySegment(SPECIES, a, 0, ByteOrder.nativeOrder());
!             intoMemorySegment(av, r, index, ByteOrder.nativeOrder());
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {
                  Assert.fail("Unexpected IndexOutOfBoundsException");
              }
          }
      }
  
!     @Test(dataProvider = "doubleMemorySegmentMaskProvider")
!     static void loadStoreMemorySegmentMask(IntFunction<double[]> fa,
!                                            IntFunction<MemorySegment> fb,
!                                            IntFunction<boolean[]> fm,
!                                            ByteOrder bo) {
          double[] _a = fa.apply(SPECIES.length());
!         MemorySegment a = toSegment(_a, fb);
!         MemorySegment r = fb.apply((int) a.byteSize());
          boolean[] mask = fm.apply(SPECIES.length());
          VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
  
!         int l = (int) a.byteSize();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromMemorySegment(SPECIES, a, i, bo, vmask);
!                 av.intoMemorySegment(r, i, bo);
              }
          }
!         assertArraysEquals(segmentToArray(r), _a, mask);
  
  
!         r = fb.apply((int) a.byteSize());
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromMemorySegment(SPECIES, a, i, bo);
!                 av.intoMemorySegment(r, i, bo, vmask);
              }
          }
!         assertArraysEquals(segmentToArray(r), _a, mask);
      }
  
      @Test(dataProvider = "doubleByteMaskProviderForIOOBE")
!     static void loadMemorySegmentMaskIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi, IntFunction<boolean[]> fm) {
!         MemorySegment a = toSegment(fa.apply(SPECIES.length()), i -> MemorySegment.allocateNative(i, ResourceScope.newImplicitScope()));
!         MemorySegment r = MemorySegment.allocateNative(a.byteSize(), ResourceScope.newImplicitScope());
          boolean[] mask = fm.apply(SPECIES.length());
          VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
  
!         int l = (int) a.byteSize();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = fromMemorySegment(a, i, ByteOrder.nativeOrder(), vmask);
!                 av.intoMemorySegment(r, i, ByteOrder.nativeOrder());
              }
          }
  
!         int index = fi.apply((int) a.byteSize());
!         boolean shouldFail = isIndexOutOfBoundsForMask(mask, index, (int) a.byteSize(), SPECIES.elementSize() / 8);
          try {
!             fromMemorySegment(a, index, ByteOrder.nativeOrder(), vmask);
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {

*** 672,248 ***
              }
          }
      }
  
      @Test(dataProvider = "doubleByteMaskProviderForIOOBE")
!     static void storeByteBufferMaskIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi, IntFunction<boolean[]> fm) {
!         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), ByteBuffer::allocateDirect);
!         ByteBuffer r = ByteBuffer.allocateDirect(a.limit());
          boolean[] mask = fm.apply(SPECIES.length());
          VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
  
!         int l = a.limit();
-         int s = SPECIES.vectorByteSize();
- 
-         for (int ic = 0; ic < INVOC_COUNT; ic++) {
-             for (int i = 0; i < l; i += s) {
-                 DoubleVector av = DoubleVector.fromByteBuffer(SPECIES, a, i, ByteOrder.nativeOrder());
-                 intoByteBuffer(av, r, i, ByteOrder.nativeOrder(), vmask);
-             }
-         }
- 
-         int index = fi.apply(a.limit());
-         boolean shouldFail = isIndexOutOfBoundsForMask(mask, index, a.limit(), SPECIES.elementSize() / 8);
-         try {
-             DoubleVector av = DoubleVector.fromByteBuffer(SPECIES, a, 0, ByteOrder.nativeOrder());
-             intoByteBuffer(av, a, index, ByteOrder.nativeOrder(), vmask);
-             if (shouldFail) {
-                 Assert.fail("Failed to throw IndexOutOfBoundsException");
-             }
-         } catch (IndexOutOfBoundsException e) {
-             if (!shouldFail) {
-                 Assert.fail("Unexpected IndexOutOfBoundsException");
-             }
-         }
-     }
- 
- 
-     @Test(dataProvider = "doubleByteBufferProvider")
-     static void loadStoreReadonlyByteBuffer(IntFunction<double[]> fa,
-                                     IntFunction<ByteBuffer> fb,
-                                     ByteOrder bo) {
-         ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb).asReadOnlyBuffer();
- 
-         try {
-             SPECIES.zero().intoByteBuffer(a, 0, bo);
-             Assert.fail("ReadOnlyBufferException expected");
-         } catch (ReadOnlyBufferException e) {
-         }
- 
-         try {
-             SPECIES.zero().intoByteBuffer(a, 0, bo, SPECIES.maskAll(true));
-             Assert.fail("ReadOnlyBufferException expected");
-         } catch (ReadOnlyBufferException e) {
-         }
- 
-         try {
-             SPECIES.zero().intoByteBuffer(a, 0, bo, SPECIES.maskAll(false));
-             Assert.fail("ReadOnlyBufferException expected");
-         } catch (ReadOnlyBufferException e) {
-         }
- 
-         try {
-             VectorMask<Double> m = SPECIES.shuffleFromOp(i -> i % 2 == 0 ? 1 : -1)
-                     .laneIsValid();
-             SPECIES.zero().intoByteBuffer(a, 0, bo, m);
-             Assert.fail("ReadOnlyBufferException expected");
-         } catch (ReadOnlyBufferException e) {
-         }
-     }
- 
- 
-     @Test(dataProvider = "doubleByteArrayProvider")
-     static void loadStoreByteArray(IntFunction<double[]> fa,
-                                     ByteOrder bo) {
-         byte[] a = toByteArray(fa.apply(SPECIES.length()), byte[]::new, bo);
-         byte[] r = new byte[a.length];
- 
-         int s = SPECIES.vectorByteSize();
-         int l = a.length;
- 
-         for (int ic = 0; ic < INVOC_COUNT; ic++) {
-             for (int i = 0; i < l; i += s) {
-                 DoubleVector av = DoubleVector.fromByteArray(SPECIES, a, i, bo);
-                 av.intoByteArray(r, i, bo);
-             }
-         }
-         Assert.assertEquals(r, a, "Byte arrays not equal");
-     }
- 
-     @Test(dataProvider = "doubleByteProviderForIOOBE")
-     static void loadByteArrayIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi) {
-         byte[] a = toByteArray(fa.apply(SPECIES.length()), byte[]::new, ByteOrder.nativeOrder());
-         byte[] r = new byte[a.length];
- 
          int s = SPECIES.vectorByteSize();
-         int l = a.length;
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = fromByteArray(a, i, ByteOrder.nativeOrder());
!                 av.intoByteArray(r, i, ByteOrder.nativeOrder());
              }
          }
  
!         int index = fi.apply(a.length);
!         boolean shouldFail = isIndexOutOfBounds(SPECIES.vectorByteSize(), index, a.length);
          try {
!             fromByteArray(a, index, ByteOrder.nativeOrder());
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {
                  Assert.fail("Unexpected IndexOutOfBoundsException");
              }
          }
      }
  
!     @Test(dataProvider = "doubleByteProviderForIOOBE")
!     static void storeByteArrayIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi) {
!         byte[] a = toByteArray(fa.apply(SPECIES.length()), byte[]::new, ByteOrder.nativeOrder());
!         byte[] r = new byte[a.length];
! 
-         int s = SPECIES.vectorByteSize();
-         int l = a.length;
- 
-         for (int ic = 0; ic < INVOC_COUNT; ic++) {
-             for (int i = 0; i < l; i += s) {
-                 DoubleVector av = DoubleVector.fromByteArray(SPECIES, a, i, ByteOrder.nativeOrder());
-                 intoByteArray(av, r, i, ByteOrder.nativeOrder());
-             }
-         }
- 
-         int index = fi.apply(a.length);
-         boolean shouldFail = isIndexOutOfBounds(SPECIES.vectorByteSize(), index, a.length);
-         try {
-             DoubleVector av = DoubleVector.fromByteArray(SPECIES, a, 0, ByteOrder.nativeOrder());
-             intoByteArray(av, r, index, ByteOrder.nativeOrder());
-             if (shouldFail) {
-                 Assert.fail("Failed to throw IndexOutOfBoundsException");
-             }
-         } catch (IndexOutOfBoundsException e) {
-             if (!shouldFail) {
-                 Assert.fail("Unexpected IndexOutOfBoundsException");
-             }
-         }
-     }
- 
- 
-     @Test(dataProvider = "doubleByteArrayMaskProvider")
-     static void loadStoreByteArrayMask(IntFunction<double[]> fa,
-                                   IntFunction<boolean[]> fm,
-                                   ByteOrder bo) {
-         byte[] a = toByteArray(fa.apply(SPECIES.length()), byte[]::new, bo);
-         byte[] r = new byte[a.length];
-         boolean[] mask = fm.apply(SPECIES.length());
-         VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
- 
-         int s = SPECIES.vectorByteSize();
-         int l = a.length;
- 
-         for (int ic = 0; ic < INVOC_COUNT; ic++) {
-           for (int i = 0; i < l; i += s) {
-               DoubleVector av = DoubleVector.fromByteArray(SPECIES, a, i, bo, vmask);
-               av.intoByteArray(r, i, bo);
-           }
-         }
-         assertArraysEquals(r, a, mask);
- 
- 
-         r = new byte[a.length];
- 
-         for (int ic = 0; ic < INVOC_COUNT; ic++) {
-             for (int i = 0; i < l; i += s) {
-                 DoubleVector av = DoubleVector.fromByteArray(SPECIES, a, i, bo);
-                 av.intoByteArray(r, i, bo, vmask);
-             }
-         }
-         assertArraysEquals(r, a, mask);
-     }
  
!     @Test(dataProvider = "doubleByteMaskProviderForIOOBE")
!     static void loadByteArrayMaskIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi, IntFunction<boolean[]> fm) {
!         byte[] a = toByteArray(fa.apply(SPECIES.length()), byte[]::new, ByteOrder.nativeOrder());
!         byte[] r = new byte[a.length];
-         boolean[] mask = fm.apply(SPECIES.length());
-         VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
  
!         int s = SPECIES.vectorByteSize();
!         int l = a.length;
  
!         for (int ic = 0; ic < INVOC_COUNT; ic++) {
!             for (int i = 0; i < l; i += s) {
!                 DoubleVector av = fromByteArray(a, i, ByteOrder.nativeOrder(), vmask);
!                 av.intoByteArray(r, i, ByteOrder.nativeOrder());
-             }
-         }
  
!         int index = fi.apply(a.length);
!         boolean shouldFail = isIndexOutOfBoundsForMask(mask, index, a.length, SPECIES.elementSize() / 8);
!         try {
!             fromByteArray(a, index, ByteOrder.nativeOrder(), vmask);
!             if (shouldFail) {
!                 Assert.fail("Failed to throw IndexOutOfBoundsException");
-             }
-         } catch (IndexOutOfBoundsException e) {
-             if (!shouldFail) {
-                 Assert.fail("Unexpected IndexOutOfBoundsException");
-             }
-         }
      }
  
-     @Test(dataProvider = "doubleByteMaskProviderForIOOBE")
-     static void storeByteArrayMaskIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi, IntFunction<boolean[]> fm) {
-         byte[] a = toByteArray(fa.apply(SPECIES.length()), byte[]::new, ByteOrder.nativeOrder());
-         byte[] r = new byte[a.length];
-         boolean[] mask = fm.apply(SPECIES.length());
-         VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
- 
-         int s = SPECIES.vectorByteSize();
-         int l = a.length;
- 
-         for (int ic = 0; ic < INVOC_COUNT; ic++) {
-             for (int i = 0; i < l; i += s) {
-                 DoubleVector av = DoubleVector.fromByteArray(SPECIES, a, i, ByteOrder.nativeOrder());
-                 intoByteArray(av, r, i, ByteOrder.nativeOrder(), vmask);
-             }
-         }
- 
-         int index = fi.apply(a.length);
-         boolean shouldFail = isIndexOutOfBoundsForMask(mask, index, a.length, SPECIES.elementSize() / 8);
-         try {
-             DoubleVector av = DoubleVector.fromByteArray(SPECIES, a, 0, ByteOrder.nativeOrder());
-             intoByteArray(av, a, index, ByteOrder.nativeOrder(), vmask);
-             if (shouldFail) {
-                 Assert.fail("Failed to throw IndexOutOfBoundsException");
-             }
-         } catch (IndexOutOfBoundsException e) {
-             if (!shouldFail) {
-                 Assert.fail("Unexpected IndexOutOfBoundsException");
-             }
-         }
-     }
  
      @Test(dataProvider = "maskProvider")
      static void loadStoreMask(IntFunction<boolean[]> fm) {
          boolean[] a = fm.apply(SPECIES.length());
          boolean[] r = new boolean[a.length];
--- 597,70 ---
              }
          }
      }
  
      @Test(dataProvider = "doubleByteMaskProviderForIOOBE")
!     static void storeMemorySegmentMaskIOOBE(IntFunction<double[]> fa, IntFunction<Integer> fi, IntFunction<boolean[]> fm) {
!         MemorySegment a = toSegment(fa.apply(SPECIES.length()), i -> MemorySegment.allocateNative(i, ResourceScope.newImplicitScope()));
!         MemorySegment r = MemorySegment.allocateNative(a.byteSize(), ResourceScope.newImplicitScope());
          boolean[] mask = fm.apply(SPECIES.length());
          VectorMask<Double> vmask = VectorMask.fromValues(SPECIES, mask);
  
!         int l = (int) a.byteSize();
          int s = SPECIES.vectorByteSize();
  
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              for (int i = 0; i < l; i += s) {
!                 DoubleVector av = DoubleVector.fromMemorySegment(SPECIES, a, i, ByteOrder.nativeOrder());
!                 intoMemorySegment(av, r, i, ByteOrder.nativeOrder(), vmask);
              }
          }
  
!         int index = fi.apply((int) a.byteSize());
!         boolean shouldFail = isIndexOutOfBoundsForMask(mask, index, (int) a.byteSize(), SPECIES.elementSize() / 8);
          try {
!             DoubleVector av = DoubleVector.fromMemorySegment(SPECIES, a, 0, ByteOrder.nativeOrder());
+             intoMemorySegment(av, a, index, ByteOrder.nativeOrder(), vmask);
              if (shouldFail) {
                  Assert.fail("Failed to throw IndexOutOfBoundsException");
              }
          } catch (IndexOutOfBoundsException e) {
              if (!shouldFail) {
                  Assert.fail("Unexpected IndexOutOfBoundsException");
              }
          }
      }
  
!     @Test(dataProvider = "doubleMemorySegmentProvider")
!     static void loadStoreReadonlyMemorySegment(IntFunction<double[]> fa,
!                                                IntFunction<MemorySegment> fb,
!                                                ByteOrder bo) {
!         MemorySegment a = toSegment(fa.apply(SPECIES.length()), fb).asReadOnly();
  
!         Assert.assertThrows(
!                 UnsupportedOperationException.class,
!                 () -> SPECIES.zero().intoMemorySegment(a, 0, bo)
!         );
  
!         Assert.assertThrows(
!                 UnsupportedOperationException.class,
+                 () -> SPECIES.zero().intoMemorySegment(a, 0, bo, SPECIES.maskAll(true))
+         );
  
!         Assert.assertThrows(
!                 UnsupportedOperationException.class,
!                 () -> SPECIES.zero().intoMemorySegment(a, 0, bo, SPECIES.maskAll(false))
!         );
  
!         VectorMask<Double> m = SPECIES.shuffleFromOp(i -> i % 2 == 0 ? 1 : -1)
!                 .laneIsValid();
!         Assert.assertThrows(
!                 UnsupportedOperationException.class,
!                 () -> SPECIES.zero().intoMemorySegment(a, 0, bo, m)
!         );
      }
  
  
      @Test(dataProvider = "maskProvider")
      static void loadStoreMask(IntFunction<boolean[]> fm) {
          boolean[] a = fm.apply(SPECIES.length());
          boolean[] r = new boolean[a.length];

*** 925,10 ***
--- 672,11 ---
              }
          }
          Assert.assertEquals(r, a);
      }
  
+ 
      @Test
      static void loadStoreShuffle() {
          IntUnaryOperator fn = a -> a + 5;
          for (int ic = 0; ic < INVOC_COUNT; ic++) {
              var shuffle = VectorShuffle.fromOp(SPECIES, fn);
< prev index next >