added asm/div64.h compatibility header so comedi can use 64 bit integer division
authorFrank Mori Hess <fmhess@speakeasy.net>
Sat, 9 Mar 2002 03:54:52 +0000 (03:54 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sat, 9 Mar 2002 03:54:52 +0000 (03:54 +0000)
macro

include/asm/div64.h [new file with mode: 0644]

diff --git a/include/asm/div64.h b/include/asm/div64.h
new file mode 100644 (file)
index 0000000..778f61e
--- /dev/null
@@ -0,0 +1,63 @@
+/***************************************************************************
+                                  asm/div64.h
+                             -------------------
+
+
+    copyright            : (C) 2002 by Frank Mori Hess
+    email                : fmhess@users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef _DIV64_COMPAT_H
+#define _DIV64_COMPAT_H
+
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
+
+extern inline u64 my_ull_div(u64 numerator, unsigned long denominator)
+{
+       u32 value;
+       u64 remainder, temp, answer = 0;
+       unsigned int shift;
+       static const u32 max_u32 = 0xffffffff;
+
+       remainder = numerator;
+
+       while(remainder >= denominator)
+       {
+               shift = 0;
+               numerator = remainder;
+               // shift most significant bits into 32 bit variable
+               while(numerator > max_u32)
+               {
+                       numerator >>= 1;
+                       shift++;
+               }
+               value = numerator;
+               value /= denominator;
+               temp = ((u64) value) << shift;
+               answer += temp;
+               remainder -= temp * denominator;
+       }
+
+       return answer;
+}
+
+#define do_div(n, base) ((n) = my_ull_div(n, base))
+
+#else
+
+#include_next <asm/div64.h>
+
+#endif
+
+#endif // _DIV64_COMPAT_H