11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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 Byte64VectorLoadStoreTests
28 *
29 */
30
31 import jdk.incubator.vector.Vector.Shape;
32 import jdk.incubator.vector.Vector.Species;
33 import jdk.incubator.vector.Vector;
34
35 import jdk.incubator.vector.ByteVector;
36
37 import org.testng.Assert;
38 import org.testng.annotations.DataProvider;
39 import org.testng.annotations.Test;
40
41 import java.nio.ByteBuffer;
42 import java.nio.ByteOrder;
43 import java.util.List;
44 import java.util.function.IntFunction;
45
46 @Test
47 public class Byte64VectorLoadStoreTests extends AbstractVectorTest {
48 static final Species<Byte> SPECIES =
49 ByteVector.SPECIES_64;
50
51 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
52
53 static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask) {
54 int i = 0;
55 try {
56 for (; i < a.length; i++) {
57 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i]);
58 }
59 } catch (AssertionError e) {
60 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i], "at index #" + i);
61 }
62 }
63
64 static void assertArraysEquals(byte[] a, byte[] r, int[] im) {
65 int i = 0;
66 try {
67 for (; i < a.length; i++) {
68 Assert.assertEquals(a[im[i]], r[i]);
181 @Test(dataProvider = "byteProvider")
182 static void loadStoreArray(IntFunction<byte[]> fa) {
183 byte[] a = fa.apply(SPECIES.length());
184 byte[] r = new byte[a.length];
185
186 for (int ic = 0; ic < INVOC_COUNT; ic++) {
187 for (int i = 0; i < a.length; i += SPECIES.length()) {
188 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
189 av.intoArray(r, i);
190 }
191 }
192 Assert.assertEquals(a, r);
193 }
194
195 @Test(dataProvider = "byteMaskProvider")
196 static void loadStoreMaskArray(IntFunction<byte[]> fa,
197 IntFunction<boolean[]> fm) {
198 byte[] a = fa.apply(SPECIES.length());
199 byte[] r = new byte[a.length];
200 boolean[] mask = fm.apply(SPECIES.length());
201 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
202
203 for (int ic = 0; ic < INVOC_COUNT; ic++) {
204 for (int i = 0; i < a.length; i += SPECIES.length()) {
205 ByteVector av = ByteVector.fromArray(SPECIES, a, i, vmask);
206 av.intoArray(r, i);
207 }
208 }
209 assertArraysEquals(a, r, mask);
210
211 r = new byte[a.length];
212 for (int ic = 0; ic < INVOC_COUNT; ic++) {
213 for (int i = 0; i < a.length; i += SPECIES.length()) {
214 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
215 av.intoArray(r, i, vmask);
216 }
217 }
218
219 assertArraysEquals(a, r, mask);
220 }
221
255 for (int ic = 0; ic < INVOC_COUNT; ic++) {
256 for (int i = 0; i < l; i += s) {
257 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
258 av.intoByteBuffer(r, i);
259 }
260 }
261 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
262 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
263 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
264 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
265 Assert.assertEquals(a, r, "Buffers not equal");
266 }
267
268 @Test(dataProvider = "byteByteBufferMaskProvider")
269 static void loadStoreByteBufferMask(IntFunction<byte[]> fa,
270 IntFunction<ByteBuffer> fb,
271 IntFunction<boolean[]> fm) {
272 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
273 ByteBuffer r = fb.apply(a.limit());
274 boolean[] mask = fm.apply(SPECIES.length());
275 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
276
277 int l = a.limit();
278 int s = SPECIES.length() * SPECIES.elementSize() / 8;
279
280 for (int ic = 0; ic < INVOC_COUNT; ic++) {
281 for (int i = 0; i < l; i += s) {
282 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
283 av.intoByteBuffer(r, i);
284 }
285 }
286 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
287 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
288 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
289 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
290 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
291
292 a = toBuffer(fa.apply(SPECIES.length()), fb);
293 r = fb.apply(a.limit());
294 for (int ic = 0; ic < INVOC_COUNT; ic++) {
295 for (int i = 0; i < l; i += s) {
296 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
297 av.intoByteBuffer(r, i, vmask);
298 }
299 }
300 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
301 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
302 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
303 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
304 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
305 }
306
307 @Test(dataProvider = "byteByteBufferMaskProvider")
308 static void loadReadOnlyStoreByteBufferMask(IntFunction<byte[]> fa,
309 IntFunction<ByteBuffer> fb,
310 IntFunction<boolean[]> fm) {
311 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
312 a = a.asReadOnlyBuffer().order(a.order());
313 ByteBuffer r = fb.apply(a.limit());
314 boolean[] mask = fm.apply(SPECIES.length());
315 Vector.Mask<Byte> vmask = ByteVector.maskFromValues(SPECIES, mask);
316
317 int l = a.limit();
318 int s = SPECIES.length() * SPECIES.elementSize() / 8;
319
320 for (int ic = 0; ic < INVOC_COUNT; ic++) {
321 for (int i = 0; i < l; i += s) {
322 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
323 av.intoByteBuffer(r, i);
324 }
325 }
326 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
327 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
328 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
329 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
330 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
331 }
332 }
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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 Byte64VectorLoadStoreTests
28 *
29 */
30
31 import jdk.incubator.vector.VectorShape;
32 import jdk.incubator.vector.VectorSpecies;
33 import jdk.incubator.vector.VectorMask;
34 import jdk.incubator.vector.Vector;
35
36 import jdk.incubator.vector.ByteVector;
37
38 import org.testng.Assert;
39 import org.testng.annotations.DataProvider;
40 import org.testng.annotations.Test;
41
42 import java.nio.ByteBuffer;
43 import java.nio.ByteOrder;
44 import java.util.List;
45 import java.util.function.IntFunction;
46
47 @Test
48 public class Byte64VectorLoadStoreTests extends AbstractVectorTest {
49 static final VectorSpecies<Byte> SPECIES =
50 ByteVector.SPECIES_64;
51
52 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
53
54 static void assertArraysEquals(byte[] a, byte[] r, boolean[] mask) {
55 int i = 0;
56 try {
57 for (; i < a.length; i++) {
58 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i]);
59 }
60 } catch (AssertionError e) {
61 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : (byte) 0, r[i], "at index #" + i);
62 }
63 }
64
65 static void assertArraysEquals(byte[] a, byte[] r, int[] im) {
66 int i = 0;
67 try {
68 for (; i < a.length; i++) {
69 Assert.assertEquals(a[im[i]], r[i]);
182 @Test(dataProvider = "byteProvider")
183 static void loadStoreArray(IntFunction<byte[]> fa) {
184 byte[] a = fa.apply(SPECIES.length());
185 byte[] r = new byte[a.length];
186
187 for (int ic = 0; ic < INVOC_COUNT; ic++) {
188 for (int i = 0; i < a.length; i += SPECIES.length()) {
189 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
190 av.intoArray(r, i);
191 }
192 }
193 Assert.assertEquals(a, r);
194 }
195
196 @Test(dataProvider = "byteMaskProvider")
197 static void loadStoreMaskArray(IntFunction<byte[]> fa,
198 IntFunction<boolean[]> fm) {
199 byte[] a = fa.apply(SPECIES.length());
200 byte[] r = new byte[a.length];
201 boolean[] mask = fm.apply(SPECIES.length());
202 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
203
204 for (int ic = 0; ic < INVOC_COUNT; ic++) {
205 for (int i = 0; i < a.length; i += SPECIES.length()) {
206 ByteVector av = ByteVector.fromArray(SPECIES, a, i, vmask);
207 av.intoArray(r, i);
208 }
209 }
210 assertArraysEquals(a, r, mask);
211
212 r = new byte[a.length];
213 for (int ic = 0; ic < INVOC_COUNT; ic++) {
214 for (int i = 0; i < a.length; i += SPECIES.length()) {
215 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
216 av.intoArray(r, i, vmask);
217 }
218 }
219
220 assertArraysEquals(a, r, mask);
221 }
222
256 for (int ic = 0; ic < INVOC_COUNT; ic++) {
257 for (int i = 0; i < l; i += s) {
258 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
259 av.intoByteBuffer(r, i);
260 }
261 }
262 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
263 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
264 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
265 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
266 Assert.assertEquals(a, r, "Buffers not equal");
267 }
268
269 @Test(dataProvider = "byteByteBufferMaskProvider")
270 static void loadStoreByteBufferMask(IntFunction<byte[]> fa,
271 IntFunction<ByteBuffer> fb,
272 IntFunction<boolean[]> fm) {
273 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
274 ByteBuffer r = fb.apply(a.limit());
275 boolean[] mask = fm.apply(SPECIES.length());
276 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
277
278 int l = a.limit();
279 int s = SPECIES.length() * SPECIES.elementSize() / 8;
280
281 for (int ic = 0; ic < INVOC_COUNT; ic++) {
282 for (int i = 0; i < l; i += s) {
283 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
284 av.intoByteBuffer(r, i);
285 }
286 }
287 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
288 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
289 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
290 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
291 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
292
293 a = toBuffer(fa.apply(SPECIES.length()), fb);
294 r = fb.apply(a.limit());
295 for (int ic = 0; ic < INVOC_COUNT; ic++) {
296 for (int i = 0; i < l; i += s) {
297 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i);
298 av.intoByteBuffer(r, i, vmask);
299 }
300 }
301 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
302 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
303 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
304 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
305 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
306 }
307
308 @Test(dataProvider = "byteByteBufferMaskProvider")
309 static void loadReadOnlyStoreByteBufferMask(IntFunction<byte[]> fa,
310 IntFunction<ByteBuffer> fb,
311 IntFunction<boolean[]> fm) {
312 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
313 a = a.asReadOnlyBuffer().order(a.order());
314 ByteBuffer r = fb.apply(a.limit());
315 boolean[] mask = fm.apply(SPECIES.length());
316 VectorMask<Byte> vmask = VectorMask.fromValues(SPECIES, mask);
317
318 int l = a.limit();
319 int s = SPECIES.length() * SPECIES.elementSize() / 8;
320
321 for (int ic = 0; ic < INVOC_COUNT; ic++) {
322 for (int i = 0; i < l; i += s) {
323 ByteVector av = ByteVector.fromByteBuffer(SPECIES, a, i, vmask);
324 av.intoByteBuffer(r, i);
325 }
326 }
327 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
328 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
329 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
330 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
331 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
332 }
333 }
|