aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-arm/div64.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-arm/div64.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-arm/div64.h')
-rw-r--r--include/asm-arm/div64.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/asm-arm/div64.h b/include/asm-arm/div64.h
new file mode 100644
index 000000000000..3682616804ca
--- /dev/null
+++ b/include/asm-arm/div64.h
@@ -0,0 +1,48 @@
1#ifndef __ASM_ARM_DIV64
2#define __ASM_ARM_DIV64
3
4#include <asm/system.h>
5
6/*
7 * The semantics of do_div() are:
8 *
9 * uint32_t do_div(uint64_t *n, uint32_t base)
10 * {
11 * uint32_t remainder = *n % base;
12 * *n = *n / base;
13 * return remainder;
14 * }
15 *
16 * In other words, a 64-bit dividend with a 32-bit divisor producing
17 * a 64-bit result and a 32-bit remainder. To accomplish this optimally
18 * we call a special __do_div64 helper with completely non standard
19 * calling convention for arguments and results (beware).
20 */
21
22#ifdef __ARMEB__
23#define __xh "r0"
24#define __xl "r1"
25#else
26#define __xl "r0"
27#define __xh "r1"
28#endif
29
30#define do_div(n,base) \
31({ \
32 register unsigned int __base asm("r4") = base; \
33 register unsigned long long __n asm("r0") = n; \
34 register unsigned long long __res asm("r2"); \
35 register unsigned int __rem asm(__xh); \
36 asm( __asmeq("%0", __xh) \
37 __asmeq("%1", "r2") \
38 __asmeq("%2", "r0") \
39 __asmeq("%3", "r4") \
40 "bl __do_div64" \
41 : "=r" (__rem), "=r" (__res) \
42 : "r" (__n), "r" (__base) \
43 : "ip", "lr", "cc"); \
44 n = __res; \
45 __rem; \
46})
47
48#endif