Search Linux Wireless

[PATCH 13/13] ath5k: Optimize ath5k_cw_validate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Optimize ath5k_cw_validate by using the classic (X & (X - 1)) == 0
check to see if a number is power of 2.

Signed-off-by: Nick Kossifidis <mickflemm@xxxxxxxxx>
---
 drivers/net/wireless/ath/ath5k/qcu.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/net/wireless/ath/ath5k/qcu.c b/drivers/net/wireless/ath/ath5k/qcu.c
index e50e64d..cdbaad7 100644
--- a/drivers/net/wireless/ath/ath5k/qcu.c
+++ b/drivers/net/wireless/ath/ath5k/qcu.c
@@ -111,6 +111,16 @@ ath5k_cw_validate(u16 cw_req)
 	u32 cw = 1;
 	cw_req = min(cw_req, (u16)1023);
 
+	/* Check if cw_req + 1 a power of 2 */
+	if (!((cw_req + 1) & cw_req))
+		return cw_req;
+
+	/* Check if cw_req is a power of 2 */
+	if (!(cw_req & (cw_req - 1)))
+		return cw_req - 1;
+
+	/* If none of the above is correct
+	 * find the closest power of 2 */
 	while (cw < cw_req)
 		cw = (cw << 1) | 1;
 
-- 
1.7.8.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux