From: Al Viro <viro@ZenIV.linux.org.uk>
To: Jakub Kicinski <kubakici@wp.pl>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH] new byteorder primitives - ..._{replace,get}_bits()
Date: Wed, 13 Dec 2017 01:30:56 +0000 [thread overview]
Message-ID: <20171213013056.GB21978@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20171212170437.4b129e50@cakuba.netronome.com>
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.
next prev parent reply other threads:[~2017-12-13 1:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20171210045326.GO21978@ZenIV.linux.org.uk>
[not found] ` <420a198d-61f8-81cf-646d-10446cb41def@synopsys.com>
[not found] ` <20171211050520.GV21978@ZenIV.linux.org.uk>
2017-12-11 5:38 ` [RFC][PATCH] apparent big-endian bugs in dwc-xlgmac Al Viro
2017-12-11 6:46 ` Jie Deng
2017-12-11 15:54 ` [RFC][PATCH] new byteorder primitives - ..._{replace,get}_bits() Al Viro
2017-12-12 4:02 ` Jakub Kicinski
2017-12-12 6:20 ` Al Viro
2017-12-12 19:45 ` Al Viro
2017-12-12 20:04 ` Jakub Kicinski
2017-12-12 23:48 ` Al Viro
2017-12-12 23:59 ` Jakub Kicinski
2017-12-13 0:36 ` Al Viro
2017-12-13 1:04 ` Jakub Kicinski
2017-12-13 1:30 ` Al Viro [this message]
2017-12-13 1:35 ` Jakub Kicinski
2017-12-13 1:51 ` Al Viro
2017-12-13 2:44 ` Jakub Kicinski
2017-12-13 14:22 ` Al Viro
2017-12-13 17:45 ` Al Viro
2017-12-15 2:33 ` [RFC][PATCH] Add primitives for manipulating bitfields both in host- and fixed-endian Al Viro
2017-12-15 5:07 ` Jakub Kicinski
2017-12-15 5:34 ` Al Viro
2017-12-15 16:48 ` [RFC][PATCH v2] " Al Viro
2017-12-13 19:04 ` [RFC][PATCH] new byteorder primitives - ..._{replace,get}_bits() Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171213013056.GB21978@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=kubakici@wp.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox