diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile | 5 | ||||
| -rw-r--r-- | lib/div64.c | 22 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/Makefile b/lib/Makefile index 992a39ef9ffd..ae57f357fec0 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ | 5 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ |
| 6 | rbtree.o radix-tree.o dump_stack.o \ | 6 | rbtree.o radix-tree.o dump_stack.o \ |
| 7 | idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \ | 7 | idr.o int_sqrt.o bitmap.o extable.o prio_tree.o \ |
| 8 | sha1.o irq_regs.o reciprocal_div.o | 8 | sha1.o irq_regs.o reciprocal_div.o |
| 9 | 9 | ||
| 10 | lib-$(CONFIG_MMU) += ioremap.o | 10 | lib-$(CONFIG_MMU) += ioremap.o |
| @@ -12,7 +12,8 @@ lib-$(CONFIG_SMP) += cpumask.o | |||
| 12 | 12 | ||
| 13 | lib-y += kobject.o kref.o kobject_uevent.o klist.o | 13 | lib-y += kobject.o kref.o kobject_uevent.o klist.o |
| 14 | 14 | ||
| 15 | obj-y += sort.o parser.o halfmd4.o debug_locks.o random32.o bust_spinlocks.o | 15 | obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
| 16 | bust_spinlocks.o | ||
| 16 | 17 | ||
| 17 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 18 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
| 18 | CFLAGS_kobject.o += -DDEBUG | 19 | CFLAGS_kobject.o += -DDEBUG |
diff --git a/lib/div64.c b/lib/div64.c index 365719f84832..c3d7655cdfb5 100644 --- a/lib/div64.c +++ b/lib/div64.c | |||
| @@ -58,4 +58,26 @@ uint32_t __div64_32(uint64_t *n, uint32_t base) | |||
| 58 | 58 | ||
| 59 | EXPORT_SYMBOL(__div64_32); | 59 | EXPORT_SYMBOL(__div64_32); |
| 60 | 60 | ||
| 61 | /* 64bit divisor, dividend and result. dynamic precision */ | ||
| 62 | uint64_t div64_64(uint64_t dividend, uint64_t divisor) | ||
| 63 | { | ||
| 64 | uint32_t d = divisor; | ||
| 65 | |||
| 66 | if (divisor > 0xffffffffULL) { | ||
| 67 | unsigned int shift = fls(divisor >> 32); | ||
| 68 | |||
| 69 | d = divisor >> shift; | ||
| 70 | dividend >>= shift; | ||
| 71 | } | ||
| 72 | |||
| 73 | /* avoid 64 bit division if possible */ | ||
| 74 | if (dividend >> 32) | ||
| 75 | do_div(dividend, d); | ||
| 76 | else | ||
| 77 | dividend = (uint32_t) dividend / d; | ||
| 78 | |||
| 79 | return dividend; | ||
| 80 | } | ||
| 81 | EXPORT_SYMBOL(div64_64); | ||
| 82 | |||
| 61 | #endif /* BITS_PER_LONG == 32 */ | 83 | #endif /* BITS_PER_LONG == 32 */ |
