Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Aug 2014 13:50:50 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        Davide Italiano <davide@freebsd.org>, svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, d@delphij.net
Subject:   Re: svn commit: r270227 - head/sys/sys
Message-ID:  <20140821133529.J1207@besplex.bde.org>
In-Reply-To: <20140821063422.P11841@besplex.bde.org>
References:  <201408201632.s7KGW2vF093636@svn.freebsd.org> <53F4FA1E.2000103@delphij.net> <20140821063422.P11841@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140821133529.J1207>