< prev index next >

test/jdk/jdk/incubator/vector/templates/Unit-header.template

Print this page
*** 87,11 ***
--- 87,13 ---
      }
  
      private static final int Max = 256;  // juts so we can do N/$bits$
  #end[MaxBit]
  
+ #if[BITWISE]
      private static final $type$ CONST_SHIFT = $Boxtype$.SIZE / 2;
+ #end[BITWISE]
  
      static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / $bits$);
  
      interface FUnOp {
          $type$ apply($type$ a);

*** 290,10 ***
--- 292,59 ---
              int idx = i + j;
              Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
          }
      }
  
+     static void assertcompressArraysEquals($type$[] r, $type$[] a, boolean[] m, int vector_len) {
+         int i = 0, j = 0, k = 0;
+         try {
+             for (; i < a.length; i += vector_len) {
+                 k = 0;
+                 for (j = 0; j < vector_len; j++) {
+                     if (m[(i + j) % SPECIES.length()]) {
+                         Assert.assertEquals(r[i + k], a[i + j]);
+                         k++;
+                     }
+                 }
+                 for (; k < vector_len; k++) {
+                     Assert.assertEquals(r[i + k], ($type$)0);
+                 }
+             }
+         } catch (AssertionError e) {
+             int idx = i + k;
+             if (m[(i + j) % SPECIES.length()]) {
+                 Assert.assertEquals(r[idx], a[i + j], "at index #" + idx);
+             } else {
+                 Assert.assertEquals(r[idx], ($type$)0, "at index #" + idx);
+             }
+         }
+     }
+ 
+     static void assertexpandArraysEquals($type$[] r, $type$[] a, boolean[] m, int vector_len) {
+         int i = 0, j = 0, k = 0;
+         try {
+             for (; i < a.length; i += vector_len) {
+                 k = 0;
+                 for (j = 0; j < vector_len; j++) {
+                     if (m[(i + j) % SPECIES.length()]) {
+                         Assert.assertEquals(r[i + j], a[i + k]);
+                         k++;
+                     } else {
+                         Assert.assertEquals(r[i + j], ($type$)0);
+                     }
+                 }
+             }
+         } catch (AssertionError e) {
+             int idx = i + j;
+             if (m[idx % SPECIES.length()]) {
+                 Assert.assertEquals(r[idx], a[i + k], "at index #" + idx);
+             } else {
+                 Assert.assertEquals(r[idx], ($type$)0, "at index #" + idx);
+             }
+         }
+     }
+ 
      static void assertSelectFromArraysEquals($type$[] r, $type$[] a, $type$[] order, int vector_len) {
          int i = 0, j = 0;
          try {
              for (; i < a.length; i += vector_len) {
                  for (j = 0; j < vector_len; j++) {

*** 1063,12 ***
              }
          } catch (AssertionError e) {
              Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
          }
      }
- 
  #if[!Double]
      static void assertArraysEquals(double[] r, $type$[] a, int offs) {
          int i = 0;
          try {
              for (; i < r.length; i++) {
                  Assert.assertEquals(r[i], (double)(a[i+offs]));
--- 1114,12 ---
              }
          } catch (AssertionError e) {
              Assert.assertEquals(r[i], (long)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
          }
      }
  #if[!Double]
+ 
      static void assertArraysEquals(double[] r, $type$[] a, int offs) {
          int i = 0;
          try {
              for (; i < r.length; i++) {
                  Assert.assertEquals(r[i], (double)(a[i+offs]));

*** 1077,11 ***
              Assert.assertEquals(r[i], (double)(a[i+offs]), "at index #" + i + ", input = " + a[i+offs]);
          }
      }
  #end[!Double]
  
- 
      static $bitstype$ bits($type$ e) {
          return {#if[FP]? $Type$.$type$To$Bitstype$Bits(e): e};
      }
  
      static final List<IntFunction<$type$[]>> $TYPE$_GENERATORS = List.of(
--- 1128,10 ---

*** 1171,23 ***
                  flatMap(fm -> $TYPE$_GENERATORS.stream().map(fa -> {
                      return new Object[] {fa, fm};
                  })).
                  toArray(Object[][]::new);
      }
- 
  #if[!Int]
  #if[!byteOrShort]
      @DataProvider
      public Object[][] $type$toIntUnaryOpProvider() {
          return INT_$TYPE$_GENERATORS.stream().
                  map(f -> new Object[]{f}).
                  toArray(Object[][]::new);
      }
  #end[!byteOrShort]
  #end[!Int]
- 
  #if[FP]
      @DataProvider
      public Object[][] $type$toLongUnaryOpProvider() {
          return LONG_$TYPE$_GENERATORS.stream().
                  map(f -> new Object[]{f}).
                  toArray(Object[][]::new);
--- 1221,23 ---
                  flatMap(fm -> $TYPE$_GENERATORS.stream().map(fa -> {
                      return new Object[] {fa, fm};
                  })).
                  toArray(Object[][]::new);
      }
  #if[!Int]
  #if[!byteOrShort]
+ 
      @DataProvider
      public Object[][] $type$toIntUnaryOpProvider() {
          return INT_$TYPE$_GENERATORS.stream().
                  map(f -> new Object[]{f}).
                  toArray(Object[][]::new);
      }
  #end[!byteOrShort]
  #end[!Int]
  #if[FP]
+ 
      @DataProvider
      public Object[][] $type$toLongUnaryOpProvider() {
          return LONG_$TYPE$_GENERATORS.stream().
                  map(f -> new Object[]{f}).
                  toArray(Object[][]::new);

*** 1236,12 ***
                      flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
                          return new Object[] {fa, fs, fm};
                  }))).
                  toArray(Object[][]::new);
      }
- 
  #if[!Int]
      static final List<BiFunction<Integer,Integer,$type$[]>> $TYPE$_SHUFFLE_GENERATORS = List.of(
              withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
                  $type$[] a = new $type$[l];
  #if[ByteMax]
                  int upper = Math.min(Byte.MAX_VALUE + 1, m);
--- 1286,12 ---
                      flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
                          return new Object[] {fa, fs, fm};
                  }))).
                  toArray(Object[][]::new);
      }
  #if[!Int]
+ 
      static final List<BiFunction<Integer,Integer,$type$[]>> $TYPE$_SHUFFLE_GENERATORS = List.of(
              withToStringBi("shuffle[random]", (Integer l, Integer m) -> {
                  $type$[] a = new $type$[l];
  #if[ByteMax]
                  int upper = Math.min(Byte.MAX_VALUE + 1, m);

*** 1271,11 ***
                      flatMap(fs -> $TYPE$_GENERATORS.stream().map(fa -> {
                          return new Object[] {fa, fs, fm};
                  }))).
                  toArray(Object[][]::new);
      }
- 
  #end[!Int]
  
      static final List<IntFunction<$type$[]>> $TYPE$_COMPARE_GENERATORS = List.of(
              withToString("$type$[i]", (int s) -> {
                  return fill(s * BUFFER_REPS,
--- 1321,10 ---

*** 1403,19 ***
  
      static final IntFunction<boolean[]> fmr = (vl) -> {
          int length = BUFFER_REPS * vl;
          return new boolean[length];
      };
- 
  #if[!Long]
      static final IntFunction<long[]> lfr = (vl) -> {
          int length = BUFFER_REPS * vl;
          return new long[length];
      };
  #end[!Long]
- 
  #if[BITWISE]
      static void replaceZero($type$[] a, $type$ v) {
          for (int i = 0; i < a.length; i++) {
              if (a[i] == 0) {
                  a[i] = v;
              }
--- 1452,19 ---
  
      static final IntFunction<boolean[]> fmr = (vl) -> {
          int length = BUFFER_REPS * vl;
          return new boolean[length];
      };
  #if[!Long]
+ 
      static final IntFunction<long[]> lfr = (vl) -> {
          int length = BUFFER_REPS * vl;
          return new long[length];
      };
  #end[!Long]
  #if[BITWISE]
+ 
      static void replaceZero($type$[] a, $type$ v) {
          for (int i = 0; i < a.length; i++) {
              if (a[i] == 0) {
                  a[i] = v;
              }

*** 1449,10 ***
--- 1498,53 ---
  #if[short]
          return (short)(((((short)a) & 0xFFFF) >>> (b & 15)) | ((((short)a) & 0xFFFF) << (16 - (b & 15))));
  #else[short]
          return (byte)(((((byte)a) & 0xFF) >>> (b & 7)) | ((((byte)a) & 0xFF) << (8 - (b & 7))));
  #end[short]
+ #end[intOrLong]
+     }
+ 
+     static $type$ TRAILING_ZEROS_COUNT_scalar($type$ a) {
+ #if[intOrLong]
+         return $Wideboxtype$.numberOfTrailingZeros(a);
+ #else[intOrLong]
+ #if[short]
+         return (short) (a != 0 ? Integer.numberOfTrailingZeros(a) : 16);
+ #else[short]
+         return (byte) (a != 0 ? Integer.numberOfTrailingZeros(a) : 8);
+ #end[short]
+ #end[intOrLong]
+     }
+ 
+     static $type$ LEADING_ZEROS_COUNT_scalar($type$ a) {
+ #if[intOrLong]
+         return $Wideboxtype$.numberOfLeadingZeros(a);
+ #else[intOrLong]
+ #if[short]
+         return (short) (a >= 0 ? Integer.numberOfLeadingZeros(a) - 16 : 0);
+ #else[short]
+         return (byte) (a >= 0 ? Integer.numberOfLeadingZeros(a) - 24 : 0);
+ #end[short]
+ #end[intOrLong]
+     }
+ 
+     static $type$ REVERSE_scalar($type$ a) {
+ #if[intOrLong]
+         return $Wideboxtype$.reverse(a);
+ #else[intOrLong]
+ #if[short]
+         $type$ b = ROL_scalar(a, ($type$) 8);
+         b = (short) (((b & 0x5555) << 1) | ((b & 0xAAAA) >>> 1));
+         b = (short) (((b & 0x3333) << 2) | ((b & 0xCCCC) >>> 2));
+         b = (short) (((b & 0x0F0F) << 4) | ((b & 0xF0F0) >>> 4));
+         return b;
+ #else[short]
+         $type$ b = ($type$) ROL_scalar(a, ($type$) 4);
+         b = (byte) (((b & 0x55) << 1) | ((b & 0xAA) >>> 1));
+         b = (byte) (((b & 0x33) << 2) | ((b & 0xCC) >>> 2));
+         return b;
+ #end[short]
  #end[intOrLong]
      }
  #end[BITWISE]
  
      static boolean eq($type$ a, $type$ b) {

*** 1476,12 ***
      }
  
      static boolean ge($type$ a, $type$ b) {
          return a >= b;
      }
- 
  #if[!FP]
      static boolean ult($type$ a, $type$ b) {
          return $Boxtype$.compareUnsigned(a, b) < 0;
      }
  
      static boolean ule($type$ a, $type$ b) {
--- 1568,12 ---
      }
  
      static boolean ge($type$ a, $type$ b) {
          return a >= b;
      }
  #if[!FP]
+ 
      static boolean ult($type$ a, $type$ b) {
          return $Boxtype$.compareUnsigned(a, b) < 0;
      }
  
      static boolean ule($type$ a, $type$ b) {

*** 1591,24 ***
  #else[FP]
          Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
          Assert.assertEquals(asIntegral.species(), SPECIES);
  #end[FP]
      }
- 
  #if[FP]
      @Test
      void viewAsFloatingLanesTest() {
          Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
          Assert.assertEquals(asFloating.species(), SPECIES);
      }
  #else[FP]
  #if[byteOrShort]
      @Test(expectedExceptions = UnsupportedOperationException.class)
      void viewAsFloatingLanesTest() {
          SPECIES.zero().viewAsFloatingLanes();
      }
  #else[byteOrShort]
      @Test
      void viewAsFloatingLanesTest() {
          Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
          VectorSpecies<?> asFloatingSpecies = asFloating.species();
          Assert.assertNotEquals(asFloatingSpecies.elementType(), SPECIES.elementType());
--- 1683,26 ---
  #else[FP]
          Vector<?> asIntegral = SPECIES.zero().viewAsIntegralLanes();
          Assert.assertEquals(asIntegral.species(), SPECIES);
  #end[FP]
      }
  #if[FP]
+ 
      @Test
      void viewAsFloatingLanesTest() {
          Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
          Assert.assertEquals(asFloating.species(), SPECIES);
      }
  #else[FP]
  #if[byteOrShort]
+ 
      @Test(expectedExceptions = UnsupportedOperationException.class)
      void viewAsFloatingLanesTest() {
          SPECIES.zero().viewAsFloatingLanes();
      }
  #else[byteOrShort]
+ 
      @Test
      void viewAsFloatingLanesTest() {
          Vector<?> asFloating = SPECIES.zero().viewAsFloatingLanes();
          VectorSpecies<?> asFloatingSpecies = asFloating.species();
          Assert.assertNotEquals(asFloatingSpecies.elementType(), SPECIES.elementType());

*** 1616,12 ***
          Assert.assertEquals(asFloatingSpecies.length(), SPECIES.length());
          Assert.assertEquals(asFloating.viewAsIntegralLanes().species(), SPECIES);
      }
  #end[byteOrShort]
  #end[FP]
- 
  #if[BITWISE]
      @Test
      // Test div by 0.
      static void bitwiseDivByZeroSmokeTest() {
          try {
              $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
--- 1710,12 ---
          Assert.assertEquals(asFloatingSpecies.length(), SPECIES.length());
          Assert.assertEquals(asFloating.viewAsIntegralLanes().species(), SPECIES);
      }
  #end[byteOrShort]
  #end[FP]
  #if[BITWISE]
+ 
      @Test
      // Test div by 0.
      static void bitwiseDivByZeroSmokeTest() {
          try {
              $abstractvectortype$ a = ($abstractvectortype$) SPECIES.broadcast(0).addIndex(1);
< prev index next >