From owner-cvs-all Sun Sep 10 20:56: 3 2000 Delivered-To: cvs-all@freebsd.org Received: from gidora.zeta.org.au (gidora.zeta.org.au [203.26.10.25]) by hub.freebsd.org (Postfix) with SMTP id 5D3FB37B424 for ; Sun, 10 Sep 2000 20:55:53 -0700 (PDT) Received: (qmail 22757 invoked from network); 11 Sep 2000 03:55:44 -0000 Received: from unknown (HELO bde.zeta.org.au) (203.2.228.102) by gidora.zeta.org.au with SMTP; 11 Sep 2000 03:55:44 -0000 Date: Mon, 11 Sep 2000 14:55:41 +1100 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Doug Rabson Cc: John Baldwin , Doug Rabson , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/sys ktr.h In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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