r300/compiler: Fix loop unrolling
authorTom Stellard <tstellar@gmail.com>
Fri, 25 Jun 2010 01:45:46 +0000 (18:45 -0700)
committerMarek Olšák <maraeo@gmail.com>
Sat, 3 Jul 2010 02:32:41 +0000 (04:32 +0200)
src/mesa/drivers/dri/r300/compiler/radeon_emulate_loops.c

index 696cfd5ddc99519246208e2693c0bec8eb76b671..131e9e7436d8eeddcd194448f4cdd915601f495f 100644 (file)
@@ -267,8 +267,22 @@ static int transform_const_loop(struct emulate_loop_state * s,
         * simple, since we only support increment and decrement loops.
         */
        limit_value = get_constant_value(s->C, limit, 0);
-       iterations = (int) ((limit_value - counter_value.Value) /
+       DBG("Limit is %f.\n", limit_value);
+       switch(loop->Cond->U.I.Opcode){
+       case RC_OPCODE_SGT:
+       case RC_OPCODE_SLT:
+               iterations = (int) ceilf((limit_value - counter_value.Value) /
                                                        count_inst.Amount);
+               break;
+
+       case RC_OPCODE_SLE:
+       case RC_OPCODE_SGE:
+               iterations = (int) floorf((limit_value - counter_value.Value) /
+                                                       count_inst.Amount) + 1;
+               break;
+       default:
+               return 0;
+       }
 
        DBG("Loop will have %d iterations.\n", iterations);