From 3456f0879e12382dcbe07dbe118d3e87e77cc081 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Fri, 23 Feb 2018 20:16:10 -0500 Subject: [PATCH] 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. Backports commit 6b587d3cda48e7ba26de8d30bf0d8a7063970715 from qemu --- qemu/include/qemu/osdep.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qemu/include/qemu/osdep.h b/qemu/include/qemu/osdep.h index 589f3d8e..49a4bb0a 100644 --- a/qemu/include/qemu/osdep.h +++ b/qemu/include/qemu/osdep.h @@ -147,6 +147,17 @@ /* 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