Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Sep 2000 14:55:41 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Doug Rabson <dfr@nlsystems.com>
Cc:        John Baldwin <jhb@pike.osd.bsdi.com>, Doug Rabson <dfr@FreeBSD.org>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/sys ktr.h
Message-ID:  <Pine.BSF.4.21.0009111415320.450-100000@besplex.bde.org>
In-Reply-To: <Pine.BSF.4.21.0009110030070.49106-100000@salmon.nlsystems.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 11 Sep 2000, Doug Rabson wrote:

> On Sun, 10 Sep 2000, John Baldwin wrote:
> 
> > Doug Rabson wrote:
> > > dfr         2000/09/10 07:36:55 PDT
> > > 
> > >   Modified files:
> > >     sys/sys              ktr.h 
> > >   Log:
> > >   Use '&' instead of '%' to calculate the new value for ktr_idx.
> > 
> > Err, it isn't guaranteed that KTR_ENTRIES will be a power of 2.  If
> > it is, gcc should be optimizing the mod to a binary and though.
> 
> As I mentioned to Brian, it can only reduce to a binary and if the numbers
> are known to be non-negative.

gcc reduces divisions and moduluses by a (constant) power of 2 to shifts
and masks fairly well even for signed operations (except possibly for
quad operations).

> Possibly changing the declaration of ktr_idx
> to an unsigned int would be enough but practically speaking, a non-power
> of 2 value for KTR_ENTRIES would be a disaster for performance.

I usually use `%' for modulus operations, and the cast the divisor (never
the dividend) to suitable unsigned type if this would help when the divisor
is a power of 2.  Exception: gcc doesn't optimize quads very well, so
use `&', and maybe cast the dividend to unsigned so that the result is
unsigned.

The ktr macros are inefficient, so another division wouldn't be much more
of a disaster for performance.

Bruce



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0009111415320.450-100000>