[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/sys/kern
> On Fri, Jan 16, 2009 at 10:58:41AM +0200, Alan Barrett wrote:
> > On Fri, 16 Jan 2009, YAMAMOTO Takashi wrote:
> > > cache_prune: use (a - b > 0) rather than (a > b) to compare ticks.
> > Why? At first glance, both tests do the same thing.
> > Both the variables are signed int, so there could be cases where a-b is
> > undefined while a>b is defined. Is this likely to be a problem, or are
> > the actual ranges of the variables such that overflow can't happen?
> Probably because thay are actually modulo 2^32 values, so if the
> 'old' value is 0x7fffffff and the 'new' 0x80000001 you want the
> difference of 'new - old' > 0 (2 > 0) being true not 'new > old'
> which is false.
> Of course you need to use unsigned ints for modulo arithmetic because
> C allows i++ to saturate for integers.
> (Then you need to cast the result of the subtract to signed ...)
i always keep forgetting that the behaviour of integer overflow
is undefined. :)
hardclock_ticks itself is updated with wrapv semantics...
> David Laight: david%l8s.co.uk@localhost
Main Index |
Thread Index |