linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Larry Finger <Larry.Finger@lwfinger.net>
To: Jan Ceuleers <jan.ceuleers@computer.org>
Cc: "Devendra.Naga" <devendra.aaru@gmail.com>,
	chaoming_li@realsil.com.cn, linville@tuxdriver.com,
	paul.gortmaker@windriver.com, joe@perches.com,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] wireless: move ifs' in _rtl92c_store_pwrIndex_diffrate_offset into elseif statements
Date: Sun, 05 Feb 2012 10:05:44 -0600	[thread overview]
Message-ID: <4F2EA8D8.4080907@lwfinger.net> (raw)
In-Reply-To: <4F2E39F6.70803@computer.org>

On 02/05/2012 02:12 AM, Jan Ceuleers wrote:
> On 01/30/2012 07:50 AM, Devendra.Naga wrote:
>> From: "Devendra.Naga"<devendra.aaru@gmail.com>
>>
>> The regaddr is compared against different rates in each case and the
>> powerlevels are set
>> accordingly. as this can match for the first if and we still check for other
>> powerlevels too,
>> use else if ratherthan using if statements
>> Signed-off-by: Devendra.Naga<devendra.aaru@gmail.com>
> If this is correct, and I'm not saying it is or isn't, would it not be clearer
> to turn this whole section into a switch statement? The cases that requiring
> fiddling with the bitmask would need to be dealt with in the default: case.

Yes, it is correct. It might be clearer if it were written as a switch 
statement, but that would be a lot more intrusive. Besides, have you ever looked 
at the way gcc compiles a switch? I have done some reverse engineering, and at 
least some implementations generate code that looks like if .. else if .. .. 
else. I have not looked at the generated code, but I'm quite certain that the 
optimizer in gcc is good enough to know that once it gets a match between 
regaddr and one of the RTXAGC constants, there is no need to test the rest, and 
that the change to "else if" is mostly cosmetic, and will not greatly affect the 
execution.

> Why was it written as a series of if statements to begin with: can (or could)
> any of these if statements change the value of regaddr such that later ifs
> evaluate differently? From reading only the patch the answer seems to be "no",
> so that looks good.

I cannot answer the question of why it was written this way - you would have to 
ask the original authors. As to the possibility of the code changing regaddr, 
you either need to look more carefully at the code, or you need to restudy how C 
works.

> Or what about turning this into a data-driven section? It looks like values of
> regaddr are being translated into offsets into
> rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt]. Can this be done with a lookup table?

I would state it a little differently - the values of regaddr are used to 
determine where in the double-indexed array rtlphy->MCS_TXPWR[][] that the 
quantity "data" should be placed. There are always multiple ways to do anything. 
For the kernel, a major rule is to make minimal changes that are easy to verify. 
The patch in question meets that condition. If this code were in the hot path, 
it might be worth the effort required to do a complete rewrite with the 
associated testing, but in my mind, that effort would be wasted. Something that 
would be easy to do, easy to verify, and would reduce the size of the generated 
code would be

int index;

if (regaddr == RTXAGC_A_RATE18_06) {
	index = 0;
else if (if (regaddr == RTXAGC_A_RATE54_24) {
	index = 1;
.....
}
rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][index] = data;
RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
          "MCSTxPowerLevelOriginalOffset[%d][%d] = 0x%x\n",
          rtlphy->pwrgroup_cnt, index,
          rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][index]);
...

Larry

  reply	other threads:[~2012-02-05 16:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-30  6:50 [PATCH 1/1] wireless: move ifs' in _rtl92c_store_pwrIndex_diffrate_offset into elseif statements Devendra.Naga
2012-01-30 23:38 ` Larry Finger
2012-02-05  8:12 ` Jan Ceuleers
2012-02-05 16:05   ` Larry Finger [this message]
2012-02-06 11:26     ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F2EA8D8.4080907@lwfinger.net \
    --to=larry.finger@lwfinger.net \
    --cc=chaoming_li@realsil.com.cn \
    --cc=devendra.aaru@gmail.com \
    --cc=jan.ceuleers@computer.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=netdev@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).