From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 474D11CFBA for ; Sat, 29 Nov 2025 11:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764416809; cv=none; b=HEqW6WuVHGJ/pLvGo+UwRzyIBFZGKSxJk9oyaTaA3a7i0WyMWyxLy3NlKQwKMvI/TrpOJcUuradvbmLC3rdqspM6hhMVbrAdw/PUI+B700nT7aimwT2hpMnRZ8z4hZY4l+wekF2/LW7nERBDPqu6Kqrc4jG9sI9rAXk1cn5Dtt0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764416809; c=relaxed/simple; bh=R6dSfRo/gczXQ84c5VUKWh5hiqUZjOqiyOEJoV0s2Ak=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h6SDXmt4xqh+dBZ4Oc0/Sv8HFBE+tB90DYPXFogVvN4rdnzH5hAsNnL5ULI4LiP+5lpqeavWZUBN8bo+qhwLqvIo4OSM++Y0Wo9EvNjcnK+MSpHRyFes3n0mw1+D/7VvIt9a7UiWbbNqUzOgRZrH1qIFThwgHXMCcSKI2PrSn0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=runbox.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=ZCq7nJQO; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=runbox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="ZCq7nJQO" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vPJPT-001Utb-Mb; Sat, 29 Nov 2025 12:46:39 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector2; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date; bh=4aF0a3oX5nUNDrhcmaMaVfRPNGkSoJQBbbzJKrAJHTg=; b=ZCq7nJQOKJdaN/taT98IswWNku wKUs9CgCGNRv7Jhr+Z0KiYkcNRMxMe15nqQbmtRQZ2vmG1wiLSicjCo7xi1+V+JNXNqM/82y3zp3h aQa3yUkjtwvNoW/lsiMaLWMjb7RS3THXLrPRM7+tOgP0mz+Q6DsAs/FWMOLeh0VgdV3zsxQkNU7j8 9ohFn9kgET+xdCnMfLJHAdhbbewFSM4YCvdCc+Za72OTtODjMdQn228TG34Koo3CGEgjPFYj32Wcr BltfJjy/BcjiuB06VnKuObNZC8nb8XKrWSet18z3K3D39L9YpGzjCkdkzOaTYvsjJ06onR5RMNn8R +zCNNMjw==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vPJPT-0004ne-4H; Sat, 29 Nov 2025 12:46:39 +0100 Received: by submission01.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vPJPD-002nG1-0L; Sat, 29 Nov 2025 12:46:23 +0100 Date: Sat, 29 Nov 2025 11:46:18 +0000 From: david laight To: Linus Torvalds Cc: Rasmus Villemoes , "Yury Norov (NVIDIA)" , Linus Walleij , Nicolas Frattaroli , linux-kernel@vger.kernel.org Subject: Re: [PATCH 00/21] lib: add alternatives for GENMASK() Message-ID: <20251129114618.5bbc6c3c@pumpkin> In-Reply-To: References: <20251025164023.308884-1-yury.norov@gmail.com> <87ldjtuppl.fsf@prevas.dk> 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 Wed, 26 Nov 2025 11:44:59 -0800 Linus Torvalds wrote: > On Wed, 26 Nov 2025 at 01:07, Rasmus Villemoes wrote: > > > > There is, however, an alternative that resembles the syntax in data > > sheets even more closely: > > > > #define BITS(low_high) GENMASK((0 ? low_high), (1 ? low_high)) > > Oh, me likey. That's a much better idea than my crazy syntax. > > Linus > I've had a couple of further thoughts... 1) GENMASK() could just swap the two arguments if they are constant and in the wrong order, so GENMASK(2, 4) and GENMASK(4, 2) are equivalent. Easily done without too much bloat in a statement expression. 2) It a lot of cases the result from GENMASK() is only ever passed to FIELD_XXX(). The latter really don't want the mask - they want the two bit numbers. (In particular the low bit number.) So you could change the headers to have (eg): #define REGISTER_BITS_FOR_XXX (5:7) Then the expected calling 'convention' would be FIELD_XXX((lo:hi), val). All done with: #define _BIT_LO(lo_hi) (1 ? lo_hi) #define _BIT_HI(lo_hi) (0 ? lo_hi) #define FIELD_XXX(lo_hi, ...) ({ u32 _lo = _BIT_LO lo_hi; u32 _hi = _BIT_HI lo_hi; ... Any attempted use without the 'magic macros' will be a nice syntax error. David