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