public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Timothy Miller <miller@techsource.com>
To: Ricardo Nabinger Sanchez <rnsanchez@terra.com.br>
Cc: linux-kernel@vger.kernel.org, Frank.Cornelis@elis.ugent.be
Subject: Re: [PATCH] sched: CPU_THRESHOLD
Date: Mon, 25 Aug 2003 13:12:02 -0400	[thread overview]
Message-ID: <3F4A4362.4020601@techsource.com> (raw)
In-Reply-To: 20030823195740.7133874d.rnsanchez@terra.com.br



Ricardo Nabinger Sanchez wrote:
> hello Frank,
> 
> 
>>-	*imbalance = (max_load - nr_running) / 2;
>>+	*imbalance = (max_load - nr_running) >> 1;
> 
> 
> I think it is a good coding practice to keep things human-readable. 
> In this code snippet, the division by 2 is quickly understood by most
> readers (specially those who didn't write it).  The right shift may
> obfuscate the real meaning of this operation, which is a single
> division by 2, not a bit-oriented expression.
> 
> Assuming that sched.c will be compiled with optimizations enabled, the
> compiler will change the human-readable division by a fast machine
> right shift operation, whenever possible (gcc surely will).
> 
> Thus, we keep the kernel code more readable, and sometimes let the
> compiler apply newer (and hopefully faster) optimizations than some
> tricks we have known as fastest available.
> 
> Regards, and please let me know what do you think about it.
> 

Note that right-shift rounds towards negative infinity, while divide 
rounds towards zero.

If the operands are unsigned, then rsh and divide will yield the same 
instructions (on x86).  OTOH, if they are signed, then you get different 
results.  For this rsh, obviously, you get a shift, but for divide, you 
get something like this:

; divide edx by 2
mov ecx,edx
lsr ecx,31
asr edx,1
add edx,ecx



  reply	other threads:[~2003-08-25 16:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-23 22:57 [PATCH] sched: CPU_THRESHOLD Ricardo Nabinger Sanchez
2003-08-25 17:12 ` Timothy Miller [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-08-22 12:43 Frank Cornelis

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=3F4A4362.4020601@techsource.com \
    --to=miller@techsource.com \
    --cc=Frank.Cornelis@elis.ugent.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rnsanchez@terra.com.br \
    /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