Skip to content

Commit

Permalink
[arm64] bug fix for fma and cast in checkrounding test
Browse files Browse the repository at this point in the history
  • Loading branch information
lathuili committed Feb 13, 2024
1 parent aeab80b commit b58a4c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
33 changes: 31 additions & 2 deletions unitTest/checkRounding/checkRounding.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,23 @@ class testInvariantProdDivm:public test<REALTYPE>{
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
Expand All @@ -413,12 +424,30 @@ class testInvariantProdDivm:public test<REALTYPE>{
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
Expand Down Expand Up @@ -654,7 +683,7 @@ class testCast:public test<REALTYPE,REALTYPEREF>{
}

REALTYPE compute(){
REALTYPEREF ref=0.1;
volatile REALTYPEREF ref=0.1;
return ((REALTYPE)ref);
}
};
Expand All @@ -670,7 +699,7 @@ class testCastm:public test<REALTYPE,REALTYPEREF>{
}

REALTYPE compute(){
REALTYPEREF ref=-0.1;
volatile REALTYPEREF ref=-0.1;
return ((REALTYPE)ref);
}
};
Expand Down
2 changes: 1 addition & 1 deletion unitTest/nocheckExemples/cast.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdlib>


#include <immintrin.h>
//#include <immintrin.h>
//#include <avxintrin_emu.h>
int main(int argc, char** argv){
double a;
Expand Down

0 comments on commit b58a4c5

Please sign in to comment.