< prev index next >

test/hotspot/jtreg/compiler/vectorapi/reshape/utils/VectorReshapeHelper.java

Print this page
*** 33,10 ***
--- 33,11 ---
  import java.nio.ByteOrder;
  import java.util.List;
  import java.util.random.RandomGenerator;
  import java.util.stream.Collectors;
  import java.util.stream.Stream;
+ import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.vector.*;
  import jdk.test.lib.Asserts;
  import jdk.test.lib.Utils;
  
  public class VectorReshapeHelper {

*** 211,59 ***
              }
          }
      }
  
      @ForceInline
!     public static void vectorExpandShrink(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp, byte[] input, byte[] output) {
!         isp.fromByteArray(input, 0, ByteOrder.nativeOrder())
                  .reinterpretShape(osp, 0)
!                 .intoByteArray(output, 0, ByteOrder.nativeOrder());
      }
  
      public static void runExpandShrinkHelper(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp) throws Throwable {
          var random = Utils.getRandomInstance();
          String testMethodName = VectorSpeciesPair.makePair(isp, osp).format();
          var caller = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass();
          var testMethod = MethodHandles.lookup().findStatic(caller,
                  testMethodName,
!                 MethodType.methodType(void.class, byte.class.arrayType(), byte.class.arrayType()));
          byte[] input = new byte[isp.vectorByteSize()];
          byte[] output = new byte[osp.vectorByteSize()];
          for (int iter = 0; iter < INVOCATIONS; iter++) {
              random.nextBytes(input);
  
!             testMethod.invokeExact(input, output);
  
              for (int i = 0; i < osp.vectorByteSize(); i++) {
                  int expected = i < isp.vectorByteSize() ? input[i] : 0;
                  int actual = output[i];
                  Asserts.assertEquals(expected, actual);
              }
          }
      }
  
      @ForceInline
!     public static void vectorDoubleExpandShrink(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp, byte[] input, byte[] output) {
!         isp.fromByteArray(input, 0, ByteOrder.nativeOrder())
                  .reinterpretShape(osp, 0)
                  .reinterpretShape(isp, 0)
!                 .intoByteArray(output, 0, ByteOrder.nativeOrder());
      }
  
      public static void runDoubleExpandShrinkHelper(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp) throws Throwable {
          var random = Utils.getRandomInstance();
          String testMethodName = VectorSpeciesPair.makePair(isp, osp).format();
          var caller = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass();
          var testMethod = MethodHandles.lookup().findStatic(caller,
                  testMethodName,
!                 MethodType.methodType(void.class, byte.class.arrayType(), byte.class.arrayType()));
          byte[] input = new byte[isp.vectorByteSize()];
          byte[] output = new byte[isp.vectorByteSize()];
          for (int iter = 0; iter < INVOCATIONS; iter++) {
              random.nextBytes(input);
  
!             testMethod.invokeExact(input, output);
  
              for (int i = 0; i < isp.vectorByteSize(); i++) {
                  int expected = i < osp.vectorByteSize() ? input[i] : 0;
                  int actual = output[i];
                  Asserts.assertEquals(expected, actual);
--- 212,65 ---
              }
          }
      }
  
      @ForceInline
!     public static void vectorExpandShrink(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp,
!                                           MemorySegment input, MemorySegment output) {
+         isp.fromMemorySegment(input, 0, ByteOrder.nativeOrder())
                  .reinterpretShape(osp, 0)
!                 .intoMemorySegment(output, 0, ByteOrder.nativeOrder());
      }
  
      public static void runExpandShrinkHelper(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp) throws Throwable {
          var random = Utils.getRandomInstance();
          String testMethodName = VectorSpeciesPair.makePair(isp, osp).format();
          var caller = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass();
          var testMethod = MethodHandles.lookup().findStatic(caller,
                  testMethodName,
!                 MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class));
          byte[] input = new byte[isp.vectorByteSize()];
          byte[] output = new byte[osp.vectorByteSize()];
+         MemorySegment msInput = MemorySegment.ofArray(input);
+         MemorySegment msOutput = MemorySegment.ofArray(output);
          for (int iter = 0; iter < INVOCATIONS; iter++) {
              random.nextBytes(input);
  
!             testMethod.invokeExact(msInput, msOutput);
  
              for (int i = 0; i < osp.vectorByteSize(); i++) {
                  int expected = i < isp.vectorByteSize() ? input[i] : 0;
                  int actual = output[i];
                  Asserts.assertEquals(expected, actual);
              }
          }
      }
  
      @ForceInline
!     public static void vectorDoubleExpandShrink(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp,
!                                                 MemorySegment input, MemorySegment output) {
+         isp.fromMemorySegment(input, 0, ByteOrder.nativeOrder())
                  .reinterpretShape(osp, 0)
                  .reinterpretShape(isp, 0)
!                 .intoMemorySegment(output, 0, ByteOrder.nativeOrder());
      }
  
      public static void runDoubleExpandShrinkHelper(VectorSpecies<Byte> isp, VectorSpecies<Byte> osp) throws Throwable {
          var random = Utils.getRandomInstance();
          String testMethodName = VectorSpeciesPair.makePair(isp, osp).format();
          var caller = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass();
          var testMethod = MethodHandles.lookup().findStatic(caller,
                  testMethodName,
!                 MethodType.methodType(void.class, MemorySegment.class, MemorySegment.class));
          byte[] input = new byte[isp.vectorByteSize()];
          byte[] output = new byte[isp.vectorByteSize()];
+         MemorySegment msInput = MemorySegment.ofArray(input);
+         MemorySegment msOutput = MemorySegment.ofArray(output);
          for (int iter = 0; iter < INVOCATIONS; iter++) {
              random.nextBytes(input);
  
!             testMethod.invokeExact(msInput, msOutput);
  
              for (int i = 0; i < isp.vectorByteSize(); i++) {
                  int expected = i < osp.vectorByteSize() ? input[i] : 0;
                  int actual = output[i];
                  Asserts.assertEquals(expected, actual);
< prev index next >