Thread (22 messages) 22 messages, 5 authors, 2011-11-21
STALE5343d

[PATCH 13/13] ath5k: Optimize ath5k_cw_validate

From: Nick Kossifidis <mickflemm@gmail.com>
Date: 2011-11-20 07:58:03
Subsystem: atheros ath generic utilities, atheros ath5k wireless driver, the rest · Maintainers: Jeff Johnson, Jiri Slaby, Nick Kossifidis, Luis Chamberlain, Linus Torvalds

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@gmail.com>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help