vc4: Add initial support for math opcodes
authorEric Anholt <eric@anholt.net>
Wed, 16 Jul 2014 15:25:22 +0000 (08:25 -0700)
committerEric Anholt <eric@anholt.net>
Sat, 9 Aug 2014 01:59:46 +0000 (18:59 -0700)
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qpu_emit.c

index 8a9373594727675507fbf76c85f2127e127d2f3b..2107ef73c1ff6af8d785a1f815c3952fcfdee95c 100644 (file)
@@ -258,6 +258,10 @@ emit_tgsi_instruction(struct tgsi_to_qir *trans,
                 [TGSI_OPCODE_DP2] = { 0, tgsi_to_qir_dp2 },
                 [TGSI_OPCODE_DP3] = { 0, tgsi_to_qir_dp3 },
                 [TGSI_OPCODE_DP4] = { 0, tgsi_to_qir_dp4 },
+                [TGSI_OPCODE_RCP] = { QOP_RCP, tgsi_to_qir_alu },
+                [TGSI_OPCODE_RSQ] = { QOP_RSQ, tgsi_to_qir_alu },
+                [TGSI_OPCODE_EX2] = { QOP_EXP2, tgsi_to_qir_alu },
+                [TGSI_OPCODE_LG2] = { QOP_LOG2, tgsi_to_qir_alu },
                 [TGSI_OPCODE_LIT] = { QOP_MOV, tgsi_to_qir_alu }, /* XXX */
         };
         static int asdf = 0;
index 0f6f2c171a4b25b9299ad477d61d80a6b0ef72be..330876734d1b6bbee068553d489e5b7a332f4b07 100644 (file)
@@ -196,6 +196,43 @@ vc4_generate_code(struct qcompile *c)
                                                qpu_m_NOP());
                         break;
 
+                case QOP_RCP:
+                case QOP_RSQ:
+                case QOP_EXP2:
+                case QOP_LOG2:
+                        switch (qinst->op) {
+                        case QOP_RCP:
+                                insts[ni++] = qpu_inst(qpu_a_MOV(qpu_rb(QPU_W_SFU_RECIP),
+                                                                 src[0]),
+                                                       qpu_m_NOP());
+                                break;
+                        case QOP_RSQ:
+                                insts[ni++] = qpu_inst(qpu_a_MOV(qpu_rb(QPU_W_SFU_RECIPSQRT),
+                                                                 src[0]),
+                                                       qpu_m_NOP());
+                                break;
+                        case QOP_EXP2:
+                                insts[ni++] = qpu_inst(qpu_a_MOV(qpu_rb(QPU_W_SFU_EXP),
+                                                                 src[0]),
+                                                       qpu_m_NOP());
+                                break;
+                        case QOP_LOG2:
+                                insts[ni++] = qpu_inst(qpu_a_MOV(qpu_rb(QPU_W_SFU_LOG),
+                                                                 src[0]),
+                                                       qpu_m_NOP());
+                                break;
+                        default:
+                                abort();
+                        }
+
+                        insts[ni++] = qpu_inst(qpu_a_NOP(), qpu_m_NOP());
+                        insts[ni++] = qpu_inst(qpu_a_NOP(), qpu_m_NOP());
+
+                        insts[ni++] = qpu_inst(qpu_a_MOV(dst, qpu_r4()),
+                                               qpu_m_NOP());
+
+                        break;
+
                 case QOP_PACK_COLORS:
                         for (int i = 0; i < 4; i++) {
                                 insts[ni++] = qpu_inst(qpu_a_NOP(),
@@ -207,7 +244,6 @@ vc4_generate_code(struct qcompile *c)
 
                         insts[ni++] = qpu_inst(qpu_a_MOV(dst, qpu_r5()),
                                                qpu_m_NOP());
-
                         break;
 
                 case QOP_TLB_COLOR_WRITE: