From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RR2Co-0002Vx-Sd for qemu-devel@nongnu.org; Thu, 17 Nov 2011 08:40:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RR2Cm-0000vJ-0b for qemu-devel@nongnu.org; Thu, 17 Nov 2011 08:40:42 -0500 Received: from mtagate1.uk.ibm.com ([194.196.100.161]:52794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RR2Cl-0000tf-Kh for qemu-devel@nongnu.org; Thu, 17 Nov 2011 08:40:39 -0500 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pAHDebJJ013058 for ; Thu, 17 Nov 2011 13:40:37 GMT Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAHDebdA2494578 for ; Thu, 17 Nov 2011 13:40:37 GMT Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAHDeaQw005783 for ; Thu, 17 Nov 2011 06:40:36 -0700 From: Stefan Hajnoczi Date: Thu, 17 Nov 2011 13:40:25 +0000 Message-Id: <1321537232-799-2-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1321537232-799-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1321537232-799-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 1/8] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Marcelo Tosatti , 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 --- 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.7.1