[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <063D6719AE5E284EB5DD2968C1650D6D1C9F646B@AcuExch.aculab.com>
Date: Fri, 21 Nov 2014 10:26:23 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Denis Kirjanov' <kda@...ux-powerpc.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
CC: Alexei Starovoitov <ast@...mgrid.com>
Subject: RE: [PATCH net-next] filter: add bpf_optimize_div()
From: Denis Kirjanov
> optimize_div() found in mips bpf jit is really usefull
> for other arches. So let's put it in filter.h
...
> +static inline int bpf_optimize_div(u32 *k)
> +{
> + /* power of 2 divides can be implemented with right shift */
> + if (!(*k & (*k-1))) {
> + *k = ilog2(*k);
> + return 1;
> + }
> +
> + return 0;
> +}
If 'k' is a constant then a 'multiply by reciprocal' is likely to
be as fast as the shift - and works for a wider range of values.
On some architectures the ilog2() may itself be expensive.
On x86 the divide might even be faster than the conditional mess
the above generates.
David
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists