Re: [PATCH v3 1/7] clk: introduce clk_div_mask() helper

From: Stephen Boyd
Date: Tue Jul 07 2015 - 19:26:31 EST


On 07/07, Andy Shevchenko wrote:
> On Thu, 2015-06-18 at 12:48 -0700, Stephen Boyd wrote:
> > On 03/31, Andy Shevchenko wrote:
> > > diff --git a/include/linux/clk-provider.h b/include/linux/clk
> > > -provider.h
> > > index 5591ea7..20b0b67 100644
> > > --- a/include/linux/clk-provider.h
> > > +++ b/include/linux/clk-provider.h
> > > @@ -353,6 +353,11 @@ struct clk_divider {
> > > spinlock_t *lock;
> > > };
> > >
> > > +static inline unsigned long clk_div_mask(u8 width)
> > > +{
> > > + return (1 << width) - 1;
> > > +}
> > > +
> >
> > Why not just change drivers to use GENMASK? It's a proven and
> > tested way to generate a bitmask.
>
> Too many unneeded calculations I suppose.

That's what compiler optimizations are for.

>
> Compare:
> mask = clk_div_mask(mm) << ms;
> which is simple ((1 << mm) - 1) << ms
> and
> mask = GENMASK(mm + ms - 1, ms);
> which is (~0 << ms) & (~0 >> (BITS_PER_LONG - 1 - (mm + ms -
> 1)))

And if mm is 32 then we hit undefined behavior.

>
> >
> > So I'd rather see drivers converted to use that macro directly
> > especially because the mask may need to start at some bit that
> > isn't 0.
>
> If you think the above is not a burden, I can do the conversion to
> GENMASK.
>
> Though it might make sense when ms = 0 explicitly.
>

Yes let's use GENMASK. I imagine the extra few instructions are
negligible.

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/