Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Kernel v2.5.75 /lib/div64.c

Filename:/lib/div64.c
Lines Added:52
Lines Deleted:0
Also changed in: (Previous) 2.5.74-bk7  2.5.74-bk6  2.5.74-bk5 
(Following)

Location
[  2.5.75
  [  lib
     o  div64.c

Patch

diff -Nru a/lib/div64.c b/lib/div64.c
--- /dev/null   Wed Dec 31 16:00:00 1969
+++ b/lib/div64.c   Thu Jul 10 13:16:29 2003
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
+ *
+ * Based on former do_div() implementation from asm-parisc/div64.h:
+ *   Copyright (C) 1999 Hewlett-Packard Co
+ *   Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
+ *
+ *
+ * Generic C version of 64bit/32bit division and modulo, with
+ * 64bit result and 32bit remainder.
+ *
+ * The fast case for (n>>32 == 0) is handled inline by do_div(). 
+ *
+ * Code generated for this function might be very inefficient
+ * for some CPUs. __div64_32() can be overridden by linking arch-specific
+ * assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S.
+ */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <asm/div64.h>
+
+/* Not needed on 64bit architectures */
+#if BITS_PER_LONG == 32
+
+uint32_t __div64_32(uint64_t *n, uint32_t base)
+{
+   uint32_t low, low2, high, rem;
+
+   low   = *n   & 0xffffffff;
+   high  = *n  >> 32;
+   rem   = high % (uint32_t)base;
+   high  = high / (uint32_t)base;
+   low2  = low >> 16;
+   low2 += rem << 16;
+   rem   = low2 % (uint32_t)base;
+   low2  = low2 / (uint32_t)base;
+   low   = low  & 0xffff;
+   low  += rem << 16;
+   rem   = low  % (uint32_t)base;
+   low   = low  / (uint32_t)base;
+
+   *n = low +
+      ((uint64_t)low2 << 16) +
+      ((uint64_t)high << 32);
+
+   return rem;
+}
+
+EXPORT_SYMBOL(__div64_32);
+
+#endif /* BITS_PER_LONG == 32 */


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.