diff options
author | Dirk Behme <dirk.behme@googlemail.com> | 2007-08-02 17:41:14 +0200 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2007-08-10 10:33:34 +0200 |
commit | f7c086e94e8ce9aad7268af97f73aa6884686f27 (patch) | |
tree | f6027f3aa957584b779daeb26efba7326630a8e8 /include/div64.h | |
parent | a22806469a8f2b69c829f4fd5361fdebd0cb01b4 (diff) |
Move 64bit division from avr32 to generic lib
Move the 64bit division from lib_avr32 to lib_generic. With this, all
boards can do_div/__div64_32 if needed, not only avr one. Code is put
to lib_generic, so no larger memory footprint if not used. No code
modifications. Thanks for proposal by HÃ¥vard Skinnemoen.
Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
Diffstat (limited to 'include/div64.h')
-rw-r--r-- | include/div64.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/include/div64.h b/include/div64.h new file mode 100644 index 00000000000..2e0ba8389e1 --- /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 */ |