mesa: Branch 'master' - 10 commits
Brian Paul
brianp at kemper.freedesktop.org
Wed Mar 28 20:54:54 UTC 2007
src/mesa/shader/prog_execute.c | 26 ----
src/mesa/shader/prog_instruction.c | 4
src/mesa/shader/prog_instruction.h | 4
src/mesa/shader/prog_print.c | 11 -
src/mesa/shader/slang/slang_codegen.c | 43 ++++---
src/mesa/shader/slang/slang_emit.c | 190 +++++++++++++++++++---------------
src/mesa/shader/slang/slang_ir.c | 8 -
src/mesa/shader/slang/slang_ir.h | 2
src/mesa/tnl/t_vb_arbprogram.c | 4
9 files changed, 136 insertions(+), 156 deletions(-)
New commits:
diff-tree b2ac30ac36c66122d6d8a73e7057a84b74c3d930 (from 3b7f2f53a222b06ca14fff44b5e1143e1b41e390)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 14:49:33 2007 -0600
optimization for the emit_not() function
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index b5a2dfa..b00ab3c 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1053,12 +1053,37 @@ emit_cond(slang_emit_info *emitInfo, sla
static struct prog_instruction *
emit_not(slang_emit_info *emitInfo, slang_ir_node *n)
{
+ static const struct {
+ gl_inst_opcode op, opNot;
+ } operators[] = {
+ { OPCODE_SLT, OPCODE_SGE },
+ { OPCODE_SLE, OPCODE_SGT },
+ { OPCODE_SGT, OPCODE_SLE },
+ { OPCODE_SGE, OPCODE_SLT },
+ { OPCODE_SEQ, OPCODE_SNE },
+ { OPCODE_SNE, OPCODE_SEQ },
+ { 0, 0 }
+ };
struct prog_instruction *inst;
+ GLuint i;
/* child expr */
- (void) emit(emitInfo, n->Children[0]);
- /* XXXX if child instr is SGT convert to SLE, if SEQ, SNE, etc */
+ inst = emit(emitInfo, n->Children[0]);
+
+#if PEEPHOLE_OPTIMIZATIONS
+ if (inst) {
+ /* if the prev instruction was a comparison instruction, invert it */
+ for (i = 0; operators[i].op; i++) {
+ if (inst->Opcode == operators[i].op) {
+ inst->Opcode = operators[i].opNot;
+ n->Store = n->Children[0]->Store;
+ return inst;
+ }
+ }
+ }
+#endif
+ /* else, invert using SEQ (v = v == 0) */
if (!n->Store)
if (!alloc_temp_storage(emitInfo, n, n->Children[0]->Store->Size))
return NULL;
@@ -1762,7 +1787,7 @@ _slang_emit_code(slang_ir_node *n, slang
emitInfo.NumSubroutines = 0;
emitInfo.EmitHighLevelInstructions = ctx->Shader.EmitHighLevelInstructions;
- emitInfo.EmitCondCodes = 0*ctx->Shader.EmitCondCodes;
+ emitInfo.EmitCondCodes = ctx->Shader.EmitCondCodes;
emitInfo.EmitComments = ctx->Shader.EmitComments;
emitInfo.EmitBeginEndSub = 0; /* XXX for compiler debug only */
diff-tree 3b7f2f53a222b06ca14fff44b5e1143e1b41e390 (from 8128f7143d9c3768df4cf669e97777e021db127a)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 14:38:36 2007 -0600
remove IR_BREAK_IF_FALSE
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 310a9f1..b5a2dfa 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1207,7 +1207,6 @@ emit_loop(slang_emit_info *emitInfo, sla
struct prog_instruction *inst = prog->Instructions + ir->InstLocation;
assert(inst->BranchTarget < 0);
if (ir->Opcode == IR_BREAK ||
- ir->Opcode == IR_BREAK_IF_FALSE ||
ir->Opcode == IR_BREAK_IF_TRUE) {
assert(inst->Opcode == OPCODE_BRK ||
inst->Opcode == OPCODE_BRA);
@@ -1269,14 +1268,12 @@ emit_cont_break(slang_emit_info *emitInf
* Either OPCODE_CONT, OPCODE_BRK or OPCODE_BRA will be emitted.
*/
static struct prog_instruction *
-emit_cont_break_if(slang_emit_info *emitInfo, slang_ir_node *n,
- GLboolean breakTrue)
+emit_cont_break_if_true(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct prog_instruction *inst;
assert(n->Opcode == IR_CONT_IF_TRUE ||
- n->Opcode == IR_BREAK_IF_TRUE ||
- n->Opcode == IR_BREAK_IF_FALSE);
+ n->Opcode == IR_BREAK_IF_TRUE);
/* evaluate condition expr, setting cond codes */
inst = emit(emitInfo, n->Children[0]);
@@ -1289,11 +1286,11 @@ emit_cont_break_if(slang_emit_info *emit
/* opcode selection */
if (emitInfo->EmitHighLevelInstructions) {
+ const gl_inst_opcode opcode
+ = (n->Opcode == IR_CONT_IF_TRUE) ? OPCODE_CONT : OPCODE_BRK;
if (emitInfo->EmitCondCodes) {
- gl_inst_opcode opcode
- = (n->Opcode == IR_CONT_IF_TRUE) ? OPCODE_CONT : OPCODE_BRK;
inst = new_instruction(emitInfo, opcode);
- inst->DstReg.CondMask = breakTrue ? COND_NE : COND_EQ;
+ inst->DstReg.CondMask = COND_NE;
return inst;
}
else {
@@ -1302,35 +1299,12 @@ emit_cont_break_if(slang_emit_info *emit
* ENDIF
*/
GLint ifInstLoc;
- if (n->Opcode == IR_CONT_IF_TRUE ||
- n->Opcode == IR_BREAK_IF_TRUE) {
- ifInstLoc = emitInfo->prog->NumInstructions;
- inst = new_instruction(emitInfo, OPCODE_IF);
- storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
- }
- else {
- /* invert the expression */
- if (!alloc_temp_storage(emitInfo, n, 1))
- return NULL;
- inst = new_instruction(emitInfo, OPCODE_SEQ);
- storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
- constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
- storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
- inst->Comment = _mesa_strdup("Invert true/false");
-
- ifInstLoc = emitInfo->prog->NumInstructions;
- inst = new_instruction(emitInfo, OPCODE_IF);
- storage_to_src_reg(&inst->SrcReg[0], n->Store);
- free_temp_storage(emitInfo->vt, n);
- }
+ ifInstLoc = emitInfo->prog->NumInstructions;
+ inst = new_instruction(emitInfo, OPCODE_IF);
+ storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
n->InstLocation = emitInfo->prog->NumInstructions;
- if (n->Opcode == IR_BREAK_IF_TRUE ||
- n->Opcode == IR_BREAK_IF_FALSE) {
- inst = new_instruction(emitInfo, OPCODE_BRK);
- }
- else {
- inst = new_instruction(emitInfo, OPCODE_CONT);
- }
+
+ inst = new_instruction(emitInfo, opcode);
inst = new_instruction(emitInfo, OPCODE_ENDIF);
emitInfo->prog->Instructions[ifInstLoc].BranchTarget
@@ -1341,7 +1315,7 @@ emit_cont_break_if(slang_emit_info *emit
else {
assert(emitInfo->EmitCondCodes);
inst = new_instruction(emitInfo, OPCODE_BRA);
- inst->DstReg.CondMask = breakTrue ? COND_NE : COND_EQ;
+ inst->DstReg.CondMask = COND_NE;
return inst;
}
}
@@ -1677,11 +1651,9 @@ emit(slang_emit_info *emitInfo, slang_ir
case IR_LOOP:
return emit_loop(emitInfo, n);
- case IR_BREAK_IF_FALSE:
- return emit_cont_break_if(emitInfo, n, GL_FALSE);
case IR_BREAK_IF_TRUE:
case IR_CONT_IF_TRUE:
- return emit_cont_break_if(emitInfo, n, GL_TRUE);
+ return emit_cont_break_if_true(emitInfo, n);
case IR_BREAK:
/* fall-through */
case IR_CONT:
@@ -1790,7 +1762,7 @@ _slang_emit_code(slang_ir_node *n, slang
emitInfo.NumSubroutines = 0;
emitInfo.EmitHighLevelInstructions = ctx->Shader.EmitHighLevelInstructions;
- emitInfo.EmitCondCodes = ctx->Shader.EmitCondCodes;
+ emitInfo.EmitCondCodes = 0*ctx->Shader.EmitCondCodes;
emitInfo.EmitComments = ctx->Shader.EmitComments;
emitInfo.EmitBeginEndSub = 0; /* XXX for compiler debug only */
diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c
index dd17b4a..0c2e65a 100644
--- a/src/mesa/shader/slang/slang_ir.c
+++ b/src/mesa/shader/slang/slang_ir.c
@@ -326,10 +326,6 @@ _slang_print_ir_tree(const slang_ir_node
case IR_BREAK:
printf("BREAK\n");
break;
- case IR_BREAK_IF_FALSE:
- printf("BREAK_IF_FALSE\n");
- _slang_print_ir_tree(n->Children[0], indent+3);
- break;
case IR_BREAK_IF_TRUE:
printf("BREAK_IF_TRUE\n");
_slang_print_ir_tree(n->Children[0], indent+3);
diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
index a183ea6..69db4b5 100644
--- a/src/mesa/shader/slang/slang_ir.h
+++ b/src/mesa/shader/slang/slang_ir.h
@@ -73,7 +73,6 @@ typedef enum
IR_BREAK, /* break loop */
IR_BREAK_IF_TRUE,
- IR_BREAK_IF_FALSE,
IR_CONT_IF_TRUE,
/* Children[0] = the condition expression */
diff-tree 8128f7143d9c3768df4cf669e97777e021db127a (from 393a93ea324701ef5a545ba99c7d627ab5f9097f)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 14:33:25 2007 -0600
don't generate IR_BREAK_IF_FALSE
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 5e6c91b..6350dff 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -469,6 +469,13 @@ new_float_literal(const float v[4], GLui
}
+static slang_ir_node *
+new_not(slang_ir_node *n)
+{
+ return new_node1(IR_NOT, n);
+}
+
+
/**
* Inlined subroutine.
*/
@@ -520,15 +527,15 @@ new_break(slang_ir_node *loopNode)
/**
- * Make new IR_BREAK_IF_TRUE or IR_BREAK_IF_FALSE node.
+ * Make new IR_BREAK_IF_TRUE.
*/
static slang_ir_node *
-new_break_if(slang_ir_node *loopNode, slang_ir_node *cond, GLboolean breakTrue)
+new_break_if_true(slang_ir_node *loopNode, slang_ir_node *cond)
{
slang_ir_node *n;
assert(loopNode);
assert(loopNode->Opcode == IR_LOOP);
- n = new_node1(breakTrue ? IR_BREAK_IF_TRUE : IR_BREAK_IF_FALSE, cond);
+ n = new_node1(IR_BREAK_IF_TRUE, cond);
if (n) {
/* insert this node at head of linked list */
n->List = loopNode->List;
@@ -1420,8 +1427,8 @@ _slang_gen_while(slang_assemble_ctx * A,
}
else {
slang_ir_node *cond
- = new_cond(_slang_gen_operation(A, &oper->children[0]));
- breakIf = new_break_if(A->CurLoop, cond, GL_FALSE);
+ = new_cond(new_not(_slang_gen_operation(A, &oper->children[0])));
+ breakIf = new_break_if_true(A->CurLoop, cond);
}
body = _slang_gen_operation(A, &oper->children[1]);
loop->Children[0] = new_seq(breakIf, body);
@@ -1480,8 +1487,8 @@ _slang_gen_do(slang_assemble_ctx * A, co
}
else {
slang_ir_node *cond
- = new_cond(_slang_gen_operation(A, &oper->children[1]));
- loop->Children[1] = new_break_if(A->CurLoop, cond, GL_FALSE);
+ = new_cond(new_not(_slang_gen_operation(A, &oper->children[1])));
+ loop->Children[1] = new_break_if_true(A->CurLoop, cond);
}
/* XXX we should do infinite loop detection, as above */
@@ -1516,8 +1523,8 @@ _slang_gen_for(slang_assemble_ctx * A, c
prevLoop = A->CurLoop;
A->CurLoop = loop;
- cond = new_cond(_slang_gen_operation(A, &oper->children[1]));
- breakIf = new_break_if(A->CurLoop, cond, GL_FALSE);
+ cond = new_cond(new_not(_slang_gen_operation(A, &oper->children[1])));
+ breakIf = new_break_if_true(A->CurLoop, cond);
body = _slang_gen_operation(A, &oper->children[3]);
incr = _slang_gen_operation(A, &oper->children[2]);
@@ -1609,7 +1616,7 @@ _slang_gen_if(slang_assemble_ctx * A, co
if (is_operation_type(&oper->children[1], SLANG_OPER_BREAK)) {
/* Special case: generate a conditional break */
- ifBody = new_break_if(A->CurLoop, cond, GL_TRUE);
+ ifBody = new_break_if_true(A->CurLoop, cond);
if (haveElseClause) {
elseBody = _slang_gen_operation(A, &oper->children[2]);
return new_seq(ifBody, elseBody);
diff-tree 393a93ea324701ef5a545ba99c7d627ab5f9097f (from 3e7d43cd480203f0f861345776454628df0d9a42)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 14:25:30 2007 -0600
Get rid of IR_CONT_IF_FALSE
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 46d72e2..310a9f1 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1216,7 +1216,6 @@ emit_loop(slang_emit_info *emitInfo, sla
}
else {
assert(ir->Opcode == IR_CONT ||
- ir->Opcode == IR_CONT_IF_FALSE ||
ir->Opcode == IR_CONT_IF_TRUE);
assert(inst->Opcode == OPCODE_CONT ||
inst->Opcode == OPCODE_BRA);
@@ -1276,7 +1275,6 @@ emit_cont_break_if(slang_emit_info *emit
struct prog_instruction *inst;
assert(n->Opcode == IR_CONT_IF_TRUE ||
- n->Opcode == IR_CONT_IF_FALSE ||
n->Opcode == IR_BREAK_IF_TRUE ||
n->Opcode == IR_BREAK_IF_FALSE);
@@ -1293,8 +1291,7 @@ emit_cont_break_if(slang_emit_info *emit
if (emitInfo->EmitHighLevelInstructions) {
if (emitInfo->EmitCondCodes) {
gl_inst_opcode opcode
- = (n->Opcode == IR_CONT_IF_TRUE || n->Opcode == IR_CONT_IF_FALSE)
- ? OPCODE_CONT : OPCODE_BRK;
+ = (n->Opcode == IR_CONT_IF_TRUE) ? OPCODE_CONT : OPCODE_BRK;
inst = new_instruction(emitInfo, opcode);
inst->DstReg.CondMask = breakTrue ? COND_NE : COND_EQ;
return inst;
@@ -1681,7 +1678,6 @@ emit(slang_emit_info *emitInfo, slang_ir
case IR_LOOP:
return emit_loop(emitInfo, n);
case IR_BREAK_IF_FALSE:
- case IR_CONT_IF_FALSE:
return emit_cont_break_if(emitInfo, n, GL_FALSE);
case IR_BREAK_IF_TRUE:
case IR_CONT_IF_TRUE:
diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c
index 95b154d..dd17b4a 100644
--- a/src/mesa/shader/slang/slang_ir.c
+++ b/src/mesa/shader/slang/slang_ir.c
@@ -334,10 +334,6 @@ _slang_print_ir_tree(const slang_ir_node
printf("BREAK_IF_TRUE\n");
_slang_print_ir_tree(n->Children[0], indent+3);
break;
- case IR_CONT_IF_FALSE:
- printf("CONT_IF_FALSE\n");
- _slang_print_ir_tree(n->Children[0], indent+3);
- break;
case IR_CONT_IF_TRUE:
printf("CONT_IF_TRUE\n");
_slang_print_ir_tree(n->Children[0], indent+3);
diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
index a9a530a..a183ea6 100644
--- a/src/mesa/shader/slang/slang_ir.h
+++ b/src/mesa/shader/slang/slang_ir.h
@@ -75,7 +75,6 @@ typedef enum
IR_BREAK_IF_TRUE,
IR_BREAK_IF_FALSE,
IR_CONT_IF_TRUE,
- IR_CONT_IF_FALSE,
/* Children[0] = the condition expression */
IR_MOVE,
diff-tree 3e7d43cd480203f0f861345776454628df0d9a42 (from 1bbd69251b2738428795c06bb19c3a21797d6846)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 14:23:33 2007 -0600
Get rid of BRK0, BRK1, CONT0, CONT1 instructions.
diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index 7908976..013d65c 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -727,32 +727,6 @@ _mesa_execute_program(GLcontext * ctx,
pc = inst->BranchTarget - 1;
}
break;
- case OPCODE_BRK0: /* Break if zero */
- /* fall-through */
- case OPCODE_CONT0: /* Continue if zero */
- {
- GLfloat a[4];
- fetch_vector1(&inst->SrcReg[0], machine, a);
- if (a[0] == 0.0) {
- /* take branch */
- /* Subtract 1 here since we'll do pc++ at end of for-loop */
- pc = inst->BranchTarget - 1;
- }
- }
- break;
- case OPCODE_BRK1: /* Break if non-zero */
- /* fall-through */
- case OPCODE_CONT1: /* Continue if non-zero */
- {
- GLfloat a[4];
- fetch_vector1(&inst->SrcReg[0], machine, a);
- if (a[0] != 0.0) {
- /* take branch */
- /* Subtract 1 here since we'll do pc++ at end of for-loop */
- pc = inst->BranchTarget - 1;
- }
- }
- break;
case OPCODE_CAL: /* Call subroutine (conditional) */
if (eval_condition(machine, inst)) {
/* call the subroutine */
diff --git a/src/mesa/shader/prog_instruction.c b/src/mesa/shader/prog_instruction.c
index 272caf6..1e8e081 100644
--- a/src/mesa/shader/prog_instruction.c
+++ b/src/mesa/shader/prog_instruction.c
@@ -138,13 +138,9 @@ static const struct instruction_info Ins
{ OPCODE_BGNSUB, "BGNSUB", 0 },
{ OPCODE_BRA, "BRA", 0 },
{ OPCODE_BRK, "BRK", 0 },
- { OPCODE_BRK0, "BRK0", 1 },
- { OPCODE_BRK1, "BRK1", 1 },
{ OPCODE_CAL, "CAL", 0 },
{ OPCODE_CMP, "CMP", 3 },
{ OPCODE_CONT, "CONT", 0 },
- { OPCODE_CONT0, "CONT0", 1 },
- { OPCODE_CONT1, "CONT1", 1 },
{ OPCODE_COS, "COS", 1 },
{ OPCODE_DDX, "DDX", 1 },
{ OPCODE_DDY, "DDY", 1 },
diff --git a/src/mesa/shader/prog_instruction.h b/src/mesa/shader/prog_instruction.h
index dc2d2dc..c800757 100644
--- a/src/mesa/shader/prog_instruction.h
+++ b/src/mesa/shader/prog_instruction.h
@@ -153,13 +153,9 @@ typedef enum prog_opcode {
OPCODE_BGNSUB, /* opt */
OPCODE_BRA, /* 2 X */
OPCODE_BRK, /* 2 opt */
- OPCODE_BRK0, /* opt */
- OPCODE_BRK1, /* opt */
OPCODE_CAL, /* 2 2 */
OPCODE_CMP, /* X */
OPCODE_CONT, /* opt */
- OPCODE_CONT0, /* opt */
- OPCODE_CONT1, /* opt */
OPCODE_COS, /* X 2 X X */
OPCODE_DDX, /* X X */
OPCODE_DDY, /* X X */
diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c
index a43bebb..e92837f 100644
--- a/src/mesa/shader/prog_print.c
+++ b/src/mesa/shader/prog_print.c
@@ -606,17 +606,6 @@ _mesa_print_instruction_opt(const struct
print_comment(inst);
break;
- case OPCODE_BRK0:
- case OPCODE_BRK1:
- case OPCODE_CONT0:
- case OPCODE_CONT1:
- _mesa_printf("%s ", _mesa_opcode_string(inst->Opcode));
- print_src_reg(&inst->SrcReg[0], mode, prog);
- _mesa_printf("; ");
- _mesa_printf(" # (goto %d)", inst->BranchTarget);
- print_comment(inst);
- break;
-
case OPCODE_BGNSUB:
if (mode == PROG_PRINT_NV) {
_mesa_printf("%s:\n", inst->Comment); /* comment is label */
diff --git a/src/mesa/tnl/t_vb_arbprogram.c b/src/mesa/tnl/t_vb_arbprogram.c
index f0e326f..2edb1c5 100644
--- a/src/mesa/tnl/t_vb_arbprogram.c
+++ b/src/mesa/tnl/t_vb_arbprogram.c
@@ -741,13 +741,9 @@ static gpu_function opcode_func[MAX_OPCO
do_NOP,/*BGNSUB*/
do_NOP,/*BRA*/
do_NOP,/*BRK*/
- do_NOP,/*BRK0*/
- do_NOP,/*BRK1*/
do_NOP,/*CAL*/
do_NOP,/*CMP*/
do_NOP,/*CONT*/
- do_NOP,/*CONT0*/
- do_NOP,/*CONT1*/
do_NOP,/*COS*/
do_NOP,/*DDX*/
do_NOP,/*DDY*/
diff-tree 1bbd69251b2738428795c06bb19c3a21797d6846 (from f841b04601e469f3d4203733d12bb6415d12b9c8)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 14:21:26 2007 -0600
Don't emit OPCODE_CONT0/1, BRK0/1 instructions, clean-ups elsewhere.
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index dd71933..46d72e2 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -171,7 +171,7 @@ free_temp_storage(slang_var_table *vt, s
_slang_free_temp(vt, n->Store);
n->Store->Index = -1;
n->Store->Size = -1;
- _mesa_free(n->Store);
+ /*_mesa_free(n->Store);*/ /* XXX leak */
n->Store = NULL;
}
}
@@ -1078,17 +1078,20 @@ static struct prog_instruction *
emit_if(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct gl_program *prog = emitInfo->prog;
- struct prog_instruction *ifInst, *inst;
GLuint ifInstLoc, elseInstLoc = 0;
GLuint condWritemask = 0;
- inst = emit(emitInfo, n->Children[0]); /* the condition */
- if (emitInfo->EmitCondCodes) {
- if (!inst) {
- /* error recovery */
- return NULL;
+ /* emit condition expression code */
+ {
+ struct prog_instruction *inst;
+ inst = emit(emitInfo, n->Children[0]);
+ if (emitInfo->EmitCondCodes) {
+ if (!inst) {
+ /* error recovery */
+ return NULL;
+ }
+ condWritemask = inst->DstReg.WriteMask;
}
- condWritemask = inst->DstReg.WriteMask;
}
#if 0
@@ -1097,7 +1100,7 @@ emit_if(slang_emit_info *emitInfo, slang
ifInstLoc = prog->NumInstructions;
if (emitInfo->EmitHighLevelInstructions) {
- ifInst = new_instruction(emitInfo, OPCODE_IF);
+ struct prog_instruction *ifInst = new_instruction(emitInfo, OPCODE_IF);
if (emitInfo->EmitCondCodes) {
ifInst->DstReg.CondMask = COND_NE; /* if cond is non-zero */
/* only test the cond code (1 of 4) that was updated by the
@@ -1112,7 +1115,7 @@ emit_if(slang_emit_info *emitInfo, slang
}
else {
/* conditional jump to else, or endif */
- ifInst = new_instruction(emitInfo, OPCODE_BRA);
+ struct prog_instruction *ifInst = new_instruction(emitInfo, OPCODE_BRA);
ifInst->DstReg.CondMask = COND_EQ; /* BRA if cond is zero */
ifInst->Comment = _mesa_strdup("if zero");
ifInst->DstReg.CondSwizzle = writemask_to_swizzle(condWritemask);
@@ -1134,15 +1137,12 @@ emit_if(slang_emit_info *emitInfo, slang
inst->Comment = _mesa_strdup("else");
inst->DstReg.CondMask = COND_TR; /* always branch */
}
- ifInst = prog->Instructions + ifInstLoc;
- ifInst->BranchTarget = prog->NumInstructions;
-
+ prog->Instructions[ifInstLoc].BranchTarget = prog->NumInstructions;
emit(emitInfo, n->Children[2]);
}
else {
/* no else body */
- ifInst = prog->Instructions + ifInstLoc;
- ifInst->BranchTarget = prog->NumInstructions /*+ 1*/;
+ prog->Instructions[ifInstLoc].BranchTarget = prog->NumInstructions;
}
if (emitInfo->EmitHighLevelInstructions) {
@@ -1150,9 +1150,7 @@ emit_if(slang_emit_info *emitInfo, slang
}
if (n->Children[2]) {
- struct prog_instruction *elseInst;
- elseInst = prog->Instructions + elseInstLoc;
- elseInst->BranchTarget = prog->NumInstructions;
+ prog->Instructions[elseInstLoc].BranchTarget = prog->NumInstructions;
}
return NULL;
}
@@ -1162,7 +1160,7 @@ static struct prog_instruction *
emit_loop(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct gl_program *prog = emitInfo->prog;
- struct prog_instruction *beginInst, *endInst;
+ struct prog_instruction *endInst;
GLuint beginInstLoc, tailInstLoc, endInstLoc;
slang_ir_node *ir;
@@ -1198,8 +1196,7 @@ emit_loop(slang_emit_info *emitInfo, sla
if (emitInfo->EmitHighLevelInstructions) {
/* BGNLOOP's BranchTarget points to the ENDLOOP inst */
- beginInst = prog->Instructions + beginInstLoc;
- beginInst->BranchTarget = prog->NumInstructions - 1;
+ prog->Instructions[beginInstLoc].BranchTarget = prog->NumInstructions -1;
}
/* Done emitting loop code. Now walk over the loop's linked list of
@@ -1213,8 +1210,6 @@ emit_loop(slang_emit_info *emitInfo, sla
ir->Opcode == IR_BREAK_IF_FALSE ||
ir->Opcode == IR_BREAK_IF_TRUE) {
assert(inst->Opcode == OPCODE_BRK ||
- inst->Opcode == OPCODE_BRK0 ||
- inst->Opcode == OPCODE_BRK1 ||
inst->Opcode == OPCODE_BRA);
/* go to instruction after end of loop */
inst->BranchTarget = endInstLoc + 1;
@@ -1224,8 +1219,6 @@ emit_loop(slang_emit_info *emitInfo, sla
ir->Opcode == IR_CONT_IF_FALSE ||
ir->Opcode == IR_CONT_IF_TRUE);
assert(inst->Opcode == OPCODE_CONT ||
- inst->Opcode == OPCODE_CONT0 ||
- inst->Opcode == OPCODE_CONT1 ||
inst->Opcode == OPCODE_BRA);
/* go to instruction at tail of loop */
inst->BranchTarget = endInstLoc;
@@ -1280,7 +1273,6 @@ static struct prog_instruction *
emit_cont_break_if(slang_emit_info *emitInfo, slang_ir_node *n,
GLboolean breakTrue)
{
- gl_inst_opcode opcode;
struct prog_instruction *inst;
assert(n->Opcode == IR_CONT_IF_TRUE ||
@@ -1300,36 +1292,61 @@ emit_cont_break_if(slang_emit_info *emit
/* opcode selection */
if (emitInfo->EmitHighLevelInstructions) {
if (emitInfo->EmitCondCodes) {
- if (n->Opcode == IR_CONT_IF_TRUE ||
- n->Opcode == IR_CONT_IF_FALSE)
- opcode = OPCODE_CONT;
- else
- opcode = OPCODE_BRK;
+ gl_inst_opcode opcode
+ = (n->Opcode == IR_CONT_IF_TRUE || n->Opcode == IR_CONT_IF_FALSE)
+ ? OPCODE_CONT : OPCODE_BRK;
+ inst = new_instruction(emitInfo, opcode);
+ inst->DstReg.CondMask = breakTrue ? COND_NE : COND_EQ;
+ return inst;
}
else {
- if (n->Opcode == IR_CONT_IF_TRUE)
- opcode = OPCODE_CONT1;
- else if (n->Opcode == IR_CONT_IF_FALSE)
- opcode = OPCODE_CONT0;
- else if (n->Opcode == IR_BREAK_IF_TRUE)
- opcode = OPCODE_BRK1;
- else if (n->Opcode == IR_BREAK_IF_FALSE)
- opcode = OPCODE_BRK0;
+ /* IF reg
+ * BRK/CONT;
+ * ENDIF
+ */
+ GLint ifInstLoc;
+ if (n->Opcode == IR_CONT_IF_TRUE ||
+ n->Opcode == IR_BREAK_IF_TRUE) {
+ ifInstLoc = emitInfo->prog->NumInstructions;
+ inst = new_instruction(emitInfo, OPCODE_IF);
+ storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
+ }
+ else {
+ /* invert the expression */
+ if (!alloc_temp_storage(emitInfo, n, 1))
+ return NULL;
+ inst = new_instruction(emitInfo, OPCODE_SEQ);
+ storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
+ constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
+ storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
+ inst->Comment = _mesa_strdup("Invert true/false");
+
+ ifInstLoc = emitInfo->prog->NumInstructions;
+ inst = new_instruction(emitInfo, OPCODE_IF);
+ storage_to_src_reg(&inst->SrcReg[0], n->Store);
+ free_temp_storage(emitInfo->vt, n);
+ }
+ n->InstLocation = emitInfo->prog->NumInstructions;
+ if (n->Opcode == IR_BREAK_IF_TRUE ||
+ n->Opcode == IR_BREAK_IF_FALSE) {
+ inst = new_instruction(emitInfo, OPCODE_BRK);
+ }
+ else {
+ inst = new_instruction(emitInfo, OPCODE_CONT);
+ }
+ inst = new_instruction(emitInfo, OPCODE_ENDIF);
+
+ emitInfo->prog->Instructions[ifInstLoc].BranchTarget
+ = emitInfo->prog->NumInstructions;
+ return inst;
}
}
else {
- opcode = OPCODE_BRA;
- }
-
- inst = new_instruction(emitInfo, opcode);
- if (emitInfo->EmitCondCodes) {
+ assert(emitInfo->EmitCondCodes);
+ inst = new_instruction(emitInfo, OPCODE_BRA);
inst->DstReg.CondMask = breakTrue ? COND_NE : COND_EQ;
+ return inst;
}
- else {
- /* BRK0, BRK1, CONT0, CONT1 uses SrcReg[0] as the condition */
- storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
- }
- return inst;
}
diff-tree f841b04601e469f3d4203733d12bb6415d12b9c8 (from b463d521432c675c6336fde8b39870717e099be5)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 14:14:00 2007 -0600
simplify, clean-up break/cont code
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 22bcfe6..5e6c91b 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -539,15 +539,15 @@ new_break_if(slang_ir_node *loopNode, sl
/**
- * Make new IR_CONT_IF_TRUE or IR_CONT_IF_FALSE node.
+ * Make new IR_CONT_IF_TRUE node.
*/
static slang_ir_node *
-new_cont_if(slang_ir_node *loopNode, slang_ir_node *cond, GLboolean contTrue)
+new_cont_if_true(slang_ir_node *loopNode, slang_ir_node *cond)
{
slang_ir_node *n;
assert(loopNode);
assert(loopNode->Opcode == IR_LOOP);
- n = new_node1(contTrue ? IR_CONT_IF_TRUE : IR_CONT_IF_FALSE, cond);
+ n = new_node1(IR_CONT_IF_TRUE, cond);
if (n) {
/* insert this node at head of linked list */
n->List = loopNode->List;
@@ -1391,7 +1391,7 @@ _slang_gen_while(slang_assemble_ctx * A,
* BREAK if !expr (child[0])
* body code (child[1])
*/
- slang_ir_node *prevLoop, *loop, *cond, *breakIf, *body;
+ slang_ir_node *prevLoop, *loop, *breakIf, *body;
GLboolean isConst, constTrue;
/* type-check expression */
@@ -1414,12 +1414,13 @@ _slang_gen_while(slang_assemble_ctx * A,
prevLoop = A->CurLoop;
A->CurLoop = loop;
- cond = new_cond(_slang_gen_operation(A, &oper->children[0]));
if (isConst && constTrue) {
/* while(nonzero constant), no conditional break */
breakIf = NULL;
}
else {
+ slang_ir_node *cond
+ = new_cond(_slang_gen_operation(A, &oper->children[0]));
breakIf = new_break_if(A->CurLoop, cond, GL_FALSE);
}
body = _slang_gen_operation(A, &oper->children[1]);
@@ -1453,7 +1454,7 @@ _slang_gen_do(slang_assemble_ctx * A, co
* tail code:
* BREAK if !expr (child[1])
*/
- slang_ir_node *prevLoop, *loop, *cond;
+ slang_ir_node *prevLoop, *loop;
GLboolean isConst, constTrue;
/* type-check expression */
@@ -1478,7 +1479,8 @@ _slang_gen_do(slang_assemble_ctx * A, co
loop->Children[1] = NULL; /* no tail code */
}
else {
- cond = new_cond(_slang_gen_operation(A, &oper->children[1]));
+ slang_ir_node *cond
+ = new_cond(_slang_gen_operation(A, &oper->children[1]));
loop->Children[1] = new_break_if(A->CurLoop, cond, GL_FALSE);
}
@@ -1616,7 +1618,7 @@ _slang_gen_if(slang_assemble_ctx * A, co
}
else if (is_operation_type(&oper->children[1], SLANG_OPER_CONTINUE)) {
/* Special case: generate a conditional break */
- ifBody = new_cont_if(A->CurLoop, cond, GL_TRUE);
+ ifBody = new_cont_if_true(A->CurLoop, cond);
if (haveElseClause) {
elseBody = _slang_gen_operation(A, &oper->children[2]);
return new_seq(ifBody, elseBody);
diff-tree b463d521432c675c6336fde8b39870717e099be5 (from 7e4a7fdddd0b333d6825ac0154affeb520c5f0fe)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 13:29:57 2007 -0600
added some null ptr checks to handle error recovery
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index eeaeab1..dd71933 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -508,8 +508,13 @@ emit_arith(slang_emit_info *emitInfo, sl
/* normal case */
/* gen code for children */
- for (i = 0; i < info->NumParams; i++)
+ for (i = 0; i < info->NumParams; i++) {
emit(emitInfo, n->Children[i]);
+ if (!n->Children[i] || !n->Children[i]->Store) {
+ /* error recovery */
+ return NULL;
+ }
+ }
/* gen this instruction and src registers */
inst = new_instruction(emitInfo, info->InstOpcode);
@@ -997,6 +1002,11 @@ emit_cond(slang_emit_info *emitInfo, sla
/* emit code for the expression */
inst = emit(emitInfo, n->Children[0]);
+ if (!n->Children[0]->Store) {
+ /* error recovery */
+ return NULL;
+ }
+
assert(n->Children[0]->Store);
/*assert(n->Children[0]->Store->Size == 1);*/
@@ -1074,7 +1084,10 @@ emit_if(slang_emit_info *emitInfo, slang
inst = emit(emitInfo, n->Children[0]); /* the condition */
if (emitInfo->EmitCondCodes) {
- assert(inst);
+ if (!inst) {
+ /* error recovery */
+ return NULL;
+ }
condWritemask = inst->DstReg.WriteMask;
}
diff-tree 7e4a7fdddd0b333d6825ac0154affeb520c5f0fe (from ee2f31e281969fb505a767630cd04b9e08db1b9a)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 13:23:44 2007 -0600
Use constant_to_src_reg() to simplify some code
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index cbc71f3..eeaeab1 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -232,6 +232,27 @@ storage_to_src_reg(struct prog_src_regis
}
+/*
+ * Setup an instrucion src register to point to a scalar constant.
+ */
+static void
+constant_to_src_reg(struct prog_src_register *src, GLfloat val,
+ slang_emit_info *emitInfo)
+{
+ GLuint zeroSwizzle;
+ GLint zeroReg;
+ GLfloat value[4];
+
+ value[0] = val;
+ zeroReg = _mesa_add_unnamed_constant(emitInfo->prog->Parameters,
+ value, 1, &zeroSwizzle);
+ assert(zeroReg >= 0);
+
+ src->File = PROGRAM_CONSTANT;
+ src->Index = zeroReg;
+ src->Swizzle = zeroSwizzle;
+}
+
/**
* Add new instruction at end of given program.
@@ -556,14 +577,9 @@ emit_compare(slang_emit_info *emitInfo,
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
}
else if (size <= 4) {
- static const GLfloat zero[4] = { 0, 0, 0, 0 };
- GLuint zeroSwizzle, swizzle;
- GLint zeroReg = _mesa_add_unnamed_constant(emitInfo->prog->Parameters,
- zero, 4, &zeroSwizzle);
+ GLuint swizzle;
gl_inst_opcode dotOp;
- assert(zeroReg >= 0);
-
assert(!n->Store);
if (!n->Store) {
if (!alloc_temp_storage(emitInfo, n, size)) /* 'size' bools */
@@ -606,9 +622,7 @@ emit_compare(slang_emit_info *emitInfo,
/* compute tmp2.x = !tmp2.x via tmp2.x = (tmp2.x == 0) */
inst = new_instruction(emitInfo, OPCODE_SEQ);
storage_to_src_reg(&inst->SrcReg[0], n->Store);
- inst->SrcReg[1].File = PROGRAM_CONSTANT;
- inst->SrcReg[1].Index = zeroReg;
- inst->SrcReg[1].Swizzle = zeroSwizzle;
+ constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
inst->Comment = _mesa_strdup("Invert true/false");
}
@@ -1029,16 +1043,8 @@ emit_cond(slang_emit_info *emitInfo, sla
static struct prog_instruction *
emit_not(slang_emit_info *emitInfo, slang_ir_node *n)
{
- GLfloat zero = 0.0;
- slang_ir_storage st;
struct prog_instruction *inst;
- /* need zero constant */
- st.File = PROGRAM_CONSTANT;
- st.Size = 1;
- st.Index = _mesa_add_unnamed_constant(emitInfo->prog->Parameters, &zero,
- 1, &st.Swizzle);
-
/* child expr */
(void) emit(emitInfo, n->Children[0]);
/* XXXX if child instr is SGT convert to SLE, if SEQ, SNE, etc */
@@ -1050,8 +1056,7 @@ emit_not(slang_emit_info *emitInfo, slan
inst = new_instruction(emitInfo, OPCODE_SEQ);
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
- storage_to_src_reg(&inst->SrcReg[1], &st);
-
+ constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
free_temp_storage(emitInfo->vt, n->Children[0]);
inst->Comment = _mesa_strdup("NOT");
diff-tree ee2f31e281969fb505a767630cd04b9e08db1b9a (from dad97b4688ea25caf15cae66194db6ddbb98e936)
Author: Brian <brian at yutani.localnet.net>
Date: Wed Mar 28 12:48:27 2007 -0600
added missing returns after slang_info_log_error() calls
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index bd403b7..22bcfe6 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -2450,11 +2450,13 @@ _slang_gen_operation(slang_assemble_ctx
case SLANG_OPER_BREAK:
if (!A->CurLoop) {
slang_info_log_error(A->log, "'break' not in loop");
+ return NULL;
}
return new_break(A->CurLoop);
case SLANG_OPER_CONTINUE:
if (!A->CurLoop) {
slang_info_log_error(A->log, "'continue' not in loop");
+ return NULL;
}
return _slang_gen_continue(A, oper);
case SLANG_OPER_DISCARD:
More information about the mesa-commit
mailing list