[dpdk-dev,1/2] eal: add macros to align value to multiple

Message ID 20180314094100.12373-1-pbhagavatula@caviumnetworks.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Pavan Nikhilesh March 14, 2018, 9:40 a.m. UTC
  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(+)

--
2.16.2
  

Comments

Ananyev, Konstantin March 14, 2018, 10:42 a.m. UTC | #1
Hi Pavan,

> 
> 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)

I think you need to add braces around mul:
(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
Same above.
Konstantin

> +
> +/**
> + * 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
  
Pavan Nikhilesh March 16, 2018, 8:41 a.m. UTC | #2
Hi Konstantin,

On Wed, Mar 14, 2018 at 10:42:54AM +0000, Ananyev, Konstantin wrote:
> Hi Pavan,
>
> >
> > 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)
>
> I think you need to add braces around mul:
> (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> Same above.

Agreed, will roll up a v2.

> Konstantin

Thanks for reviewing,
Pavan.

>
> > +
> > +/**
> > + * 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
>
  

Patch

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
  *