public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/5781] New: Slow sine function for special values on AMD64 - second attempt
@ 2008-02-21  9:11 grugh at centrum dot cz
  2008-02-21  9:39 ` [Bug math/5781] " jakub at redhat dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: grugh at centrum dot cz @ 2008-02-21  9:11 UTC (permalink / raw)
  To: glibc-bugs

I would like to repost my previously deleted bug by (lazy IMHO)
carlos@codesoucery.com. The math sin function is at least 1000x slower on 64bit
distributions for special numbers (and carlos dosn't care about it). 
I can't try it with CVS head, because I cannot connect to cvs through our firewall.
But even when I tried the latest snapshot, I couldn't build it (maybe another bug):
a - elf/dl-vdso.os
: /home/inova/projects/glibc/build/libc_pic.a
gcc   -nostdlib -nostartfiles -r -o
/home/inova/projects/glibc/build/elf/librtld.map.o '-Wl,-('
/home/inova/projects/glibc/build/elf/dl-allobjs.os
/home/inova/projects/glibc/build/libc_pic.a -lgcc '-Wl,-)'
-Wl,-Map,/home/inova/projects/glibc/build/elf/librtld.mapT
/home/inova/projects/glibc/build/libc_pic.a(init-first.os):(.data+0x0): multiple
definition of `__libc_multiple_libcs'
/home/inova/projects/glibc/build/elf/dl-allobjs.os:/home/inova/projects/glibc/src/glibc-20080218/elf/rtld.c:641:
first defined here
/home/inova/projects/glibc/build/libc_pic.a(dl-addr.os): In function
`_dl_addr_inside_object':
/home/inova/projects/glibc/src/glibc-20080218/elf/dl-addr.c:158: multiple
definition of `_dl_addr_inside_object'
/home/inova/projects/glibc/build/elf/dl-allobjs.os:/home/inova/projects/glibc/src/glibc-20080218/elf/dl-open.c:700:
first defined here
collect2: ld returned 1 exit status
make[2]: *** [/home/inova/projects/glibc/build/elf/librtld.map] Error 1
make[2]: Leaving directory `/home/inova/projects/glibc/src/glibc-20080218/elf'
make[1]: *** [elf/subdir_lib] Error 2
make[1]: Leaving directory `/home/inova/projects/glibc/src/glibc-20080218'
make: *** [all] Error 2 

Please, anyone with 64bit distribution and glibc CVS head, could you try the
attached example and post the time results of it? (or help me to build the
snapshot...)
Thank you

====== Original bug report ======================================
The math sin(double) function is in 64bit distribution (Kubuntu 7.10 AMD64 and
Fedora - unknown version) unreasonable slow (~400 microseconds on Atlon64 X2
4800+!!!) for some special values. In 32bit distribution is everything fine.
I captured some of those values:
0.93340582292648832662962377071381  0x3fedde75e36bb000
2.3328432680770916363144351635128   0x4002a9a9bb38add0
3.7439477503636453548097051680088   0x400df39ae0cdf500
3.9225160069792437411706487182528   0x400f615012801950
4.0711651639931289992091478779912   0x401048df854fdc20
4.7858438478542097982426639646292   0x401324b43fe92fc0
5.9840767662578002727968851104379   0x4017efb1d1df52a0

Example:
#include <math.h>
int main(int argc, char** argv) {
    volatile double value = 0.93340582292648832662962377071381;
    volatile double out;
    int i;
    for (i=0; i < 20000; i++)
        out = sin(value);
    return 0;
}

-- 
           Summary: Slow sine function for special values on AMD64 - second
                    attempt
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
        AssignedTo: aj at suse dot de
        ReportedBy: grugh at centrum dot cz
                CC: glibc-bugs at sources dot redhat dot com
  GCC host triplet: x86_64-unknown-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=5781

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
  2008-02-21  9:11 [Bug math/5781] New: Slow sine function for special values on AMD64 - second attempt grugh at centrum dot cz
@ 2008-02-21  9:39 ` jakub at redhat dot com
  2008-02-21 17:10 ` joseph at codesourcery dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: jakub at redhat dot com @ 2008-02-21  9:39 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From jakub at redhat dot com  2008-02-21 09:39 -------
Most of the double routines in libm come from IBM accurate matematical library,
which ensures <= 0.5ulp error.  Trigonometric etc. functions are computed using
floating point computations, but if the possible error from that is too high, it 
uses slower multiprecision computation to guarantee ultimate precise result.
Guess you just picked some worst-case values.
i386 uses the non-precise hardware instructions instead, so doesn't guarantee
the <= 0.5ulp precision.



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://sourceware.org/bugzilla/show_bug.cgi?id=5781

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
  2008-02-21  9:11 [Bug math/5781] New: Slow sine function for special values on AMD64 - second attempt grugh at centrum dot cz
  2008-02-21  9:39 ` [Bug math/5781] " jakub at redhat dot com
@ 2008-02-21 17:10 ` joseph at codesourcery dot com
  2008-02-21 17:43 ` jakub at redhat dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: joseph at codesourcery dot com @ 2008-02-21 17:10 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From joseph at codesourcery dot com  2008-02-21 17:09 -------
Subject: Re:  Slow sine function for special values on AMD64
 - second attempt

On Thu, 21 Feb 2008, jakub at redhat dot com wrote:

> which ensures <= 0.5ulp error.  Trigonometric etc. functions are 
> computed using floating point computations, but if the possible error 
> from that is too high, it uses slower multiprecision computation to 
> guarantee ultimate precise result. Guess you just picked some worst-case 
> values.

Note that the crlibm developers were willing to contribute their code, an 
advantage of which is *much* better worst-case performance.



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=5781

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
  2008-02-21  9:11 [Bug math/5781] New: Slow sine function for special values on AMD64 - second attempt grugh at centrum dot cz
  2008-02-21  9:39 ` [Bug math/5781] " jakub at redhat dot com
  2008-02-21 17:10 ` joseph at codesourcery dot com
@ 2008-02-21 17:43 ` jakub at redhat dot com
  2008-02-22  9:01 ` grugh at centrum dot cz
  2008-07-14 14:17 ` grugh at centrum dot cz
  4 siblings, 0 replies; 13+ messages in thread
From: jakub at redhat dot com @ 2008-02-21 17:43 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From jakub at redhat dot com  2008-02-21 17:42 -------
Yeah, I'm aware of crlibm, I think if it proves itself that it won't be much
slower on average, has the same ultimate precision guarantees and faster
worst-cases, I don't see a reason why it can't be integrated.  It will be a lot
of work to integrate it though.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=5781

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
  2008-02-21  9:11 [Bug math/5781] New: Slow sine function for special values on AMD64 - second attempt grugh at centrum dot cz
                   ` (2 preceding siblings ...)
  2008-02-21 17:43 ` jakub at redhat dot com
@ 2008-02-22  9:01 ` grugh at centrum dot cz
  2008-07-14 14:17 ` grugh at centrum dot cz
  4 siblings, 0 replies; 13+ messages in thread
From: grugh at centrum dot cz @ 2008-02-22  9:01 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From grugh at centrum dot cz  2008-02-22 09:00 -------
Is there any compile flag or #define, which can disable the <=0.5 ulp precision
and the math sin function will use only the fast built-in fp intructions?
For our real-time software it is necessary to be "quick", the ultra precision
has low priority.
Now we are using a workaround: I can put the original argument to long double
variable and call sinl function with long double result. Both, the new argument
and the result, have to be volatile to disable the compiler optimization of it
(probably uses the "fast" sin instead).

Results of sin(0.93340582292648832662962377071381)
----------------------------------------------------
distr function    value                    result_type printf_format
--------------------------------------------------------------------
32 sin  0.80365140438773496889268699305831 double      "%.32g"
32 sinl 0.80365140438773496889268699305831 double      "%.32g"
32 sinl 0.80365140438773491338153576180048 long double "%.32Lg

64 sin  0.80365140438773485787038453054265 double      "%.32g"
 (~ -5.5511151231257827021181583404541e-17 difference from 80bit value)
64 sinl 0.80365140438773496889268699305831 double      "%.32g"
 (~ +5.5511151231257827021181583404541e-17 difference from 80bit value )
64 sinl 0.80365140438773491338153576180048 long double "%.32Lg"


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=5781

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
  2008-02-21  9:11 [Bug math/5781] New: Slow sine function for special values on AMD64 - second attempt grugh at centrum dot cz
                   ` (3 preceding siblings ...)
  2008-02-22  9:01 ` grugh at centrum dot cz
@ 2008-07-14 14:17 ` grugh at centrum dot cz
  4 siblings, 0 replies; 13+ messages in thread
From: grugh at centrum dot cz @ 2008-07-14 14:17 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From grugh at centrum dot cz  2008-07-14 14:16 -------
I'm not the only one with such problems:
http://sources.redhat.com/bugzilla/show_bug.cgi?id=5997
I assume that for the 64-bit distribution (x86_64), it should use sin and sinf
from i386 arch (sysdeps\i386\fpu\s_sin.S and sysdeps\i386\fpu\s_sinf.S) and only
sinl implementation is explicit x86_64. But the sin and sinf are now used as
software versions (IBM library). And it's usually bit slower, sometimes MUCH
MORE slower (1000x).
IBM library is perhaps only emergency implementation (if there is no hw support)
and it's not used for "better" (<= 0.5ULP) precision.
"The First Step is to Admit You Have a Problem!"

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


http://sourceware.org/bugzilla/show_bug.cgi?id=5781

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
       [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2014-02-06  7:40 ` john.wilkinson at spirent dot com
@ 2014-02-06 15:48 ` carlos at redhat dot com
  6 siblings, 0 replies; 13+ messages in thread
From: carlos at redhat dot com @ 2014-02-06 15:48 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=5781

Carlos O'Donell <carlos at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |carlos at redhat dot com

--- Comment #11 from Carlos O'Donell <carlos at redhat dot com> ---
(In reply to John Wilkinson from comment #9)
> I have also come across a very similar issue on i7 Intel platforms, please
> see bug 16531. Calls to cos can take around 0.15 ms, 1000 times their normal
> time, which is a serious problem for the real-time system we are developing.

The default libm functions never guarantee constant runtime. You will have this
same problem for many of the functions provided by the library.

However we are working on enhancing libm to include something like what you're
looking for. Please have look at and comment:
https://sourceware.org/glibc/wiki/libm

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
       [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2014-02-05 21:07 ` john.wilkinson at spirent dot com
@ 2014-02-06  7:40 ` john.wilkinson at spirent dot com
  2014-02-06 15:48 ` carlos at redhat dot com
  6 siblings, 0 replies; 13+ messages in thread
From: john.wilkinson at spirent dot com @ 2014-02-06  7:40 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=5781

--- Comment #10 from John Wilkinson <john.wilkinson at spirent dot com> ---
*** Bug 16531 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
       [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2013-12-03 18:40 ` jsm28 at gcc dot gnu.org
@ 2014-02-05 21:07 ` john.wilkinson at spirent dot com
  2014-02-06  7:40 ` john.wilkinson at spirent dot com
  2014-02-06 15:48 ` carlos at redhat dot com
  6 siblings, 0 replies; 13+ messages in thread
From: john.wilkinson at spirent dot com @ 2014-02-05 21:07 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=5781

John Wilkinson <john.wilkinson at spirent dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.wilkinson at spirent dot com

--- Comment #9 from John Wilkinson <john.wilkinson at spirent dot com> ---
I have also come across a very similar issue on i7 Intel platforms, please see
bug 16531. Calls to cos can take around 0.15 ms, 1000 times their normal time,
which is a serious problem for the real-time system we are developing.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
       [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2013-04-10  4:25 ` siddhesh at redhat dot com
@ 2013-12-03 18:40 ` jsm28 at gcc dot gnu.org
  2014-02-05 21:07 ` john.wilkinson at spirent dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2013-12-03 18:40 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=5781

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
       [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
  2012-02-29 20:20 ` jsm28 at gcc dot gnu.org
  2013-04-01 12:54 ` siddhesh at redhat dot com
@ 2013-04-10  4:25 ` siddhesh at redhat dot com
  2013-12-03 18:40 ` jsm28 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: siddhesh at redhat dot com @ 2013-04-10  4:25 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=5781

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |ASSIGNED
         AssignedTo|unassigned at sourceware    |siddhesh at redhat dot com
                   |dot org                     |

--- Comment #8 from Siddhesh Poyarekar <siddhesh at redhat dot com> 2013-04-10 04:25:05 UTC ---
Opening this since I've been working on improvements to the multiple precision
bits that should have positive effect here.  In fact as I mentioned in comment
7, improvements are already evident.

Since optimization patches can go on forever, I'm going to put a cap on it for
the resolution of this bug.  The cap is to implement findings of [1] if
applicable.

[1] http://perso.ens-lyon.fr/jean-michel.muller/TMDworstcases.pdf

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
       [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
  2012-02-29 20:20 ` jsm28 at gcc dot gnu.org
@ 2013-04-01 12:54 ` siddhesh at redhat dot com
  2013-04-10  4:25 ` siddhesh at redhat dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: siddhesh at redhat dot com @ 2013-04-01 12:54 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=5781

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |siddhesh at redhat dot com

--- Comment #7 from Siddhesh Poyarekar <siddhesh at redhat dot com> 2013-04-01 12:54:41 UTC ---
FWIW, the function now runs much faster after the multiple precision
improvements.  The worst case is only about a 100 times slower now instead of
1000 times.

I've not looked yet, but I think there is a case for capping maximum precision
for worst case computation for sin (and all trigonometric functions) as well,
so this could get even better.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug math/5781] Slow sine function for special values on AMD64 - second attempt
       [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
@ 2012-02-29 20:20 ` jsm28 at gcc dot gnu.org
  2013-04-01 12:54 ` siddhesh at redhat dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2012-02-29 20:20 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=5781

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |SUSPENDED
         AssignedTo|aj at suse dot de           |unassigned at sourceware
                   |                            |dot org

--- Comment #6 from Joseph Myers <jsm28 at gcc dot gnu.org> 2012-02-29 20:19:32 UTC ---
Confirmed with current sources.  Suspending until a faster correctly rounding
implementation (such as that proposed in
http://gcc.gnu.org/ml/gcc/2012-02/msg00298.html ) is available as this is
probably not amenable to a simple local fix.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-02-06 15:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-21  9:11 [Bug math/5781] New: Slow sine function for special values on AMD64 - second attempt grugh at centrum dot cz
2008-02-21  9:39 ` [Bug math/5781] " jakub at redhat dot com
2008-02-21 17:10 ` joseph at codesourcery dot com
2008-02-21 17:43 ` jakub at redhat dot com
2008-02-22  9:01 ` grugh at centrum dot cz
2008-07-14 14:17 ` grugh at centrum dot cz
     [not found] <bug-5781-131@http.sourceware.org/bugzilla/>
2012-02-29 20:20 ` jsm28 at gcc dot gnu.org
2013-04-01 12:54 ` siddhesh at redhat dot com
2013-04-10  4:25 ` siddhesh at redhat dot com
2013-12-03 18:40 ` jsm28 at gcc dot gnu.org
2014-02-05 21:07 ` john.wilkinson at spirent dot com
2014-02-06  7:40 ` john.wilkinson at spirent dot com
2014-02-06 15:48 ` carlos at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).