summaryrefslogtreecommitdiff
path: root/include/div64.h
diff options
context:
space:
mode:
authorGerald Van Baren <vanbaren@cideas.com>2007-08-10 19:19:50 -0400
committerGerald Van Baren <vanbaren@cideas.com>2007-08-10 19:19:50 -0400
commit29eaae953476f2bba4d5c7ac097b96cd827c1dff (patch)
tree537faa4c04db58ee7b070b56bd7de7bd116092d3 /include/div64.h
parented8e5f362a2fc572eb9c1854f6c76c291b0f9a0f (diff)
parentfb56579ffe7ef3275b7036bb7b924e5a0d32bd70 (diff)
downloadu-boot-imx-29eaae953476f2bba4d5c7ac097b96cd827c1dff.zip
u-boot-imx-29eaae953476f2bba4d5c7ac097b96cd827c1dff.tar.gz
u-boot-imx-29eaae953476f2bba4d5c7ac097b96cd827c1dff.tar.bz2
Merge git://www.denx.de/git/u-boot
Diffstat (limited to 'include/div64.h')
-rw-r--r--include/div64.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/div64.h b/include/div64.h
new file mode 100644
index 0000000..2e0ba83
--- /dev/null
+++ b/include/div64.h
@@ -0,0 +1,39 @@
+#ifndef _ASM_GENERIC_DIV64_H
+#define _ASM_GENERIC_DIV64_H
+/*
+ * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
+ * Based on former asm-ppc/div64.h and asm-m68knommu/div64.h
+ *
+ * The semantics of do_div() are:
+ *
+ * uint32_t do_div(uint64_t *n, uint32_t base)
+ * {
+ * uint32_t remainder = *n % base;
+ * *n = *n / base;
+ * return remainder;
+ * }
+ *
+ * NOTE: macro parameter n is evaluated multiple times,
+ * beware of side effects!
+ */
+
+#include <linux/types.h>
+
+extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
+
+/* The unnecessary pointer compare is there
+ * to check for type safety (n must be 64bit)
+ */
+# define do_div(n,base) ({ \
+ uint32_t __base = (base); \
+ uint32_t __rem; \
+ (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
+ if (((n) >> 32) == 0) { \
+ __rem = (uint32_t)(n) % __base; \
+ (n) = (uint32_t)(n) / __base; \
+ } else \
+ __rem = __div64_32(&(n), __base); \
+ __rem; \
+ })
+
+#endif /* _ASM_GENERIC_DIV64_H */