This message generated a parse failure. Raw output follows here. Please use 'back' to navigate. From devnull@lkml.org Fri May 31 13:39:10 2024 >From mailfetcher Fri Jan 12 15:28:06 2024 Authentication-Results: pi4.bmw12.nl; dmarc=fail (p=none dis=none) header.from=ACULAB.COM R-Authentication-Results: VERIFYING; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=aculab.com (policy=none); spf=pass (VERIFYING: domain of "linux-kernel+bounces-24749-lkml=bmw12.nl@vger.kernel.org" designates 2604:1380:45d1:ec00::1 as permit Received: from secure.jasper.es [188.166.10.231] by 1dc7d414a5be with IMAP (fetchmail-6.3.26) for (single-drop); Fri, 12 Jan 2024 15:28:06 +0100 (CET) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pi4.bmw12.nl Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DAE911C23B48 for To: 'Dan Carpenter' Cc: "linux-kernel@vger.kernel.org" , "Linus Torvalds" , 'Andy Shevchenko' , 'Andrew Morton' , "'Matthew Wilcox (Oracle)'" References: <41d93ca827a248698ec64bf57e0c05a5@AcuMS.aculab.com> <737627fd-b68b-4c9d-8700-f0e0d6d9cec8@moroto.mountain> <8e45b321c49b4c27a61b2db076ed5383@AcuMS.aculab.com> <02701430-65cf-44ab-8a8b-752c5d973d21@morot In-Reply-To: <02701430-65cf-44ab-8a8b-752c5d973d21@moroto.mountain> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: list-unsubscribe: Mime-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Action: no action X-Rspamd-Server: pi4 X-Rspamd-Queue-Id: 9C1E43F04E X-Spamd-Result: default: False [-0.76 / 6.00]; RCVD_IN_DNSWL_MED(-0.40)[2604:1380:45d1:ec00::1:from,52.25.139.140:received]; R_SPF_ALLOW(-0.20)[+ip6:2604:1380:45d1:ec00::/64:c]; MAILLIST(-0.15)[generic]; MIME_GOOD(-0.10)[text/plain]; DMARC_POLICY_SOFTFAIL(0.10)[aculab.c From: Dan Carpenter > Sent: 12 January 2024 14:03 >=20 > On Fri, Jan 12, 2024 at 01:40:30PM +0000, David Laight wrote: > > From: Dan Carpenter > > > Sent: 12 January 2024 12:50 > > > > > > On Mon, Sep 18, 2023 at 08:16:30AM +0000, David Laight wrote: > > > > +/** > > > > + * umin - return minimum of two non-negative values > > > > + * Signed types are zero extended to match a larger unsigned typ= e. > > > > + * @x: first value > > > > + * @y: second value > > > > + */ > > > > +#define umin(x, y)=09\ > > > > +=09__careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, <) > > > > > > Why do we match "a larger unsigned type" instead of ULL_MAX? Presuma= bly > > > it helps performance somehow... I agree that it's probably fine but = I > > > would be more comfortable if it skipped UINT_MAX and jumped directly = to > > > ULONG_MAX. These days 4 gigs is small potatoes. The vmalloc() funct= ion > > > can allocate 4G so we've had integer overflow bugs with this before. > > > > The '+ 0ul*' carefully zero extend signed values without changing > > unsigned values. > > The compiler detects when it has zero-extended both sides and > > uses the smaller compare. > > In essence: > > =09x + 0u converts 'int' to 'unsigned int'. > > =09=09Avoids the sign extension adding 0ul on 64bit. > > =09x + 0ul converts a 'long' to 'unsigned long'. > > =09=09Avoids the sign extension adding 0ull on 32bit > > =09x + 0ull converts a 'long long' to 'unsigned long long'. > > You need all three to avoid sign extensions and get an unsigned > > compare. >=20 > So unsigned int compares are faster than unsigned long compares? >=20 > It's just sort of weird how it works. >=20 > =09min_t(unsigned long, -1, 10000000000)); =3D> 10000000000 > =09umin(umin(-1, 10000000000)); =3D> UINT_MAX >=20 > UINT_MAX is just kind of a random value. I would have prefered > ULONG_MAX, it's equally random but it's more safe because nothing can > allocate ULONG_MAX bytes. umin() is only defined for non-negative values. So that example is really outside the domain of the function. Consider: =09int x =3D some_positive_value; =09unsigned long long y; then: =09min_t(unsigned long long, x, y); =09Does (unsigned long long)x which is (unsigned long long)(long long)x =09and requires that x be sign extended to 64bits. =09On 32bit that is quite horrid. whereas: =09umin(x, y); =09Only has to zero extend x. =09So is compiled as: =09=09y:hi || y:lo > x ? x ; y If both values are 32bit the compiler generates a 32bit compare (even on 64bit). =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)