From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTBZk-0005R1-0j for qemu-devel@nongnu.org; Wed, 23 Nov 2011 07:05:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTBK4-0002Cs-S5 for qemu-devel@nongnu.org; Wed, 23 Nov 2011 06:49:05 -0500 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:50544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTBK4-00023X-JK for qemu-devel@nongnu.org; Wed, 23 Nov 2011 06:49:04 -0500 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pANBm342017166 for ; Wed, 23 Nov 2011 11:48:03 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pANBm3VN2605198 for ; Wed, 23 Nov 2011 11:48:03 GMT Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pANBm2P7028968 for ; Wed, 23 Nov 2011 04:48:03 -0700 From: Stefan Hajnoczi Date: Wed, 23 Nov 2011 11:47:51 +0000 Message-Id: <1322048878-26348-2-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1322048878-26348-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1322048878-26348-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v4 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