Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752674AbcLGIna (ORCPT ); Wed, 7 Dec 2016 03:43:30 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:49590 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752005AbcLGIn3 (ORCPT ); Wed, 7 Dec 2016 03:43:29 -0500 DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org EA91C61568 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=kvalo@codeaurora.org From: Kalle Valo To: Sebastian Frias Cc: zijun_hu , Andrew Morton , linux-kernel@vger.kernel.org, Linus Torvalds , Mason , Harvey Harrison , Borislav Petkov , Jakub Kicinski Subject: Re: [PATCH v3] add equivalent of BIT(x) for bitfields References: Date: Wed, 07 Dec 2016 10:42:48 +0200 In-Reply-To: (Sebastian Frias's message of "Tue, 6 Dec 2016 11:06:42 +0100") Message-ID: <87bmwom8on.fsf@purkki.adurom.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1178 Lines: 41 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? Adding Jakub to comment more. -- Kalle Valo