From b58a4c5c369189b5554a84720bec0af89872317b Mon Sep 17 00:00:00 2001 From: Bruno LATHUILIERE Date: Tue, 13 Feb 2024 11:42:51 +0100 Subject: [PATCH] [arm64] bug fix for fma and cast in checkrounding test --- unitTest/checkRounding/checkRounding.cxx | 33 ++++++++++++++++++++++-- unitTest/nocheckExemples/cast.cxx | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/unitTest/checkRounding/checkRounding.cxx b/unitTest/checkRounding/checkRounding.cxx index 4bcff9c1..645b1f99 100644 --- a/unitTest/checkRounding/checkRounding.cxx +++ b/unitTest/checkRounding/checkRounding.cxx @@ -397,12 +397,23 @@ class testInvariantProdDivm:public test{ inline double myFma(const double& a, const double& b, const double& c){ double d; #ifdef TEST_FMA +#if defined(__X86_64__) __m128d ai, bi,ci,di; ai = _mm_load_sd(&a); bi = _mm_load_sd(&b); ci = _mm_load_sd(&c); di=_mm_fmadd_sd(ai,bi,ci); d=_mm_cvtsd_f64(di); +#elif defined(__aarch64__) + const float64x1_t ai=vld1_f64(&a); + const float64x1_t bi=vld1_f64(&b); + const float64x1_t ci=vld1_f64(&c); + const float64x1_t di=vfma_f64(ci,ai,bi);// warning strange argument order + // cf doc : https://developer.arm.com/architectures/instruction-set/intrinsics/#q=vfma + vst1_f64(&d, di); +#else +#error "notyet implemented for this architecture" +#endif #else d=a*b+c; #endif @@ -413,12 +424,30 @@ class testInvariantProdDivm:public test{ inline float myFma(const float& a, const float& b, const float& c){ float d; #ifdef TEST_FMA +#if defined(__X86_64__) __m128 ai, bi,ci,di; ai = _mm_load_ss(&a); bi = _mm_load_ss(&b); ci = _mm_load_ss(&c); di=_mm_fmadd_ss(ai,bi,ci); d=_mm_cvtss_f32(di); +#elif defined(__aarch64__) + float av[2]={a,0}; + float bv[2]={b,0}; + float cv[2]={c,0}; + + float32x2_t ap=vld1_f32(av); + float32x2_t bp=vld1_f32(bv); + float32x2_t cp=vld1_f32(cv); + + float32x2_t resp= vfma_f32(cp,ap,bp); // warning strange argument order + // cf doc : https://developer.arm.com/architectures/instruction-set/intrinsics/#q=vfma + float res[2]; + vst1_f32(res, resp); + d=res[0]; +#else +#error "notyet implemented for this architecture" +#endif #else d=a*b+c; #endif @@ -654,7 +683,7 @@ class testCast:public test{ } REALTYPE compute(){ - REALTYPEREF ref=0.1; + volatile REALTYPEREF ref=0.1; return ((REALTYPE)ref); } }; @@ -670,7 +699,7 @@ class testCastm:public test{ } REALTYPE compute(){ - REALTYPEREF ref=-0.1; + volatile REALTYPEREF ref=-0.1; return ((REALTYPE)ref); } }; diff --git a/unitTest/nocheckExemples/cast.cxx b/unitTest/nocheckExemples/cast.cxx index ebac9a87..6cba03ec 100644 --- a/unitTest/nocheckExemples/cast.cxx +++ b/unitTest/nocheckExemples/cast.cxx @@ -3,7 +3,7 @@ #include -#include +//#include //#include int main(int argc, char** argv){ double a;