Commit d8fa338e authored by Gábor Stefanik's avatar Gábor Stefanik Committed by John W. Linville

b43: LP-PHY: Fix and simplify Qdiv roundup

The Qdiv roundup routine is essentially a fixed-point
division algorithm, using only integer math.
However, the version in the specs had a major error
that has been recently fixed (a missing quotient++).

Replace Qdiv roundup with a rewritten, simplified version.
Signed-off-by: default avatarGábor Stefanik <netrolller.3d@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent ca9152e3
...@@ -1032,9 +1032,10 @@ static int lpphy_loopback(struct b43_wldev *dev) ...@@ -1032,9 +1032,10 @@ static int lpphy_loopback(struct b43_wldev *dev)
return index; return index;
} }
/* Fixed-point division algorithm using only integer math. */
static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision) static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
{ {
u32 quotient, remainder, rbit, roundup, tmp; u32 quotient, remainder;
if (divisor == 0) if (divisor == 0)
return 0; return 0;
...@@ -1042,20 +1043,16 @@ static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision) ...@@ -1042,20 +1043,16 @@ static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
quotient = dividend / divisor; quotient = dividend / divisor;
remainder = dividend % divisor; remainder = dividend % divisor;
rbit = divisor & 0x1; while (precision > 0) {
roundup = (divisor >> 1) + rbit;
while (precision != 0) {
tmp = remainder - roundup;
quotient <<= 1; quotient <<= 1;
if (remainder >= roundup) if (remainder << 1 >= divisor) {
remainder = (tmp << 1) + rbit; quotient++;
else remainder = (remainder << 1) - divisor;
remainder <<= 1; }
precision--; precision--;
} }
if (remainder >= roundup) if (remainder << 1 >= divisor)
quotient++; quotient++;
return quotient; return quotient;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment