summaryrefslogtreecommitdiffhomepage
path: root/ir/adt
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2016-02-13 20:27:54 +0100
committerMatthias Braun <matze@braunis.de>2016-02-13 20:47:39 +0100
commitdada81acdc6376be5dbe66118fcd28d25ca11902 (patch)
tree49fe0e092bfb0a24c06de8c865935ca7c54e1e1b /ir/adt
parent206f8441e918c355160fd80c783d37f8a7e88be0 (diff)
Use round_up2() more often and cleanup its implementation
Diffstat (limited to 'ir/adt')
-rw-r--r--ir/adt/bitfiddle.h26
1 files changed, 14 insertions, 12 deletions
diff --git a/ir/adt/bitfiddle.h b/ir/adt/bitfiddle.h
index 1dd72aa..bba3ccf 100644
--- a/ir/adt/bitfiddle.h
+++ b/ir/adt/bitfiddle.h
@@ -100,18 +100,6 @@ static inline uint32_t log2_ceil(uint32_t x)
}
/**
- * Round up to the next multiple of a power of two.
- * @param x A value.
- * @param pot A power of two.
- * @return x rounded up to the next multiple of pot.
- */
-static inline unsigned round_up2(unsigned x, unsigned pot)
-{
- unsigned pot_m1 = pot-1;
- return (x + pot_m1) & ~pot_m1;
-}
-
-/**
* Returns the biggest power of 2 that is equal or smaller than @p x
* (see hackers delight power-of-2 boundaries, page 48)
*/
@@ -165,4 +153,18 @@ static inline bool is_po2_or_zero(unsigned x)
return (x & (x-1)) == 0;
}
+/**
+ * Round up to the next multiple of a power of two.
+ * @param x A value.
+ * @param pot A power of two.
+ * @return x rounded up to the next multiple of pot.
+ */
+static inline unsigned round_up2(unsigned x, unsigned po2)
+{
+ assert(is_po2_or_zero(po2) && po2 > 0);
+ unsigned const po2_minus_one = po2-1;
+ unsigned const po2_mask = ~po2_minus_one;
+ return (x + po2_minus_one) & po2_mask;
+}
+
#endif