From owner-freebsd-current@FreeBSD.ORG Sat Dec 15 09:01:16 2012 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0A542588; Sat, 15 Dec 2012 09:01:16 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail06.syd.optusnet.com.au (mail06.syd.optusnet.com.au [211.29.132.187]) by mx1.freebsd.org (Postfix) with ESMTP id 8D23C8FC12; Sat, 15 Dec 2012 09:01:14 +0000 (UTC) Received: from c122-106-175-26.carlnfd1.nsw.optusnet.com.au (c122-106-175-26.carlnfd1.nsw.optusnet.com.au [122.106.175.26]) by mail06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id qBF915ck029165 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 15 Dec 2012 20:01:06 +1100 Date: Sat, 15 Dec 2012 20:01:05 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Bruce Evans Subject: Re: [RFC/RFT] calloutng In-Reply-To: <20121215183409.U1603@besplex.bde.org> Message-ID: <20121215194819.C1778@besplex.bde.org> References: <20121215183409.U1603@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.0 cv=e5de0tV/ c=1 sm=1 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=mUAV9h2nInsA:10 a=fliXX_qwswpPfyGDAOYA:9 a=CjuIK1q_8ugA:10 a=bxQHXO5Py4tHmhUgaywp5w==:117 X-Mailman-Approved-At: Sat, 15 Dec 2012 12:27:43 +0000 Cc: Davide Italiano , freebsd-arch@FreeBSD.org, freebsd-current , Oliver Pinter X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Dec 2012 09:01:16 -0000 On Sat, 15 Dec 2012, Bruce Evans wrote: > On Fri, 14 Dec 2012, Oliver Pinter wrote: >> >> What is this 1844674407309000LL constant? > > This is > > 2**64 / 10**6 * 10**3 > > obfuscated by printing it in hex and doing the scaling by powers of > 10 manually, and then giving it a bogus type using the abominable long > long misfeature. I try to kill this obfuscation and the abimination > whenever I see them. In sys/time.h, this resulted in a related binary > conversion using a scale factor of > > ((uint64_t)1 << 63) / (1000000000 >> 1). > > Here the power of 2 term is 2**63. 2**64 cannot be used since it exceeds > uintmax_t. The power of 10 term is 10**9. This is divided by 2 to > compensate for dividing 2**64 by 2. The abomination is avoided by using > smaller literal values and expandling them to 64-bit values using shifts. Bah, this is only de-obfuscated and de-abominated in my version: % Index: time.h % =================================================================== % RCS file: /home/ncvs/src/sys/sys/time.h,v % retrieving revision 1.65 % diff -u -2 -r1.65 time.h % --- time.h 7 Apr 2004 04:19:49 -0000 1.65 % +++ time.h 7 Apr 2004 11:28:54 -0000 % @@ -118,6 +118,5 @@ % % bt->sec = ts->tv_sec; % - /* 18446744073 = int(2^64 / 1000000000) */ % - bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; % + bt->frac = ts->tv_nsec * (((uint64_t)1 << 63) / (1000000000 >> 1)); % } % The magic 1844... in time.h is at least commented on. This makes it less obscure, but takes twice as many source lines and risks the comment getting out of date with the code. The comment is also sloppy with types and uses the '^' operator without saying that it is exponentiation and nothing like the C '^' operator. The types are especially critical in the shift exprression. I like to use the Fortran '**' operator in C comments without saying what it is instead. In another reply to this thread, the value in the explanation is off by a factor of 1000 and the rounding to a multiple of 1000 is not explained. It is easy to have such errors in comments, while the code tends to be more correct since it gets checked by running it. Bruce