From owner-cvs-all Mon Sep 11 1:51:30 2000 Delivered-To: cvs-all@freebsd.org Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by hub.freebsd.org (Postfix) with ESMTP id 6D91A37B423; Mon, 11 Sep 2000 01:51:25 -0700 (PDT) Received: from nlsys.demon.co.uk ([158.152.125.33] helo=herring.nlsystems.com) by anchor-post-31.mail.demon.net with esmtp (Exim 2.12 #1) id 13YPJC-000Bgh-0V; Mon, 11 Sep 2000 09:51:24 +0100 Received: from salmon.nlsystems.com (salmon.nlsystems.com [10.0.0.3]) by herring.nlsystems.com (8.9.3/8.8.8) with ESMTP id JAA02976; Mon, 11 Sep 2000 09:52:09 +0100 (BST) (envelope-from dfr@nlsystems.com) Date: Mon, 11 Sep 2000 09:51:44 +0100 (BST) From: Doug Rabson To: Bruce Evans 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, Bruce Evans wrote: > 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). Not this one. With the modulus, the code sequence was something like: addl t1, 0x1, t1 lda t0, 1023(t1) cmovge t1, t1, t0 sra t0, 0xa, t0 sll t0, 0xa, t0 subl t1, t0, t1 and with logical and: lda t4, 1023(zero) addq t0, 0x1, t0 and t0, t4, t0 Also, the compiler managed to mix several other instructions into this sequence which probably improved pipelining significantly > > > 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. The KTR_EXTEND ones are very slow but the non-extended ones are a bit more reasonable. -- Doug Rabson Mail: dfr@nlsystems.com Nonlinear Systems Ltd. Phone: +44 20 8348 3944 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message