RE: [PATCH v2 1/8] minmax: Put all the clamp() definitions together

David Laight
2024-07-31T08:10:47Z

From: Linus Torvalds
> Sent: 31 July 2024 00:04
>
> On Tue, 30 Jul 2024 at 15:44, Linus Torvalds
> <torvalds@linuxfoundation.org> wrote:
> >
> > Does this work for you?
>
> It seems to at least build cleanly here, but I'm not claiming it's all
> that great.
>
> The nested __cmp() is still rather less than optimal from an expansion
> standpoint, but at least it expands only those unique temporaries.

That is the main gain, IIRC Arnd did suggest splitting it but that is
a relatively small gain.

> [ Side note: having not looked at a lot of the resulting pre-processed
> mess, I'm not convinced it really helps to make those unique names so
> long.
>
> The whole "__UNIQUE_ID_" prefix looks good once, but to some degree
> it actually hides the important part, which is the actual prefix and
> the unique number.

I just passed __COUNTER__ through in my min3() patch to avoid
passing lots of parameters and then appended it to the name
giving _x_12345 (etc).
The __UNIQUE_ID_() define just seemed excessive - especially
since all compiler versions support __COUNTER__.

Just need to remember a relay #define since #define arguments get
expanded when they are substituted not at the 'call' site.
(Which is also true for __UNIQUE_ID())

That also makes it much easier to add an extra unique name.

> But honestly, nobody ever looks at this part normally, so it
> probably doesn't matter ]

Except that when you do it is all a right PITA.
Not helped by the actual name being rammed on the end.

>
> It might be possible to cut down on that by doing them in series
> instead of nested, but I think that would require something like
> generating a fourth unique name, and something along the lines of
>
> __auto_type u4 = __cmp(op, ux, uy); __cmp(op, u4, uz);
>
> as that last line.
>
> And no, I did *not* try that, and there might be something I'm missing.

If you have to pass through a 'u4' name that could easily take longer.

David

>
> Linus

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)