From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUfXm-0006kk-T6 for qemu-devel@nongnu.org; Tue, 02 Aug 2016 15:40:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUfXl-0003cY-Vi for qemu-devel@nongnu.org; Tue, 02 Aug 2016 15:40:02 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUfXl-0003cI-PO for qemu-devel@nongnu.org; Tue, 02 Aug 2016 15:40:01 -0400 Received: by mail-wm0-x243.google.com with SMTP id o80so32557427wme.0 for ; Tue, 02 Aug 2016 12:40:01 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 2 Aug 2016 21:39:27 +0200 Message-Id: <1470166775-3671-18-git-send-email-pbonzini@redhat.com> In-Reply-To: <1470166775-3671-1-git-send-email-pbonzini@redhat.com> References: <1470166775-3671-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 17/25] osdep: Document differences in rounding macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Eric Blake 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 Message-Id: <1469129688-22848-4-git-send-email-eblake@redhat.com> Signed-off-by: Paolo Bonzini --- 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 d7c111d..9e9fa61 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.7.4