Skip to content
Permalink
Browse files
8278796: Incorrect behavior of FloatVector.withLane on X86
Backport-of: 8494fec665bfa51d1702827bd0aa4f4547e67729
  • Loading branch information
TheRealMDoerr committed Mar 7, 2022
1 parent b3aa42d commit ec2c521ca75c30c4a26c2db9df14990f9fb471a8
Showing 34 changed files with 283 additions and 189 deletions.
@@ -4333,7 +4333,8 @@ instruct insertF(vec dst, regF val, immU8 idx) %{
assert(vector_element_basic_type(this) == T_FLOAT, "sanity");
assert($idx$$constant < (int)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 );
%}
@@ -4353,13 +4354,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 {
@@ -3264,13 +3264,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 {
@@ -3264,13 +3264,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 {
@@ -3264,13 +3264,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 {
@@ -3264,13 +3264,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 {
@@ -3269,13 +3269,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 {
@@ -2449,13 +2449,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 {
@@ -2449,13 +2449,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 {
@@ -2449,13 +2449,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 {
@@ -2449,13 +2449,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 {
@@ -2454,13 +2454,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 {
@@ -2459,13 +2459,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;

1 comment on commit ec2c521

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on ec2c521 Mar 7, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.