From owner-cvs-all Tue Nov 28 17:10:32 2000 Delivered-To: cvs-all@freebsd.org Received: from guru.mired.org (okc-65-26-235-186.mmcable.com [65.26.235.186]) by hub.freebsd.org (Postfix) with SMTP id D5B2237B401 for ; Tue, 28 Nov 2000 17:10:29 -0800 (PST) Received: (qmail 67345 invoked by uid 100); 29 Nov 2000 01:10:29 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14884.22405.22813.41567@guru.mired.org> Date: Tue, 28 Nov 2000 19:10:29 -0600 (CST) To: "Brian F. Feldman" Cc: cvs-all@freebsd.org Subject: Re: cvs commit: src/usr.sbin/inetd builtins.c In-Reply-To: <80189770@toto.iv> X-Mailer: VM 6.75 under 21.1 (patch 10) "Capitol Reef" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ X-Message: You should get a better mailer. Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Brian F. Feldman types: > Warner Losh wrote: > > In message <20001126182240.A8051@fw.wintelcom.net> Alfred Perlstein writes: > > : - if ((to.tv_usec += tv.tv_usec) >= 1000000) { > > : + to.tv_usec += tv.tv_usec; > > : + if (to.tv_usec >= 1000000) { > > : to.tv_usec -= 1000000; > > : to.tv_sec++; > > : } > > > > Shouldn't this be > > if (to.tv_usec >= 1000000) { > > to.tv_sec += to.tv_usec / 1000000; > > to.tv_usec %= 1000000; > > } > > I asked Poul-Henning the same thing with regard to similar checks in the > kernel code. The reply was that, although this is the "most correct" way of > doing things, a properly done calculation of to.tv_usec + tv.tv_usec in > this (and many other) case(s) will result in a maximum of 1999998, so at > most one subtraction and increment will be necessary. > > If it's not possible to have a higher tv_usec, you save the REALLY expensive > divide-family instructions. Does it make sense to be paranoid about this, and do: while (to.tv_usec >= 1000000) { to.tv_usec -= 1000000; to.tv_sec++; } Which costs one extra compare in the normal case, but insures that the value is right if the assumption happens to fail (but will do so slowly)?