Import 2.3.18pre1
[davej-history.git] / include / asm-alpha / delay.h
blobf60e9b5a755d013c7132185b7836c9880f4ffffd
1 #ifndef __ALPHA_DELAY_H
2 #define __ALPHA_DELAY_H
4 #include <asm/smp.h>
6 /*
7 * Copyright (C) 1993 Linus Torvalds
9 * Delay routines, using a pre-computed "loops_per_second" value.
12 extern __inline__ void
13 __delay(unsigned long loops)
15 register unsigned long r0 __asm__("$0") = loops;
16 #ifdef MODULE
17 __asm__ __volatile__("lda $28,___delay; jsr $28,($28),0"
18 : "=r"(r0) : "r"(r0) : "$28");
19 #else
20 __asm__ __volatile__("bsr $28,___delay" : "=r"(r0) : "r"(r0) : "$28");
21 #endif
25 * division by multiplication: you don't have to worry about
26 * loss of precision.
28 * Use only for very small delays ( < 1 msec). Should probably use a
29 * lookup table, really, as the multiplications take much too long with
30 * short delays. This is a "reasonable" implementation, though (and the
31 * first constant multiplications gets optimized away if the delay is
32 * a constant).
34 * Optimize small constants further by exposing the second multiplication
35 * to the compiler. In addition, mulq is 2 cycles faster than umulh.
38 extern __inline__ void
39 __udelay(unsigned long usecs, unsigned long lps)
41 /* compute (usecs * 2**64 / 10**6) * loops_per_sec / 2**64 */
43 usecs *= 0x000010c6f7a0b5edUL; /* 2**64 / 1000000 */
44 __asm__("umulh %1,%2,%0" :"=r" (usecs) :"r" (usecs),"r" (lps));
45 __delay(usecs);
48 extern __inline__ void
49 __small_const_udelay(unsigned long usecs, unsigned long lps)
51 /* compute (usecs * 2**32 / 10**6) * loops_per_sec / 2**32 */
53 usecs *= 0x10c6; /* 2^32 / 10^6 */
54 usecs *= lps;
55 usecs >>= 32;
56 __delay(usecs);
59 #ifdef __SMP__
60 #define udelay(usecs) \
61 (__builtin_constant_p(usecs) && usecs < 0x100000000UL \
62 ? __small_const_udelay(usecs, \
63 cpu_data[smp_processor_id()].loops_per_sec) \
64 : __udelay(usecs, \
65 cpu_data[smp_processor_id()].loops_per_sec))
66 #else
67 #define udelay(usecs) \
68 (__builtin_constant_p(usecs) && usecs < 0x100000000UL \
69 ? __small_const_udelay(usecs, loops_per_sec) \
70 : __udelay(usecs, loops_per_sec))
71 #endif
74 #endif /* defined(__ALPHA_DELAY_H) */