< prev index next >

test/jdk/jdk/incubator/vector/FloatMaxVectorLoadStoreTests.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  *      FloatMaxVectorLoadStoreTests
  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.FloatVector;
  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.FloatBuffer;
  46 import java.nio.ByteOrder;
  47 import java.util.List;
  48 import java.util.function.IntFunction;
  49 
  50 @Test
  51 public class FloatMaxVectorLoadStoreTests extends AbstractVectorTest {
  52     static final Species<Float> SPECIES =
  53                 FloatVector.SPECIES_MAX;
  54 
  55     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
  56 
  57     static Shape getMaxBit() {
  58         return Shape.S_Max_BIT;
  59     }
  60 
  61     static void assertArraysEquals(float[] a, float[] r, boolean[] mask) {
  62         int i = 0;
  63         try {
  64             for (; i < a.length; i++) {
  65                 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (float) 0, r[i]);
  66             }
  67         } catch (AssertionError e) {
  68             Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (float) 0, r[i], "at index #" + i);
  69         }
  70     }
  71 
  72     static void assertArraysEquals(float[] a, float[] 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 = "floatProvider")
 190     static void loadStoreArray(IntFunction<float[]> fa) {
 191         float[] a = fa.apply(SPECIES.length());
 192         float[] r = new float[a.length];
 193 
 194         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 195             for (int i = 0; i < a.length; i += SPECIES.length()) {
 196                 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
 197                 av.intoArray(r, i);
 198             }
 199         }
 200         Assert.assertEquals(a, r);
 201     }
 202 
 203     @Test(dataProvider = "floatMaskProvider")
 204     static void loadStoreMaskArray(IntFunction<float[]> fa,
 205                                    IntFunction<boolean[]> fm) {
 206         float[] a = fa.apply(SPECIES.length());
 207         float[] r = new float[a.length];
 208         boolean[] mask = fm.apply(SPECIES.length());
 209         Vector.Mask<Float> vmask = FloatVector.maskFromValues(SPECIES, mask);
 210 
 211         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 212             for (int i = 0; i < a.length; i += SPECIES.length()) {
 213                 FloatVector av = FloatVector.fromArray(SPECIES, a, i, vmask);
 214                 av.intoArray(r, i);
 215             }
 216         }
 217         assertArraysEquals(a, r, mask);
 218 
 219         r = new float[a.length];
 220         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 221             for (int i = 0; i < a.length; i += SPECIES.length()) {
 222                 FloatVector av = FloatVector.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                 FloatVector av = FloatVector.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 = "floatByteBufferMaskProvider")
 277     static void loadStoreByteBufferMask(IntFunction<float[]> 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         Vector.Mask<Float> vmask = FloatVector.maskFromValues(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                 FloatVector av = FloatVector.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                 FloatVector av = FloatVector.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 = "floatByteBufferMaskProvider")
 316     static void loadReadOnlyStoreByteBufferMask(IntFunction<float[]> 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         Vector.Mask<Float> vmask = FloatVector.maskFromValues(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                 FloatVector av = FloatVector.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 }


  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  *      FloatMaxVectorLoadStoreTests
  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.FloatVector;
  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.FloatBuffer;
  47 import java.nio.ByteOrder;
  48 import java.util.List;
  49 import java.util.function.IntFunction;
  50 
  51 @Test
  52 public class FloatMaxVectorLoadStoreTests extends AbstractVectorTest {
  53     static final VectorSpecies<Float> SPECIES =
  54                 FloatVector.SPECIES_MAX;
  55 
  56     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
  57 
  58     static VectorShape getMaxBit() {
  59         return VectorShape.S_Max_BIT;
  60     }
  61 
  62     static void assertArraysEquals(float[] a, float[] r, boolean[] mask) {
  63         int i = 0;
  64         try {
  65             for (; i < a.length; i++) {
  66                 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (float) 0, r[i]);
  67             }
  68         } catch (AssertionError e) {
  69             Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (float) 0, r[i], "at index #" + i);
  70         }
  71     }
  72 
  73     static void assertArraysEquals(float[] a, float[] r, int[] im) {
  74         int i = 0;
  75         try {
  76             for (; i < a.length; i++) {
  77                 Assert.assertEquals(a[im[i]], r[i]);
  78             }
  79         } catch (AssertionError e) {


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


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