diff options
author | Alyssa Rosenzweig <[email protected]> | 2019-07-26 14:25:25 -0700 |
---|---|---|
committer | Alyssa Rosenzweig <[email protected]> | 2019-08-02 09:57:15 -0700 |
commit | 62a5ee3bb4397e2a049b1fd4b36c55975ed26e6b (patch) | |
tree | b77e028d56da6d7367b473ee105317b9afe7cbb8 /src/panfrost | |
parent | d066ca3575e1aba706bafb1a434f5d7765c10181 (diff) |
pan/midgard: Flip conditionals
We would like to flip ops to have a constant in the second place to
enable inlining of the constant.
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Diffstat (limited to 'src/panfrost')
-rw-r--r-- | src/panfrost/midgard/midgard_compile.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index c4a50cbaee0..23a05607847 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -1789,6 +1789,41 @@ inline_alu_constants(compiler_context *ctx) } } +/* Being a little silly with the names, but returns the op that is the bitwise + * inverse of the op with the argument switched. I.e. (f and g are + * contrapositives): + * + * f(a, b) = ~g(b, a) + * + * Corollary: if g is the contrapositve of f, f is the contrapositive of g: + * + * f(a, b) = ~g(b, a) + * ~f(a, b) = g(b, a) + * ~f(a, b) = ~h(a, b) where h is the contrapositive of g + * f(a, b) = h(a, b) + * + * Thus we define this function in pairs. + */ + +static inline midgard_alu_op +mir_contrapositive(midgard_alu_op op) +{ + switch (op) { + case midgard_alu_op_flt: + return midgard_alu_op_fle; + case midgard_alu_op_fle: + return midgard_alu_op_flt; + + case midgard_alu_op_ilt: + return midgard_alu_op_ile; + case midgard_alu_op_ile: + return midgard_alu_op_ilt; + + default: + unreachable("No known contrapositive"); + } +} + /* Midgard supports two types of constants, embedded constants (128-bit) and * inline constants (16-bit). Sometimes, especially with scalar ops, embedded * constants can be demoted to inline constants, for space savings and @@ -1819,13 +1854,19 @@ embedded_to_inline_constant(compiler_context *ctx) int op = ins->alu.op; if (ins->ssa_args.src0 == SSA_FIXED_REGISTER(REGISTER_CONSTANT)) { + bool flip = alu_opcode_props[op].props & OP_COMMUTES; + switch (op) { - /* These ops require an operational change to flip - * their arguments TODO */ + /* Conditionals can be inverted */ case midgard_alu_op_flt: - case midgard_alu_op_fle: case midgard_alu_op_ilt: + case midgard_alu_op_fle: case midgard_alu_op_ile: + ins->alu.op = mir_contrapositive(ins->alu.op); + ins->invert = true; + flip = true; + break; + case midgard_alu_op_fcsel: case midgard_alu_op_icsel: DBG("Missed non-commutative flip (%s)\n", alu_opcode_props[op].name); @@ -1833,7 +1874,7 @@ embedded_to_inline_constant(compiler_context *ctx) break; } - if (alu_opcode_props[op].props & OP_COMMUTES) { + if (flip) { /* Flip the SSA numbers */ ins->ssa_args.src0 = ins->ssa_args.src1; ins->ssa_args.src1 = SSA_FIXED_REGISTER(REGISTER_CONSTANT); |