Module: Mesa
Branch: master
Commit: 29a1d6aee7a07ab9d0d6007226719a2fa8a5ee25
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=29a1d6aee7a07ab9d0d6007226719a2fa8a5ee25

Author: Tom Stellard <[email protected]>
Date:   Sat Jun 12 22:12:32 2010 -0700

r300/compiler: Correctly calculate the max number of iterations for loops.

---

 .../dri/r300/compiler/radeon_emulate_loops.c       |   25 ++++++-------------
 1 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_emulate_loops.c 
b/src/mesa/drivers/dri/r300/compiler/radeon_emulate_loops.c
index 1aaaa6c..696cfd5 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_emulate_loops.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_emulate_loops.c
@@ -78,22 +78,13 @@ static int src_reg_is_immediate(struct rc_src_register * 
src,
        c->Program.Constants.Constants[src->Index].Type==RC_CONSTANT_IMMEDIATE;
 }
 
-static unsigned int loop_count_instructions(struct loop_info * loop)
+static unsigned int loop_calc_iterations(struct emulate_loop_state *s, 
+                       struct loop_info * loop, unsigned int max_instructions)
 {
-       unsigned int count = 0;
-       struct rc_instruction * inst = loop->BeginLoop->Next;
-       while(inst != loop->EndLoop){
-               count++;
-               inst = inst->Next;
-       }
-       return count;
-}
-
-static unsigned int loop_calc_iterations(struct loop_info * loop,
-               unsigned int loop_count, unsigned int max_instructions)
-{
-       unsigned int icount = loop_count_instructions(loop);
-       return max_instructions / (loop_count * icount);
+       unsigned int total_i = rc_recompute_ips(s->C);
+       unsigned int loop_i = (loop->EndLoop->IP - loop->BeginLoop->IP) - 1;
+       /* +1 because the program already has one iteration of the loop. */
+       return 1 + ((max_instructions - total_i) / (s->LoopCount * loop_i));
 }
 
 static void loop_unroll(struct emulate_loop_state * s,
@@ -439,8 +430,8 @@ void rc_emulate_loops(struct emulate_loop_state *s,
                if(!s->Loops[i].EndLoop){
                        continue;
                }
-               unsigned int iterations = loop_calc_iterations(&s->Loops[i],
-                                               s->LoopCount, max_instructions);
+               unsigned int iterations = loop_calc_iterations(s, &s->Loops[i],
+                                                       max_instructions);
                loop_unroll(s, &s->Loops[i], iterations);
        }
 }

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to