RE: [PATCH v2 1/8] minmax: Put all the clamp() definitions together
From: David Laight
Date: Mon Jul 29 2024 - 04:03:09 EST
From: Linus Torvalds
> Sent: 28 July 2024 23:23
>
> On Sun, 28 Jul 2024 at 15:14, David Laight <David.Laight@xxxxxxxxxx> wrote:
> >
> > Ok, but those can't be used as array sizes or constants.
> > So the temporaries don't matter.
>
> No, mut I don't want the insane size explosion from unnecessarily just
> forcing it to use min()/max().
>
> > Don't they just work with min() - if not where is the signednes mismatch?
>
> David - this whole discussion is BECAUSE THESE THINGS ARE A TOTAL
> DISASTER WHEN USED IN DEEP MACRO EXPANSION.
>
> So no. It does not work - because core macros like HUGETLB_PAGE_ORDER
> end up being used deep in the VM layer, and I don't want to see
> another stupid multi-ten-kB line just because min() is such a pig.
>
> End result: I'm going to make the rule be that when you do macro
> definitions using constants, then "MIN()/MAX()" is preferable simply
> because it avoids the insane expansion noise.
I think you still need the temporaries if values aren't constant.
And you really don't want the casts unless you actually need them
to do something 'useful' - unlikely especially since negative
values are unusual.
Now you may want to avoid the explosive nature of min(), but if MIN()
(or MIN_T) evaluates its arguments twice someone will use it in the
wrong place.
David
>
> Then in normal *code* you should use min() and max(). But not for
> things like macro "constants" even if those constants end up being
> some computed thing.
>
> Linus
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)