summaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-11-18 22:04:46 +0000
committerDavid S. Miller <davem@davemloft.net>2010-11-19 10:06:54 -0800
commitc26aed40f4fd18f86bcc6aba557cab700b129b73 (patch)
treee723d358ddd6facc3af4f37be02fabcf71e3e605 /net/core
parent8c1592d68bc89248bfd0ee287648f41c1370d826 (diff)
downloadblackbird-op-linux-c26aed40f4fd18f86bcc6aba557cab700b129b73.tar.gz
blackbird-op-linux-c26aed40f4fd18f86bcc6aba557cab700b129b73.zip
filter: use reciprocal divide
At compile time, we can replace the DIV_K instruction (divide by a constant value) by a reciprocal divide. At exec time, the expensive divide is replaced by a multiply, a less expensive operation on most processors. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Changli Gao <xiaosuo@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/filter.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index c0b68f7c8036..23e0a2a9a4de 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -37,6 +37,7 @@
#include <asm/uaccess.h>
#include <asm/unaligned.h>
#include <linux/filter.h>
+#include <linux/reciprocal_div.h>
enum {
BPF_S_RET_K = 1,
@@ -205,7 +206,7 @@ unsigned int sk_run_filter(struct sk_buff *skb, const struct sock_filter *fentry
A /= X;
continue;
case BPF_S_ALU_DIV_K:
- A /= K;
+ A = reciprocal_divide(A, K);
continue;
case BPF_S_ALU_AND_X:
A &= X;
@@ -506,6 +507,7 @@ int sk_chk_filter(struct sock_filter *filter, int flen)
/* check for division by zero */
if (ftest->k == 0)
return -EINVAL;
+ ftest->k = reciprocal_value(ftest->k);
break;
case BPF_S_LD_MEM:
case BPF_S_LDX_MEM:
OpenPOWER on IntegriCloud