< prev index next > test/jdk/jdk/incubator/vector/VectorReshapeTests.java
Print this page
/*
- * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 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.
*
* 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.
*/
+ import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.vector.*;
import jdk.internal.vm.annotation.ForceInline;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
- import java.lang.invoke.MethodHandles;
- import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.List;
import java.util.function.IntFunction;
import jdk.incubator.vector.VectorShape;
}
@ForceInline
static <E>
void testVectorReshape(VectorSpecies<E> a, VectorSpecies<E> b, byte[] input, byte[] output, boolean lanewise) {
Class<?> atype = a.elementType(), btype = b.elementType();
- Vector<E> av = a.fromByteArray(input, 0, ByteOrder.nativeOrder());
+ MemorySegment inputMs = MemorySegment.ofArray(input);
+ MemorySegment outputMs = MemorySegment.ofArray(output);
+ Vector<E> av = a.fromMemorySegment(inputMs, 0, ByteOrder.nativeOrder());
int partLimit = partLimit(a, b, lanewise);
int block = Math.min(a.vectorByteSize(), b.vectorByteSize());
if (false)
System.out.println("testing "+a+"->"+b+
(lanewise?" (lanewise)":" (reinterpret)")+
if (partLimit > 0) {
for (int part = 0; part < partLimit; part++) {
Vector<E> bv = (lanewise
? av.castShape(b, part)
: av.reinterpretShape(b, part));
- bv.intoByteArray(output, 0, ByteOrder.nativeOrder());
+ bv.intoMemorySegment(outputMs, 0, ByteOrder.nativeOrder());
// expansion: slice some of the input
origin = part * block;
expected = Arrays.copyOfRange(input, origin, origin + block);
if (lanewise) {
expected = castByteArrayData(expected, atype, btype);
} else if (partLimit < 0) {
for (int part = 0; part > partLimit; part--) {
Vector<E> bv = (lanewise
? av.castShape(b, part)
: av.reinterpretShape(b, part));
- bv.intoByteArray(output, 0, ByteOrder.nativeOrder());
+ bv.intoMemorySegment(outputMs, 0, ByteOrder.nativeOrder());
// contraction: unslice the input into part of the output
byte[] logical = input;
if (lanewise) {
logical = castByteArrayData(input, atype, btype);
}
} else {
int part = 0;
Vector<E> bv = (lanewise
? av.castShape(b, part)
: av.reinterpretShape(b, part));
- bv.intoByteArray(output, 0, ByteOrder.nativeOrder());
+ bv.intoMemorySegment(outputMs, 0, ByteOrder.nativeOrder());
// in-place copy, no resize
expected = input;
origin = 0;
if (lanewise) {
expected = castByteArrayData(expected, atype, btype);
}
@ForceInline
static <E,F>
void testVectorRebracket(VectorSpecies<E> a, VectorSpecies<F> b, byte[] input, byte[] output, boolean lanewise) {
Class<?> atype = a.elementType(), btype = b.elementType();
- Vector<E> av = a.fromByteArray(input, 0, ByteOrder.nativeOrder());
+ MemorySegment inputMs = MemorySegment.ofArray(input);
+ MemorySegment outputMs = MemorySegment.ofArray(output);
+ Vector<E> av = a.fromMemorySegment(inputMs, 0, ByteOrder.nativeOrder());
int partLimit = partLimit(a, b, lanewise);
int block;
assert(input.length == output.length);
if (!lanewise)
block = Math.min(a.vectorByteSize(), b.vectorByteSize());
if (partLimit > 0) {
for (int part = 0; part < partLimit; part++) {
Vector<F> bv = (lanewise
? av.castShape(b, part)
: av.reinterpretShape(b, part));
- bv.intoByteArray(output, 0, ByteOrder.nativeOrder());
+ bv.intoMemorySegment(outputMs, 0, ByteOrder.nativeOrder());
// expansion: slice some of the input
origin = part * block;
expected = Arrays.copyOfRange(input, origin, origin + block);
if (lanewise) {
expected = castByteArrayData(expected, atype, btype);
} else if (partLimit < 0) {
for (int part = 0; part > partLimit; part--) {
Vector<F> bv = (lanewise
? av.castShape(b, part)
: av.reinterpretShape(b, part));
- bv.intoByteArray(output, 0, ByteOrder.nativeOrder());
+ bv.intoMemorySegment(outputMs, 0, ByteOrder.nativeOrder());
// contraction: unslice the input into part of the output
byte[] logical = input;
if (lanewise) {
logical = castByteArrayData(input, atype, btype);
}
} else {
int part = 0;
Vector<F> bv = (lanewise
? av.castShape(b, part)
: av.reinterpretShape(b, part));
- bv.intoByteArray(output, 0, ByteOrder.nativeOrder());
+ bv.intoMemorySegment(outputMs, 0, ByteOrder.nativeOrder());
// in-place copy, no resize
expected = input;
origin = 0;
if (lanewise) {
expected = castByteArrayData(expected, atype, btype);
< prev index next >