osdep: Document differences in rounding macros

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.
This commit is contained in:
Eric Blake 2018-02-25 21:04:45 -05:00 committed by Lioncash
parent bc434da124
commit 30cbcafc05
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -141,7 +141,8 @@
/* Round number down to multiple */ /* Round number down to multiple */
#define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m)) #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)) #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
/* Check if n is a multiple of m */ /* Check if n is a multiple of m */
@ -172,6 +173,9 @@
#define QEMU_PTR_IS_ALIGNED(p, n) QEMU_IS_ALIGNED((uintptr_t)(p), (n)) #define QEMU_PTR_IS_ALIGNED(p, n) QEMU_IS_ALIGNED((uintptr_t)(p), (n))
#endif #endif
/* 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 #ifndef ROUND_UP
#define ROUND_UP(n,d) (((n) + (d) - 1) & -(d)) #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
#endif #endif