From: Joe Perches <joe@perches.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [KERNEL]: Avoid divide in IS_ALIGN
Date: Tue, 20 Nov 2007 10:17:15 -0800 [thread overview]
Message-ID: <1195582635.4675.145.camel@localhost> (raw)
In-Reply-To: <20071120135607.GA18346@gondor.apana.org.au>
On Tue, 2007-11-20 at 21:56 +0800, Herbert Xu wrote:
> [KERNEL]: Avoid divide in IS_ALIGN
> I was happy to discover the brand new IS_ALIGN macro and quickly
> used it in my code. To my dismay I found that the generated code
> used division to perform the test.
> This patch fixes it by changing the % test to an &. This avoids
> the division.
Perhaps this should use is_power_of_2?
#define IS_ALIGNED(x, a) \
({ typeof(x) _a = (typeof(x))(a); \
is_power_of_2(_a) ? (((x) & (_a - 1)) == 0) \
: (((x) % _a == 0); })
gcc -o2/oS seems to do the right thing.
next prev parent reply other threads:[~2007-11-20 18:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-20 13:56 [KERNEL]: Avoid divide in IS_ALIGN Herbert Xu
2007-11-20 18:17 ` Joe Perches [this message]
2007-11-20 20:22 ` Andrew Morton
2007-11-20 21:43 ` linux-os (Dick Johnson)
2007-11-21 13:06 ` linux-os (Dick Johnson)
2007-11-21 13:35 ` Andreas Schwab
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=1195582635.4675.145.camel@localhost \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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.