diff options
author | Eric Biederman <ebiederm@xmission.com> | 2004-11-05 19:55:46 +0000 |
---|---|---|
committer | Eric Biederman <ebiederm@xmission.com> | 2004-11-05 19:55:46 +0000 |
commit | 7a9c836f93de8373c122d483894599b3eaf4b151 (patch) | |
tree | e30622091f23ff1b66d31ad567324052dd1f6e24 /src | |
parent | 692f2c7aed911dc193e96b214b62366ad04c89b2 (diff) |
- How did I forget to cvs add this?
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1763 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src')
-rw-r--r-- | src/include/arch-generic/div64.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/include/arch-generic/div64.h b/src/include/arch-generic/div64.h new file mode 100644 index 0000000000..a6bc97532a --- /dev/null +++ b/src/include/arch-generic/div64.h @@ -0,0 +1,59 @@ +#ifndef ARCH_GENERIC_DIV64_H +#define ARCH_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 <limits.h> +#include <stdint.h> + +#if ULONG_MAX == 4294967295 + +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 (likely(((n) >> 32) == 0)) { \ + __rem = (uint32_t)(n) % __base; \ + (n) = (uint32_t)(n) / __base; \ + } else \ + __rem = __div64_32(&(n), __base); \ + __rem; \ + }) + +#elif ULONG_MAX == 18446744073709551615 + +# define do_div(n,base) ({ \ + uint32_t __base = (base); \ + uint32_t __rem; \ + __rem = ((uint64_t)(n)) % __base; \ + (n) = ((uint64_t)(n)) / __base; \ + __rem; \ + }) + + +#else /* BITS_PER_LONG == ?? */ + +# error do_div() does not yet support the C64 + +#endif /* BITS_PER_LONG */ + +#endif /* ARCH_GENERIC_DIV64_H */ |