This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] New numbers in the benchtests.


On 12/19/2017 12:54 PM, Joseph Myers wrote:
Here is a possible cause for the failures, not verified as such:

The exp implementation was using get_rounding_mode.  But tgamma uses
SET_RESTORE_ROUND and calls exp within the scope of SET_RESTORE_ROUND.
SET_RESTORE_ROUND, for x86_64, only sets the SSE rounding mode, but
get_rounding_mode gets the x87 rounding mode.  The effect would have been
that the code in exp found that the x87 rounding mode was not to-nearest,
then redundantly set the SSE rounding mode to to-nearest, then ended up
trying to restore the rounding mode and actually setting the SSE rounding
mode to the not-to-nearest value of the x87 rounding modes.

If this hypothesis is correct, I advise resubmitting the patch in a form
that just uses SET_RESTORE_ROUND (FE_TONEAREST) like other libm functions
- the performance improvement was sufficient that presumably even this
form would still perform better than the existing code.  Then, once that
is properly validated and checked in, it would be possible to restore the
optimization that the use of get_rounding_mode and separate code paths
were intended to achieve.  To do that, you'd need libc_fegetround{,f,l}
which by default just use get_rounding_mode, but on x86 __SSE2_MATH__ do
something different for the float and double versions to get the SSE
rounding mode instead; exp would use libc_fegetround instead of using
get_rounding_mode directly.


I did note in the comments (fairly far down) to the patch that
"For x86, tgamma showed a few values where the ulp increased to
6 (max ulp for tgamma is 5). Sparc tgamma did not show these failures."

As noted tgamma as currently computed is seriously non-linear in its
behavior with 1-bit differences in exp() likely to result in many-bit
differences in computed values. Nelson Beebe's recent (Aug 2017) book
"The Mathematical Function Computation Handbook" (over 1100 pgs) gives
an extended discussion of how to reduce the ulp diffs. But that's
beyond the scope of the current project.

I'll investigate Joseph's hypothesis.
If the hypothesis is correct, I find it odd for get_rounding_mode
to not have matching behavior with libc_fesetround for x86.

- patrick


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]