Skip to content

Commit 4d70689

Browse files
author
Ian Graves
committed
8351993: VectorShuffle access to and from MemorySegments
Reviewed-by: psandoz
1 parent afcbf6b commit 4d70689

File tree

66 files changed

+6307
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+6307
-387
lines changed

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractShuffle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte128Vector.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -895,6 +897,25 @@ public void intoArray(int[] a, int offset) {
895897
.intoArray(a, offset + species.length() * 3);
896898
}
897899

900+
@Override
901+
@ForceInline
902+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
903+
VectorSpecies<Integer> species = IntVector.SPECIES_128;
904+
Vector<Byte> v = toBitsVector();
905+
v.convertShape(VectorOperators.B2I, species, 0)
906+
.reinterpretAsInts()
907+
.intoMemorySegment(ms, offset, bo);
908+
v.convertShape(VectorOperators.B2I, species, 1)
909+
.reinterpretAsInts()
910+
.intoMemorySegment(ms, offset + species.vectorByteSize(), bo);
911+
v.convertShape(VectorOperators.B2I, species, 2)
912+
.reinterpretAsInts()
913+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 2, bo);
914+
v.convertShape(VectorOperators.B2I, species, 3)
915+
.reinterpretAsInts()
916+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 3, bo);
917+
}
918+
898919
@Override
899920
@ForceInline
900921
public final Byte128Mask laneIsValid() {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte256Vector.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -927,6 +929,25 @@ public void intoArray(int[] a, int offset) {
927929
.intoArray(a, offset + species.length() * 3);
928930
}
929931

932+
@Override
933+
@ForceInline
934+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
935+
VectorSpecies<Integer> species = IntVector.SPECIES_256;
936+
Vector<Byte> v = toBitsVector();
937+
v.convertShape(VectorOperators.B2I, species, 0)
938+
.reinterpretAsInts()
939+
.intoMemorySegment(ms, offset, bo);
940+
v.convertShape(VectorOperators.B2I, species, 1)
941+
.reinterpretAsInts()
942+
.intoMemorySegment(ms, offset + species.vectorByteSize(), bo);
943+
v.convertShape(VectorOperators.B2I, species, 2)
944+
.reinterpretAsInts()
945+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 2, bo);
946+
v.convertShape(VectorOperators.B2I, species, 3)
947+
.reinterpretAsInts()
948+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 3, bo);
949+
}
950+
930951
@Override
931952
@ForceInline
932953
public final Byte256Mask laneIsValid() {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte512Vector.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -991,6 +993,25 @@ public void intoArray(int[] a, int offset) {
991993
.intoArray(a, offset + species.length() * 3);
992994
}
993995

996+
@Override
997+
@ForceInline
998+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
999+
VectorSpecies<Integer> species = IntVector.SPECIES_512;
1000+
Vector<Byte> v = toBitsVector();
1001+
v.convertShape(VectorOperators.B2I, species, 0)
1002+
.reinterpretAsInts()
1003+
.intoMemorySegment(ms, offset, bo);
1004+
v.convertShape(VectorOperators.B2I, species, 1)
1005+
.reinterpretAsInts()
1006+
.intoMemorySegment(ms, offset + species.vectorByteSize(), bo);
1007+
v.convertShape(VectorOperators.B2I, species, 2)
1008+
.reinterpretAsInts()
1009+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 2, bo);
1010+
v.convertShape(VectorOperators.B2I, species, 3)
1011+
.reinterpretAsInts()
1012+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 3, bo);
1013+
}
1014+
9941015
@Override
9951016
@ForceInline
9961017
public final Byte512Mask laneIsValid() {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte64Vector.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -879,6 +881,25 @@ public void intoArray(int[] a, int offset) {
879881
.intoArray(a, offset + species.length() * 3);
880882
}
881883

884+
@Override
885+
@ForceInline
886+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
887+
VectorSpecies<Integer> species = IntVector.SPECIES_64;
888+
Vector<Byte> v = toBitsVector();
889+
v.convertShape(VectorOperators.B2I, species, 0)
890+
.reinterpretAsInts()
891+
.intoMemorySegment(ms, offset, bo);
892+
v.convertShape(VectorOperators.B2I, species, 1)
893+
.reinterpretAsInts()
894+
.intoMemorySegment(ms, offset + species.vectorByteSize(), bo);
895+
v.convertShape(VectorOperators.B2I, species, 2)
896+
.reinterpretAsInts()
897+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 2, bo);
898+
v.convertShape(VectorOperators.B2I, species, 3)
899+
.reinterpretAsInts()
900+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 3, bo);
901+
}
902+
882903
@Override
883904
@ForceInline
884905
public final Byte64Mask laneIsValid() {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteMaxVector.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -865,6 +867,25 @@ public void intoArray(int[] a, int offset) {
865867
.intoArray(a, offset + species.length() * 3);
866868
}
867869

870+
@Override
871+
@ForceInline
872+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
873+
VectorSpecies<Integer> species = IntVector.SPECIES_MAX;
874+
Vector<Byte> v = toBitsVector();
875+
v.convertShape(VectorOperators.B2I, species, 0)
876+
.reinterpretAsInts()
877+
.intoMemorySegment(ms, offset, bo);
878+
v.convertShape(VectorOperators.B2I, species, 1)
879+
.reinterpretAsInts()
880+
.intoMemorySegment(ms, offset + species.vectorByteSize(), bo);
881+
v.convertShape(VectorOperators.B2I, species, 2)
882+
.reinterpretAsInts()
883+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 2, bo);
884+
v.convertShape(VectorOperators.B2I, species, 3)
885+
.reinterpretAsInts()
886+
.intoMemorySegment(ms, offset + species.vectorByteSize() * 3, bo);
887+
}
888+
868889
@Override
869890
@ForceInline
870891
public final ByteMaxMask laneIsValid() {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double128Vector.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -864,9 +866,40 @@ public void intoArray(int[] a, int offset) {
864866
a[offset + i] = laneSource(i);
865867
}
866868
}
867-
}
869+
}
870+
868871
}
869872

873+
@Override
874+
@ForceInline
875+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
876+
switch (length()) {
877+
case 1 -> ms.set(ValueLayout.OfInt.JAVA_INT_UNALIGNED, offset, laneSource(0));
878+
case 2 -> toBitsVector()
879+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_64, 0)
880+
.reinterpretAsInts()
881+
.intoMemorySegment(ms, offset, bo);
882+
case 4 -> toBitsVector()
883+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_128, 0)
884+
.reinterpretAsInts()
885+
.intoMemorySegment(ms, offset, bo);
886+
case 8 -> toBitsVector()
887+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_256, 0)
888+
.reinterpretAsInts()
889+
.intoMemorySegment(ms, offset, bo);
890+
case 16 -> toBitsVector()
891+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_512, 0)
892+
.reinterpretAsInts()
893+
.intoMemorySegment(ms, offset, bo);
894+
default -> {
895+
VectorIntrinsics.checkFromIndexSize(offset, length(), ms.byteSize() / 4);
896+
for (int i = 0; i < length(); i++) {
897+
ms.setAtIndex(ValueLayout.JAVA_INT_UNALIGNED, offset + (i << 2), laneSource(i));
898+
}
899+
}
900+
}
901+
}
902+
870903
@Override
871904
@ForceInline
872905
public final Double128Mask laneIsValid() {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double256Vector.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -868,9 +870,40 @@ public void intoArray(int[] a, int offset) {
868870
a[offset + i] = laneSource(i);
869871
}
870872
}
871-
}
873+
}
874+
872875
}
873876

877+
@Override
878+
@ForceInline
879+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
880+
switch (length()) {
881+
case 1 -> ms.set(ValueLayout.OfInt.JAVA_INT_UNALIGNED, offset, laneSource(0));
882+
case 2 -> toBitsVector()
883+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_64, 0)
884+
.reinterpretAsInts()
885+
.intoMemorySegment(ms, offset, bo);
886+
case 4 -> toBitsVector()
887+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_128, 0)
888+
.reinterpretAsInts()
889+
.intoMemorySegment(ms, offset, bo);
890+
case 8 -> toBitsVector()
891+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_256, 0)
892+
.reinterpretAsInts()
893+
.intoMemorySegment(ms, offset, bo);
894+
case 16 -> toBitsVector()
895+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_512, 0)
896+
.reinterpretAsInts()
897+
.intoMemorySegment(ms, offset, bo);
898+
default -> {
899+
VectorIntrinsics.checkFromIndexSize(offset, length(), ms.byteSize() / 4);
900+
for (int i = 0; i < length(); i++) {
901+
ms.setAtIndex(ValueLayout.JAVA_INT_UNALIGNED, offset + (i << 2), laneSource(i));
902+
}
903+
}
904+
}
905+
}
906+
874907
@Override
875908
@ForceInline
876909
public final Double256Mask laneIsValid() {

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double512Vector.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
package jdk.incubator.vector;
2626

2727
import java.lang.foreign.MemorySegment;
28+
import java.lang.foreign.ValueLayout;
29+
import java.nio.ByteOrder;
2830
import java.util.Arrays;
2931
import java.util.Objects;
3032
import java.util.function.IntUnaryOperator;
@@ -876,9 +878,40 @@ public void intoArray(int[] a, int offset) {
876878
a[offset + i] = laneSource(i);
877879
}
878880
}
879-
}
881+
}
882+
880883
}
881884

885+
@Override
886+
@ForceInline
887+
public void intoMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
888+
switch (length()) {
889+
case 1 -> ms.set(ValueLayout.OfInt.JAVA_INT_UNALIGNED, offset, laneSource(0));
890+
case 2 -> toBitsVector()
891+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_64, 0)
892+
.reinterpretAsInts()
893+
.intoMemorySegment(ms, offset, bo);
894+
case 4 -> toBitsVector()
895+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_128, 0)
896+
.reinterpretAsInts()
897+
.intoMemorySegment(ms, offset, bo);
898+
case 8 -> toBitsVector()
899+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_256, 0)
900+
.reinterpretAsInts()
901+
.intoMemorySegment(ms, offset, bo);
902+
case 16 -> toBitsVector()
903+
.convertShape(VectorOperators.L2I, IntVector.SPECIES_512, 0)
904+
.reinterpretAsInts()
905+
.intoMemorySegment(ms, offset, bo);
906+
default -> {
907+
VectorIntrinsics.checkFromIndexSize(offset, length(), ms.byteSize() / 4);
908+
for (int i = 0; i < length(); i++) {
909+
ms.setAtIndex(ValueLayout.JAVA_INT_UNALIGNED, offset + (i << 2), laneSource(i));
910+
}
911+
}
912+
}
913+
}
914+
882915
@Override
883916
@ForceInline
884917
public final Double512Mask laneIsValid() {

0 commit comments

Comments
 (0)