From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXZNc-0001Ax-Ia for qemu-devel@nongnu.org; Mon, 05 Dec 2011 09:18:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXZNU-0000KA-5X for qemu-devel@nongnu.org; Mon, 05 Dec 2011 09:18:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXZNT-0000Jq-O6 for qemu-devel@nongnu.org; Mon, 05 Dec 2011 09:18:43 -0500 From: Kevin Wolf Date: Mon, 5 Dec 2011 15:21:06 +0100 Message-Id: <1323094878-7967-30-git-send-email-kwolf@redhat.com> In-Reply-To: <1323094878-7967-1-git-send-email-kwolf@redhat.com> References: <1323094878-7967-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 29/41] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Stefan Hajnoczi 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 Signed-off-by: Kevin Wolf --- qemu-common.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/qemu-common.h b/qemu-common.h index 2ce47aa..44870fe 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -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 -- 1.7.6.4