shibatch / sleef

SIMD Library for Evaluating Elementary Functions, vectorized libm and DFT
https://sleef.org
Boost Software License 1.0
637 stars 129 forks source link

problem about simd xexpfrexp #438

Open longbiao7498 opened 2 years ago

longbiao7498 commented 2 years ago

There seems to be something wrong with xexpfrexp. when input is 2.1445984715023983335e-308,the output of libm's frexp and scalr expfrexp of sleef is -1022 while simd expfrexp of sleef is -969. And the vector implementation of xexpfrexp is inconsistent with its scalar implementation. @shibatch Below is my fix:

EXPORT CONST VECTOR_CC vint xexpfrexp(vdouble x) {
  vopmask o = vlt_vo_vd_vd(vabs_vd_vd(x), vcast_vd_d(DBL_MIN));
  x = vsel_vd_vo_vd_vd(o, vmul_vd_vd_vd(x, vcast_vd_d((double)(UINT64_C(1) << 63))), x);

  vint ret = vcastu_vi_vi2(vreinterpret_vi2_vd(x));
  ret = vsub_vi_vi_vi(vand_vi_vi_vi(vsrl_vi_vi_i(ret, 20), vcast_vi_i(0x7ff)), vcast_vi_i(0x3fe));
  o = vcast_vo32_vo64(o);
  ret = vsel_vi_vo_vi_vi(o, vadd_vi_vi_vi(vcast_vi_i(-63), ret), ret);

  vopmask o1 = vor_vo_vo_vo(vor_vo_vo_vo(veq_vo_vd_vd(x, vcast_vd_d(0)), visnan_vo_vd(x)), visinf_vo_vd(x));
  o1 = vcast_vo32_vo64(o1);
  ret = vsel_vi_vo_vi_vi(o1, vcast_vi_i(0), ret);
  return ret;
}