bifrost: Simplify derivatives a bit
authorJason Ekstrand <jason.ekstrand@collabora.com>
Fri, 11 Mar 2022 22:09:28 +0000 (16:09 -0600)
committerMarge Bot <emma+marge@anholt.net>
Sat, 12 Mar 2022 02:27:02 +0000 (02:27 +0000)
Instead of two magic ternary operations, define a new `axis` temporary
which is 1 for X and 2 for Y.  Then define everything else in terms of
this variable.  In particular, the mask operation we do on LANE_ID is a
mask so it makes more sense to use ~axis than 1/2 but in the other
order.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15352>

src/panfrost/bifrost/bifrost_compile.c

index 5ea945f..b811e1f 100644 (file)
@@ -2141,13 +2141,14 @@ bi_emit_alu(bi_builder *b, nir_alu_instr *instr)
 
         case nir_op_fddx:
         case nir_op_fddy: {
+                unsigned axis = instr->op == nir_op_fddx ? 1 : 2;
                 bi_index lane1 = bi_lshift_and_i32(b,
                                 bi_fau(BIR_FAU_LANE_ID, false),
-                                bi_imm_u32(instr->op == nir_op_fddx ? 2 : 1),
+                                bi_imm_u32(0x3 & ~axis),
                                 bi_imm_u8(0));
 
                 bi_index lane2 = bi_iadd_u32(b, lane1,
-                                bi_imm_u32(instr->op == nir_op_fddx ? 1 : 2),
+                                bi_imm_u32(axis),
                                 false);
 
                 bi_index left, right;