]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Thu, 17 Nov 2011 13:40:25 +0000 (13:40 +0000)
committerKevin Wolf <kwolf@redhat.com>
Mon, 5 Dec 2011 13:51:37 +0000 (14:51 +0100)
Add macros for aligning a number to a multiple, for example:

QEMU_ALIGN_DOWN(500, 2000) = 0
QEMU_ALIGN_UP(500, 2000) = 2000

Since ALIGN_UP() is a common macro name use the QEMU_* namespace prefix.
Hopefully this will protect us from included headers that leak something
with a similar name.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-common.h

index 2ce47aa12d710df967960e696a06413c55f55bce..44870fe5236e480ee6b68c5b5a0a71a5baa1ec40 100644 (file)
@@ -341,6 +341,12 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
     return res.ll;
 }
 
+/* Round number down to multiple */
+#define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m))
+
+/* Round number up to multiple */
+#define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
+
 #include "module.h"
 
 #endif