2024-09-09 08:57:42 +00:00
|
|
|
#include <linux/kernel.h>
|
2024-09-09 08:52:07 +00:00
|
|
|
#include <asm/div64.h>
|
|
|
|
#include <linux/reciprocal_div.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
/*
|
|
|
|
* For a description of the algorithm please have a look at
|
|
|
|
* include/linux/reciprocal_div.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct reciprocal_value reciprocal_value(u32 d)
|
2024-09-09 08:52:07 +00:00
|
|
|
{
|
2024-09-09 08:57:42 +00:00
|
|
|
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;
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(reciprocal_value);
|