public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [KERNEL]: Avoid divide in IS_ALIGN
@ 2007-11-20 13:56 Herbert Xu
  2007-11-20 18:17 ` Joe Perches
  2007-11-20 21:43 ` linux-os (Dick Johnson)
  0 siblings, 2 replies; 6+ messages in thread
From: Herbert Xu @ 2007-11-20 13:56 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton, Linux Kernel Mailing List

Hi:

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

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 94bc996..39b3fa6 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -35,7 +35,7 @@ extern const char linux_proc_banner[];
 #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
-#define IS_ALIGNED(x,a)		(((x) % ((typeof(x))(a))) == 0)
+#define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-11-21 13:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-20 13:56 [KERNEL]: Avoid divide in IS_ALIGN Herbert Xu
2007-11-20 18:17 ` Joe Perches
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox