From: Eric Sesterhenn <snakebyte@gmx.de>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] Correct imprecise >= comparisons
Date: Thu, 09 Feb 2006 00:06:29 +0000 [thread overview]
Message-ID: <1139443589.30321.5.camel@alice> (raw)
In-Reply-To: <20060208185312.GA26914@rhlx01.fht-esslingen.de>
[-- Attachment #1: Type: text/plain, Size: 877 bytes --]
hi,
> in the kernel source tree, there are several places (less important ones
> and high-profile ones such as TCP/IP) which do "incorrect" checks such as:
>
> if (val >= max)
> val = max;
>
> which can instead be expressed as
>
> if (val > max)
> val = max;
>
> in order to cut down on both executed cycles and cache write invalidation.
I am wondering if it is actually worth the effort, since it seems to
me as if this would normally be an exception that val >= max. And
instead of returning with an error or aborting you normalize the value.
Therefore the val=max statement is just executed pretty rarely, when an
user supplies a bad value for example. Even if there would be something
like
foo(int x){
if (x>=2000)
x=2000;
// more code
}
bar (void){
for (int i=0; i<4000; i++)
foo(i);
}
you just win in one of the many cases...
Just my 2 Cents :)
Eric
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
next prev parent reply other threads:[~2006-02-09 0:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-08 18:53 [KJ] Correct imprecise >= comparisons Andreas Mohr
2006-02-09 0:06 ` Eric Sesterhenn [this message]
2006-02-09 12:20 ` Andreas Mohr
2006-02-09 12:44 ` Matthew Wilcox
2006-02-09 12:52 ` Eric Sesterhenn
2006-02-09 13:45 ` Andreas Mohr
2006-02-09 14:06 ` Eric Sesterhenn
2006-02-09 15:35 ` Håkon Løvdal
2006-02-09 22:16 ` Darren Jenkins
2006-02-10 0:30 ` Adrian Bunk
2006-02-10 1:05 ` Darren Jenkins
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=1139443589.30321.5.camel@alice \
--to=snakebyte@gmx.de \
--cc=kernel-janitors@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.