[dpdk-stable] [EXT] Re: [PATCH] eal: fix macros to align value

Thomas Monjalon thomas at monjalon.net
Wed Jun 24 10:30:18 CEST 2020


24/06/2020 10:24, Harman Kalra:
> On Wed, Jun 24, 2020 at 10:13:18AM +0200, Thomas Monjalon wrote:
> > 09/06/2020 21:17, Harman Kalra:
> > > Found an issue while using RTE_ALIGN_MUL_NEAR with an
> > > expression, like as passed in estimate_tsc_freq().
> > > RTE_ALIGN_MUL_FLOOR resulted in unexpected value in the
> > > above function as division has more precedence over
> > > substraction.
> > 
> > The only change I see is adding parenthesis around v.
> > Am I right?
> 
> Yes, parathesis are required if an expression is passed.

I think the commit log needs to be updated.
I don't see the relation between
	"division has more precedence over substraction"
and
	"parathesis are required if an expression is passed"


> > >  #define RTE_ALIGN_MUL_CEIL(v, mul) \
> > > -	(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > +	((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > [...]
> > >  #define RTE_ALIGN_MUL_FLOOR(v, mul) \
> > > -	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > +	(((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > [...]
> > >  	({							\
> > >  		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
> > >  		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
> > > -		(ceil - v) > (v - floor) ? floor : ceil;	\
> > > +		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
> > >  	})
> > 
> > 
> > 
> > 
> 







More information about the stable mailing list