r300/compiler: Add peephole optimization for the 'sub' presubtract operation
authorTom Stellard <tstellar@gmail.com>
Mon, 6 Sep 2010 17:57:20 +0000 (10:57 -0700)
committerTom Stellard <tstellar@gmail.com>
Sat, 11 Sep 2010 01:18:09 +0000 (18:18 -0700)
src/mesa/drivers/dri/r300/compiler/radeon_optimize.c

index 3ff07d60396dcb898fb43205b5162c15e4c44821..2bed2dd9c5f293dd2e9afa94b6f8d4ecaab4d8e3 100644 (file)
@@ -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)) {