summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers
diff options
context:
space:
mode:
authorTom Stellard <[email protected]>2010-09-06 10:57:20 -0700
committerTom Stellard <[email protected]>2010-09-10 18:18:09 -0700
commit564653b9f196b9bf91fe772fd1ca1e131ff33774 (patch)
treebd15383ef73b4c30c53d688e21307612175238c3 /src/mesa/drivers
parenta64b4a05af362fff52c9e52eb51cd92fe164afcc (diff)
r300/compiler: Add peephole optimization for the 'sub' presubtract operation
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r--src/mesa/drivers/dri/r300/compiler/radeon_optimize.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c b/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
index 3ff07d60396..2bed2dd9c5f 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
@@ -597,19 +597,32 @@ static int presub_helper(
return can_remove;
}
+/* This function assumes that s->Inst->U.I.SrcReg[0] and
+ * s->Inst->U.I.SrcReg[1] aren't both negative. */
static void presub_replace_add(struct peephole_state *s,
struct rc_instruction * inst,
unsigned int src_index)
{
- inst->U.I.PreSub.SrcReg[0] = s->Inst->U.I.SrcReg[0];
- inst->U.I.PreSub.SrcReg[1] = s->Inst->U.I.SrcReg[1];
+ rc_presubtract_op presub_opcode;
+ if (s->Inst->U.I.SrcReg[1].Negate || s->Inst->U.I.SrcReg[0].Negate)
+ presub_opcode = RC_PRESUB_SUB;
+ else
+ presub_opcode = RC_PRESUB_ADD;
+
+ if (s->Inst->U.I.SrcReg[1].Negate) {
+ inst->U.I.PreSub.SrcReg[0] = s->Inst->U.I.SrcReg[1];
+ inst->U.I.PreSub.SrcReg[1] = s->Inst->U.I.SrcReg[0];
+ } else {
+ inst->U.I.PreSub.SrcReg[0] = s->Inst->U.I.SrcReg[0];
+ inst->U.I.PreSub.SrcReg[1] = s->Inst->U.I.SrcReg[1];
+ }
inst->U.I.PreSub.SrcReg[0].Negate = 0;
inst->U.I.PreSub.SrcReg[1].Negate = 0;
- inst->U.I.PreSub.Opcode = RC_PRESUB_ADD;
+ inst->U.I.PreSub.Opcode = presub_opcode;
inst->U.I.SrcReg[src_index] = chain_srcregs(inst->U.I.SrcReg[src_index],
inst->U.I.PreSub.SrcReg[0]);
inst->U.I.SrcReg[src_index].File = RC_FILE_PRESUB;
- inst->U.I.SrcReg[src_index].Index = RC_PRESUB_ADD;
+ inst->U.I.SrcReg[src_index].Index = presub_opcode;
}
static int peephole_add_presub_add(
@@ -648,10 +661,6 @@ static int peephole_add_presub_add(
if (!src1)
return 0;
- /* XXX Only do add for now. */
- if (src0->Negate)
- return 0;
-
s.Inst = inst_add;
s.WriteMask = inst_add->U.I.DstReg.WriteMask;
if (presub_helper(c, &s, RC_PRESUB_ADD, presub_replace_add)) {