This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


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

Re: Should we optimize memset to bzero?


On Fri, Nov 02, 2001 at 05:51:03PM +0100, Jakub Jelinek wrote:
> On Fri, Nov 02, 2001 at 08:44:06AM -0800, H . J . Lu wrote:
> > On Fri, Nov 02, 2001 at 05:38:00PM +0100, Jakub Jelinek wrote:
> > > On Fri, Nov 02, 2001 at 08:28:49AM -0800, H . J . Lu wrote:
> > > > Should we optimize memset to bzero? Like
> > > > 
> > > > #define memset(s, c, n) \
> > > > (__extension__ ((__builtin_constant_p (c) && (c) == 0) \
> > > > 		? __bzero ((s), (n)) : __memset ((s), (c), (n)))
> > > 
> > > And we don't? Look at bits/string2.h...
> > 
> > We do? Try this
> > 
> > --s.c--
> > #include <string.h>
> > 
> > void
> > foo (char *x, int l)
> > {
> >   memset (x, 0, l);
> > }
> > ---
> > 
> > # gcc -O2 -S s.c
> > 
> > BTW, in many cases, gcc won't inline those string/memory functions.
> 
> Well, the thing is that glibc further optimizes __bzero(s,n) with
> __builtin_memset(s,0,n); which often generates better code.
> But, teaching gcc that it can use __bzero is difficult, since __bzero
> is not part of any standard.

Do we have any ideas when gcc will inline __builtin_memset(s,0,n)? I don't
believe gcc will inline it if `n' is not a small constant. Can we guess what
that small constant is?



H.J.


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