/* * 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. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
staticvoid assertReductionArraysEquals(byte[] r, byte rc, byte[] a,
FReductionOp f, FReductionAllOp fa) { int i = 0; try { Assert.assertEquals(rc, fa.apply(a)); for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(r[i], f.apply(a, i));
}
} catch (AssertionError e) { Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
}
interface FReductionMaskedOp { byte apply(byte[] a, int idx, boolean[] mask);
}
interface FReductionAllMaskedOp { byte apply(byte[] a, boolean[] mask);
}
staticvoid assertReductionArraysEqualsMasked(byte[] r, byte rc, byte[] a, boolean[] mask,
FReductionMaskedOp f, FReductionAllMaskedOp fa) { int i = 0; try { Assert.assertEquals(rc, fa.apply(a, mask)); for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(r[i], f.apply(a, i, mask));
}
} catch (AssertionError e) { Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
}
}
interface FReductionOpLong { long apply(byte[] a, int idx);
}
interface FReductionAllOpLong { long apply(byte[] a);
}
staticvoid assertReductionLongArraysEquals(long[] r, long rc, byte[] a,
FReductionOpLong f, FReductionAllOpLong fa) { int i = 0; try { Assert.assertEquals(rc, fa.apply(a)); for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(r[i], f.apply(a, i));
}
} catch (AssertionError e) { Assert.assertEquals(rc, fa.apply(a), "Final result is incorrect!"); Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
}
interface FReductionMaskedOpLong { long apply(byte[] a, int idx, boolean[] mask);
}
interface FReductionAllMaskedOpLong { long apply(byte[] a, boolean[] mask);
}
staticvoid assertReductionLongArraysEqualsMasked(long[] r, long rc, byte[] a, boolean[] mask,
FReductionMaskedOpLong f, FReductionAllMaskedOpLong fa) { int i = 0; try { Assert.assertEquals(rc, fa.apply(a, mask)); for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(r[i], f.apply(a, i, mask));
}
} catch (AssertionError e) { Assert.assertEquals(rc, fa.apply(a, mask), "Final result is incorrect!"); Assert.assertEquals(r[i], f.apply(a, i, mask), "at index #" + i);
}
}
interface FBoolReductionOp { boolean apply(boolean[] a, int idx);
}
staticvoid assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReductionOp f) { int i = 0; try { for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(r[i], f.apply(a, i));
}
} catch (AssertionError e) { Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
}
interface FMaskReductionOp { int apply(boolean[] a, int idx);
}
staticvoid assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) { int i = 0; try { for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(r[i], f.apply(a, i));
}
} catch (AssertionError e) { Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
}
staticvoid assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index, int start, int end) { int i = start; try { for (; i < end; i += 1) { if(i%SPECIES.length() == index) { Assert.assertEquals(r[i], element);
} else { Assert.assertEquals(r[i], a[i]);
}
}
} catch (AssertionError e) { if (i%SPECIES.length() == index) { Assert.assertEquals(r[i], element, "at index #" + i);
} else { Assert.assertEquals(r[i], a[i], "at index #" + i);
}
}
}
staticvoid assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, int vector_len) { int i = 0, j = 0; try { for (; i < a.length; i += vector_len) { for (j = 0; j < vector_len; j++) { Assert.assertEquals(r[i+j], a[i+order[i+j]]);
}
}
} catch (AssertionError e) { int idx = i + j; Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]);
}
}
staticvoid assertcompressArraysEquals(byte[] r, byte[] 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], (byte)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], (byte)0, "at index #" + idx);
}
}
}
staticvoid assertexpandArraysEquals(byte[] r, byte[] 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], (byte)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], (byte)0, "at index #" + idx);
}
}
}
staticvoid assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] order, int vector_len) { int i = 0, j = 0; try { for (; i < a.length; i += vector_len) { for (j = 0; j < vector_len; j++) { Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]);
}
}
} catch (AssertionError e) { int idx = i + j; Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]]);
}
}
staticvoid assertRearrangeArraysEquals(byte[] r, byte[] a, int[] order, boolean[] mask, int vector_len) { int i = 0, j = 0; try { for (; i < a.length; i += vector_len) { for (j = 0; j < vector_len; j++) { if (mask[j % SPECIES.length()]) Assert.assertEquals(r[i+j], a[i+order[i+j]]); else Assert.assertEquals(r[i+j], (byte)0);
}
}
} catch (AssertionError e) { int idx = i + j; if (mask[j % SPECIES.length()]) Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); else Assert.assertEquals(r[i+j], (byte)0, "at index #" + idx + ", input = " + a[i+order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
}
}
staticvoid assertSelectFromArraysEquals(byte[] r, byte[] a, byte[] order, boolean[] mask, int vector_len) { int i = 0, j = 0; try { for (; i < a.length; i += vector_len) { for (j = 0; j < vector_len; j++) { if (mask[j % SPECIES.length()]) Assert.assertEquals(r[i+j], a[i+(int)order[i+j]]); else Assert.assertEquals(r[i+j], (byte)0);
}
}
} catch (AssertionError e) { int idx = i + j; if (mask[j % SPECIES.length()]) Assert.assertEquals(r[i+j], a[i+(int)order[i+j]], "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]); else Assert.assertEquals(r[i+j], (byte)0, "at index #" + idx + ", input = " + a[i+(int)order[i+j]] + ", mask = " + mask[j % SPECIES.length()]);
}
}
staticvoid assertBroadcastArraysEquals(byte[] r, byte[] a) { int i = 0; for (; i < a.length; i += SPECIES.length()) { int idx = i; for (int j = idx; j < (idx + SPECIES.length()); j++)
a[j]=a[idx];
}
try { for (i = 0; i < a.length; i++) { Assert.assertEquals(r[i], a[i]);
}
} catch (AssertionError e) { Assert.assertEquals(r[i], a[i], "at index #" + i + ", input = " + a[i]);
}
}
interface FBinOp { byte apply(byte a, byte b);
}
interface FBinMaskOp { byte apply(byte a, byte b, boolean m);
static FBinMaskOp lift(FBinOp f) { return (a, b, m) -> m ? f.apply(a, b) : a;
}
}
staticvoid assertArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(r[i], f.apply(a[i], b[i]));
}
} catch (AssertionError e) { Assert.assertEquals(r[i], f.apply(a[i], b[i]), "(" + a[i] + ", " + b[i] + ") at index #" + i);
}
}
staticvoid assertBroadcastArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]));
}
} catch (AssertionError e) { Assert.assertEquals(r[i], f.apply(a[i], b[(i / SPECIES.length()) * SPECIES.length()]), "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
}
}
staticvoid assertBroadcastLongArraysEquals(byte[] r, byte[] a, byte[] b, FBinOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()])));
}
} catch (AssertionError e) { Assert.assertEquals(r[i], f.apply(a[i], (byte)((long)b[(i / SPECIES.length()) * SPECIES.length()])), "(" + a[i] + ", " + b[(i / SPECIES.length()) * SPECIES.length()] + ") at index #" + i);
}
}
staticvoid assertArraysEquals(byte[] r, byte[] a, byte[] b, boolean[] mask, FBinOp f) {
assertArraysEquals(r, a, b, mask, FBinMaskOp.lift(f));
}
// Create combinations of pairs // @@@ Might be sensitive to order e.g. div by 0 staticfinal List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
Stream.of(BYTE_GENERATORS.get(0)).
flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
collect(Collectors.toList());
@DataProvider public Object[][] boolUnaryOpProvider() { return BOOL_ARRAY_GENERATORS.stream().
map(f -> new Object[]{f}).
toArray(Object[][]::new);
}
@Test // Test all shuffle related operations. staticvoid shuffleTest() { // To test backend instructions, make sure that C2 is used. for (int loop = 0; loop < INVOC_COUNT * INVOC_COUNT; loop++) {
iotaShuffle();
}
}
@Test // Test div by 0. staticvoid bitwiseDivByZeroSmokeTest() { try {
ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1);
ByteVector b = (ByteVector) SPECIES.broadcast(0);
a.div(b); Assert.fail();
} catch (ArithmeticException e) {
}
try {
ByteVector a = (ByteVector) SPECIES.broadcast(0).addIndex(1);
ByteVector b = (ByteVector) SPECIES.broadcast(0);
VectorMask<Byte> m = a.lt((byte) 1);
a.div(b, m); Assert.fail();
} catch (ArithmeticException e) {
}
}
staticbyte ADD(byte a, byte b) { return (byte)(a + b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid ADDByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.ADD, bv).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, Byte64VectorTests::ADD);
}
staticbyte add(byte a, byte b) { return (byte)(a + b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid addByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.add(bv).intoArray(r, i);
}
assertArraysEquals(r, a, b, Byte64VectorTests::add);
}
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.ADD, bv, vmask).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, mask, Byte64VectorTests::ADD);
}
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.add(bv, vmask).intoArray(r, i);
}
assertArraysEquals(r, a, b, mask, Byte64VectorTests::add);
}
staticbyte SUB(byte a, byte b) { return (byte)(a - b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid SUBByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SUB, bv).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, Byte64VectorTests::SUB);
}
staticbyte sub(byte a, byte b) { return (byte)(a - b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid subByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.sub(bv).intoArray(r, i);
}
assertArraysEquals(r, a, b, Byte64VectorTests::sub);
}
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.SUB, bv, vmask).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, mask, Byte64VectorTests::SUB);
}
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.sub(bv, vmask).intoArray(r, i);
}
assertArraysEquals(r, a, b, mask, Byte64VectorTests::sub);
}
staticbyte MUL(byte a, byte b) { return (byte)(a * b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid MULByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.MUL, bv).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, Byte64VectorTests::MUL);
}
staticbyte mul(byte a, byte b) { return (byte)(a * b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid mulByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.mul(bv).intoArray(r, i);
}
assertArraysEquals(r, a, b, Byte64VectorTests::mul);
}
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.MUL, bv, vmask).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, mask, Byte64VectorTests::MUL);
}
for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.mul(bv, vmask).intoArray(r, i);
}
assertArraysEquals(r, a, b, mask, Byte64VectorTests::mul);
}
staticbyte DIV(byte a, byte b) { return (byte)(a / b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid DIVByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
replaceZero(b, (byte) 1);
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.DIV, bv).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, Byte64VectorTests::DIV);
}
staticbyte div(byte a, byte b) { return (byte)(a / b);
}
@Test(dataProvider = "byteBinaryOpProvider") staticvoid divByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) { byte[] a = fa.apply(SPECIES.length()); byte[] b = fb.apply(SPECIES.length()); byte[] r = fr.apply(SPECIES.length());
replaceZero(b, (byte) 1);
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.div(bv).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, Byte64VectorTests::div);
}
for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
av.lanewise(VectorOperators.DIV, bv, vmask).intoArray(r, i);
}
}
assertArraysEquals(r, a, b, mask, Byte64VectorTests::DIV);
}
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.