From: David Laight <David.Laight@ACULAB.COM>
To: 'Alexey Dobriyan' <adobriyan@gmail.com>,
Matthew Wilcox <willy@infradead.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"torvalds@linux-foundation.org" <torvalds@linux-foundation.org>,
"Jason@zx2c4.com" <Jason@zx2c4.com>,
"hch@infradead.org" <hch@infradead.org>,
"andriy.shevchenko@linux.intel.com"
<andriy.shevchenko@linux.intel.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: RE: + minmax-add-umina-b-and-umaxa-b.patch added to mm-nonmm-unstable branch
Date: Thu, 28 Sep 2023 08:55:17 +0000 [thread overview]
Message-ID: <decc112eaf2b4edca53b9a8f2d70ddf9@AcuMS.aculab.com> (raw)
In-Reply-To: <b1198988-b60e-41e2-99bf-6af145e1d201@p183>
From: Alexey Dobriyan
> Sent: 28 September 2023 09:39
>
> On Wed, Sep 27, 2023 at 09:00:37PM +0100, Matthew Wilcox wrote:
> > On Wed, Sep 27, 2023 at 10:21:41PM +0300, Alexey Dobriyan wrote:
> > > On Wed, Sep 27, 2023 at 10:30:33AM -0700, Andrew Morton wrote:
> > > > +#define umin(x, y) \
> > > > + __careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, <)
> > >
> > > kmin() and kmax() are (of course!) much better names.
> >
> > it's unsigned, not user.
Linus suggested umin() as being much shorter than the min_unsigned()
I'd originally used.
> Yes, but the same idea applies to signed types:
The kernel pretty much never wants a cast to convert a large
unsigned value to a negative signed one.
If the types mismatch both values are normally non-negative
so doing an unsigned compare is right.
If you do need to treat 0u - 1 as a signed value then adding
an explicit cast is probably a good idea!
> min, max require identical types
> min_t force type
> kmin, kmax are relaxed min/max versions if signednesses match.
The 'identical types' case is pointless, and the 'force type'
often buggy.
The only reason for any type-check is to stop 'integer promotion'
converting a negative value to a very large unsigned one.
And even that isn't why the typecheck was added to min().
(That is, there is no indication that it ever caused a bug.)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2023-09-28 8:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230927173033.AF86DC433C7@smtp.kernel.org>
2023-09-27 19:21 ` + minmax-add-umina-b-and-umaxa-b.patch added to mm-nonmm-unstable branch Alexey Dobriyan
2023-09-27 20:00 ` Matthew Wilcox
2023-09-28 8:38 ` Alexey Dobriyan
2023-09-28 8:55 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=decc112eaf2b4edca53b9a8f2d70ddf9@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=Jason@zx2c4.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox