Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932194AbcLGKBC (ORCPT ); Wed, 7 Dec 2016 05:01:02 -0500 Received: from smtpoutz29.laposte.net ([194.117.213.104]:56806 "EHLO smtp.laposte.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752308AbcLGKBB (ORCPT ); Wed, 7 Dec 2016 05:01:01 -0500 Subject: Re: [PATCH v3] add equivalent of BIT(x) for bitfields To: Kalle Valo References: <87bmwom8on.fsf@purkki.adurom.net> Cc: zijun_hu , Andrew Morton , linux-kernel@vger.kernel.org, Linus Torvalds , Mason , Harvey Harrison , Borislav Petkov , Jakub Kicinski From: Sebastian Frias Message-ID: <489b2ea4-0678-97ac-f46e-4fc8a7853358@laposte.net> Date: Wed, 7 Dec 2016 11:00:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <87bmwom8on.fsf@purkki.adurom.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-VR-SrcIP: 92.154.11.170 X-VR-FullState: 0 X-VR-Score: -100 X-VR-Cause-1: gggruggvucftvghtrhhoucdtuddrfeelfedrhedvgddtgecutefuodetggdotefrodftvfcurfhrohhf X-VR-Cause-2: ihhlvgemucfntefrqffuvffgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhs X-VR-Cause-3: ucdlqddutddtmdenucfjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeehnecuhfhrohhmpefu X-VR-Cause-4: vggsrghsthhirghnucfhrhhirghsuceoshhfkeegsehlrghpohhsthgvrdhnvghtqeenucffohhmrghi X-VR-Cause-5: nhepmhgrrhgtrdhinhhfohenucfkphepledvrdduheegrdduuddrudejtdenucfrrghrrghmpehmohgu X-VR-Cause-6: vgepshhmthhpohhuthdphhgvlhhopegludejvddrvdejrddtrddvudegngdpihhnvghtpeelvddrudeh X-VR-Cause-7: gedruddurddujedtpdhmrghilhhfrhhomhepshhfkeegsehlrghpohhsthgvrdhnvghtpdhrtghpthht X-VR-Cause-8: ohepkhhvrghlohestghouggvrghurhhorhgrrdhorhhg X-VR-AvState: No X-VR-State: 0 X-VR-State: 0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1332 Lines: 41 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?