Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/mac68k/mac68k Eliminate more overhead in delay(); t...



details:   https://anonhg.NetBSD.org/src/rev/7420ba3ef58a
branches:  trunk
changeset: 473639:7420ba3ef58a
user:      scottr <scottr%NetBSD.org@localhost>
date:      Fri Jun 11 06:51:39 1999 +0000

description:
Eliminate more overhead in delay(); there's no point in doing the same
thing in both the calibrator function and the actual delay function.  At
this point, _delay() does all of the work, so we can garbage collect
dummy_delay() and make _delay() an alternate entry point for delay().

This results in a small (but measurable) improvement on the IIci.

diffstat:

 sys/arch/mac68k/mac68k/clock.c  |  50 ++++------------------------------------
 sys/arch/mac68k/mac68k/locore.s |  29 ++++++++++++++++++-----
 2 files changed, 27 insertions(+), 52 deletions(-)

diffs (139 lines):

diff -r 3cdd28a175a2 -r 7420ba3ef58a sys/arch/mac68k/mac68k/clock.c
--- a/sys/arch/mac68k/mac68k/clock.c    Fri Jun 11 01:44:47 1999 +0000
+++ b/sys/arch/mac68k/mac68k/clock.c    Fri Jun 11 06:51:39 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.37 1999/06/09 06:59:53 scottr Exp $        */
+/*     $NetBSD: clock.c,v 1.38 1999/06/11 06:51:39 scottr Exp $        */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -100,7 +100,6 @@
 #endif
 
 void   rtclock_intr __P((void));
-int    _delay __P((u_int));
 
 #define        DIFF19041970    2082844800
 #define        DIFF19701990    630720000
@@ -412,6 +411,8 @@
                    "to the PRAM on this system.\n");
 #endif
 }
+
+
 /*
  * The Macintosh timers decrement once every 1.2766 microseconds.
  * MGFH2, p. 180
@@ -419,52 +420,11 @@
 #define        CLK_RATE        12766
 
 #define        DELAY_CALIBRATE (0xffffff << 7) /* Large value for calibration */
-#define        LARGE_DELAY     0x40000         /* About 335 msec */
 
 u_int          delay_factor = DELAY_CALIBRATE;
 volatile int   delay_flag = 1;
 
-/*
- * delay(usec)
- *     Delay at least usec microseconds.
- *
- * The delay_factor is scaled up by a factor of 128 to avoid loss
- * of precision for small delays.
- */
-void
-delay(usec)
-       u_int usec;
-{
-       volatile u_int cycles;
-
-       if (usec > LARGE_DELAY)
-               cycles = ((usec + 127) >> 7) * delay_factor;
-       else
-               cycles = ((usec > 0 ? usec : 1) * delay_factor) >> 7;
-
-       (void)_delay(cycles);
-}
-
-static u_int   dummy_delay __P((u_int));
-/*
- * Dummy delay calibration.  Functionally identical to delay(), but
- * returns the number of times through the loop.
- */
-static u_int
-dummy_delay(usec)
-       u_int usec;
-{
-       volatile u_int cycles;
-
-       if (usec > LARGE_DELAY)
-               cycles = ((usec + 127) >> 7) * delay_factor;
-       else
-               cycles = ((usec > 0 ? usec : 1) * delay_factor) >> 7;
-
-       cycles = _delay(cycles);
-       return ((delay_factor >> 7) - cycles);
-}
-
+int            _delay __P((u_int));
 static void    delay_timer1_irq __P((void *));
 
 static void
@@ -500,7 +460,7 @@
                delay_flag = 1;
                via_reg(VIA1, vT1C) = 0;        /* 1024 clock ticks */
                via_reg(VIA1, vT1CH) = 4;       /* (approx 1.3 msec) */
-               sum += dummy_delay(1);
+               sum += ((delay_factor >> 7) - _delay(1));
        }
 
        /* Disable timer interrupts and reset service routine */
diff -r 3cdd28a175a2 -r 7420ba3ef58a sys/arch/mac68k/mac68k/locore.s
--- a/sys/arch/mac68k/mac68k/locore.s   Fri Jun 11 01:44:47 1999 +0000
+++ b/sys/arch/mac68k/mac68k/locore.s   Fri Jun 11 06:51:39 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.s,v 1.116 1999/06/09 15:34:08 scottr Exp $      */
+/*     $NetBSD: locore.s,v 1.117 1999/06/11 06:51:39 scottr Exp $      */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -1491,7 +1491,12 @@
        rts
 
 /*
- * Low-level microsecond delay helper
+ * delay() - delay for a specified number of microseconds
+ * _delay() - calibrator helper for delay()
+ *
+ * Notice that delay_factor is scaled up by a factor of 128 to avoid loss
+ * of precision for small delays.  As a result of this we need to avoid
+ * overflow.
  *
  * The branch target for the loops must be aligned on a half-line (8-byte)
  * boundary to minimize cache effects.  This guarantees both that there
@@ -1499,11 +1504,21 @@
  * the loops will run from a single cache half-line.
  */
        .align  8                       | align to half-line boundary
-       nop                             | pad to align Ldelay
-       nop
-       nop
-ENTRY(_delay)
-       movl    sp@(4),d0               | get iterations
+                                       | (use nop instructions if necessary!)
+ALTENTRY(_delay, _delay)
+ENTRY(delay)
+       movl    sp@(4),d0               | get microseconds to delay
+       cmpl    #0x40000,d0             | is it a "large" delay?
+       bls     Ldelayshort             | no, normal calculation
+       movql   #0x7f,d1                | adjust for scaled multipler (to
+       addl    d1,d0                   |   avoid overflow)
+       lsrl    #7,d0
+       mulul   _C_LABEL(delay_factor),d0 | calculate number of loop iterations
+       bra     Ldelaysetup             | go do it!
+Ldelayshort:
+       mulul   _C_LABEL(delay_factor),d0 | calculate number of loop iterations
+       lsrl    #7,d0                   | adjust for scaled multiplier
+Ldelaysetup:
        jeq     Ldelayexit              | bail out if nothing to do
        movql   #0,d1                   | put bits 15-0 in d1 for the
        movw    d0,d1                   |   inner loop, and move bits



Home | Main Index | Thread Index | Old Index