From 7b23a58b85712d12ffbb48c6a276e412f3d20ee9 Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Wed, 21 Mar 2012 21:54:50 +0100 Subject: [PATCH 23/55] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros RH-Author: Jeffrey Cody Message-id: Patchwork-id: 38872 O-Subject: [RHEL6.3 qemu-kvm PATCH v8 23/54] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros Bugzilla: 582475 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Kevin Wolf 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 (cherry picked from commmit 3951690a4a29e031492090131d001e5047938631) Signed-off-by: Stefan Hajnoczi Signed-off-by: Anthony Liguori Signed-off-by: Jeff Cody --- qemu-common.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) Signed-off-by: Michal Novotny --- qemu-common.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/qemu-common.h b/qemu-common.h index 42adee8..9b01f50 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -301,6 +301,12 @@ static inline uint8_t from_bcd(uint8_t val) return ((val >> 4) * 10) + (val & 0x0f); } +/* 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 /* dyngen-exec.h hack */ -- 1.7.7.6