Mesa (main): r300: replace recursive calls with loops

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Feb 2 17:08:20 UTC 2022


Module: Mesa
Branch: main
Commit: 9322b76fc498febf6f99849723a5c48fb38817ef
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9322b76fc498febf6f99849723a5c48fb38817ef

Author: Filip Gawin <filip.gawin at zoho.com>
Date:   Wed Oct  6 16:50:21 2021 +0200

r300: replace recursive calls with loops

Recursive "loops" tend to be more difficult to follow
and understand. Additionally iterative approach should be
nicer for compiler. (Less to allocate on stack and easier to optimize)

Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13226>

---

 .../drivers/r300/compiler/radeon_pair_schedule.c   | 58 ++++++++++------------
 1 file changed, 27 insertions(+), 31 deletions(-)

diff --git a/src/gallium/drivers/r300/compiler/radeon_pair_schedule.c b/src/gallium/drivers/r300/compiler/radeon_pair_schedule.c
index 9e008149e57..1c8130cdf35 100644
--- a/src/gallium/drivers/r300/compiler/radeon_pair_schedule.c
+++ b/src/gallium/drivers/r300/compiler/radeon_pair_schedule.c
@@ -367,45 +367,41 @@ static void calc_score_readers(struct schedule_instruction * sinst)
  */
 static void commit_update_reads(struct schedule_state * s,
 					struct schedule_instruction * sinst){
-	unsigned int i;
-	for(i = 0; i < sinst->NumReadValues; ++i) {
-		struct reg_value * v = sinst->ReadValues[i];
-		assert(v->NumReaders > 0);
-		v->NumReaders--;
-		if (!v->NumReaders) {
-			if (v->Next) {
-				decrease_dependencies(s, v->Next->Writer);
+	do {
+		for(unsigned int i = 0; i < sinst->NumReadValues; ++i) {
+			struct reg_value * v = sinst->ReadValues[i];
+			assert(v->NumReaders > 0);
+			v->NumReaders--;
+			if (!v->NumReaders) {
+				if (v->Next) {
+					decrease_dependencies(s, v->Next->Writer);
+				}
 			}
 		}
-	}
-	if (sinst->PairedInst) {
-		commit_update_reads(s, sinst->PairedInst);
-	}
+	} while ((sinst = sinst->PairedInst));
 }
 
 static void commit_update_writes(struct schedule_state * s,
 					struct schedule_instruction * sinst){
-	unsigned int i;
-	for(i = 0; i < sinst->NumWriteValues; ++i) {
-		struct reg_value * v = sinst->WriteValues[i];
-		if (v->NumReaders) {
-			for(struct reg_value_reader * r = v->Readers; r; r = r->Next) {
-				decrease_dependencies(s, r->Reader);
+	do {
+		for(unsigned int i = 0; i < sinst->NumWriteValues; ++i) {
+			struct reg_value * v = sinst->WriteValues[i];
+			if (v->NumReaders) {
+				for(struct reg_value_reader * r = v->Readers; r; r = r->Next) {
+					decrease_dependencies(s, r->Reader);
+				}
+			} else {
+				/* This happens in instruction sequences of the type
+				 *  OP r.x, ...;
+				 *  OP r.x, r.x, ...;
+				 * See also the subtlety in how instructions that both
+				 * read and write the same register are scanned.
+				 */
+				if (v->Next)
+					decrease_dependencies(s, v->Next->Writer);
 			}
-		} else {
-			/* This happens in instruction sequences of the type
-			 *  OP r.x, ...;
-			 *  OP r.x, r.x, ...;
-			 * See also the subtlety in how instructions that both
-			 * read and write the same register are scanned.
-			 */
-			if (v->Next)
-				decrease_dependencies(s, v->Next->Writer);
 		}
-	}
-	if (sinst->PairedInst) {
-		commit_update_writes(s, sinst->PairedInst);
-	}
+	} while ((sinst = sinst->PairedInst));
 }
 
 static void notify_sem_wait(struct schedule_state *s)



More information about the mesa-commit mailing list