Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751679AbdLOFHY (ORCPT ); Fri, 15 Dec 2017 00:07:24 -0500 Received: from mx3.wp.pl ([212.77.101.9]:4145 "EHLO mx3.wp.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751135AbdLOFHV (ORCPT ); Fri, 15 Dec 2017 00:07:21 -0500 Date: Thu, 14 Dec 2017 21:07:13 -0800 From: Jakub Kicinski To: Al Viro Cc: Linus Torvalds , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH] Add primitives for manipulating bitfields both in host- and fixed-endian. Message-ID: <20171214210713.6be03d43@cakuba.netronome.com> In-Reply-To: <20171215023343.GG21978@ZenIV.linux.org.uk> References: <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> <20171212173528.340cd002@cakuba.netronome.com> <20171213015125.GC21978@ZenIV.linux.org.uk> <20171212184400.13b27cf8@cakuba.netronome.com> <20171213142212.GD21978@ZenIV.linux.org.uk> <20171213174554.GE21978@ZenIV.linux.org.uk> <20171215023343.GG21978@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-WP-MailID: 6cb8a12f72b41232e6cb85e731e2e064 X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 000000A [0WPU] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 940 Lines: 21 Looks great to me! On Fri, 15 Dec 2017 02:33:43 +0000, Al Viro wrote: > The following primitives are defined in linux/bitfield.h: > > * u32 le32_get_bits(__le32 val, u32 field) extracts the contents of the > bitfield specified by @field in little-endian 32bit value @val and > converts it to host-endian. > > * void le32p_replace_bits(__le32 *p, u32 v, u32 field) replaces > the contents of the bitfield specified by @field in little-endian > 32bit object pointet to by *p with the value of @v. New value is > given in host-endian and stored as little-endian. > > * __le32 le32_replace_bits(__le32 old, u32 v, u32 field) is equivalent to > ({__le32 tmp = old; le32p_replace_bits(&old, v, field); tmp;}) > In other words, instead of modifying an object in memory, it takes > the initial value and returns the modified one. the current macros take filed/mask as first param, not sure if it's worth maintaining the order