From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Peter 1 Oberparleiter <Peter.Oberparleiter@de.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Harvey Harrison <harvey.harrison@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] consolidate all within() implementations
Date: Wed, 21 May 2008 12:48:52 +0200 [thread overview]
Message-ID: <1211366932.6463.81.camel@lappy.programming.kicks-ass.net> (raw)
In-Reply-To: <OFC011E4F1.61EF5440-ONC1257450.0038CB52-C1257450.003A0375@de.ibm.com>
On Wed, 2008-05-21 at 12:33 +0200, Peter 1 Oberparleiter wrote:
> Peter Zijlstra <a.p.zijlstra@chello.nl> wrote on 21.05.2008 12:04:26:
> > > +static inline int addr_within_len(const void *addr, const void
> *start,
> > > + size_t len)
> > > +{
> > > + return ((unsigned long) addr >= (unsigned long) start) &&
> > > + ((unsigned long) addr < ((unsigned long) start + len));
> > > +}
> >
> > might be my braindamage, but I'd have written it like:
> >
> > static inline int
> > addr_within_len(const void *addr, const void *start, size_t len)
> > {
> > return (unsigned long)addr - (unsigned long)start < len;
> > }
>
> Definitely another way to put it. In my opinion the intention of the
> implementation is more easily understood though when spelling it out
> as (a>=b) && (a<c).
peter@lappy:~/tmp$ cat cmp.c
int within_len1(const void *addr, const void *start, unsigned long len)
{
return (unsigned long)addr - (unsigned long)start < len;
}
int within1(const void *addr, const void *start, const void *end)
{
return within_len1(addr, start,
(unsigned long)end - (unsigned long)start);
}
peter@lappy:~/tmp$ cat cmp2.c
int within_len2(const void *addr, const void *start, unsigned long len)
{
return ((unsigned long) addr >= (unsigned long) start) &&
((unsigned long) addr < ((unsigned long) start + len));
}
int within2(const void *addr, const void *start, const void *end)
{
return ((unsigned long) addr >= (unsigned long) start) &&
((unsigned long) addr < ((unsigned long) end));
}
peter@lappy:~/tmp$ gcc -S -Os cmp*.c
peter@lappy:~/tmp$ ls -la cmp*.o
-rw-r--r-- 1 peter peter 752 2008-05-21 12:43 cmp2.o
-rw-r--r-- 1 peter peter 743 2008-05-21 12:43 cmp.o
Also look at the .s output and notice mine doesn't have any additional
branches ;-)
> > static inline int
> > addr_within(const void *add, const void *start, const void *end)
> > {
> > return addr_within_len(addr, start,
> > (unsigned long)end - (unsigned long)start);
> > }
>
> For empty ranges (start > end), this produces different (less expected)
> results than the previous version.
agreed, do we care about those?
next prev parent reply other threads:[~2008-05-21 10:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-19 8:45 Peter Oberparleiter
2008-05-19 20:50 ` Harvey Harrison
2008-05-20 8:08 ` Peter Oberparleiter
2008-05-20 9:45 ` Andrew Morton
2008-05-20 15:42 ` Peter Oberparleiter
2008-05-21 10:04 ` Peter Zijlstra
2008-05-21 10:33 ` Peter 1 Oberparleiter
2008-05-21 10:48 ` Peter Zijlstra [this message]
2008-05-21 13:50 ` Peter 1 Oberparleiter
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=1211366932.6463.81.camel@lappy.programming.kicks-ass.net \
--to=a.p.zijlstra@chello.nl \
--cc=Peter.Oberparleiter@de.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=harvey.harrison@gmail.com \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome