Received: from eggs.gnu.org ([2001:4830:134:3::10]:33677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQJkS-0006W3-Qa for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:35:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQJkO-0008Jh-Eb for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:35:07 -0400 Received: from resqmta-po-05v.sys.comcast.net ([2001:558:fe16:19:96:114:154:164]:34940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQJkO-0008IB-9W for qemu-devel@nongnu.org; Thu, 21 Jul 2016 15:35:04 -0400 From: Eric Blake Date: Thu, 21 Jul 2016 13:34:47 -0600 Message-Id: <1469129688-22848-4-git-send-email-eblake@redhat.com> In-Reply-To: <1469129688-22848-1-git-send-email-eblake@redhat.com> References: <1469129688-22848-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH 3/4] osdep: Document differences in rounding macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, pl@kamp.de, pbonzini@redhat.com Make it obvious which macros are safe in which situations. Useful since QEMU_ALIGN_UP and ROUND_UP both purport to do the same thing, but differ on whether the alignment must be a power of 2. Signed-off-by: Eric Blake --- include/qemu/osdep.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index fbb8759..9991fb0 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -158,7 +158,8 @@ extern int daemon(int, int); /* Round number down to multiple */ #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) -/* Round number up to multiple */ +/* Round number up to multiple. Safe when m is not a power of 2 (see + * ROUND_UP for a faster version when a power of 2 is guaranteed) */ #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) /* Check if n is a multiple of m */ @@ -175,6 +176,9 @@ extern int daemon(int, int); /* Check if pointer p is n-bytes aligned */ #define QEMU_PTR_IS_ALIGNED(p, n) QEMU_IS_ALIGNED((uintptr_t)(p), (n)) +/* Round number up to multiple. Requires that d be a power of 2 (see + * QEMU_ALIGN_UP for a safer but slower version on arbitrary + * numbers) */ #ifndef ROUND_UP #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d)) #endif -- 2.5.5