Blame SOURCES/0120-Move-ilog-functions-from-util.c-to-defs.h.patch

089393
From c9e41cd3485fa1a65dc6206c5b210b4be4c5597c Mon Sep 17 00:00:00 2001
089393
From: =?UTF-8?q?=C3=81kos=20Uzonyi?= <uzonyi.akos@gmail.com>
089393
Date: Sat, 13 Jun 2020 18:18:32 +0200
089393
Subject: [PATCH 120/138] Move ilog* functions from util.c to defs.h
089393
089393
* util.c (ILOG2_ITER_, ilog2_klong, ilog2_64, ilog2_32): Move ...
089393
* defs.h: ... here.
089393
---
089393
 defs.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
089393
 util.c | 62 --------------------------------------------------------------
089393
 2 files changed, 60 insertions(+), 62 deletions(-)
089393
089393
diff --git a/defs.h b/defs.h
089393
index 3aa07fb..d8bd513 100644
089393
--- a/defs.h
089393
+++ b/defs.h
089393
@@ -1698,4 +1698,64 @@ scno_is_valid(kernel_ulong_t scno)
089393
 
089393
 # define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(sys_ ## syscall_name)(struct tcb *tcp)
089393
 
089393
+#define ILOG2_ITER_(val_, ret_, bit_)					\
089393
+	do {								\
089393
+		typeof(ret_) shift_ =					\
089393
+			((val_) > ((((typeof(val_)) 1)			\
089393
+				   << (1 << (bit_))) - 1)) << (bit_);	\
089393
+		(val_) >>= shift_;					\
089393
+		(ret_) |= shift_;					\
089393
+	} while (0)
089393
+
089393
+/**
089393
+ * Calculate floor(log2(val)), with the exception of val == 0, for which 0
089393
+ * is returned as well.
089393
+ *
089393
+ * @param val 64-bit value to calculate integer base-2 logarithm for.
089393
+ * @return    (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
089393
+ */
089393
+static inline unsigned int
089393
+ilog2_64(uint64_t val)
089393
+{
089393
+	unsigned int ret = 0;
089393
+
089393
+	ILOG2_ITER_(val, ret, 5);
089393
+	ILOG2_ITER_(val, ret, 4);
089393
+	ILOG2_ITER_(val, ret, 3);
089393
+	ILOG2_ITER_(val, ret, 2);
089393
+	ILOG2_ITER_(val, ret, 1);
089393
+	ILOG2_ITER_(val, ret, 0);
089393
+
089393
+	return ret;
089393
+}
089393
+
089393
+/**
089393
+ * Calculate floor(log2(val)), with the exception of val == 0, for which 0
089393
+ * is returned as well.
089393
+ *
089393
+ * @param val 32-bit value to calculate integer base-2 logarithm for.
089393
+ * @return    (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
089393
+ */
089393
+static inline unsigned int
089393
+ilog2_32(uint32_t val)
089393
+{
089393
+	unsigned int ret = 0;
089393
+
089393
+	ILOG2_ITER_(val, ret, 4);
089393
+	ILOG2_ITER_(val, ret, 3);
089393
+	ILOG2_ITER_(val, ret, 2);
089393
+	ILOG2_ITER_(val, ret, 1);
089393
+	ILOG2_ITER_(val, ret, 0);
089393
+
089393
+	return ret;
089393
+}
089393
+
089393
+#if SIZEOF_KERNEL_LONG_T > 4
089393
+# define ilog2_klong ilog2_64
089393
+#else
089393
+# define ilog2_klong ilog2_32
089393
+#endif
089393
+
089393
+#undef ILOG2_ITER_
089393
+
089393
 #endif /* !STRACE_DEFS_H */
089393
diff --git a/util.c b/util.c
089393
index 59696b5..cde76c1 100644
089393
--- a/util.c
089393
+++ b/util.c
089393
@@ -1120,68 +1120,6 @@ dumpiov_upto(struct tcb *const tcp, const int len, const kernel_ulong_t addr,
089393
 #undef iov
089393
 }
089393
 
089393
-#define ILOG2_ITER_(val_, ret_, bit_)					\
089393
-	do {								\
089393
-		typeof(ret_) shift_ =					\
089393
-			((val_) > ((((typeof(val_)) 1)			\
089393
-				   << (1 << (bit_))) - 1)) << (bit_);	\
089393
-		(val_) >>= shift_;					\
089393
-		(ret_) |= shift_;					\
089393
-	} while (0)
089393
-
089393
-#if SIZEOF_KERNEL_LONG_T > 4
089393
-
089393
-# define ilog2_klong ilog2_64
089393
-/**
089393
- * Calculate floor(log2(val)), with the exception of val == 0, for which 0
089393
- * is returned as well.
089393
- *
089393
- * @param val 64-bit value to calculate integer base-2 logarithm for.
089393
- * @return    (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
089393
- */
089393
-static inline unsigned int
089393
-ilog2_64(uint64_t val)
089393
-{
089393
-	unsigned int ret = 0;
089393
-
089393
-	ILOG2_ITER_(val, ret, 5);
089393
-	ILOG2_ITER_(val, ret, 4);
089393
-	ILOG2_ITER_(val, ret, 3);
089393
-	ILOG2_ITER_(val, ret, 2);
089393
-	ILOG2_ITER_(val, ret, 1);
089393
-	ILOG2_ITER_(val, ret, 0);
089393
-
089393
-	return ret;
089393
-}
089393
-
089393
-#else /* SIZEOF_KERNEL_LONG_T == 4 */
089393
-
089393
-# define ilog2_klong ilog2_32
089393
-/**
089393
- * Calculate floor(log2(val)), with the exception of val == 0, for which 0
089393
- * is returned as well.
089393
- *
089393
- * @param val 32-bit value to calculate integer base-2 logarithm for.
089393
- * @return    (unsigned int) floor(log2(val)) if val > 0, 0 if val == 0.
089393
- */
089393
-static inline unsigned int
089393
-ilog2_32(uint32_t val)
089393
-{
089393
-	unsigned int ret = 0;
089393
-
089393
-	ILOG2_ITER_(val, ret, 4);
089393
-	ILOG2_ITER_(val, ret, 3);
089393
-	ILOG2_ITER_(val, ret, 2);
089393
-	ILOG2_ITER_(val, ret, 1);
089393
-	ILOG2_ITER_(val, ret, 0);
089393
-
089393
-	return ret;
089393
-}
089393
-
089393
-#endif /* SIZEOF_KERNEL_LONG_T */
089393
-
089393
-#undef ILOG2_ITER_
089393
-
089393
 void
089393
 dumpstr(struct tcb *const tcp, const kernel_ulong_t addr,
089393
 	const kernel_ulong_t len)
089393
-- 
089393
2.1.4
089393