linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mac80211: optimise ieee80211_get_hdrlen
@ 2007-03-27 16:01 Johannes Berg
  2007-03-28 19:11 ` Jouni Malinen
  0 siblings, 1 reply; 8+ messages in thread
From: Johannes Berg @ 2007-03-27 16:01 UTC (permalink / raw)
  To: Jiri Benc; +Cc: linux-wireless

This patch optimises the ieee80211_get_hdrlen function by exploiting the
bit masks directly.

On powerpc, this decreases the function by 4 instructions, but more
importantly it kills 4 of the 5 branches it contained.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>

---
And don't ask me how the compiler actually gets by with a single branch
now!

It was fun to do but in my userspace test program on powerpc doesn't
seem to change much, CPU time goes down by like 2%...

 net/mac80211/ieee80211.c |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

--- wireless-dev.orig/net/mac80211/ieee80211.c	2007-03-27 16:33:47.163155480 +0200
+++ wireless-dev/net/mac80211/ieee80211.c	2007-03-27 16:33:48.473155480 +0200
@@ -258,19 +258,24 @@ int ieee80211_get_hdrlen(u16 fc)
 	case IEEE80211_FTYPE_DATA:
 		if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
 			hdrlen = 30; /* Addr4 */
-		if (fc & IEEE80211_STYPE_QOS_DATA)
-			hdrlen += 2; /* QoS Control Field */
+		/* QoS Control Field */
+		hdrlen += (fc & IEEE80211_STYPE_QOS_DATA)
+				>> (ilog2(IEEE80211_STYPE_QOS_DATA)-1);
 		break;
 	case IEEE80211_FTYPE_CTL:
-		switch (fc & IEEE80211_FCTL_STYPE) {
-		case IEEE80211_STYPE_CTS:
-		case IEEE80211_STYPE_ACK:
+		/*
+		 * ACK and CTS are 10 bytes, all others 16. To see how
+		 * to get this condition consider
+		 *   subtype mask:   0b0000000011110000 (0x00F0)
+		 *   ACK subtype:    0b0000000011010000 (0x00D0)
+		 *   CTS subtype:    0b0000000011000000 (0x00C0)
+		 *   bits that matter:         ^^^      (0x00E0)
+		 *   value of those: 0b0000000011000000 (0x00C0)
+		 */
+		if ((fc & 0xE0) == 0xC0)
 			hdrlen = 10;
-			break;
-		default:
+		else
 			hdrlen = 16;
-			break;
-		}
 		break;
 	}
 



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-04-28 14:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-27 16:01 [PATCH] mac80211: optimise ieee80211_get_hdrlen Johannes Berg
2007-03-28 19:11 ` Jouni Malinen
2007-03-29 11:07   ` Johannes Berg
2007-03-29 15:48     ` Jouni Malinen
2007-04-27 15:10   ` Johannes Berg
2007-04-28 13:40     ` Jiri Benc
2007-04-28 13:58       ` Johannes Berg
2007-04-28 14:35         ` Jiri Benc

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).