public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* callgrind and sin/cos under GCC
@ 2012-09-11 14:57 Pete Flugstad
  2012-09-11 15:00 ` Andrew Haley
  0 siblings, 1 reply; 6+ messages in thread
From: Pete Flugstad @ 2012-09-11 14:57 UTC (permalink / raw)
  To: gcc-help

Hi,

   I'm trying to profile (using valgrind's callgrind) some code that
uses sin/cos and I'm seeing some things I'm not expecting.

  My OS is Ubuntu 12.04/x86_64, hardware is an Intel Xeon X5690.  GCC
is the distro version, gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1.  I'm
compiling with -O2.

  The strange thing is that I'm seeing sincos (from libm.so) is
showing up in the callgrind output.   From reading the manual, GCC
should replace our calls to sin and cos with __builtin_ versions,
right?   I'm not using -fno-builtin.

Thanks,
Pete

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

* Re: callgrind and sin/cos under GCC
  2012-09-11 14:57 callgrind and sin/cos under GCC Pete Flugstad
@ 2012-09-11 15:00 ` Andrew Haley
  2012-09-11 15:16   ` Markus Trippelsdorf
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Haley @ 2012-09-11 15:00 UTC (permalink / raw)
  To: pete.flugstad; +Cc: gcc-help

On 09/11/2012 03:56 PM, Pete Flugstad wrote:
> Hi,
> 
>    I'm trying to profile (using valgrind's callgrind) some code that
> uses sin/cos and I'm seeing some things I'm not expecting.
> 
>   My OS is Ubuntu 12.04/x86_64, hardware is an Intel Xeon X5690.  GCC
> is the distro version, gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1.  I'm
> compiling with -O2.
> 
>   The strange thing is that I'm seeing sincos (from libm.so) is
> showing up in the callgrind output.   From reading the manual, GCC
> should replace our calls to sin and cos with __builtin_ versions,
> right? 

Yes, it does, and one of the things that expanding the builtins does is
call sincos().

Andrew.

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

* Re: callgrind and sin/cos under GCC
  2012-09-11 15:00 ` Andrew Haley
@ 2012-09-11 15:16   ` Markus Trippelsdorf
  2012-09-11 15:18     ` Andrew Haley
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Trippelsdorf @ 2012-09-11 15:16 UTC (permalink / raw)
  To: Andrew Haley; +Cc: pete.flugstad, gcc-help

On 2012.09.11 at 16:00 +0100, Andrew Haley wrote:
> On 09/11/2012 03:56 PM, Pete Flugstad wrote:
> > Hi,
> > 
> >    I'm trying to profile (using valgrind's callgrind) some code that
> > uses sin/cos and I'm seeing some things I'm not expecting.
> > 
> >   My OS is Ubuntu 12.04/x86_64, hardware is an Intel Xeon X5690.  GCC
> > is the distro version, gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1.  I'm
> > compiling with -O2.
> > 
> >   The strange thing is that I'm seeing sincos (from libm.so) is
> > showing up in the callgrind output.   From reading the manual, GCC
> > should replace our calls to sin and cos with __builtin_ versions,
> > right? 
> 
> Yes, it does, and one of the things that expanding the builtins does is
> call sincos().

BTW, s_sincos.S was removed from glibc a while ago. So if you're running
a recent glibc version you end up with the slow floating-point sin/cos
implementation, that causes a 50% slowdown.
See: http://sourceware.org/bugzilla/show_bug.cgi?id=14412

However Intel has recently posted fast SSE sin/cos/sincos versions for
libm (sinf, cosf and sincosf). I think gcc should be updated to call
those instead. 

-- 
Markus

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

* Re: callgrind and sin/cos under GCC
  2012-09-11 15:16   ` Markus Trippelsdorf
@ 2012-09-11 15:18     ` Andrew Haley
  2012-09-11 16:31       ` Pete Flugstad
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Haley @ 2012-09-11 15:18 UTC (permalink / raw)
  To: Markus Trippelsdorf; +Cc: pete.flugstad, gcc-help

On 09/11/2012 04:15 PM, Markus Trippelsdorf wrote:
> On 2012.09.11 at 16:00 +0100, Andrew Haley wrote:
>> On 09/11/2012 03:56 PM, Pete Flugstad wrote:
>>> Hi,
>>>
>>>    I'm trying to profile (using valgrind's callgrind) some code that
>>> uses sin/cos and I'm seeing some things I'm not expecting.
>>>
>>>   My OS is Ubuntu 12.04/x86_64, hardware is an Intel Xeon X5690.  GCC
>>> is the distro version, gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1.  I'm
>>> compiling with -O2.
>>>
>>>   The strange thing is that I'm seeing sincos (from libm.so) is
>>> showing up in the callgrind output.   From reading the manual, GCC
>>> should replace our calls to sin and cos with __builtin_ versions,
>>> right? 
>>
>> Yes, it does, and one of the things that expanding the builtins does is
>> call sincos().
> 
> BTW, s_sincos.S was removed from glibc a while ago. So if you're running
> a recent glibc version you end up with the slow floating-point sin/cos
> implementation, that causes a 50% slowdown.
> See: http://sourceware.org/bugzilla/show_bug.cgi?id=14412
> 
> However Intel has recently posted fast SSE sin/cos/sincos versions for
> libm (sinf, cosf and sincosf). I think gcc should be updated to call
> those instead. 

Well, gcc will call whatever sincos is in the library.  If there's a faster
accurate way to do sincos(), glibc should do it.

Andrew.


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

* Re: callgrind and sin/cos under GCC
  2012-09-11 15:18     ` Andrew Haley
@ 2012-09-11 16:31       ` Pete Flugstad
  2012-09-11 16:47         ` Markus Trippelsdorf
  0 siblings, 1 reply; 6+ messages in thread
From: Pete Flugstad @ 2012-09-11 16:31 UTC (permalink / raw)
  To: Andrew Haley, Markus Trippelsdorf; +Cc: gcc-help

Markus wrote:
> BTW, s_sincos.S was removed from glibc a while ago. So if you're running
> a recent glibc version you end up with the slow floating-point sin/cos
> implementation, that causes a 50% slowdown.
> See: http://sourceware.org/bugzilla/show_bug.cgi?id=14412
>
> However Intel has recently posted fast SSE sin/cos/sincos versions for
> libm (sinf, cosf and sincosf). I think gcc should be updated to call
> those instead.

Correction on my part, we're using Ubuntu 11.10, which uses glibc 2.13.

So if I'm reading at the various ChangeLogs and BugZilla's correctly,
we should still have the s_sincos.S impl (we don't have large inputs,
so we're not seeing any problems).  This s_sincos.S calls fsincos (X87
instruction?).

The reason this came up is we were comparing the profiling results we
got under Visual Studio (using AMD Code Analyst) and while generally
the profiling was consistent, the call to sincos (and atan2) was
taking quite a bit more relative time than with Visual Studio.  So
we're basically digging to try and figure out why.

Would Intel's SSE2 version make any difference in this case?  (we're
using doubles, not floats).

Thanks,
Pete

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

* Re: callgrind and sin/cos under GCC
  2012-09-11 16:31       ` Pete Flugstad
@ 2012-09-11 16:47         ` Markus Trippelsdorf
  0 siblings, 0 replies; 6+ messages in thread
From: Markus Trippelsdorf @ 2012-09-11 16:47 UTC (permalink / raw)
  To: Pete Flugstad; +Cc: Andrew Haley, gcc-help

On 2012.09.11 at 11:30 -0500, Pete Flugstad wrote:
> Markus wrote:
> > BTW, s_sincos.S was removed from glibc a while ago. So if you're running
> > a recent glibc version you end up with the slow floating-point sin/cos
> > implementation, that causes a 50% slowdown.
> > See: http://sourceware.org/bugzilla/show_bug.cgi?id=14412
> >
> > However Intel has recently posted fast SSE sin/cos/sincos versions for
> > libm (sinf, cosf and sincosf). I think gcc should be updated to call
> > those instead.
> 
> Correction on my part, we're using Ubuntu 11.10, which uses glibc 2.13.
> 
> So if I'm reading at the various ChangeLogs and BugZilla's correctly,
> we should still have the s_sincos.S impl (we don't have large inputs,
> so we're not seeing any problems).  This s_sincos.S calls fsincos (X87
> instruction?).

Yes, it was removed in 2.16.

> The reason this came up is we were comparing the profiling results we
> got under Visual Studio (using AMD Code Analyst) and while generally
> the profiling was consistent, the call to sincos (and atan2) was
> taking quite a bit more relative time than with Visual Studio.  So
> we're basically digging to try and figure out why.
> 
> Would Intel's SSE2 version make any difference in this case?  (we're
> using doubles, not floats).

Doubles should be fine. Sinf and cosf are already available in the
current glibc git tree. So if you are willing to build glibc trunk of
today, you should be able to measure the difference for yourself,

-- 
Markus

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

end of thread, other threads:[~2012-09-11 16:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-11 14:57 callgrind and sin/cos under GCC Pete Flugstad
2012-09-11 15:00 ` Andrew Haley
2012-09-11 15:16   ` Markus Trippelsdorf
2012-09-11 15:18     ` Andrew Haley
2012-09-11 16:31       ` Pete Flugstad
2012-09-11 16:47         ` Markus Trippelsdorf

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).