Messages in this thread | | | Date | Tue, 18 Oct 2011 00:03:21 +0200 | From | Ingo Molnar <> | Subject | Re: Linux 3.1-rc9 |
| |
* Ingo Molnar <mingo@elte.hu> wrote:
> > > In particular we could try something like: > > > > > > (high*2^32 + low)/1e9 ~== ( high * (2^64/1e9) ) / 2^32 > > > > > > ... which reduces it all to a 64-bit multiplication (or two > > > 32-bit multiplications) with a known constant, at the cost of 1 > > > nsec imprecision of the result - but that's an OK approximation > > > in my opinion. > > > > > > > We can do much better than that with reciprocal multiplication. > > Yes, 2^64/1e9 is the reciprocal.
So basically, to extend on the pseudocode above, we could do the equivalent of:
/* 2^64/1e9: */ #define MAGIC 18446744073ULL
secs_fast = ((nsecs >> 32) * MAGIC) >> 32; secs_fast += (nsecs & 0xFFFFFFFF)/1000000000;
to get to the precise 'timeval.secs' field - these are all 32-bit operations: a 32-bit multiplication and a 32-bit division if i counted it right.
(Likewise we can get the remainder as well, for timeval.nsecs.)
So I think if we add 32-bit optimized reciprocal multiplication based timeval and timespec routines, we can change ktime_t to a simple scalar type on 64-bit and 32-bit architectures alike.
It would likely be faster as well: the 32-bit ktime operations are more complex than straightforward u64 operations.
Thomas, what do you think?
Thanks,
Ingo
| |