summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedorov <serge.fdrv@gmail.com>2016-04-22 19:08:44 +0300
committerRichard Henderson <rth@twiddle.net>2016-05-12 14:06:40 -1000
commit6b587d3cda48e7ba26de8d30bf0d8a7063970715 (patch)
treeea8d42502dcc0e8f1d87004bef1d5865b786f2c2
parent18a60a76147569ca9e11b0607e50ce4012fe1aaa (diff)
downloadqemu-6b587d3cda48e7ba26de8d30bf0d8a7063970715.tar.gz
qemu-6b587d3cda48e7ba26de8d30bf0d8a7063970715.tar.bz2
qemu-6b587d3cda48e7ba26de8d30bf0d8a7063970715.zip
include/qemu/osdep.h: Add macros for pointer alignment
These macros provide a convenient way to n-byte align pointers up and down and check if a pointer is n-byte aligned. Signed-off-by: Sergey Fedorov <serge.fdrv@gmail.com> Signed-off-by: Sergey Fedorov <sergey.fedorov@linaro.org> Message-Id: <1461341333-19646-3-git-send-email-sergey.fedorov@linaro.org> Signed-off-by: Richard Henderson <rth@twiddle.net>
-rw-r--r--include/qemu/osdep.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index e3bc50b613..1e3221cbec 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -161,6 +161,17 @@ extern int daemon(int, int);
/* Check if n is a multiple of m */
#define QEMU_IS_ALIGNED(n, m) (((n) % (m)) == 0)
+/* n-byte align pointer down */
+#define QEMU_ALIGN_PTR_DOWN(p, n) \
+ ((typeof(p))QEMU_ALIGN_DOWN((uintptr_t)(p), (n)))
+
+/* n-byte align pointer up */
+#define QEMU_ALIGN_PTR_UP(p, n) \
+ ((typeof(p))QEMU_ALIGN_UP((uintptr_t)(p), (n)))
+
+/* Check if pointer p is n-bytes aligned */
+#define QEMU_PTR_IS_ALIGNED(p, n) QEMU_IS_ALIGNED((uintptr_t)(p), (n))
+
#ifndef ROUND_UP
#define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
#endif