Received: from eggs.gnu.org ([2001:4830:134:3::10]:39760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bU9Nc-0008UD-UK for qemu-devel@nongnu.org; Mon, 01 Aug 2016 05:19:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bU9Nc-0003bU-14 for qemu-devel@nongnu.org; Mon, 01 Aug 2016 05:19:24 -0400 References: <1469129688-22848-1-git-send-email-eblake@redhat.com> <1469129688-22848-4-git-send-email-eblake@redhat.com> From: Paolo Bonzini Message-ID: Date: Mon, 1 Aug 2016 11:19:12 +0200 MIME-Version: 1.0 In-Reply-To: <1469129688-22848-4-git-send-email-eblake@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 3/4] osdep: Document differences in rounding macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, pl@kamp.de On 21/07/2016 21:34, Eric Blake wrote: > 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 Ouch, this is ugly, especially since DIV_ROUND_UP does not require alignment! Not your fault of course, and the patch is arguably an improvement. Paolo