[dpdk-dev,v2] eal: add macros to align value to multiple
Checks
Commit Message
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.
v2 Changes:
- Use paranthesis around mul (Konstantin).
- Squash test_common patch.
lib/librte_eal/common/include/rte_common.h | 16 ++++++++++++++++
test/test/test_common.c | 12 ++++++++++++
2 files changed, 28 insertions(+)
--
2.16.2
Comments
20/03/2018 14:24, 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.
>
> v2 Changes:
> - Use paranthesis around mul (Konstantin).
> - Squash test_common patch.
Applied, thanks
@@ -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
*
@@ -128,6 +128,18 @@ test_align(void)
FAIL("rte_is_aligned");
}
}
+
+ for (p = 1; p <= MAX_NUM / 2; p++) {
+ for (i = 1; i <= MAX_NUM / 2; i++) {
+ val = RTE_ALIGN_MUL_CEIL(i, p);
+ if (val % p != 0 || val < i)
+ FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
+ val = RTE_ALIGN_MUL_FLOOR(i, p);
+ if (val % p != 0 || val > i)
+ FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
+ }
+ }
+
return 0;
}