Revert "x86/entry/64: Add missing irqflags tracing to native_load_gs_index()"
[linux/fpc-iii.git] / lib / reciprocal_div.c
blobfcb4ce682c6fae37d71aa6138007b51cd0d8a2b3
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <asm/div64.h>
4 #include <linux/reciprocal_div.h>
5 #include <linux/export.h>
7 /*
8 * For a description of the algorithm please have a look at
9 * include/linux/reciprocal_div.h
12 struct reciprocal_value reciprocal_value(u32 d)
14 struct reciprocal_value R;
15 u64 m;
16 int l;
18 l = fls(d - 1);
19 m = ((1ULL << 32) * ((1ULL << l) - d));
20 do_div(m, d);
21 ++m;
22 R.m = (u32)m;
23 R.sh1 = min(l, 1);
24 R.sh2 = max(l - 1, 0);
26 return R;
28 EXPORT_SYMBOL(reciprocal_value);