Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752374AbdLMBfi (ORCPT ); Tue, 12 Dec 2017 20:35:38 -0500 Received: from mx3.wp.pl ([212.77.101.9]:30543 "EHLO mx3.wp.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750749AbdLMBff (ORCPT ); Tue, 12 Dec 2017 20:35:35 -0500 Date: Tue, 12 Dec 2017 17:35:28 -0800 From: Jakub Kicinski To: Al Viro Cc: Linus Torvalds , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH] new byteorder primitives - ..._{replace,get}_bits() Message-ID: <20171212173528.340cd002@cakuba.netronome.com> In-Reply-To: <20171213013056.GB21978@ZenIV.linux.org.uk> References: <20171211053803.GW21978@ZenIV.linux.org.uk> <20171211155422.GA12326@ZenIV.linux.org.uk> <20171211200224.23bc5df4@cakuba.netronome.com> <20171212062002.GY21978@ZenIV.linux.org.uk> <20171212194532.GA7062@ZenIV.linux.org.uk> <20171212120409.64b6362e@cakuba.netronome.com> <20171212234856.GZ21978@ZenIV.linux.org.uk> <20171212155933.03c88eab@cakuba.netronome.com> <20171213003659.GA21978@ZenIV.linux.org.uk> <20171212170437.4b129e50@cakuba.netronome.com> <20171213013056.GB21978@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-WP-MailID: b2ee5c3b6fc5fbcfa608656858e90209 X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 000000A [0VP0] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1979 Lines: 45 On Wed, 13 Dec 2017 01:30:56 +0000, Al Viro wrote: > 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... It used to be __always_inline, but apparently LLVM/clang doesn't propagate constants :( 4e59532541c8 ("nfp: don't depend on compiler constant propagation") > > 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.