[KERNEL]: Avoid divide in IS_ALIGN
- From: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 20 Nov 2007 21:56:07 +0800
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@xxxxxxxxxxxxxxxxxxx>
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
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))
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [KERNEL]: Avoid divide in IS_ALIGN
- From: linux-os \(*** Johnson\)
- Re: [KERNEL]: Avoid divide in IS_ALIGN
- From: Joe Perches
- Re: [KERNEL]: Avoid divide in IS_ALIGN
- Prev by Date: [PATCH] ipmi: add the standard watchdog timeout ioctls
- Next by Date: [PATCH] mm snapshot broken-out-2007-11-20-01-45 build failer tumbler/snapper
- Previous by thread: [PATCH] ipmi: add the standard watchdog timeout ioctls
- Next by thread: Re: [KERNEL]: Avoid divide in IS_ALIGN
- Index(es):