thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
a83cc2
From d9fa07a04ee19ad713b053f6a649178361d822a8 Mon Sep 17 00:00:00 2001
a83cc2
From: Paolo Bonzini <pbonzini@redhat.com>
a83cc2
Date: Fri, 16 Jul 2021 16:51:31 -0400
a83cc2
Subject: [PATCH 15/43] osdep: provide ROUND_DOWN macro
a83cc2
a83cc2
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
RH-Bugzilla: 1957194
a83cc2
a83cc2
osdep.h provides a ROUND_UP macro to hide bitwise operations for the
a83cc2
purpose of rounding a number up to a power of two; add a ROUND_DOWN
a83cc2
macro that does the same with truncation towards zero.
a83cc2
a83cc2
While at it, change the formatting of some comments.
a83cc2
a83cc2
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
a83cc2
(cherry picked from commit c9797456f64ce72c03eb2969d97ac1dd4698d91e)
a83cc2
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
a83cc2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
---
a83cc2
 include/qemu/osdep.h | 28 ++++++++++++++++++++++------
a83cc2
 1 file changed, 22 insertions(+), 6 deletions(-)
a83cc2
a83cc2
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
a83cc2
index cb2a07e472..e327220992 100644
a83cc2
--- a/include/qemu/osdep.h
a83cc2
+++ b/include/qemu/osdep.h
a83cc2
@@ -316,11 +316,16 @@ extern "C" {
a83cc2
     })
a83cc2
 #endif
a83cc2
 
a83cc2
-/* Round number down to multiple */
a83cc2
+/*
a83cc2
+ * Round number down to multiple. Safe when m is not a power of 2 (see
a83cc2
+ * ROUND_DOWN for a faster version when a power of 2 is guaranteed).
a83cc2
+ */
a83cc2
 #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m))
a83cc2
 
a83cc2
-/* Round number up to multiple. Safe when m is not a power of 2 (see
a83cc2
- * ROUND_UP for a faster version when a power of 2 is guaranteed) */
a83cc2
+/*
a83cc2
+ * Round number up to multiple. Safe when m is not a power of 2 (see
a83cc2
+ * ROUND_UP for a faster version when a power of 2 is guaranteed).
a83cc2
+ */
a83cc2
 #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m))
a83cc2
 
a83cc2
 /* Check if n is a multiple of m */
a83cc2
@@ -337,11 +342,22 @@ extern "C" {
a83cc2
 /* Check if pointer p is n-bytes aligned */
a83cc2
 #define QEMU_PTR_IS_ALIGNED(p, n) QEMU_IS_ALIGNED((uintptr_t)(p), (n))
a83cc2
 
a83cc2
-/* Round number up to multiple. Requires that d be a power of 2 (see
a83cc2
+/*
a83cc2
+ * Round number down to multiple. Requires that d be a power of 2 (see
a83cc2
  * QEMU_ALIGN_UP for a safer but slower version on arbitrary
a83cc2
- * numbers); works even if d is a smaller type than n.  */
a83cc2
+ * numbers); works even if d is a smaller type than n.
a83cc2
+ */
a83cc2
+#ifndef ROUND_DOWN
a83cc2
+#define ROUND_DOWN(n, d) ((n) & -(0 ? (n) : (d)))
a83cc2
+#endif
a83cc2
+
a83cc2
+/*
a83cc2
+ * Round number up to multiple. Requires that d be a power of 2 (see
a83cc2
+ * QEMU_ALIGN_UP for a safer but slower version on arbitrary
a83cc2
+ * numbers); works even if d is a smaller type than n.
a83cc2
+ */
a83cc2
 #ifndef ROUND_UP
a83cc2
-#define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d)))
a83cc2
+#define ROUND_UP(n, d) ROUND_DOWN((n) + (d) - 1, (d))
a83cc2
 #endif
a83cc2
 
a83cc2
 #ifndef DIV_ROUND_UP
a83cc2
-- 
a83cc2
2.27.0
a83cc2