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 */
}
break;
case OPCODE_IF:
- if (eval_condition(machine, inst)) {
- /* do if-clause (just continue execution) */
- }
- else {
- /* go to the instruction after ELSE or ENDIF */
- assert(inst->BranchTarget >= 0);
- pc = inst->BranchTarget - 1;
+ {
+ GLboolean cond;
+ /* eval condition */
+ if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
+ GLfloat a[4];
+ fetch_vector1(&inst->SrcReg[0], machine, a);
+ cond = (a[0] != 0.0);
+ }
+ else {
+ cond = eval_condition(machine, inst);
+ }
+ /* do if/else */
+ if (cond) {
+ /* do if-clause (just continue execution) */
+ }
+ else {
+ /* go to the instruction after ELSE or ENDIF */
+ assert(inst->BranchTarget >= 0);
+ pc = inst->BranchTarget - 1;
+ }
}
break;
case OPCODE_ELSE:
{ 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", 1 },
+ { OPCODE_CONT, "CONT", 0 },
+ { OPCODE_CONT0, "CONT0", 1 },
+ { OPCODE_CONT1, "CONT1", 1 },
{ OPCODE_COS, "COS", 1 },
{ OPCODE_DDX, "DDX", 1 },
{ OPCODE_DDY, "DDY", 1 },
struct gl_program *prog;
/* code-gen options */
GLboolean EmitHighLevelInstructions;
+ GLboolean EmitCondCodes;
GLboolean EmitComments;
} slang_emit_info;
static struct prog_instruction *
emit_cond(slang_emit_info *emitInfo, slang_ir_node *n)
{
- /* Conditional expression (in if/while/for stmts).
- * Need to update condition code register.
- * Next instruction is typically an IR_IF.
- */
struct prog_instruction *inst;
if (!n->Children[0])
inst = emit(emitInfo, n->Children[0]);
- if (inst) {
- /* set inst's CondUpdate flag */
- inst->CondUpdate = GL_TRUE;
- n->Store = n->Children[0]->Store;
- return inst; /* XXX or null? */
+ if (emitInfo->EmitCondCodes) {
+ /* Conditional expression (in if/while/for stmts).
+ * Need to update condition code register.
+ * Next instruction is typically an IR_IF.
+ */
+ if (inst) {
+ /* set inst's CondUpdate flag */
+ inst->CondUpdate = GL_TRUE;
+ n->Store = n->Children[0]->Store;
+ return inst; /* XXX or null? */
+ }
+ else {
+ /* This'll happen for things like "if (i) ..." where no code
+ * is normally generated for the expression "i".
+ * Generate a move instruction just to set condition codes.
+ * Note: must use full 4-component vector since all four
+ * condition codes must be set identically.
+ */
+ if (!alloc_temp_storage(emitInfo, n, 4))
+ return NULL;
+ inst = new_instruction(emitInfo, OPCODE_MOV);
+ inst->CondUpdate = GL_TRUE;
+ storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
+ storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
+ _slang_free_temp(emitInfo->vt, n->Store);
+ inst->Comment = _mesa_strdup("COND expr");
+ return inst; /* XXX or null? */
+ }
}
else {
- /* This'll happen for things like "if (i) ..." where no code
- * is normally generated for the expression "i".
- * Generate a move instruction just to set condition codes.
- * Note: must use full 4-component vector since all four
- * condition codes must be set identically.
- */
- if (!alloc_temp_storage(emitInfo, n, 4))
- return NULL;
- inst = new_instruction(emitInfo, OPCODE_MOV);
- inst->CondUpdate = GL_TRUE;
- storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
- storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
- _slang_free_temp(emitInfo->vt, n->Store);
- inst->Comment = _mesa_strdup("COND expr");
- return inst; /* XXX or null? */
+ /* No-op */
+ n->Store = n->Children[0]->Store;
+ return NULL;
}
}
ifInstLoc = prog->NumInstructions;
if (emitInfo->EmitHighLevelInstructions) {
ifInst = new_instruction(emitInfo, OPCODE_IF);
- ifInst->DstReg.CondMask = COND_NE; /* if cond is non-zero */
+ if (emitInfo->EmitCondCodes) {
+ ifInst->DstReg.CondMask = COND_NE; /* if cond is non-zero */
+ }
+ else {
+ /* test reg.x */
+ storage_to_src_reg(&ifInst->SrcReg[0], n->Children[0]->Store);
+ }
}
else {
/* conditional jump to else, or endif */
ifInst->DstReg.CondMask = COND_EQ; /* BRA if cond is zero */
ifInst->Comment = _mesa_strdup("if zero");
}
- /* which condition code to use: */
- ifInst->DstReg.CondSwizzle = n->Children[0]->Store->Swizzle;
+ if (emitInfo->EmitCondCodes) {
+ /* which condition code to use: */
+ ifInst->DstReg.CondSwizzle = n->Children[0]->Store->Swizzle;
+ }
/* if body */
emit(emitInfo, n->Children[1]);
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;
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);
/* to go instruction at top of loop */
inst->BranchTarget = beginInstLoc;
/**
- * "Continue" or "break" statement.
+ * Unconditional "continue" or "break" statement.
* Either OPCODE_CONT, OPCODE_BRK or OPCODE_BRA will be emitted.
*/
static struct prog_instruction *
gl_inst_opcode opcode;
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);
+
/* evaluate condition expr, setting cond codes */
inst = emit(emitInfo, n->Children[0]);
- assert(inst);
- inst->CondUpdate = GL_TRUE;
+ if (emitInfo->EmitCondCodes) {
+ assert(inst);
+ inst->CondUpdate = GL_TRUE;
+ }
n->InstLocation = emitInfo->prog->NumInstructions;
+
+ /* opcode selection */
if (emitInfo->EmitHighLevelInstructions) {
- if (n->Opcode == IR_CONT_IF_TRUE ||
- n->Opcode == IR_CONT_IF_FALSE)
- opcode = OPCODE_CONT;
- else
- opcode = OPCODE_BRK;
+ if (emitInfo->EmitCondCodes) {
+ if (n->Opcode == IR_CONT_IF_TRUE ||
+ n->Opcode == IR_CONT_IF_FALSE)
+ opcode = OPCODE_CONT;
+ else
+ opcode = OPCODE_BRK;
+ }
+ 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;
+ }
}
else {
opcode = OPCODE_BRA;
}
+
inst = new_instruction(emitInfo, opcode);
- inst->DstReg.CondMask = breakTrue ? COND_NE : COND_EQ;
+ if (emitInfo->EmitCondCodes) {
+ inst->DstReg.CondMask = breakTrue ? COND_NE : COND_EQ;
+ }
+ else {
+ /* BRK0, BRK1, CONT0, CONT1 */
+ storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
+ }
return inst;
}
emitInfo.prog = prog;
emitInfo.EmitHighLevelInstructions = ctx->Shader.EmitHighLevelInstructions;
- emitInfo.EmitComments = 1+ctx->Shader.EmitComments;
+ emitInfo.EmitCondCodes = 0; /* XXX temporary! */
+ emitInfo.EmitComments = ctx->Shader.EmitComments;
(void) emit(&emitInfo, n);