From patchwork Wed Aug 26 18:51:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?G=C3=A1bor_Stefanik?= X-Patchwork-Id: 44089 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7QIpWKu010803 for ; Wed, 26 Aug 2009 18:51:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752784AbZHZSv2 (ORCPT ); Wed, 26 Aug 2009 14:51:28 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752717AbZHZSv2 (ORCPT ); Wed, 26 Aug 2009 14:51:28 -0400 Received: from mail-fx0-f217.google.com ([209.85.220.217]:56513 "EHLO mail-fx0-f217.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752586AbZHZSv1 (ORCPT ); Wed, 26 Aug 2009 14:51:27 -0400 Received: by fxm17 with SMTP id 17so358129fxm.37 for ; Wed, 26 Aug 2009 11:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:mime-version:content-type :content-transfer-encoding; bh=8fJjHi6VTMdyinvfd9aqOshxiS8FY3+zJz3gASpv7NU=; b=tD06iMZ4s4idhWcLuvjyc4N8oJXfcKbtI7p1zzw+a81HFrXVIHurEdosWgewqbS4X4 BlqZBvB6ryPpgPtodZO1eMSArMjVeLt8FrJd1jRTVzq8WXpPJVXxTQARretVXkLBBdMQ +G+1KBPvezZDm3BVad16NvBlBbeXIBRDJp+qg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; b=KVqVMscgHwzDKnA+YDNims9OKxAAfMvXRSWeZ/1OEJFMsf6d1u4Ob9pjNjrZJkc/jy 3iwekDXjSeYbbwAHXzkcpdkJA1swhSJ57a3l4czlIStA7m589FmTheTl3hJqkz8MU+xL fRv5rDS3joSGqjcs5s5aT8HKEMBTM0NwzjzjQ= Received: by 10.103.86.13 with SMTP id o13mr3062936mul.6.1251312688218; Wed, 26 Aug 2009 11:51:28 -0700 (PDT) Received: from localhost (pool-03f83.externet.hu [88.209.235.130]) by mx.google.com with ESMTPS id n7sm2976190mue.55.2009.08.26.11.51.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 26 Aug 2009 11:51:27 -0700 (PDT) From: =?utf-8?q?G=C3=A1bor=20Stefanik?= To: John Linville , Michael Buesch , Larry Finger , Mark Huijgen Cc: Broadcom Wireless , linux-wireless Subject: [PATCH v2] b43: LP-PHY: Fix and simplify Qdiv roundup Date: Wed, 26 Aug 2009 20:51:24 +0200 Message-Id: <1251312686-32067-1-git-send-email-netrolller.3d@gmail.com> X-Mailer: git-send-email 1.5.6 MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 --- v2: Remove divide/modulo operations from the inner loop. drivers/net/wireless/b43/phy_lp.c | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c index 7e70c07..5306f2c 100644 --- a/drivers/net/wireless/b43/phy_lp.c +++ b/drivers/net/wireless/b43/phy_lp.c @@ -1032,9 +1032,10 @@ static int lpphy_loopback(struct b43_wldev *dev) return index; } +/* Fixed-point division algorithm using only integer math. */ 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 +1043,16 @@ 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; + while (precision > 0) { quotient <<= 1; - if (remainder >= roundup) - remainder = (tmp << 1) + rbit; - else - remainder <<= 1; + if (remainder << 1 >= divisor) { + quotient++; + remainder = (remainder << 1) - divisor; + } precision--; } - if (remainder >= roundup) + if (remainder << 1 >= divisor) quotient++; return quotient;