Back to home page

LXR

 
 

    


0001 #include <linux/kernel.h>
0002 #include <asm/div64.h>
0003 #include <linux/reciprocal_div.h>
0004 #include <linux/export.h>
0005 
0006 /*
0007  * For a description of the algorithm please have a look at
0008  * include/linux/reciprocal_div.h
0009  */
0010 
0011 struct reciprocal_value reciprocal_value(u32 d)
0012 {
0013     struct reciprocal_value R;
0014     u64 m;
0015     int l;
0016 
0017     l = fls(d - 1);
0018     m = ((1ULL << 32) * ((1ULL << l) - d));
0019     do_div(m, d);
0020     ++m;
0021     R.m = (u32)m;
0022     R.sh1 = min(l, 1);
0023     R.sh2 = max(l - 1, 0);
0024 
0025     return R;
0026 }
0027 EXPORT_SYMBOL(reciprocal_value);