* [PATCH] b43: LP-PHY: Fix and simplify Qdiv roundup
@ 2009-08-25 14:40 Gábor Stefanik
2009-08-25 15:09 ` Bob Copeland
2009-08-25 20:48 ` Michael Buesch
0 siblings, 2 replies; 3+ messages in thread
From: Gábor Stefanik @ 2009-08-25 14:40 UTC (permalink / raw)
To: John Linville, Michael Buesch, Larry Finger, Mark Huijgen
Cc: Broadcom Wireless, linux-wireless
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: Gábor Stefanik <netrolller.3d@gmail.com>
---
drivers/net/wireless/b43/phy_lp.c | 14 ++++----------
1 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
index 7e70c07..d0280d5 100644
--- a/drivers/net/wireless/b43/phy_lp.c
+++ b/drivers/net/wireless/b43/phy_lp.c
@@ -1034,7 +1034,7 @@ static int lpphy_loopback(struct b43_wldev *dev)
static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
{
- u32 quotient, remainder, rbit, roundup, tmp;
+ u32 quotient, remainder;
if (divisor == 0)
return 0;
@@ -1042,20 +1042,14 @@ static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
quotient = dividend / divisor;
remainder = dividend % divisor;
- rbit = divisor & 0x1;
- roundup = (divisor >> 1) + rbit;
-
while (precision != 0) {
- tmp = remainder - roundup;
quotient <<= 1;
- if (remainder >= roundup)
- remainder = (tmp << 1) + rbit;
- else
- remainder <<= 1;
+ quotient |= (remainder << 1) / divisor;
+ remainder = (remainder << 1) % divisor;
precision--;
}
- if (remainder >= roundup)
+ if (remainder << 1 >= divisor)
quotient++;
return quotient;
--
1.5.6
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] b43: LP-PHY: Fix and simplify Qdiv roundup
2009-08-25 14:40 [PATCH] b43: LP-PHY: Fix and simplify Qdiv roundup Gábor Stefanik
@ 2009-08-25 15:09 ` Bob Copeland
2009-08-25 20:48 ` Michael Buesch
1 sibling, 0 replies; 3+ messages in thread
From: Bob Copeland @ 2009-08-25 15:09 UTC (permalink / raw)
To: Gábor Stefanik
Cc: John Linville, Michael Buesch, Larry Finger, Mark Huijgen,
Broadcom Wireless, linux-wireless
2009/8/25 Gábor Stefanik <netrolller.3d@gmail.com>:
> 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.
Hi!
> @@ -1042,20 +1042,14 @@ static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
> quotient = dividend / divisor;
> remainder = dividend % divisor;
>
> - rbit = divisor & 0x1;
> - roundup = (divisor >> 1) + rbit;
> -
> while (precision != 0) {
> - tmp = remainder - roundup;
> quotient <<= 1;
> - if (remainder >= roundup)
> - remainder = (tmp << 1) + rbit;
> - else
> - remainder <<= 1;
> + quotient |= (remainder << 1) / divisor;
> + remainder = (remainder << 1) % divisor;
> precision--;
> }
Unless precision is 0, this just added a bunch of divides into
the inner loop, which might be a big surprise to anyone expecting
this to be fast...
--
Bob Copeland %% www.bobcopeland.com
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] b43: LP-PHY: Fix and simplify Qdiv roundup
2009-08-25 14:40 [PATCH] b43: LP-PHY: Fix and simplify Qdiv roundup Gábor Stefanik
2009-08-25 15:09 ` Bob Copeland
@ 2009-08-25 20:48 ` Michael Buesch
1 sibling, 0 replies; 3+ messages in thread
From: Michael Buesch @ 2009-08-25 20:48 UTC (permalink / raw)
To: Gábor Stefanik
Cc: John Linville, Larry Finger, Mark Huijgen, Broadcom Wireless,
linux-wireless
On Tuesday 25 August 2009 16:40:17 Gábor Stefanik wrote:
> 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.
Don't we have some sort of standard library function somewhere in
the kernel for this? If not, what about creating one?
>
> Signed-off-by: Gábor Stefanik <netrolller.3d@gmail.com>
> ---
> drivers/net/wireless/b43/phy_lp.c | 14 ++++----------
> 1 files changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
> index 7e70c07..d0280d5 100644
> --- a/drivers/net/wireless/b43/phy_lp.c
> +++ b/drivers/net/wireless/b43/phy_lp.c
> @@ -1034,7 +1034,7 @@ static int lpphy_loopback(struct b43_wldev *dev)
>
> static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
> {
> - u32 quotient, remainder, rbit, roundup, tmp;
> + u32 quotient, remainder;
>
> if (divisor == 0)
> return 0;
> @@ -1042,20 +1042,14 @@ static u32 lpphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
> quotient = dividend / divisor;
> remainder = dividend % divisor;
>
> - rbit = divisor & 0x1;
> - roundup = (divisor >> 1) + rbit;
> -
> while (precision != 0) {
> - tmp = remainder - roundup;
> quotient <<= 1;
> - if (remainder >= roundup)
> - remainder = (tmp << 1) + rbit;
> - else
> - remainder <<= 1;
> + quotient |= (remainder << 1) / divisor;
> + remainder = (remainder << 1) % divisor;
> precision--;
> }
>
> - if (remainder >= roundup)
> + if (remainder << 1 >= divisor)
> quotient++;
>
> return quotient;
--
Greetings, Michael.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-08-25 20:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-25 14:40 [PATCH] b43: LP-PHY: Fix and simplify Qdiv roundup Gábor Stefanik
2009-08-25 15:09 ` Bob Copeland
2009-08-25 20:48 ` Michael Buesch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).