This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [PATCH] Define __NO_MATH_INLINES and __NO_STRING_INLINES


On Tue, May 25, 2004 at 10:42:52AM -0700, Zack Weinberg wrote:
> Ulrich Drepper <drepper@redhat.com> writes:
> 
> > Zack Weinberg wrote:
> >
> >> Go away and prove to me glibc isn't broken.  Then we can talk.
> >
> > I'm not the one who wants to change glibc. 
> 
> I'm not the one who's been refusing to post numbers since 1998.

And your numbers are where?
I did some benchmarking more than 2 years ago and the functions which were
in GCC handled better or as good as in glibc were changed in string2.h.
See http://sources.redhat.com/ml/libc-hacker/2001-11/msg00035.html and
http://sources.redhat.com/ml/libc-hacker/2002-01/msg00091.html

But if you want counterexamples:
a) the strcmp I posted in one of the previous mails (similarly strncmp)
b) e.g. strcspn.c below in x86-64 (glibc inline is 30% faster than gcc
   builtin)
c) strtok/strsep/strdup/strndup not handled at all by GCC
d) in mathinline.h on IA-32, looking just at double functions:
   __builtin_pow2 doesn't exist, __builtin_finite neither, nor
   __builtin_coshm1, __builtin_acosh1p, __builtin_sgn.
   For the remaining ones I have used a simplistic math.c below
   (built once without -D__NO_MATH_INLINES (GLIBC number) and
   once with -D__NO_MATH_INLINES (GCC number), in both cases -ffast-math):
		GLIBC	GCC
   sincos:	178	178
   tan:		181	203
   exp:		183	188
   expm1:	232	235
   atan2:	185	182
   fmod:	71	140
   sin:		128	128
   cos:		135	135
   log:		145	145
   log10:	145	211
   asin:	264	314
   acos:	269	322
   atan:	185	185
   sinh:	322	357
   cosh:	227	365
   tanh:	320	319
   floor:	103	125
   ceil:	103	125
   ldexp:	85	153
   rint:	75	75
   lrint:	71	71
   llrint:	87	87
   drem:	76	142

   This is just a quick hack, obviously don't consider this as a real
   benchmark usable for deciding.  But clearly while some functions are
   about equal speed (at which point they should be _GNUC_PREREQed, as
   GCC can do more magic in the future and/or handle constant arguments),
   but some are much faster in glibc inlines.

strcspn.c:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

# define HP_TIMING_NOW(Var) \
  ({ unsigned int _hi, _lo; \
     asm volatile ("rdtsc" : "=a" (_lo), "=d" (_hi)); \
     (Var) = ((unsigned long long int) _hi << 32) | _lo; })

size_t l;

void foo (const char *p)
{
  l = __builtin_strcspn (p, "ab");
}

void bar (const char *p)
{
  l = strcspn (p, "ab");
}

int main (void)
{
  unsigned long start, end, min;
  int i;
  min = ~0UL;
  for (i = 0; i < 50; ++i)
    {
      HP_TIMING_NOW (start);
      foo ("cdefghijklmnopqrstuvwxyade");
      HP_TIMING_NOW (end);
      end -= start;
      if (min > end)
        min = end;
    }
  printf ("GCC %ld\n", min);
  min = ~0UL;
  for (i = 0; i < 50; ++i)
    {
      HP_TIMING_NOW (start);
      bar ("cdefghijklmnopqrstuvwxyade");
      HP_TIMING_NOW (end);
      end -= start;
      if (min > end)
        min = end;
    }
  printf ("GLIBC %ld\n", min);
  return 0;
}

math.c:
#include <math.h>

#define HP_TIMING_NOW(Var)      __asm__ __volatile__ ("rdtsc" : "=A" (Var))

double s, c;

void foo (double d)
{
  s = __builtin_drem (d, 18.252);
/* or __builtin_sincos (d, &s, &c);, s = __builtin_log10 (d);, etc. */
}

void bar (double d)
{
  s = drem (d, 18.252);
}

int main (void)
{
  unsigned long long start, end, min;
  int i;
  min = ~0ULL;
  for (i = 0; i < 50; ++i)
    {
      HP_TIMING_NOW (start);
      foo (0.1451212);
      HP_TIMING_NOW (end);
      end -= start;
      if (min > end)
        min = end;
    }
  printf ("GCC %lld\n", min);
  min = ~0ULL;
  for (i = 0; i < 50; ++i)
    {
      HP_TIMING_NOW (start);
      bar (0.1451212);
      HP_TIMING_NOW (end);
      end -= start;
      if (min > end)
        min = end;
    }
  printf ("GLIBC %lld\n", min);
  return 0;
}

	Jakub


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