[PATCH] mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()

Markus Elfring posted 1 patch 11 months, 1 week ago
drivers/mtd/nand/raw/tegra_nand.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()
Posted by Markus Elfring 11 months, 1 week ago
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 28 Feb 2025 19:19:45 +0100

Reduce nested max() calls by a single max3() call in this
function implementation.

The source code was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/mtd/nand/raw/tegra_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c
index 7f9eb5f042a7..c03f11e5e18c 100644
--- a/drivers/mtd/nand/raw/tegra_nand.c
+++ b/drivers/mtd/nand/raw/tegra_nand.c
@@ -793,8 +793,8 @@ static void tegra_nand_setup_timing(struct tegra_nand_controller *ctrl,
 				timings->tRC_min), period);
 	reg |= TIMING_TCR_TAR_TRR(OFFSET(val, 3));

-	val = DIV_ROUND_UP(max(max(timings->tCS_min, timings->tCH_min),
-			       max(timings->tALS_min, timings->tALH_min)),
+	val = DIV_ROUND_UP(max3(timings->tCS_min, timings->tCH_min,
+				max(timings->tALS_min, timings->tALH_min)),
 			   period);
 	reg |= TIMING_TCS(OFFSET(val, 2));

--
2.48.1
Re: [PATCH] mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()
Posted by Miquel Raynal 11 months, 1 week ago
Hi,

On 28/02/2025 at 19:33:10 +01, Markus Elfring <Markus.Elfring@web.de> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 28 Feb 2025 19:19:45 +0100
>
> Reduce nested max() calls by a single max3() call in this
> function implementation.
>
> The source code was transformed by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

I am sorry, I do not see what gets simplified. max(max(a,b),max(c,d))
looks simpler than max3(a,b,max(c,d)). Does it bring something in terms
of optimization?

Thanks,
Miquèl
Re: mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()
Posted by Markus Elfring 11 months, 1 week ago
> I am sorry, I do not see what gets simplified. max(max(a,b),max(c,d))
> looks simpler than max3(a,b,max(c,d)).

You would eventually like to express that a maximum should be determined
from three (or even four?) values.
https://elixir.bootlin.com/linux/v6.14-rc4/source/include/linux/minmax.h#L147


>                                        Does it bring something in terms
> of optimization?
Corresponding effects depend on various factors, don't they?

Regards,
Markus
Re: mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()
Posted by Miquel Raynal 11 months, 1 week ago
On 03/03/2025 at 11:55:49 +01, Markus Elfring <Markus.Elfring@web.de> wrote:

>> I am sorry, I do not see what gets simplified. max(max(a,b),max(c,d))
>> looks simpler than max3(a,b,max(c,d)).
>
> You would eventually like to express that a maximum should be determined
> from three (or even four?) values.

If there was a max4(), why not, but in this case I don't see the point.

> https://elixir.bootlin.com/linux/v6.14-rc4/source/include/linux/minmax.h#L147
>
>
>>                                        Does it bring something in terms
>> of optimization?
> Corresponding effects depend on various factors, don't they?

Ok, so I'll assume the answer to my question is "no".

Thanks,
Miquèl
Re: mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()
Posted by Markus Elfring 11 months, 1 week ago
>> You would eventually like to express that a maximum should be determined
>> from three (or even four?) values.
>
> If there was a max4(), why not, but in this case I don't see the point.
Do you miss such a programming interface so far?
Would you be looking for corresponding software adjustments?

Regards,
Markus
Re: mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()
Posted by Miquel Raynal 11 months, 1 week ago
Sorry for not being clear.

On 03/03/2025 at 12:15:25 +01, Markus Elfring <Markus.Elfring@web.de> wrote:

>>> You would eventually like to express that a maximum should be determined
>>> from three (or even four?) values.
>>
>> If there was a max4(), why not, but in this case I don't see the point.
> Do you miss such a programming interface so far?

No.

> Would you be looking for corresponding software adjustments?

No.

Thanks,
Miquèl
Re: mtd: rawnand: tegra: Simplify maximum determination in tegra_nand_setup_timing()
Posted by Miquel Raynal 11 months, 1 week ago
On 03/03/2025 at 12:15:25 +01, Markus Elfring <Markus.Elfring@web.de> wrote:

>>> You would eventually like to express that a maximum should be determined
>>> from three (or even four?) values.
>>
>> If there was a max4(), why not, but in this case I don't see the point.
> Do you miss such a programming interface so far?

No I do not.

> Would you be looking for corresponding software adjustments?

Not necessarily, unless there is some performance improvement.

Thanks,
Miquèl