diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2019-07-19 14:50:44 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2019-07-19 14:50:44 +0000 |
commit | 83fcd37b2d4bd05d3b1511c3e7cba5216bc18926 (patch) | |
tree | a49ce3c50424ab6fc0303146e7ff0f4a6a37249f /sys/arch/amd64/isa | |
parent | 5c6807606e22eb02b379bdd08c9b8376d0632053 (diff) |
i8254_delay(): simplify tick computation
Back in the mid-90s these optimizations probably made sense, but
these days the compiler will produce even better code if we just
explicitly use 64-bit math and do the obvious thing.
joerg@netbsd.org even popped in on tech@ to agree.
ok guenther@
Diffstat (limited to 'sys/arch/amd64/isa')
-rw-r--r-- | sys/arch/amd64/isa/clock.c | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/sys/arch/amd64/isa/clock.c b/sys/arch/amd64/isa/clock.c index c355b258816..203882d5e1d 100644 --- a/sys/arch/amd64/isa/clock.c +++ b/sys/arch/amd64/isa/clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clock.c,v 1.29 2019/05/23 19:00:52 jasper Exp $ */ +/* $OpenBSD: clock.c,v 1.30 2019/07/19 14:50:43 cheloha Exp $ */ /* $NetBSD: clock.c,v 1.1 2003/04/26 18:39:50 fvdl Exp $ */ /*- @@ -187,9 +187,9 @@ rtcintr(void *arg) u_int stat = 0; /* - * If rtcintr is 'late', next intr may happen immediately. - * Get them all. (Also, see comment in cpu_initclocks().) - */ + * If rtcintr is 'late', next intr may happen immediately. + * Get them all. (Also, see comment in cpu_initclocks().) + */ while (mc146818_read(NULL, MC_REGC) & MC_REGC_PF) { statclock(frame); stat = 1; @@ -242,31 +242,8 @@ i8254_delay(int n) if (n <= 25) n = delaytab[n]; else { -#ifdef __GNUC__ - /* - * Calculate ((n * TIMER_FREQ) / 1e6) using explicit assembler - * code so we can take advantage of the intermediate 64-bit - * quantity to prevent loss of significance. - */ - int m; - __asm volatile("mul %3" - : "=a" (n), "=d" (m) - : "0" (n), "r" (TIMER_FREQ)); - __asm volatile("div %4" - : "=a" (n), "=d" (m) - : "0" (n), "1" (m), "r" (1000000)); -#else - /* - * Calculate ((n * TIMER_FREQ) / 1e6) without using floating - * point and without any avoidable overflows. - */ - int sec = n / 1000000, - usec = n % 1000000; - n = sec * TIMER_FREQ + - usec * (TIMER_FREQ / 1000000) + - usec * ((TIMER_FREQ % 1000000) / 1000) / 1000 + - usec * (TIMER_FREQ % 1000) / 1000000; -#endif + /* Force 64-bit math to avoid 32-bit overflow if possible. */ + n = (int64_t)n * TIMER_FREQ / 1000000; } limit = TIMER_FREQ / hz; |