All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] Correct imprecise >= comparisons
Date: Thu, 09 Feb 2006 12:44:51 +0000	[thread overview]
Message-ID: <20060209124451.GD1593@parisc-linux.org> (raw)
In-Reply-To: <20060208185312.GA26914@rhlx01.fht-esslingen.de>

[-- Attachment #1: Type: text/plain, Size: 1017 bytes --]

On Thu, Feb 09, 2006 at 01:20:07PM +0100, Andreas Mohr wrote:
> > > 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.
> 
> It probably is unlikely in several cases, but that makes it all the more a
> janitorial effort ;)
> It's just "unclean" to set a variable's limit if it didn't even actually
> step beyond the limit, which makes this more or less a janitorial task.

I wonder if we want a macro similar to min()/max().  Maybe we could
write it as:

limit(val, max);

which could be defined as:

#define limit(val, max)  { \
	typeof(val) _val = (val); typeof(max) _max = (max); \
	if (_val > _max) _val = _max; }

Thoughts?

[-- 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

  parent reply	other threads:[~2006-02-09 12:44 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
2006-02-09 12:20 ` Andreas Mohr
2006-02-09 12:44 ` Matthew Wilcox [this message]
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=20060209124451.GD1593@parisc-linux.org \
    --to=matthew@wil.cx \
    --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.