-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 44460 b: refs/heads/master c: 6a2d7a9 h: refs/heads/master v: v3
- Loading branch information
Eric Dumazet
authored and
Linus Torvalds
committed
Dec 13, 2006
1 parent
9c24400
commit 274d40d
Showing
5 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 02a0e53d8227aff5e62e0433f82c12c1c2805fd6 | ||
refs/heads/master: 6a2d7a955d8de6cb19ed9cd194b3c83008a22c32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef _LINUX_RECIPROCAL_DIV_H | ||
#define _LINUX_RECIPROCAL_DIV_H | ||
|
||
#include <linux/types.h> | ||
|
||
/* | ||
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <asm/div64.h> | ||
#include <linux/reciprocal_div.h> | ||
|
||
u32 reciprocal_value(u32 k) | ||
{ | ||
u64 val = (1LL << 32) + (k - 1); | ||
do_div(val, k); | ||
return (u32)val; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters