X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=datapath%2Flinux%2Fcompat%2Freciprocal_div.c;h=90ce7b1ca6432317206d81b9b27552ac3b4af5e7;hb=a27ce57b65959a3fb796ebb20958930624b0732e;hp=7ec75284052cfe0a535868c51c71012fb0105b10;hpb=1a65ba854469c6746f944b2e784100e4175e0bea;p=sliver-openvswitch.git diff --git a/datapath/linux/compat/reciprocal_div.c b/datapath/linux/compat/reciprocal_div.c index 7ec752840..90ce7b1ca 100644 --- a/datapath/linux/compat/reciprocal_div.c +++ b/datapath/linux/compat/reciprocal_div.c @@ -1,13 +1,25 @@ +#include #include #include -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) -/* definition is required since reciprocal_value() is not exported */ -u32 reciprocal_value(u32 k) +/* + * For a description of the algorithm please have a look at + * include/linux/reciprocal_div.h + */ + +struct reciprocal_value reciprocal_value(u32 d) { - u64 val = (1LL << 32) + (k - 1); - do_div(val, k); - return (u32)val; + struct reciprocal_value R; + u64 m; + int l; + + l = fls(d - 1); + m = ((1ULL << 32) * ((1ULL << l) - d)); + do_div(m, d); + ++m; + R.m = (u32)m; + R.sh1 = min(l, 1); + R.sh2 = max(l - 1, 0); + + return R; } -#endif