Subject: Re: i386 uses slow clock routine with options NTP and options HZ=100
To: None <netbsd-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 03/16/1996 06:13:44
>> A divide by a constant (which essentially is what we have) can be
>> turned into a multiply.

> It's really not a 'divide by a constant', it's 'divide by a variable
> that doesn't change,' if HZ is not speicified via a #define.

A variable that doesn't change, isn't that a constant?

Not a compile-time constant, but still, you can afford for the first
hardclock after hz is changed to be expensive if it makes the rest
cheap.  I imagine it would read something like

static int lasthz = 0;
static unsigned int mul;

#ifdef DIVIDE_IS_FAST
	... something / hz ...
#else
	if (hz != lasthz) { mul = 0x100000000ULL / hz; lasthz = hz; }
	... (something * (u_quad_t)mul) >> 32 ...
#endif

(or if there's some better way to do a 32*32 multiply and save the
_high_ half of the result...).

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu