This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: Builtins in `std'


On Wed, May 23, 2001 at 08:45:23AM -0700, Mark Mitchell wrote:
> >>>>> "Jason" == Jason Merrill <jason_merrill@redhat.com> writes:
> 
>     Jason> I agree that the current builtin handling is unfortunate.
>     Jason> But I'm not sure that moving it into the library is the
>     Jason> right path, as it creates yet another version lock between
>     Jason> library and compiler.
> 
> I don't understand this point.
> 
> The library already uses `__builtin_*' all over the place:
> 
>   namespaces std {
>   #if _GLIBCPP_HAVE___BUILTIN_FABS
>     inline double 
>     fabs(double __x) { return __builtin_fabs(__x); }
>   #else
>     extern "C" double fabs(double __x);
>   #endif
>   }
> 
> I want this code to still work, because I want us to still declare
> `::__builtin_fabs' which is safely out of the user namespace.  But, I
> want us to not declare `std::fabs' which is in the library namespace.
> I want to make it up to the V3 people to wire the latter to the
> former, as they've already done.

This way you have tight lock between g++ version and libstdc++, because if
g++ 3.1.5 decides to optimize std::foo then it has to wait until libstdc++
changes it headers.

> To be clear, I'm not proposing that the library open-code `fabs' in
> the optimal assembly code or anything like that; I just want to make
> the only builtins we declare in C++ be those that start with
> `__builtin'.

As I already wrote, this is especially bad in the global namespace, because
there the library has hard time to take care of all the global namespace
functions. Like:

#include <cstring>

using namespace std;

int foo ()
{
  return strchr ("abc", 'a') != 0;
}

will not be optimized while if it is replaced by std::strchr it will
(although as soon as those builtins are removed from std namespace
it will not be optimized either - only a very fraction of builtins have
the inline wrappers around __builtin functions even in the std:: namespace).

So I guess we should bother for C++ with the lazy builtins.

	Jakub


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