svn commit: r270227 - head/sys/sys

Bruce Evans brde at optusnet.com.au
Thu Aug 21 03:50:56 UTC 2014


On Thu, 21 Aug 2014, Bruce Evans wrote:

> On Wed, 20 Aug 2014, Xin Li wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA512
>> 
>> On 08/20/14 09:32, Davide Italiano wrote:
>>> Author: davide Date: Wed Aug 20 16:32:02 2014 New Revision: 270227
>>> URL: http://svnweb.freebsd.org/changeset/base/270227
>>> 
>>> Log: Make Bruce happy removing the "LL abomination" from time.h
>>> It's not necessary in all the three instances because they already
>>> have the correct type on all the supported arches.
>> 
>> I'm not yet 100% sure (still building with some of my changes) but
>> this looks like the change that broke powerpc build, I saw:
>
> That is a compiler bug, or excessive compiler flags to force the compiler
> to be broken.  I thought that such compilers and/or flags went away.

[It is actually -std=c99 or clang that is needed to avoid the warning.]

>>> +184,7 @@ timespec2bintime(const struct timespec *
>>> 
>>> _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)18446744073; }
>>> ...
> Older parts used the uint64_t casts to get the correct type, but also
> used the long long abomination to avoid the warning, since this used
> to be necessary for gcc on i386.

I also wished for the correct fix of spelling the magic decimal numbers
non-magically and without a comment as is already done for some numbers
elsewhere in the file.  The magic 1844mumble is 2**64 obfuscated by spelling
it in decimal.  I can only remember what 2**N is in decimal up to N = 16
and calculate it easily up to N = 20.  2**64 is best written as
(uint65_t)1 << 64, but since most arches don't have uint65_t you can only
write 2**63 using as (uint64_t)1 << 63 this method.  Dividing by 2 is
easy and gives small or recognizable decimal constants:

 	/* No comment: */
 	_bt->frac = _ts->tv_nsec * (((uint64_t)1 << 63) / 500000000);

Strictly portable code also needs an L suffix on the 500000000, since
ints might be 16 bits and then 500000000 would be too large for an int
constant and compilers might gratuitously warn about this.  FreeBSD
doesn't need this since it only supports 32-bit ints.

Bruce


More information about the svn-src-head mailing list