From 3887d846932fbbc97c9278b94bf66081e8debe40 Mon Sep 17 00:00:00 2001 From: Aaron En Ye Shi Date: Wed, 9 Dec 2020 19:32:42 +0000 Subject: [PATCH] Fix hipTestFMA to support older compiler The older compiler does not promote integral arguments to double, instead it uses float. This patch tries to support the old compiler headers, and also the newer one. Change-Id: I01e0b96a82ecddc6230cb5baf2573a318b25445b [ROCm/clr commit: d432615faa467816faaf6ac387628fd6d0c20880] --- .../hipamd/tests/src/deviceLib/hipTestFMA.cpp | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/projects/clr/hipamd/tests/src/deviceLib/hipTestFMA.cpp b/projects/clr/hipamd/tests/src/deviceLib/hipTestFMA.cpp index 9849d0271e..e18712d966 100644 --- a/projects/clr/hipamd/tests/src/deviceLib/hipTestFMA.cpp +++ b/projects/clr/hipamd/tests/src/deviceLib/hipTestFMA.cpp @@ -43,19 +43,38 @@ THE SOFTWARE. double doubleResult = fma(d, d, 3.0); Check(floatResult != doubleResult); - // To align with libcxx, if any argument has integral type, - // it is cast to double. - // Check type promotes to double. - Check(fma(f, f, 3) == doubleResult); - Check(fma(f, f, (char)3) == doubleResult); - Check(fma(f, f, (unsigned char)3) == doubleResult); - Check(fma(f, f, (short)3) == doubleResult); - Check(fma(f, f, (unsigned short)3) == doubleResult); - Check(fma(f, f, (int)3) == doubleResult); - Check(fma(f, f, (unsigned int)3) == doubleResult); - Check(fma(f, f, (long)3) == doubleResult); - Check(fma(f, f, (unsigned long)3) == doubleResult); - Check(fma(f, f, true) == fma((double)f, (double)f, 1.0)); + if(sizeof(decltype(fma(f, f, 3))) == 8) { + // To align with libcxx, if any argument has integral type, + // it is cast to double. + // Check type promotes to double. + Check(fma(f, f, 3) == doubleResult); + Check(fma(f, f, (char)3) == doubleResult); + Check(fma(f, f, (unsigned char)3) == doubleResult); + Check(fma(f, f, (short)3) == doubleResult); + Check(fma(f, f, (unsigned short)3) == doubleResult); + Check(fma(f, f, (int)3) == doubleResult); + Check(fma(f, f, (unsigned int)3) == doubleResult); + Check(fma(f, f, (long)3) == doubleResult); + Check(fma(f, f, (unsigned long)3) == doubleResult); + Check(fma(f, f, true) == fma((double)f, (double)f, 1.0)); + } else if(sizeof(decltype(fma(f, f, 3))) == 4) { + // Previous HIP headers returns float type. + // Delete this to support backwards compatibility. + // check promote to float. + Check(fma(f, f, 3) == floatResult); + Check(fma(f, f, (char)3) == floatResult); + Check(fma(f, f, (unsigned char)3) == floatResult); + Check(fma(f, f, (short)3) == floatResult); + Check(fma(f, f, (unsigned short)3) == floatResult); + Check(fma(f, f, (int)3) == floatResult); + Check(fma(f, f, (unsigned int)3) == floatResult); + Check(fma(f, f, (long)3) == floatResult); + Check(fma(f, f, (unsigned long)3) == floatResult); + Check(fma(f, f, true) == fma(f, f, 1.0f)); + } else { + assert(0 && "Invalid fma return type."); + } + Check(fma(d, (double)f, 3) == doubleResult); Check(fma(d, (double)f, (char)3) == doubleResult); Check(fma(d, (double)f, (unsigned char)3) == doubleResult);