copy down from libkern:

>use p->hashfraction when doing non-time-critical calculations, rather than
>using HASHFRACTION directly.  in time-critical calculations, if HASHFRACTION
>is a power of two, check that p->hashfraction == HASHFRACTION and if so do
>the calculation with the compiled-in value so that the compiler can optimize
>out (potentially) expensive divisions.  if p->hashfraction != HASHFRACTION,
>actually do the division.  This has the result that on machines with slow
>division, the division can be optimized out of the common case, but that
>if HASHFRACTION changes from the compiled-in value (for whatever reason),
>profiling will still work.  Changes suggested by Chris Torek.
This commit is contained in:
cgd 1996-06-12 04:16:53 +00:00
parent 0396d19a02
commit e1078396e5

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcount.c,v 1.3 1995/03/28 20:01:02 jtc Exp $ */
/* $NetBSD: mcount.c,v 1.4 1996/06/12 04:16:53 cgd Exp $ */
/*-
* Copyright (c) 1983, 1992, 1993
@ -34,7 +34,11 @@
*/
#if !defined(lint) && !defined(_KERNEL) && defined(LIBC_SCCS)
#if 0
static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93";
#else
static char rcsid[] = "$NetBSD: mcount.c,v 1.4 1996/06/12 04:16:53 cgd Exp $";
#endif
#endif
#include <sys/param.h>
@ -87,7 +91,14 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
if (frompc > p->textsize)
goto done;
frompcindex = &p->froms[frompc / (p->hashfraction * sizeof(*p->froms))];
#if (HASHFRACTION & (HASHFRACTION - 1)) == 0
if (p->hashfraction == HASHFRACTION)
frompcindex =
&p->froms[frompc / (HASHFRACTION * sizeof(*p->froms))];
else
#endif
frompcindex =
&p->froms[frompc / (p->hashfraction * sizeof(*p->froms))];
toindex = *frompcindex;
if (toindex == 0) {
/*