Skip to contentSkip to conversation

drm/amd/display: Use min()/max() helper macros

PATCH In review Deepak R Varma 1 participant 6 messages Jan 14, 2023 – Jan 22, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover drm/amd/display: Use min()/max() helper macros

This patch series proposes using standard min() / max() helper macros instead of direct variable comparison using the ternary operator or if/else evaluations. I have tested the change using a dummy module and similar simulations on my x86 machine.

Deepak R Varma (4):
drm/amd/display: Use min()/max() macros in dcn_calc_math drm/amd/display: dcn20: Use min()/max() helper macros drm/amd/display: dcn21: Use min()/max() helper macros drm/amd/display: dcn32: Use min()/max() helper macros

 .../gpu/drm/amd/display/dc/dml/calcs/dcn_calc_math.c   | 10 +++++-----
 .../drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c |  5 +----
 .../amd/display/dc/dml/dcn20/display_mode_vba_20v2.c   |  5 +----
 .../drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c |  5 +----
 drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c   |  4 ++--
 5 files changed, 10 insertions(+), 19 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 drm/amd/display: Use min()/max() macros in dcn_calc_math

Use the standard min() / max() helper macros instead of direct variable comparison using if/else blocks or ternary operator. Change identified using minmax.cocci Coccinelle semantic patch.

---
 .../gpu/drm/amd/display/dc/dml/calcs/dcn_calc_math.c   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/dml/calcs/dcn_calc_math.c +5 -5
index cac72413a097..81629f3715d3 100644
@@ -52,12 +52,12 @@ float dcn_bw_min2(const float arg1, const float arg2)
 		return arg2;
 	if (isNaN(arg2))
 		return arg1;
-	return arg1 < arg2 ? arg1 : arg2;
+	return min(arg1, arg2);
 }
 
 unsigned int dcn_bw_max(const unsigned int arg1, const unsigned int arg2)
 {
-	return arg1 > arg2 ? arg1 : arg2;
+	return max(arg1, arg2);
 }
 float dcn_bw_max2(const float arg1, const float arg2)
 {
@@ -65,7 +65,7 @@ float dcn_bw_max2(const float arg1, const float arg2)
 		return arg2;
 	if (isNaN(arg2))
 		return arg1;
-	return arg1 > arg2 ? arg1 : arg2;
+	return max(arg1, arg2);
 }
 
 float dcn_bw_floor2(const float arg, const float significance)
@@ -93,12 +93,12 @@ float dcn_bw_ceil2(const float arg, const float significance)
 
 float dcn_bw_max3(float v1, float v2, float v3)
 {
-	return v3 > dcn_bw_max2(v1, v2) ? v3 : dcn_bw_max2(v1, v2);
+	return max(v3, dcn_bw_max2(v1, v2));
 }
 
 float dcn_bw_max5(float v1, float v2, float v3, float v4, float v5)
 {
-	return dcn_bw_max3(v1, v2, v3) > dcn_bw_max2(v4, v5) ? dcn_bw_max3(v1, v2, v3) : dcn_bw_max2(v4, v5);
+	return max(dcn_bw_max3(v1, v2, v3), dcn_bw_max2(v4, v5));
 }
 
 float dcn_bw_pow(float a, float exp)
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/4 drm/amd/display: dcn20: Use min()/max() helper macros

In reply to Deepak R Varma

Use the standard min() / max() helper macros instead of direct variable comparison using if/else blocks or ternary operator. Change identified using minmax.cocci Coccinelle semantic patch.

---
 .../gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c   | 5 +----
 .../gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20v2.c | 5 +----
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c +1 -4
index d3b5b6fedf04..850bb0f973d4 100644
@@ -626,10 +626,7 @@ static bool CalculatePrefetchSchedule(
 
 	dst_y_prefetch_oto = Tpre_oto / LineTime;
 
-	if (dst_y_prefetch_oto < dst_y_prefetch_equ)
-		*DestinationLinesForPrefetch = dst_y_prefetch_oto;
-	else
-		*DestinationLinesForPrefetch = dst_y_prefetch_equ;
+	*DestinationLinesForPrefetch = min(dst_y_prefetch_oto, dst_y_prefetch_equ);
 
 	*DestinationLinesForPrefetch = dml_floor(4.0 * (*DestinationLinesForPrefetch + 0.125), 1)
 			/ 4;
drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20v2.c +1 -4
index edd098c7eb92..6f4903525acc 100644
@@ -686,10 +686,7 @@ static bool CalculatePrefetchSchedule(
 
 	dst_y_prefetch_oto = Tpre_oto / LineTime;
 
-	if (dst_y_prefetch_oto < dst_y_prefetch_equ)
-		*DestinationLinesForPrefetch = dst_y_prefetch_oto;
-	else
-		*DestinationLinesForPrefetch = dst_y_prefetch_equ;
+	*DestinationLinesForPrefetch = min(dst_y_prefetch_oto, dst_y_prefetch_equ);
 
 	*DestinationLinesForPrefetch = dml_floor(4.0 * (*DestinationLinesForPrefetch + 0.125), 1)
 			/ 4;
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/4 drm/amd/display: dcn21: Use min()/max() helper macros

In reply to Deepak R Varma

Use the standard min() / max() helper macros instead of direct variable comparison using if/else blocks or ternary operator. Change identified using minmax.cocci Coccinelle semantic patch.

---
 .../gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c   | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c +1 -4
index 1d84ae50311d..41fb5fddd85d 100644
@@ -838,10 +838,7 @@ static bool CalculatePrefetchSchedule(
 
 	dst_y_prefetch_equ = dml_floor(4.0 * (dst_y_prefetch_equ + 0.125), 1) / 4.0;
 
-	if (dst_y_prefetch_oto < dst_y_prefetch_equ)
-		*DestinationLinesForPrefetch = dst_y_prefetch_oto;
-	else
-		*DestinationLinesForPrefetch = dst_y_prefetch_equ;
+	*DestinationLinesForPrefetch = min(dst_y_prefetch_oto, dst_y_prefetch_equ);
 
 	// Limit to prevent overflow in DST_Y_PREFETCH register
 	*DestinationLinesForPrefetch = dml_min(*DestinationLinesForPrefetch, 63.75);
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/4 drm/amd/display: dcn32: Use min()/max() helper macros

In reply to Deepak R Varma

Use the standard min() / max() helper macros instead of direct variable comparison using if/else blocks or ternary operator. Change identified using minmax.cocci Coccinelle semantic patch.

---
 drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c +2 -2
index f94abd124021..80820f012891 100644
@@ -908,7 +908,7 @@ static bool subvp_drr_schedulable(struct dc *dc, struct dc_state *context, struc
 	stretched_drr_us = drr_frame_us + mall_region_us + SUBVP_DRR_MARGIN_US;
 	drr_stretched_vblank_us = (drr_timing->v_total - drr_timing->v_addressable) * drr_timing->h_total /
 			(double)(drr_timing->pix_clk_100hz * 100) * 1000000 + (stretched_drr_us - drr_frame_us);
-	max_vblank_mallregion = drr_stretched_vblank_us > mall_region_us ? drr_stretched_vblank_us : mall_region_us;
+	max_vblank_mallregion = max(drr_stretched_vblank_us, mall_region_us);
 
 	/* We consider SubVP + DRR schedulable if the stretched frame duration of the DRR display (i.e. the
 	 * highest refresh rate + margin that can support UCLK P-State switch) passes the static analysis
@@ -999,7 +999,7 @@ static bool subvp_vblank_schedulable(struct dc *dc, struct dc_state *context)
 				(double)(vblank_timing->pix_clk_100hz * 100) * 1000000;
 		subvp_active_us = main_timing->v_addressable * main_timing->h_total /
 				(double)(main_timing->pix_clk_100hz * 100) * 1000000;
-		max_vblank_mallregion = vblank_blank_us > mall_region_us ? vblank_blank_us : mall_region_us;
+		max_vblank_mallregion = max(vblank_blank_us, mall_region_us);
 
 		// Schedulable if VACTIVE region of the SubVP pipe can fit the MALL prefetch, VBLANK frame time,
 		// and the max of (VBLANK blanking time, MALL region)
Signature · 1 line
2.34.1
#5 lore raw
In reply to Deepak R Varma
Quoted 4 lines · Deepak R Varma

This patch series proposes using standard min() / max() helper macros instead of direct variable comparison using the ternary operator or if/else evaluations. I have tested the change using a dummy module and similar simulations on my x86 machine.

Hello,
May I request a review feedback and comments on this patch set please?

Thank you,
./drv

Quoted 19 lines

Deepak R Varma (4):
drm/amd/display: Use min()/max() macros in dcn_calc_math drm/amd/display: dcn20: Use min()/max() helper macros drm/amd/display: dcn21: Use min()/max() helper macros drm/amd/display: dcn32: Use min()/max() helper macros

 .../gpu/drm/amd/display/dc/dml/calcs/dcn_calc_math.c   | 10 +++++-----
 .../drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c |  5 +----
 .../amd/display/dc/dml/dcn20/display_mode_vba_20v2.c   |  5 +----
 .../drm/amd/display/dc/dml/dcn21/display_mode_vba_21.c |  5 +----
 drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c   |  4 ++--
 5 files changed, 10 insertions(+), 19 deletions(-)
Signature · 1 line
2.34.1