1 #ifndef __LINUX_RECIPROCAL_DIV_WRAPPER_H
2 #define __LINUX_RECIPROCAL_DIV_WRAPPER_H
4 #include <linux/version.h>
6 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
7 #include_next <linux/reciprocal_div.h>
10 #include <linux/types.h>
13 * This file describes reciprocical division.
15 * This optimizes the (A/B) problem, when A and B are two u32
16 * and B is a known value (but not known at compile time)
18 * The math principle used is :
19 * Let RECIPROCAL_VALUE(B) be (((1LL << 32) + (B - 1))/ B)
20 * Then A / B = (u32)(((u64)(A) * (R)) >> 32)
22 * This replaces a divide by a multiply (and a shift), and
23 * is generally less expensive in CPU cycles.
27 * Computes the reciprocal value (R) for the value B of the divisor.
28 * Should not be called before each reciprocal_divide(),
29 * or else the performance is slower than a normal divide.
31 extern u32 reciprocal_value(u32 B);
34 static inline u32 reciprocal_divide(u32 A, u32 R)
36 return (u32)(((u64)A * R) >> 32);
39 #endif /* Linux kernel < 2.6.20 */
40 #endif /* __LINUX_RECIPROCAL_DIV_WRAPPER_H */