This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: calloc = malloc + memset
- From: Andi Kleen <andi at firstfloor dot org>
- To: Marc Glisse <marc dot glisse at inria dot fr>
- Cc: Andi Kleen <andi at firstfloor dot org>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 23 Jun 2014 21:37:50 +0200
- Subject: Re: calloc = malloc + memset
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1402282337290 dot 27023 at stedding dot saclay dot inria dot fr> <874mzb8p84 dot fsf at tassilo dot jf dot intel dot com> <alpine dot DEB dot 2 dot 10 dot 1406232053390 dot 2057 at laptop-mg dot saclay dot inria dot fr>
On Mon, Jun 23, 2014 at 09:00:02PM +0200, Marc Glisse wrote:
> On Mon, 23 Jun 2014, Andi Kleen wrote:
>
> >FWIW i believe the transformation will break a large variety of micro benchmarks.
> >
> >calloc internally knows that memory fresh from the OS is zeroed.
> >But the memory may not be faulted in yet.
> >
> >memset always faults in the memory.
> >
> >So if you have some test like
> >
> > buf = malloc(...)
> > memset(buf, ...)
> > start = get_time();
> > ... do something with buf
> > end = get_time()
> >
> >Now the times will be completely off because the measured times includes
> >the page faults.
>
> Good point. I guess working around compiler optimizations is part of
> the game for micro benchmarks, and their authors would be
> disappointed if the compiler didn't mess it up regularly in new and
> entertaining ways ;-)
I would prefer to not do it. I'm not sure it has a lot of benefit.
If you want to keep it please make sure there is an easy way to turn
it off.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.