From 8a6d48c0542876eb3acfc0970c0ab7872db08d5f Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Sun, 6 Dec 2009 05:26:23 +0100 Subject: check in the original version of dde linux26. --- .../contrib/include/linux/reciprocal_div.h | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 libdde_linux26/contrib/include/linux/reciprocal_div.h (limited to 'libdde_linux26/contrib/include/linux/reciprocal_div.h') diff --git a/libdde_linux26/contrib/include/linux/reciprocal_div.h b/libdde_linux26/contrib/include/linux/reciprocal_div.h new file mode 100644 index 00000000..f9c90b33 --- /dev/null +++ b/libdde_linux26/contrib/include/linux/reciprocal_div.h @@ -0,0 +1,32 @@ +#ifndef _LINUX_RECIPROCAL_DIV_H +#define _LINUX_RECIPROCAL_DIV_H + +#include + +/* + * This file describes reciprocical division. + * + * This optimizes the (A/B) problem, when A and B are two u32 + * and B is a known value (but not known at compile time) + * + * The math principle used is : + * Let RECIPROCAL_VALUE(B) be (((1LL << 32) + (B - 1))/ B) + * Then A / B = (u32)(((u64)(A) * (R)) >> 32) + * + * This replaces a divide by a multiply (and a shift), and + * is generally less expensive in CPU cycles. + */ + +/* + * Computes the reciprocal value (R) for the value B of the divisor. + * Should not be called before each reciprocal_divide(), + * or else the performance is slower than a normal divide. + */ +extern u32 reciprocal_value(u32 B); + + +static inline u32 reciprocal_divide(u32 A, u32 R) +{ + return (u32)(((u64)A * R) >> 32); +} +#endif -- cgit v1.2.3