From patchwork Thu Nov 17 13:40:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 126220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CCA68B71FE for ; Fri, 18 Nov 2011 00:41:09 +1100 (EST) Received: from localhost ([::1]:51589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RR2Cz-0002b9-PA for incoming@patchwork.ozlabs.org; Thu, 17 Nov 2011 08:40:53 -0500 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 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.31]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pAHDeaT5005749; Thu, 17 Nov 2011 06:40:36 -0700 From: Stefan Hajnoczi To: Date: Thu, 17 Nov 2011 13:40:25 +0000 Message-Id: <1321537232-799-2-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.1 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> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.161 Cc: Kevin Wolf , Paolo Bonzini , Marcelo Tosatti , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 1/8] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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