Skip to content

Commit 07f0e03

Browse files
committed
[LoongArch] Add vector floating-point check function
Because vector support for constant folding was added in visitFMA, the [x]vfmadd.d instructions was optimized into a constant load, causing a bitwise mismatch for NaN values between the expected and actual results. (The NaN from constant folding differs from the NaN generated by the instruction.) This should resolve the buildbot failure: https://lab.llvm.org/staging/#/builders/20/builds/4041
1 parent 27a6a3a commit 07f0e03

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

SingleSource/UnitTests/Vector/LASX/lasx-xvfmadd_d.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ main ()
124124
v4u64_result = (v4u64){0xffffffffffffffff, 0xffffba8300004fc2,
125125
0xffffffffffffffff, 0xffffba8300004fc2};
126126
__m256d_out = __lasx_xvfmadd_d((__m256)v4u64_op0, (__m256)v4u64_op1, (__m256)v4u64_op2);
127-
check_lasx_out(&v4u64_result, &__m256d_out, sizeof(__m256d_out), __FILE__, __LINE__);
127+
check_lasx_fp_out(1, &v4u64_result, &__m256d_out, sizeof(__m256d_out),
128+
__FILE__, __LINE__);
128129

129130
v4u64_op0 = (v4u64){0x0000000000000000, 0x0000000000000000,
130131
0x0000000000000000, 0x0000000000000000};
@@ -146,7 +147,8 @@ main ()
146147
v4u64_result = (v4u64){0xffffffffff000000, 0x0000000000000000,
147148
0xffffffffff000000, 0x0000000000000000};
148149
__m256d_out = __lasx_xvfmadd_d((__m256)v4u64_op0, (__m256)v4u64_op1, (__m256)v4u64_op2);
149-
check_lasx_out(&v4u64_result, &__m256d_out, sizeof(__m256d_out), __FILE__, __LINE__);
150+
check_lasx_fp_out(1, &v4u64_result, &__m256d_out, sizeof(__m256d_out),
151+
__FILE__, __LINE__);
150152

151153
v4u64_op0 = (v4u64){0x00003fff00003fff, 0x00003fff00003fff,
152154
0x00003fff00003fff, 0x00003fff00003fff};

SingleSource/UnitTests/Vector/LASX/lasx_test_util.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef LASX_TEST_UTIL_H
22
#define LASX_TEST_UTIL_H
33

4+
#include <math.h>
45
#include <stdio.h>
56
#include <string.h>
67

@@ -26,4 +27,25 @@ __attribute__((noinline)) void check_lasx_out(void *expected, void *got,
2627
}
2728
}
2829

30+
// Used for comparing floating-point results when the result is NAN, but the
31+
// bitwise comparison with the expected NAN differs.
32+
__attribute__((noinline)) void check_lasx_fp_out(_Bool IsDouble, void *expected,
33+
void *got, int len,
34+
const char *fname, int line) {
35+
// num of elements
36+
int N = IsDouble == 1 ? 8 : 4;
37+
for (int i = 0; i < 32; i += N) {
38+
if (!memcmp(expected + i, got + i, N))
39+
continue;
40+
if (IsDouble && isnan(*(double *)(expected + i)) &&
41+
isnan(*(double *)(got + i)))
42+
continue;
43+
if (!IsDouble && isnan(*(float *)(expected + i)) &&
44+
isnan(*(float *)(got + i)))
45+
continue;
46+
check_lasx_out(expected, got, len, fname, line);
47+
return;
48+
}
49+
}
50+
2951
#endif

SingleSource/UnitTests/Vector/LSX/lsx-vfmadd_d.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ main ()
7070
v2u64_op2 = (v2u64){0xfff8000000000000, 0xfffb00fdfdf7ffff};
7171
v2u64_result = (v2u64){0xfff8000000000000, 0xfffb00fdfdf7ffff};
7272
__m128d_out = __lsx_vfmadd_d((__m128)v2u64_op0, (__m128)v2u64_op1, (__m128)v2u64_op2);
73-
check_lsx_out(&v2u64_result, &__m128d_out, sizeof(__m128d_out), __FILE__, __LINE__);
73+
check_lsx_fp_out(1, &v2u64_result, &__m128d_out, sizeof(__m128d_out),
74+
__FILE__, __LINE__);
7475

7576
v2u64_op0 = (v2u64){0x8000000000000000, 0x8000000000000000};
7677
v2u64_op1 = (v2u64){0x0000000000000000, 0x0000000000000000};

SingleSource/UnitTests/Vector/LSX/lsx_test_util.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef LSX_TEST_UTIL_H
22
#define LSX_TEST_UTIL_H
33

4+
#include <math.h>
45
#include <stdio.h>
56
#include <string.h>
67

@@ -25,4 +26,25 @@ __attribute__((noinline)) void check_lsx_out(void *expected, void *got, int len,
2526
}
2627
}
2728

29+
// Used for comparing floating-point results when the result is NAN, but the
30+
// bitwise comparison with the expected NAN differs.
31+
__attribute__((noinline)) void check_lsx_fp_out(_Bool IsDouble, void *expected,
32+
void *got, int len,
33+
const char *fname, int line) {
34+
// num of elements
35+
int N = IsDouble == 1 ? 8 : 4;
36+
for (int i = 0; i < 16; i += N) {
37+
if (!memcmp(expected + i, got + i, N))
38+
continue;
39+
if (IsDouble && isnan(*(double *)(expected + i)) &&
40+
isnan(*(double *)(got + i)))
41+
continue;
42+
if (!IsDouble && isnan(*(float *)(expected + i)) &&
43+
isnan(*(float *)(got + i)))
44+
continue;
45+
check_lsx_out(expected, got, len, fname, line);
46+
return;
47+
}
48+
}
49+
2850
#endif

0 commit comments

Comments
 (0)