Mesa (master): mesa: adjust BRK/ CONT BranchTarget to always point to ENDLOOP instruction

Brian Paul brianp at kemper.freedesktop.org
Tue Dec 22 21:27:57 UTC 2009


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

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Dec 22 14:15:30 2009 -0700

mesa: adjust BRK/CONT BranchTarget to always point to ENDLOOP instruction

To be more consistant.

---

 src/mesa/shader/prog_execute.c     |   20 +++++++++++++++++---
 src/mesa/shader/slang/slang_emit.c |    6 +++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index 025665a..56d174c 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -698,12 +698,26 @@ _mesa_execute_program(GLcontext * ctx,
       case OPCODE_ENDSUB:      /* end subroutine */
          break;
       case OPCODE_BRA:         /* branch (conditional) */
-         /* fall-through */
+         if (eval_condition(machine, inst)) {
+            /* take branch */
+            /* Subtract 1 here since we'll do pc++ below */
+            pc = inst->BranchTarget - 1;
+         }
+         break;
       case OPCODE_BRK:         /* break out of loop (conditional) */
-         /* fall-through */
+         ASSERT(program->Instructions[inst->BranchTarget].Opcode
+                == OPCODE_ENDLOOP);
+         if (eval_condition(machine, inst)) {
+            /* break out of loop */
+            /* pc++ at end of for-loop will put us after the ENDLOOP inst */
+            pc = inst->BranchTarget;
+         }
+         break;
       case OPCODE_CONT:        /* continue loop (conditional) */
+         ASSERT(program->Instructions[inst->BranchTarget].Opcode
+                == OPCODE_ENDLOOP);
          if (eval_condition(machine, inst)) {
-            /* take branch */
+            /* continue at ENDLOOP */
             /* Subtract 1 here since we'll do pc++ at end of for-loop */
             pc = inst->BranchTarget - 1;
          }
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 99eb254..e769d0d 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1814,7 +1814,7 @@ emit_loop(slang_emit_info *emitInfo, slang_ir_node *n)
 
    /* Done emitting loop code.  Now walk over the loop's linked list of
     * BREAK and CONT nodes, filling in their BranchTarget fields (which
-    * will point to the ENDLOOP+1 or BGNLOOP instructions, respectively).
+    * will point to the corresponding ENDLOOP instruction.
     */
    for (ir = n->List; ir; ir = ir->List) {
       struct prog_instruction *inst = prog->Instructions + ir->InstLocation;
@@ -1823,8 +1823,8 @@ emit_loop(slang_emit_info *emitInfo, slang_ir_node *n)
           ir->Opcode == IR_BREAK_IF_TRUE) {
          assert(inst->Opcode == OPCODE_BRK ||
                 inst->Opcode == OPCODE_BRA);
-         /* go to instruction after end of loop */
-         inst->BranchTarget = endInstLoc + 1;
+         /* go to instruction at end of loop */
+         inst->BranchTarget = endInstLoc;
       }
       else {
          assert(ir->Opcode == IR_CONT ||




More information about the mesa-commit mailing list