OSDN Git Service

vc4: Regularize instruction emit macros
authorEric Anholt <eric@anholt.net>
Sun, 26 Jun 2016 02:49:07 +0000 (19:49 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 4 Jul 2016 23:33:22 +0000 (16:33 -0700)
ALU0 didn't have the _dest variant, and ALU2 didn't unset the def the way
ALU1 did.  This should make the ALU[012] macros much clearer, by moving
most of their contents to vc4_qir.c

src/gallium/drivers/vc4/vc4_qir.c
src/gallium/drivers/vc4/vc4_qir.h

index 526e3a1..5d5ba1f 100644 (file)
@@ -376,13 +376,37 @@ qir_inst4(enum qop op, struct qreg dst,
         return inst;
 }
 
-void
+static void
 qir_emit(struct vc4_compile *c, struct qinst *inst)
 {
+        list_addtail(&inst->link, &c->instructions);
+}
+
+/* Updates inst to write to a new temporary, emits it, and notes the def. */
+struct qreg
+qir_emit_def(struct vc4_compile *c, struct qinst *inst)
+{
+        assert(inst->dst.file == QFILE_NULL);
+
+        inst->dst = qir_get_temp(c);
+
         if (inst->dst.file == QFILE_TEMP)
                 c->defs[inst->dst.index] = inst;
 
-        qir_emit_nodef(c, inst);
+        qir_emit(c, inst);
+
+        return inst->dst;
+}
+
+struct qinst *
+qir_emit_nondef(struct vc4_compile *c, struct qinst *inst)
+{
+        if (inst->dst.file == QFILE_TEMP)
+                c->defs[inst->dst.index] = NULL;
+
+        qir_emit(c, inst);
+
+        return inst;
 }
 
 bool
index 8813cb4..2f4b71a 100644 (file)
@@ -464,13 +464,8 @@ struct qreg qir_uniform(struct vc4_compile *c,
 void qir_schedule_instructions(struct vc4_compile *c);
 void qir_reorder_uniforms(struct vc4_compile *c);
 
-void qir_emit(struct vc4_compile *c, struct qinst *inst);
-static inline struct qinst *
-qir_emit_nodef(struct vc4_compile *c, struct qinst *inst)
-{
-        list_addtail(&inst->link, &c->instructions);
-        return inst;
-}
+struct qreg qir_emit_def(struct vc4_compile *c, struct qinst *inst);
+struct qinst *qir_emit_nondef(struct vc4_compile *c, struct qinst *inst);
 
 struct qreg qir_get_temp(struct vc4_compile *c);
 int qir_get_op_nsrc(enum qop qop);
@@ -528,62 +523,58 @@ qir_uniform_f(struct vc4_compile *c, float f)
 static inline struct qreg                                                \
 qir_##name(struct vc4_compile *c)                                        \
 {                                                                        \
-        struct qreg t = qir_get_temp(c);                                 \
-        qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef));        \
-        return t;                                                        \
+        return qir_emit_def(c, qir_inst(QOP_##name, c->undef,            \
+                                        c->undef, c->undef));            \
+}                                                                        \
+static inline struct qinst *                                             \
+qir_##name##_dest(struct vc4_compile *c, struct qreg dest)               \
+{                                                                        \
+        return qir_emit_nondef(c, qir_inst(QOP_##name, dest,             \
+                                           c->undef, c->undef));         \
 }
 
 #define QIR_ALU1(name)                                                   \
 static inline struct qreg                                                \
 qir_##name(struct vc4_compile *c, struct qreg a)                         \
 {                                                                        \
-        struct qreg t = qir_get_temp(c);                                 \
-        qir_emit(c, qir_inst(QOP_##name, t, a, c->undef));               \
-        return t;                                                        \
+        return qir_emit_def(c, qir_inst(QOP_##name, c->undef,            \
+                                        a, c->undef));                   \
 }                                                                        \
 static inline struct qinst *                                             \
 qir_##name##_dest(struct vc4_compile *c, struct qreg dest,               \
                   struct qreg a)                                         \
 {                                                                        \
-        if (dest.file == QFILE_TEMP)                                     \
-                c->defs[dest.index] = NULL;                              \
-        return qir_emit_nodef(c, qir_inst(QOP_##name, dest, a,           \
-                                          c->undef));                    \
+        return qir_emit_nondef(c, qir_inst(QOP_##name, dest, a,          \
+                                           c->undef));                   \
 }
 
 #define QIR_ALU2(name)                                                   \
 static inline struct qreg                                                \
 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b)          \
 {                                                                        \
-        struct qreg t = qir_get_temp(c);                                 \
-        qir_emit(c, qir_inst(QOP_##name, t, a, b));                      \
-        return t;                                                        \
+        return qir_emit_def(c, qir_inst(QOP_##name, c->undef, a, b));    \
 }                                                                        \
-static inline void                                                       \
+static inline struct qinst *                                             \
 qir_##name##_dest(struct vc4_compile *c, struct qreg dest,               \
                   struct qreg a, struct qreg b)                          \
 {                                                                        \
-        qir_emit_nodef(c, qir_inst(QOP_##name, dest, a, b));             \
+        return qir_emit_nondef(c, qir_inst(QOP_##name, dest, a, b));     \
 }
 
 #define QIR_NODST_1(name)                                               \
 static inline struct qinst *                                            \
 qir_##name(struct vc4_compile *c, struct qreg a)                        \
 {                                                                       \
-        struct qinst *inst = qir_inst(QOP_##name, c->undef,             \
-                                      a, c->undef);                     \
-        qir_emit(c, inst);                                              \
-        return inst;                                                    \
+        return qir_emit_nondef(c, qir_inst(QOP_##name, c->undef,        \
+                                           a, c->undef));               \
 }
 
 #define QIR_NODST_2(name)                                               \
 static inline struct qinst *                                            \
 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b)         \
 {                                                                       \
-        struct qinst *inst = qir_inst(QOP_##name, c->undef,             \
-                                      a, b);                            \
-        qir_emit(c, inst);                                              \
-        return inst;                                                    \
+        return qir_emit_nondef(c, qir_inst(QOP_##name, c->undef,        \
+                                           a, b));                      \
 }
 
 #define QIR_PAYLOAD(name)                                                \
@@ -696,9 +687,7 @@ qir_PACK_8_F(struct vc4_compile *c, struct qreg dest, struct qreg val, int chan)
 {
         assert(!dest.pack);
         dest.pack = QPU_PACK_MUL_8A + chan;
-        qir_emit(c, qir_inst(QOP_MMOV, dest, val, c->undef));
-        if (dest.file == QFILE_TEMP)
-                c->defs[dest.index] = NULL;
+        qir_emit_nondef(c, qir_inst(QOP_MMOV, dest, val, c->undef));
 }
 
 static inline struct qreg
@@ -726,10 +715,8 @@ qir_VPM_WRITE(struct vc4_compile *c, struct qreg val)
 static inline struct qreg
 qir_LOAD_IMM(struct vc4_compile *c, uint32_t val)
 {
-        struct qreg t = qir_get_temp(c);
-        qir_emit(c, qir_inst(QOP_LOAD_IMM, t,
-                             qir_reg(QFILE_LOAD_IMM, val), c->undef));
-        return t;
+        return qir_emit_def(c, qir_inst(QOP_LOAD_IMM, c->undef,
+                                        qir_reg(QFILE_LOAD_IMM, val), c->undef));
 }
 
 #endif /* VC4_QIR_H */