Skip to content

Commit

Permalink
Fix test_mm_dp_pd failure when compiling with -O2 (#643)
Browse files Browse the repository at this point in the history
The test_mm_dp_pd failed when running "make check" with -O2 passed to
ARCH_CFLAGS. Debug investigation revealed that a buffer initialized with
floats was being  cast to a buffer of doubles. The test failure occurred
due to differences  between the dot product obtained with intrinsics and
the one calculated with C++ doubles. This discrepancy arose because the
numbers were too large, causing rounding errors in the dot product
calculation.

Co-authored-by: Alexander Orlov <aorlov@aligntech.com>
  • Loading branch information
alexorlov124 and Alexander Orlov committed Jul 25, 2024
1 parent 200cd4e commit 1a854ed
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8384,22 +8384,24 @@ result_t test_mm_cvtepu8_epi64(const SSE2NEONTestImpl &impl, uint32_t iter)
return validateInt64(ret, i0, i1);
}

#define MM_DP_PD_TEST_CASE_WITH(imm8) \
do { \
const double *_a = (const double *) impl.mTestFloatPointer1; \
const double *_b = (const double *) impl.mTestFloatPointer2; \
const int imm = imm8; \
double d[2]; \
double sum = 0; \
for (size_t i = 0; i < 2; i++) \
sum += ((imm) & (1 << (i + 4))) ? _a[i] * _b[i] : 0; \
for (size_t i = 0; i < 2; i++) \
d[i] = (imm & (1 << i)) ? sum : 0; \
__m128d a = load_m128d(_a); \
__m128d b = load_m128d(_b); \
__m128d ret = _mm_dp_pd(a, b, imm); \
if (validateDouble(ret, d[0], d[1]) != TEST_SUCCESS) \
return TEST_FAIL; \
#define MM_DP_PD_TEST_CASE_WITH(imm8) \
do { \
const double _a[] = {impl.mTestFloatPointer1[0], \
impl.mTestFloatPointer1[1]}; \
const double _b[] = {impl.mTestFloatPointer2[0], \
impl.mTestFloatPointer2[1]}; \
const int imm = imm8; \
double d[2] = {0}; \
double sum = 0; \
for (size_t i = 0; i < 2; i++) \
sum += ((imm) & (1 << (i + 4))) ? _a[i] * _b[i] : 0; \
for (size_t i = 0; i < 2; i++) \
d[i] = (imm & (1 << i)) ? sum : 0; \
__m128d a = load_m128d(_a); \
__m128d b = load_m128d(_b); \
__m128d ret = _mm_dp_pd(a, b, imm); \
if (validateDouble(ret, d[0], d[1]) != TEST_SUCCESS) \
return TEST_FAIL; \
} while (0)

#define GENERATE_MM_DP_PD_TEST_CASES \
Expand Down

0 comments on commit 1a854ed

Please sign in to comment.