This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: question on cmath (gcc 4.5.1)
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Neal Becker <ndbecker2 at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 21 Nov 2010 15:33:52 -0600
- Subject: Re: question on cmath (gcc 4.5.1)
- References: <ic4mt7$cl8$1@dough.gmane.org>
On Thu, Nov 18, 2010 at 8:20 PM, Neal Becker <ndbecker2@gmail.com> wrote:
> cmath has patterns like this (taking cos as an example):
>
> ?using ::cos;
>
> ?inline float
> ?cos(float __x)
> ?{ return __builtin_cosf(__x); }
>
> ?inline long double
> ?cos(long double __x)
> ?{ return __builtin_cosl(__x); }
>
> ?template<typename _Tp>
> ? ?inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? double>::__type
> ? ?cos(_Tp __x)
> ? ?{ return __builtin_cos(__x); }
>
> Do I understand correctly, that this means float, long double will use
> __builtin_cos(xxx), but plain double will not use __builtin_cos???
>
> I've tried tracing the generated code, and that's the way it looks. ?It
> appears to just call the cos function in glibc.
<cmath> is required to be compatible with <math.h>
Most <math.h> come from the C compiler/library.
So, plain cos() (for double) is whatever your C library provides.
That is what the top using-declaration is all about.
If you are using glibc, I believe it will ultimately use __builtin_cos
unless you tell the compiler not to.
>
> Is this correct and if so, would not __builtin_cos be faster?
>
>