Skip to content

Commit 3927f2e

Browse files
Stephen HemmingerDavid S. Miller
authored andcommitted
[NET]: div64_64 consolidate (rev3)
Here is the current version of the 64 bit divide common code. Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9d729f7 commit 3927f2e

13 files changed

Lines changed: 60 additions & 63 deletions

File tree

‎include/asm-arm/div64.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __ASM_ARM_DIV64
33

44
#include <asm/system.h>
5+
#include <linux/types.h>
56

67
/*
78
* The semantics of do_div() are:
@@ -223,4 +224,6 @@
223224

224225
#endif
225226

227+
extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
228+
226229
#endif

‎include/asm-generic/div64.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
__rem; \
3131
})
3232

33+
static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
34+
{
35+
return dividend / divisor;
36+
}
37+
3338
#elif BITS_PER_LONG == 32
3439

3540
extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
@@ -49,6 +54,8 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
4954
__rem; \
5055
})
5156

57+
extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
58+
5259
#else /* BITS_PER_LONG == ?? */
5360

5461
# error do_div() does not yet support the C64

‎include/asm-i386/div64.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __I386_DIV64
22
#define __I386_DIV64
33

4+
#include <linux/types.h>
5+
46
/*
57
* do_div() is NOT a C function. It wants to return
68
* two values (the quotient and the remainder), but
@@ -45,4 +47,6 @@ div_ll_X_l_rem(long long divs, long div, long *rem)
4547
return dum2;
4648

4749
}
50+
51+
extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
4852
#endif

‎include/asm-m68k/div64.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _M68K_DIV64_H
22
#define _M68K_DIV64_H
33

4+
#include <linux/types.h>
5+
46
/* n = n / base; return rem; */
57

68
#define do_div(n, base) ({ \
@@ -23,4 +25,5 @@
2325
__rem; \
2426
})
2527

28+
extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
2629
#endif /* _M68K_DIV64_H */

‎include/asm-mips/div64.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2000, 2004 Maciej W. Rozycki
3-
* Copyright (C) 2003 Ralf Baechle
3+
* Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org)
44
*
55
* This file is subject to the terms and conditions of the GNU General Public
66
* License. See the file "COPYING" in the main directory of this archive
@@ -9,6 +9,8 @@
99
#ifndef _ASM_DIV64_H
1010
#define _ASM_DIV64_H
1111

12+
#include <linux/types.h>
13+
1214
#if (_MIPS_SZLONG == 32)
1315

1416
#include <asm/compiler.h>
@@ -78,6 +80,8 @@
7880
__quot = __quot << 32 | __low; \
7981
(n) = __quot; \
8082
__mod; })
83+
84+
extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
8185
#endif /* (_MIPS_SZLONG == 32) */
8286

8387
#if (_MIPS_SZLONG == 64)
@@ -101,6 +105,11 @@
101105
(n) = __quot; \
102106
__mod; })
103107

108+
static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
109+
{
110+
return dividend / divisor;
111+
}
112+
104113
#endif /* (_MIPS_SZLONG == 64) */
105114

106115
#endif /* _ASM_DIV64_H */

‎include/asm-um/div64.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
#include "asm/arch/div64.h"
55

6+
extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
67
#endif

‎include/asm-xtensa/div64.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111
#ifndef _XTENSA_DIV64_H
1212
#define _XTENSA_DIV64_H
1313

14+
#include <linux/types.h>
15+
1416
#define do_div(n,base) ({ \
1517
int __res = n % ((unsigned int) base); \
1618
n /= (unsigned int) base; \
1719
__res; })
1820

21+
static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
22+
{
23+
return dividend / divisor;
24+
}
1925
#endif

‎lib/Makefile‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
lib-y := ctype.o string.o vsprintf.o cmdline.o \
66
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 \
88
sha1.o irq_regs.o reciprocal_div.o
99

1010
lib-$(CONFIG_MMU) += ioremap.o
1111
lib-$(CONFIG_SMP) += cpumask.o
1212

1313
lib-y += kobject.o kref.o kobject_uevent.o klist.o
1414

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
1617

1718
ifeq ($(CONFIG_DEBUG_KOBJECT),y)
1819
CFLAGS_kobject.o += -DDEBUG

‎lib/div64.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,26 @@ uint32_t __div64_32(uint64_t *n, uint32_t base)
5858

5959
EXPORT_SYMBOL(__div64_32);
6060

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+
6183
#endif /* BITS_PER_LONG == 32 */

‎net/ipv4/tcp_cubic.c‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ MODULE_PARM_DESC(bic_scale, "scale (scaled by 1024) value for bic function (bic_
5151
module_param(tcp_friendliness, int, 0644);
5252
MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness");
5353

54-
#include <asm/div64.h>
55-
5654
/* BIC TCP Parameters */
5755
struct bictcp {
5856
u32 cnt; /* increase cwnd by 1 after ACKs */
@@ -93,27 +91,6 @@ static void bictcp_init(struct sock *sk)
9391
tcp_sk(sk)->snd_ssthresh = initial_ssthresh;
9492
}
9593

96-
/* 64bit divisor, dividend and result. dynamic precision */
97-
static inline u_int64_t div64_64(u_int64_t dividend, u_int64_t divisor)
98-
{
99-
u_int32_t d = divisor;
100-
101-
if (divisor > 0xffffffffULL) {
102-
unsigned int shift = fls(divisor >> 32);
103-
104-
d = divisor >> shift;
105-
dividend >>= shift;
106-
}
107-
108-
/* avoid 64 bit division if possible */
109-
if (dividend >> 32)
110-
do_div(dividend, d);
111-
else
112-
dividend = (uint32_t) dividend / d;
113-
114-
return dividend;
115-
}
116-
11794
/*
11895
* calculate the cubic root of x using Newton-Raphson
11996
*/

0 commit comments

Comments
 (0)