diff options
author | Eric Anholt <[email protected]> | 2016-06-25 19:49:07 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2016-07-04 16:33:22 -0700 |
commit | ac772b24a18bddc490dae171441795dedd85d7b2 (patch) | |
tree | bf3e17b02a62a36bb3eba706913e26866f8857d9 /src/gallium/drivers | |
parent | 8a52f03f5deeb36ea4d58d56fbb711a2004d7587 (diff) |
vc4: Regularize instruction emit macros
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
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/vc4/vc4_qir.c | 28 | ||||
-rw-r--r-- | src/gallium/drivers/vc4/vc4_qir.h | 61 |
2 files changed, 50 insertions, 39 deletions
diff --git a/src/gallium/drivers/vc4/vc4_qir.c b/src/gallium/drivers/vc4/vc4_qir.c index 526e3a179aa..5d5ba1f0e13 100644 --- a/src/gallium/drivers/vc4/vc4_qir.c +++ b/src/gallium/drivers/vc4/vc4_qir.c @@ -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 diff --git a/src/gallium/drivers/vc4/vc4_qir.h b/src/gallium/drivers/vc4/vc4_qir.h index 8813cb4f1ce..2f4b71a3dfa 100644 --- a/src/gallium/drivers/vc4/vc4_qir.h +++ b/src/gallium/drivers/vc4/vc4_qir.h @@ -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 */ |