[PATCH] Optimize is_power_of_2().
- From: Vegard Nossum <vegard.nossum@xxxxxxxxx>
- Date: Fri, 15 Jun 2007 18:56:42 +0200
From: Vegard Nossum <vegard@xxxxxxxxxxxx>
Date: Fri, 15 Jun 2007 18:35:49 +0200
Subject: [PATCH] Optimize is_power_of_2().
Rationale: Removes one conditional branch and reduces icache footprint.
Proof: If n is false, the product of n and any value is false. If n is
true, the truth of (n * x) is the truth of x.
Signed-off-by: Vegard Nossum <vegard@xxxxxxxxxxxx>
---
include/linux/log2.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 1b8a2c1..56196b1 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -51,7 +51,7 @@ int __ilog2_u64(u64 n)
static inline __attribute__((const))
bool is_power_of_2(unsigned long n)
{
- return (n != 0 && ((n & (n - 1)) == 0));
+ return n * !(n & (n - 1));
}
/*
--
1.5.0.6
-
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: [PATCH] Optimize is_power_of_2().
- From: Jan Engelhardt
- Re: [PATCH] Optimize is_power_of_2().
- From: H. Peter Anvin
- Re: [PATCH] Optimize is_power_of_2().
- Prev by Date: [patch 0/8] 2.6.22-rc3 perfmon2 : IBS implementation for AMD64
- Next by Date: [patch 1/8] 2.6.22-rc3 perfmon2 : IBS implementation for AMD64
- Previous by thread: [patch 0/8] 2.6.22-rc3 perfmon2 : IBS implementation for AMD64
- Next by thread: Re: [PATCH] Optimize is_power_of_2().
- Index(es):
Relevant Pages
|