[PATCH] implement expm1() as built-in x87 intrinsics

Uros Bizjak uros@kss-loka.si
Fri Apr 30 07:48:00 GMT 2004


Hello!

Attached to this message, please find a patch, which implements expm1() 
as built-in x87 intrinsics. Patch was tested by bootstraping gcc on 
i686-pc-linux-gnu, tested with new tests in gcc.dg/builtins-34.c, and 
some random torture tests.

2004-04-30  Uros Bizjak  <uros@kss-loka.si>

        * optabs.h (enum optab_index): Add new OTI_expm1.
        (expm1_optab): Define corresponding macro.
        * optabs.c (init_optabs): Initialize expm1_optab.
        * genopinit.c (optabs): Implement expm1_optab using expm1?f2
        patterns.
        * builtins.c (expand_builtin_mathfn): Handle BUILT_IN_EXPM1{,F,L}
        using expm1_optab.
        (expand_builtin): Expand BUILT_IN_EXPM1{,F,L} using
        expand_builtin_mathfn if flag_unsafe_math_optimizations is set.

        * config/i386/i386.md (expm1df2, expm1sf2, expm1xf2): New expanders
        to implement expm1, expm1f and expm1l built-ins as inline x87
        intrinsics.

testsuite:

        * gcc.dg/builtins-34.c: Also check expm1*.


expm1?f2 patterns are modelled after assembly code in mathinline.h, but 
they skip final check of _temp (which could not be zero anyway). 
Anyway,  implemented expm1() has the same negative range as exp() 
intrinsic (~ -1.0e-300) , so this testcase:

--cut here--
int main() {
  double d = -4.123e300;
  float f = -4.123e300;
  long double ld = -4.123e320;

  printf("%f %f\n", expm1(d), exp(d)-1.0);
  printf("%f %f\n", expm1f(f), expf(f)-1.0f);
  printf("%Lf %Lf\n", expm1l(ld), expl(ld)-1.0f);

  return 0;
}
--cut here--

produces:
-1.000000 -1.000000
nan nan
nan nan

However, manpage says that "The value of expm1(x) may be more accurate  
than  exp(x)-1.0 for _small_ values of x.", and indeed, running above 
testcase for input parameters {d,f,ld} = -4.123e-100 produces:

-4.123e-100 0
0 0
-4.123e-100 0

OK to commit it to mainline CVS?

    Uros.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: expm1.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20040430/cbb5977f/attachment.ksh>


More information about the Gcc-patches mailing list