Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8278796: Incorrect behavior of FloatVector.withLane on X86
Reviewed-by: sviswanathan, kvn
  • Loading branch information
Jatin Bhateja committed Dec 17, 2021
1 parent f5d7c77 commit 8494fec665bfa51d1702827bd0aa4f4547e67729
Showing 34 changed files with 283 additions and 189 deletions.
@@ -4572,7 +4572,8 @@ instruct insertF(vec dst, regF val, immU8 idx) %{
assert(Matcher::vector_element_basic_type(this) == T_FLOAT, "sanity");
assert($idx$$constant < (int)Matcher::vector_length(this), "out of bounds");

__ insertps($dst$$XMMRegister, $val$$XMMRegister, $idx$$constant);
uint x_idx = $idx$$constant & right_n_bits(2);
__ insertps($dst$$XMMRegister, $val$$XMMRegister, x_idx << 4);
%}
ins_pipe( pipe_slow );
%}
@@ -4592,13 +4593,13 @@ instruct vinsertF(vec dst, vec src, regF val, immU8 idx, vec vtmp) %{
uint y_idx = ($idx$$constant >> 2) & 1;
int vlen_enc = Assembler::AVX_256bit;
__ vextracti128($vtmp$$XMMRegister, $src$$XMMRegister, y_idx);
__ vinsertps($vtmp$$XMMRegister, $vtmp$$XMMRegister, $val$$XMMRegister, x_idx);
__ vinsertps($vtmp$$XMMRegister, $vtmp$$XMMRegister, $val$$XMMRegister, x_idx << 4);
__ vinserti128($dst$$XMMRegister, $src$$XMMRegister, $vtmp$$XMMRegister, y_idx);
} else {
assert(vlen == 16, "sanity");
uint y_idx = ($idx$$constant >> 2) & 3;
__ vextracti32x4($vtmp$$XMMRegister, $src$$XMMRegister, y_idx);
__ vinsertps($vtmp$$XMMRegister, $vtmp$$XMMRegister, $val$$XMMRegister, x_idx);
__ vinsertps($vtmp$$XMMRegister, $vtmp$$XMMRegister, $val$$XMMRegister, x_idx << 4);
__ vinserti32x4($dst$$XMMRegister, $src$$XMMRegister, $vtmp$$XMMRegister, y_idx);
}
%}
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -3444,13 +3444,16 @@ static void withByte128VectorTests(IntFunction<byte []> fa) {
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
av.withLane(0, (byte)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (byte)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (byte)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (byte)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(byte a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -3444,13 +3444,16 @@ static void withByte256VectorTests(IntFunction<byte []> fa) {
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
av.withLane(0, (byte)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (byte)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (byte)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (byte)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(byte a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -3444,13 +3444,16 @@ static void withByte512VectorTests(IntFunction<byte []> fa) {
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
av.withLane(0, (byte)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (byte)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (byte)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (byte)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(byte a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -3444,13 +3444,16 @@ static void withByte64VectorTests(IntFunction<byte []> fa) {
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
av.withLane(0, (byte)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (byte)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (byte)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (byte)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(byte a) {
return bits(a)==0;
@@ -231,10 +231,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -3449,13 +3449,16 @@ static void withByteMaxVectorTests(IntFunction<byte []> fa) {
byte[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
ByteVector av = ByteVector.fromArray(SPECIES, a, i);
av.withLane(0, (byte)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (byte)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (byte)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (byte)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(byte a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) {
int i = 0;
static void assertInsertArraysEquals(double[] r, double[] a, double element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -2457,13 +2457,16 @@ static void withDouble128VectorTests(IntFunction<double []> fa) {
double[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
av.withLane(0, (double)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (double)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (double)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (double)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(double a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) {
int i = 0;
static void assertInsertArraysEquals(double[] r, double[] a, double element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -2457,13 +2457,16 @@ static void withDouble256VectorTests(IntFunction<double []> fa) {
double[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
av.withLane(0, (double)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (double)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (double)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (double)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(double a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) {
int i = 0;
static void assertInsertArraysEquals(double[] r, double[] a, double element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -2457,13 +2457,16 @@ static void withDouble512VectorTests(IntFunction<double []> fa) {
double[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
av.withLane(0, (double)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (double)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (double)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (double)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(double a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) {
int i = 0;
static void assertInsertArraysEquals(double[] r, double[] a, double element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -2457,13 +2457,16 @@ static void withDouble64VectorTests(IntFunction<double []> fa) {
double[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
av.withLane(0, (double)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (double)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (double)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (double)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(double a) {
return bits(a)==0;
@@ -231,10 +231,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(double[] r, double[] a, double element, int index) {
int i = 0;
static void assertInsertArraysEquals(double[] r, double[] a, double element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -2462,13 +2462,16 @@ static void withDoubleMaxVectorTests(IntFunction<double []> fa) {
double[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
DoubleVector av = DoubleVector.fromArray(SPECIES, a, i);
av.withLane(0, (double)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (double)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (double)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (double)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(double a) {
return bits(a)==0;
@@ -226,10 +226,10 @@ static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReduction
}
}

static void assertInsertArraysEquals(float[] r, float[] a, float element, int index) {
int i = 0;
static void assertInsertArraysEquals(float[] r, float[] a, float element, int index, int start, int end) {
int i = start;
try {
for (; i < a.length; i += 1) {
for (; i < end; i += 1) {
if(i%SPECIES.length() == index) {
Assert.assertEquals(r[i], element);
} else {
@@ -2467,13 +2467,16 @@ static void withFloat128VectorTests(IntFunction<float []> fa) {
float[] r = fr.apply(SPECIES.length());

for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
FloatVector av = FloatVector.fromArray(SPECIES, a, i);
av.withLane(0, (float)4).intoArray(r, i);
av.withLane((j++ & (SPECIES.length()-1)), (float)(65535+i)).intoArray(r, i);
}
}

assertInsertArraysEquals(r, a, (float)4, 0);

for (int i = 0, j = 0; i < a.length; i += SPECIES.length()) {
assertInsertArraysEquals(r, a, (float)(65535+i), (j++ & (SPECIES.length()-1)), i , i + SPECIES.length());
}
}
static boolean testIS_DEFAULT(float a) {
return bits(a)==0;

3 comments on commit 8494fec

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 8494fec Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr
Copy link
Contributor

@TheRealMDoerr TheRealMDoerr commented on 8494fec Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 8494fec Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr the backport was successfully created on the branch TheRealMDoerr-backport-8494fec6 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 8494fec6 from the openjdk/jdk18 repository.

The commit being backported was authored by Jatin Bhateja on 17 Dec 2021 and was reviewed by Sandhya Viswanathan and Vladimir Kozlov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev TheRealMDoerr-backport-8494fec6:TheRealMDoerr-backport-8494fec6
$ git checkout TheRealMDoerr-backport-8494fec6
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev TheRealMDoerr-backport-8494fec6

Please sign in to comment.