* [PATCH] Avoid divides in BITS_TO_LONGS
@ 2008-02-07 7:54 Eric Dumazet
0 siblings, 0 replies; only message in thread
From: Eric Dumazet @ 2008-02-07 7:54 UTC (permalink / raw)
To: Andrew Morton; +Cc: Linux kernel
[-- Attachment #1: Type: text/plain, Size: 488 bytes --]
BITS_PER_LONG is a signed value (32 or 64)
DIV_ROUND_UP(nr, BITS_PER_LONG) performs signed arithmetic if "nr" is signed too.
Converting BITS_TO_LONGS(nr) to DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
makes sure compiler can perform a right shift, even if "nr" is a signed value,
instead of an expensive integer divide.
Applying this patch saves 141 bytes on x86 when CONFIG_CC_OPTIMIZE_FOR_SIZE=y
and speedup bitmap operations.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: BITS_TO_LONGS.patch --]
[-- Type: text/plain, Size: 472 bytes --]
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 69c1edb..be5c27c 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -6,8 +6,8 @@
#define BIT(nr) (1UL << (nr))
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
-#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_LONG)
#define BITS_PER_BYTE 8
+#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
#endif
/*
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2008-02-07 7:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-07 7:54 [PATCH] Avoid divides in BITS_TO_LONGS Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox