diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-generic/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-generic/div64.h')
-rw-r--r-- | include/asm-generic/div64.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h new file mode 100644 index 000000000000..8f4e3193342e --- /dev/null +++ b/include/asm-generic/div64.h | |||
@@ -0,0 +1,58 @@ | |||
1 | #ifndef _ASM_GENERIC_DIV64_H | ||
2 | #define _ASM_GENERIC_DIV64_H | ||
3 | /* | ||
4 | * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com> | ||
5 | * Based on former asm-ppc/div64.h and asm-m68knommu/div64.h | ||
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 | * NOTE: macro parameter n is evaluated multiple times, | ||
17 | * beware of side effects! | ||
18 | */ | ||
19 | |||
20 | #include <linux/types.h> | ||
21 | #include <linux/compiler.h> | ||
22 | |||
23 | #if BITS_PER_LONG == 64 | ||
24 | |||
25 | # define do_div(n,base) ({ \ | ||
26 | uint32_t __base = (base); \ | ||
27 | uint32_t __rem; \ | ||
28 | __rem = ((uint64_t)(n)) % __base; \ | ||
29 | (n) = ((uint64_t)(n)) / __base; \ | ||
30 | __rem; \ | ||
31 | }) | ||
32 | |||
33 | #elif BITS_PER_LONG == 32 | ||
34 | |||
35 | extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); | ||
36 | |||
37 | /* The unnecessary pointer compare is there | ||
38 | * to check for type safety (n must be 64bit) | ||
39 | */ | ||
40 | # define do_div(n,base) ({ \ | ||
41 | uint32_t __base = (base); \ | ||
42 | uint32_t __rem; \ | ||
43 | (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ | ||
44 | if (likely(((n) >> 32) == 0)) { \ | ||
45 | __rem = (uint32_t)(n) % __base; \ | ||
46 | (n) = (uint32_t)(n) / __base; \ | ||
47 | } else \ | ||
48 | __rem = __div64_32(&(n), __base); \ | ||
49 | __rem; \ | ||
50 | }) | ||
51 | |||
52 | #else /* BITS_PER_LONG == ?? */ | ||
53 | |||
54 | # error do_div() does not yet support the C64 | ||
55 | |||
56 | #endif /* BITS_PER_LONG */ | ||
57 | |||
58 | #endif /* _ASM_GENERIC_DIV64_H */ | ||