* ilog2 overkill in ieee80211_get_hdrlen?
@ 2007-10-31 6:14 bruno randolf
2007-10-31 12:20 ` Johannes Berg
0 siblings, 1 reply; 3+ messages in thread
From: bruno randolf @ 2007-10-31 6:14 UTC (permalink / raw)
To: linux-wireless
hello!
just a question...
in 'net/mac80211/util.c', in ieee80211_get_hdrlen (line 175), a function ilog2
is used to determine the number of bits to shift for
IEEE80211_STYPE_QOS_DATA. isn't that a bit of an overkill when we could just
do >> 6? i mean IEEE80211_STYPE_QOS_DATA isn't going to change after all...
/*
* The QoS Control field is two bytes and its presence is
* indicated by the IEEE80211_STYPE_QOS_DATA bit. Add 2 to
* hdrlen if that bit is set.
* This works by masking out the bit and shifting it to
* bit position 1 so the result has the value 0 or 2.
*/
hdrlen += (fc & IEEE80211_STYPE_QOS_DATA)
>> (ilog2(IEEE80211_STYPE_QOS_DATA)-1);
i don't know if there is a reason for this, but it all seems overly
complicated to me.
if (fc & IEEE80211_STYPE_QOS_DATA)
hdrlen += 2;
would be a bit more readable.
bruno
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ilog2 overkill in ieee80211_get_hdrlen?
2007-10-31 6:14 ilog2 overkill in ieee80211_get_hdrlen? bruno randolf
@ 2007-10-31 12:20 ` Johannes Berg
2007-11-01 1:42 ` bruno randolf
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2007-10-31 12:20 UTC (permalink / raw)
To: bruno randolf; +Cc: linux-wireless
[-- Attachment #1: Type: text/plain, Size: 606 bytes --]
> in 'net/mac80211/util.c', in ieee80211_get_hdrlen (line 175), a function ilog2
> is used to determine the number of bits to shift for
> IEEE80211_STYPE_QOS_DATA. isn't that a bit of an overkill when we could just
> do >> 6? i mean IEEE80211_STYPE_QOS_DATA isn't going to change after all...
Yeah but ilog2() evaluates to a constant here so it doesn't matter, and
I think this is more readable.
> if (fc & IEEE80211_STYPE_QOS_DATA)
> hdrlen += 2;
>
> would be a bit more readable.
It used to be that but that's a branch and the generated code is better
the other way.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ilog2 overkill in ieee80211_get_hdrlen?
2007-10-31 12:20 ` Johannes Berg
@ 2007-11-01 1:42 ` bruno randolf
0 siblings, 0 replies; 3+ messages in thread
From: bruno randolf @ 2007-11-01 1:42 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless
johannes,
thanks for the explanation!
bruno
On Wednesday 31 October 2007 21:20:35 Johannes Berg wrote:
> > in 'net/mac80211/util.c', in ieee80211_get_hdrlen (line 175), a function
> > ilog2 is used to determine the number of bits to shift for
> > IEEE80211_STYPE_QOS_DATA. isn't that a bit of an overkill when we could
> > just do >> 6? i mean IEEE80211_STYPE_QOS_DATA isn't going to change after
> > all...
>
> Yeah but ilog2() evaluates to a constant here so it doesn't matter, and
> I think this is more readable.
>
> > if (fc & IEEE80211_STYPE_QOS_DATA)
> > hdrlen += 2;
> >
> > would be a bit more readable.
>
> It used to be that but that's a branch and the generated code is better
> the other way.
>
> johannes
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-11-01 1:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-31 6:14 ilog2 overkill in ieee80211_get_hdrlen? bruno randolf
2007-10-31 12:20 ` Johannes Berg
2007-11-01 1:42 ` bruno randolf
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).