Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753228AbcLGLFY (ORCPT ); Wed, 7 Dec 2016 06:05:24 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35375 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751803AbcLGLFX (ORCPT ); Wed, 7 Dec 2016 06:05:23 -0500 Date: Wed, 7 Dec 2016 11:05:17 +0000 From: Jakub Kicinski To: Sebastian Frias Cc: Kalle Valo , zijun_hu , Andrew Morton , linux-kernel@vger.kernel.org, Linus Torvalds , Mason , Harvey Harrison , Borislav Petkov Subject: Re: [PATCH v3] add equivalent of BIT(x) for bitfields Message-ID: <20161207110517.45f54a9a@jkicinski-Precision-T1700> In-Reply-To: <489b2ea4-0678-97ac-f46e-4fc8a7853358@laposte.net> References: <87bmwom8on.fsf@purkki.adurom.net> <489b2ea4-0678-97ac-f46e-4fc8a7853358@laposte.net> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1704 Lines: 49 On Wed, 7 Dec 2016 11:00:57 +0100, Sebastian Frias wrote: > On 07/12/16 09:42, Kalle Valo wrote: > > Sebastian Frias writes: > > > >> Introduce GENVALUE(msb, lsb, value) macro to ease dealing with > >> continuous bitfields, just as BIT(x) does for single bits. > >> > >> GENVALUE_ULL(msb, lsb, value) macro is also added. > >> > >> This is useful mostly for creating values to be packed together > >> via OR operations, ex: > >> > >> u32 val = 0x11110000; > >> val |= GENVALUE(19, 12, 0x5a); > >> > >> now 'val = 0x1115a000' > >> > >> > >> Signed-off-by: Sebastian Frias > >> Link: https://marc.info/?l=linux-kernel&m=148094498711000&w=2 > >> --- > >> > >> Change in v2: > >> - rename the macro to GENVALUE as proposed by Linus > >> - longer comment attempts to show use case for the macro as > >> proposed by Borislav > >> > >> Change in v3: > >> - use BUILD_BUG_ON_ZERO() to break if some input parameters > >> (essentially 'lsb' but also 'msb') are not constants as > >> proposed by Linus. > >> Indeed, 'lsb' is used twice so it cannot have side-effects; > >> 'msb' is subjected to same constraints for consistency. > > > > (I missed there was v3 already, but I'll repeat what I said in v1.) > > > > Please check FIELD_PREP() from include/linux/bitfield.h, doesn't it > > already do the same? > > Indeed, it appears to do the same :-) > Any reason why "include/linux/bitfield.h" is not included by default in > bitops.h? Hi! The code is in a separate header because of circular dependencies (coming from bug.h including bitops.h, IIRC). You could possibly add an include of bitfield.h in bitops.h if you're very careful, I haven't tried TBH :)