lkml.org 
[lkml]   [2017]   [Dec]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH] new byteorder primitives - ..._{replace,get}_bits()
On Tue, Dec 12, 2017 at 05:04:37PM -0800, Jakub Kicinski wrote:
> On Wed, 13 Dec 2017 00:36:59 +0000, Al Viro wrote:
> > On Tue, Dec 12, 2017 at 03:59:33PM -0800, Jakub Kicinski wrote:
> > > > +static __always_inline __##type type##_replace_bits(__##type old, \
> > > > + base val, base mask) \
> > > > +{ \
> > > > + __##type m = to(mask); \
> > > > + if (__builtin_constant_p(val) && \
> > >
> > > Is the lack of a __builtin_constant_p(mask) test intentional? Sometimes
> > > the bitfield is a packed array and people may have a helper to which
> > > only the mask is passed as non-constant and the value is implied by the
> > > helper, thus constant.
> >
> > If the mask in non-constant, we probably shouldn't be using that at all;
> > could you show a real-world example where that would be the case?
>
> FIELD_* macros explicitly forbid this, since the code would be...
> suboptimal with the runtime ffsl. Real life examples are the hackish
> macro NFP_ETH_SET_BIT_CONFIG() in
>
> drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c

Why not simply make nfp_eth_set_bit_config() static inline and be
done with that? It's not that large and there are only few callers,
so...

> I remember there was also some Renesas code.. maybe this:
>
> https://patchwork.kernel.org/patch/9881279/
>
> it looks like cpg_z_clk_recalc_rate() and cpg_z2_clk_recalc_rate() only
> differ in mask.

*shrug*

That thing would expand into "reg &= 15" in one case and "reg >>= 8; reg &= 15"
in another. Either of which is cheaper than a function call, and definitely
cheaper than any kind of dynamic calculation of shift, no matter how implemented.

\
 
 \ /
  Last update: 2017-12-13 02:31    [W:0.058 / U:0.504 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site