Skip to contentSkip to conversation

udelay

PATCH New Vivien Chappelier 1 participant 1 message Jan 13, 2003 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udelay

Hi,

The HZ constant has been changed in 2.5 and this breaks
udelay(). Here is a patch to fix this. Note that the first multiply in
udelay is still optimized out by the compiler if the delay is constant, as in current implementation.

Vivien.

asm-mips64/delay.h +5 -5
@@ -41,11 +41,11 @@
 {
 	unsigned long lo;
 
-#if (HZ == 100)
-	usecs *= 0x00068db8bac710cbUL;		/* 2**64 / (1000000 / HZ) */
-#elif (HZ == 128)
-	usecs *= 0x0008637bd05af6c6UL;		/* 2**64 / (1000000 / HZ) */
-#endif
+/* HZ * 2**64 / 1000000 */
+#define __UDELAY_FIXED64_HZ_1000000 (0x8000000000000000UL / (500000 / HZ)) 
+
+	usecs *= __UDELAY_FIXED64_HZ_1000000;
+
 	__asm__("dmultu\t%2,%3"
 		:"=h" (usecs), "=l" (lo)
 		:"r" (usecs),"r" (lpj));
asm-mips/delay.h +4 -5
@@ -40,11 +40,10 @@
 {
 	unsigned long lo;
 
-#if (HZ == 100)
-	usecs *= 0x00068db8;		/* 2**32 / (1000000 / HZ) */
-#elif (HZ == 128)
-	usecs *= 0x0008637b;		/* 2**32 / (1000000 / HZ) */
-#endif
+/* HZ * 2**32 / 1000000 */
+#define __UDELAY_FIXED32_HZ_1000000 (0x80000000UL / (500000 / HZ)) 
+
+	usecs *= __UDELAY_FIXED32_HZ_1000000;
 	__asm__("multu\t%2,%3"
 		:"=h" (usecs), "=l" (lo)
 		:"r" (usecs),"r" (lpj));