00001 #ifndef ARCH_GENERIC_DIV64_H
00002 #define ARCH_GENERIC_DIV64_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ULONG_MAX
00021 #include <limits.h>
00022 #endif
00023 #include <stdint.h>
00024
00025 #if ULONG_MAX == 4294967295
00026
00027 extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
00028
00029
00030
00031
00032 # define do_div(n,base) ({ \
00033 uint32_t __base = (base); \
00034 uint32_t __rem; \
00035 (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
00036 if (((n) >> 32) == 0) { \
00037 __rem = (uint32_t)(n) % __base; \
00038 (n) = (uint32_t)(n) / __base; \
00039 } else \
00040 __rem = __div64_32(&(n), __base); \
00041 __rem; \
00042 })
00043
00044 #elif ULONG_MAX == 18446744073709551615
00045
00046 # define do_div(n,base) ({ \
00047 uint32_t __base = (base); \
00048 uint32_t __rem; \
00049 __rem = ((uint64_t)(n)) % __base; \
00050 (n) = ((uint64_t)(n)) / __base; \
00051 __rem; \
00052 })
00053
00054
00055 #else
00056
00057 # error do_div() does not yet support the C64
00058
00059 #endif
00060
00061 #endif