]> git.proxmox.com Git - mirror_qemu.git/commitdiff
Make pow2ceil() and pow2floor() inline
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 24 Jul 2015 12:33:12 +0000 (13:33 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 7 Sep 2015 13:19:01 +0000 (14:19 +0100)
Since the pow2floor() function is now used in a hot code path,
make it inline; for consistency, provide pow2ceil() as an inline
function too.

Because these functions use ctz64() we have to put the inline
versions into host-utils.h, so they have access to ctz64(),
and move the inline is_power_of_2() along with them.

We then need to include host-utils.h from qemu-common.h so that
the files which use these functions via qemu-common.h still have
access to them.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1437741192-20955-7-git-send-email-peter.maydell@linaro.org

include/qemu-common.h
include/qemu/host-utils.h
util/cutils.c

index f3288216504f635ccf838468c7310ff41ce79944..efaf919884ac3801e24ca0ec637f54744b7ba5c9 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "glib-compat.h"
 #include "qemu/option.h"
+#include "qemu/host-utils.h"
 
 /* HOST_LONG_BITS is the size of a native pointer in bits. */
 #if UINTPTR_MAX == UINT32_MAX
@@ -416,21 +417,6 @@ static inline uint8_t from_bcd(uint8_t val)
 /* Round number up to multiple */
 #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
 
-static inline bool is_power_of_2(uint64_t value)
-{
-    if (!value) {
-        return 0;
-    }
-
-    return !(value & (value - 1));
-}
-
-/* round down to the nearest power of 2*/
-int64_t pow2floor(int64_t value);
-
-/* round up to the nearest power of 2 (0 if overflow) */
-uint64_t pow2ceil(uint64_t value);
-
 #include "qemu/module.h"
 
 /*
index c27d3dc898ff602e7156866ae393d5b1f30ac4c9..7d36ebfd5b6102b9f3a88ca546f0bc2df4b151f2 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "qemu/compiler.h"   /* QEMU_GNUC_PREREQ */
 #include <limits.h>
+#include <stdbool.h>
 
 #ifdef CONFIG_INT128
 static inline void mulu64(uint64_t *plow, uint64_t *phigh,
@@ -408,4 +409,36 @@ static inline int ctpop64(uint64_t val)
 # error Unknown sizeof long
 #endif
 
+static inline bool is_power_of_2(uint64_t value)
+{
+    if (!value) {
+        return 0;
+    }
+
+    return !(value & (value - 1));
+}
+
+/* round down to the nearest power of 2*/
+static inline int64_t pow2floor(int64_t value)
+{
+    if (!is_power_of_2(value)) {
+        value = 0x8000000000000000ULL >> clz64(value);
+    }
+    return value;
+}
+
+/* round up to the nearest power of 2 (0 if overflow) */
+static inline uint64_t pow2ceil(uint64_t value)
+{
+    uint8_t nlz = clz64(value);
+
+    if (is_power_of_2(value)) {
+        return value;
+    }
+    if (!nlz) {
+        return 0;
+    }
+    return 1ULL << (64 - nlz);
+}
+
 #endif
index 43aafde8a59a8a2d9a84bfba7816d9413b62a711..923445267f723bd4f9585ee8d0a6d856186b17f7 100644 (file)
@@ -469,29 +469,6 @@ int qemu_parse_fd(const char *param)
     return fd;
 }
 
-/* round down to the nearest power of 2*/
-int64_t pow2floor(int64_t value)
-{
-    if (!is_power_of_2(value)) {
-        value = 0x8000000000000000ULL >> clz64(value);
-    }
-    return value;
-}
-
-/* round up to the nearest power of 2 (0 if overflow) */
-uint64_t pow2ceil(uint64_t value)
-{
-    uint8_t nlz = clz64(value);
-
-    if (is_power_of_2(value)) {
-        return value;
-    }
-    if (!nlz) {
-        return 0;
-    }
-    return 1ULL << (64 - nlz);
-}
-
 /*
  * Implementation of  ULEB128 (http://en.wikipedia.org/wiki/LEB128)
  * Input is limited to 14-bit numbers