From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 228952FCC04 for ; Tue, 9 Dec 2025 09:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765274193; cv=none; b=ZTHY6Mxo8CiUKl5hO42ABGjKFJZIRpAGVe4T7WtS9k+Ey8cYm3JeRv48u6MXj4NaRYPMff9/BVud+D+yRnEka+22NY6ikU868XGVFzj42MSS0DvH2oQvWJ1EjSCLX+jZsIElbTJgbTWgrsWhxxQYCNKUn3It9DfC6NswMad06rI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765274193; c=relaxed/simple; bh=0ztR6jj1kdHeM2HvWUV76MiZZnJx3iX4COKK8r02Bqc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pna4QfVVVxam7E/9uNR/r2Ef4eNcIoSRIVwyEIma6F9nyW6ABScw64Vp4TGZsfQD0Jy8+cMeqRi2agnyQYw9O2DcFZ8f6lfHyp2tRfYNNjKu/kG2NxR8lwVv5I0taBGkewn8Z/T/FMMTMuzSNjs1U1Rpw+EbqdHupak2nLfLhKs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bZjD5AZK; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bZjD5AZK" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-42b47f662a0so3204439f8f.0 for ; Tue, 09 Dec 2025 01:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765274188; x=1765878988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Y+NhgqRfgxOwgdPhqdTsST7UgPu+2reXJUJ1H1ugq6Q=; b=bZjD5AZKldn9eUheexC1Y1odtGkVDuOmpiu2djpFh1bzSaZHWgFaynZktCDczpIHxo 2gRndYMLHIgUDE6iAOzF2lDIhI3SCOunE2GNUenm0WCnqJ+dkEcwDXpTHBLfE73OwiXO 9Gef3pV4eLVb04t7TCgJ8cepakUX7tDK8xW1/9Lzs1IwfFw/r8RV75oNFVw1+hV23MOy 0k/tmslyMwbR9f+g76Lzcn12uym3loRKLD9F3sHh7eAt37kXUdPiiWjVmFEmYFhrb8XG JmOApU61/yOdZ4uFD3yOpVqRZVtZW3GxkSE6OnRJ138x1eyWntSWYcNsYONgJOLVYqdd Ba4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765274188; x=1765878988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Y+NhgqRfgxOwgdPhqdTsST7UgPu+2reXJUJ1H1ugq6Q=; b=ePB0ih39lXbQ/QvEHQbaZgJyyEfJUDe1JUWnVeXmVDPPpUK8o4i22uvg+eQTWrw5Vq jT5H73vU8Z1LzOuvaXDgnZWzmQycBCVHXdmm9f1c+dQgSs5iySdorwv3R3xKFgGcdAFw 5xZkvgd7jZHSxMXcLGmimgIrdkmtr3T9or28ap0LKmjwrc6XkwG4dm1drAaaINEgFnMx Ao4t8wuSuQF3LeYp1THrqLPNMyrMSqldGRApFtect54bThh8xE3kq3Q0nQVzkhtErt76 v002z59HOsiGKBV2met2e+OhWHKngeHXwBJey13JXdEOY26oNOwwqdLC9y6xu+4qc5gh c2Hw== X-Forwarded-Encrypted: i=1; AJvYcCVrHVFGVL67V9VOdj/HxL3alE6713LDcI9iJXbI9zFBCMxPJ2zvTuVXgE4dhUTybQoG/KL28dBup5ISyZo=@vger.kernel.org X-Gm-Message-State: AOJu0YzSpCQVEE4USzRIDvxNP7K7KFZOvg+pUuK+Kh0p9AS/HHdfkznP qzCBGMY1h1+rUv95k1xqOigMJhaOoNp4B/wT2p6GfjcHuhNTRlkxZE8o X-Gm-Gg: ASbGncvBOpU9GFGvGYBvD6kokD4WAJCDZZJCA7Jlt13hEhEsvm/atgDD1I2PhcJWxJF rQTrrbQSIvohPZ0Vo11h03C4nzVlNgn9GtwtOj9GPQny+p0jV0hthW0SqnfClHO7JozXgbonaR2 be+fxxSsAvdGLA5w57YyZcvIqCt41VZMQKDM2rSXunHGHaRHi7/2S4qeDi8LlzEe6pD98PV4s1f 0wG5cVmn8GxRn4MO+2T0Dit/LRMvLumnlI2nhscuOIL6mTPRw4gXlswcC1JDtMGVmUEcklCI20C 3cwJxjGhX+BABLzc15uROSUJnc9ce+R7Bpf4l007Y1Cjk+Xhl4LzH044S0ko8VgPqpdTEIwJ9ld x56mdRH4Zb4uas77HFnso7FhLFe8/PG+2QkLRaUWEKzeKLZsUgXNULKwRzUpzitJjIXno5w//TQ S1qSGkk0bmP3sPpOzhu4Drcbg0rC6XWJ4KtBrJybmBByNgYynUJgXi X-Google-Smtp-Source: AGHT+IG7hc90ntk8TlUXpcPXG+fItVwX9c1S1X97vIBaIvlLCfuiaQPSSG3/jWgjpLUJhtwJztiraA== X-Received: by 2002:a05:6000:1843:b0:42b:3108:5671 with SMTP id ffacd0b85a97d-42fa086938bmr1149928f8f.29.1765274188199; Tue, 09 Dec 2025 01:56:28 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42f7d353f80sm30431284f8f.41.2025.12.09.01.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Dec 2025 01:56:27 -0800 (PST) Date: Tue, 9 Dec 2025 09:56:26 +0000 From: David Laight To: Yury Norov Cc: Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Geert Uytterhoeven , Nicolas Frattaroli Subject: Re: [PATCH 3/9] bitmap: Use FIELD_PREP() in expansion of FIELD_PREP_WM16() Message-ID: <20251209095626.2f664ffb@pumpkin> In-Reply-To: References: <20251208224250.536159-1-david.laight.linux@gmail.com> <20251208224250.536159-4-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 8 Dec 2025 19:54:37 -0500 Yury Norov wrote: > + Nicolas Frattaroli > > It's always good to CC an author of the original implementation, > isn't? > > On Mon, Dec 08, 2025 at 10:42:44PM +0000, david.laight.linux@gmail.com wrote: > > From: David Laight > > > > Instead of directly expanding __BF_FIELD_CHECK() (which really ought > > not be used outside bitfield) and open-coding the generation of the > > masked value, just call FIELD_PREP() > > That's fair. > > > and add an extra check for > > the mask being at most 16 bits. > > Maybe it's time to introduce FIELD_PREP16()? > > > Signed-off-by: David Laight > > --- > > include/linux/hw_bitfield.h | 17 ++++++++--------- > > 1 file changed, 8 insertions(+), 9 deletions(-) > > > > diff --git a/include/linux/hw_bitfield.h b/include/linux/hw_bitfield.h > > index df202e167ce4..d7f21b60449b 100644 > > --- a/include/linux/hw_bitfield.h > > +++ b/include/linux/hw_bitfield.h > > @@ -23,15 +23,14 @@ > > * register, a bit in the lower half is only updated if the corresponding bit > > * in the upper half is high. > > */ > > -#define FIELD_PREP_WM16(_mask, _val) \ > > - ({ \ > > - typeof(_val) __val = _val; \ > > - typeof(_mask) __mask = _mask; \ > > - __BF_FIELD_CHECK(__mask, ((u16)0U), __val, \ > > - "HWORD_UPDATE: "); \ > > - (((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) | \ > > - ((__mask) << 16); \ > > - }) > > +#define FIELD_PREP_WM16(mask, val) \ > > +({ \ > > + __auto_type _mask = mask; \ > > Is __auto_type any better than typeof()? Generally yes. Mainly because you only get one expansion of the #define parameter. > > > + u32 _val = FIELD_PREP(_mask, val); \ > > + BUILD_BUG_ON_MSG(_mask > 0xffffu, \ > > + "FIELD_PREP_WM16: mask too large"); \ > > Not necessary to split this line. > > > + _val | (_mask << 16); \ > > +}) > > Can you share bloat-o-meter and code generation examples? The generated code is going to be pretty much unchanged. The changes only really affect the compile-time checks. > > For the next version please try to keep as much history > untouched as possible. I'm going to resend the same patches with the full cc list for now. David > > Thanks, > Yury > > > > > /** > > * FIELD_PREP_WM16_CONST() - prepare a constant bitfield element with a mask in > > -- > > 2.39.5