DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple
@ 2018-03-14  9:40 Pavan Nikhilesh
  2018-03-14  9:41 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Pavan Nikhilesh @ 2018-03-14  9:40 UTC (permalink / raw)
  To: jerin.jacob, thomas; +Cc: dev, Pavan Nikhilesh

Add macros to align given value to the multiple of the supplied
integer.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---

 Common code needed for OcteonTx event timer device.

 lib/librte_eal/common/include/rte_common.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index c7803e41c..2052b5300 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -190,6 +190,22 @@ static void __attribute__((constructor(prio), used)) func(void)
  */
 #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)

+/**
+ * Macro to align a value to the multiple of given value. The resultant
+ * value will be of the same type as the first parameter and will be no lower
+ * than the first parameter.
+ */
+#define RTE_ALIGN_MUL_CEIL(v, mul) \
+	(((v + (typeof(v)) mul - 1) / ((typeof(v)) mul)) * (typeof(v))mul)
+
+/**
+ * Macro to align a value to the multiple of given value. The resultant
+ * value will be of the same type as the first parameter and will be no higher
+ * than the first parameter.
+ */
+#define RTE_ALIGN_MUL_FLOOR(v, mul) \
+	((v / ((typeof(v)) mul)) * (typeof(v))mul)
+
 /**
  * Checks if a pointer is aligned to a given power-of-two value
  *
--
2.16.2

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [dpdk-dev] [PATCH 1/2] eal: add API to align integer to previous power of 2
@ 2018-02-17 10:49 Pavan Nikhilesh
  2018-02-17 10:49 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
  0 siblings, 1 reply; 9+ messages in thread
From: Pavan Nikhilesh @ 2018-02-17 10:49 UTC (permalink / raw)
  To: jerin.jacob, thomas; +Cc: dev, Pavan Nikhilesh

Add 32b and 64b API's to align the given integer to the previous power
of 2.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
 lib/librte_eal/common/include/rte_common.h | 36 ++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index c7803e41c..126914f07 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -259,6 +259,24 @@ rte_align32pow2(uint32_t x)
 	return x + 1;
 }
 
+/**
+ * Aligns input parameter to the previous power of 2
+ *
+ * @param x
+ *   The integer value to algin
+ *
+ * @return
+ *   Input parameter aligned to the previous power of 2
+ */
+static inline uint32_t
+rte_align32lowpow2(uint32_t x)
+{
+	x = rte_align32pow2(x);
+	x--;
+
+	return x - (x >> 1);
+}
+
 /**
  * Aligns 64b input parameter to the next power of 2
  *
@@ -282,6 +300,24 @@ rte_align64pow2(uint64_t v)
 	return v + 1;
 }
 
+/**
+ * Aligns 64b input parameter to the previous power of 2
+ *
+ * @param v
+ *   The 64b value to align
+ *
+ * @return
+ *   Input parameter aligned to the previous power of 2
+ */
+static inline uint64_t
+rte_align64lowpow2(uint64_t v)
+{
+	v = rte_align64pow2(v);
+	v--;
+
+	return v - (v >> 1);
+}
+
 /*********** Macros for calculating min and max **********/
 
 /**
-- 
2.16.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-04-04  9:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14  9:40 [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Pavan Nikhilesh
2018-03-14  9:41 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
2018-03-15 23:53   ` Thomas Monjalon
2018-03-16  8:56     ` Pavan Nikhilesh
2018-03-14 10:42 ` [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Ananyev, Konstantin
2018-03-16  8:41   ` Pavan Nikhilesh
2018-03-20 13:24 ` [dpdk-dev] [PATCH v2] " Pavan Nikhilesh
2018-04-04  9:14   ` Thomas Monjalon
  -- strict thread matches above, loose matches on Subject: below --
2018-02-17 10:49 [dpdk-dev] [PATCH 1/2] eal: add API to align integer to previous power of 2 Pavan Nikhilesh
2018-02-17 10:49 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).