v3dv: don't lower uadd_carry and usub_borrow

We can produce slightly better code for these in the backend, so
do that. For this we need to:

1. Fix our implementation of uadd_carry (which wasn't used) to return
   an integer instead of a boolean value.
2. Add an implementation of usub_borrow.

Notice these are only used in Vulkan. In GL these instructions are
always unconditionally lowered by the state tracker in GLSL IR so
we never get to see them in the backend.

Shader-db stats from a collection of Vulkan samples:

total instructions in shared programs: 122351 -> 122345 (<.01%)
instructions in affected programs: 196 -> 190 (-3.06%)
helped: 2
HURT: 0

total uniforms in shared programs: 18670 -> 18672 (0.01%)
uniforms in affected programs: 59 -> 61 (3.39%)
helped: 0
HURT: 2

total max-temps in shared programs: 13145 -> 13147 (0.02%)
max-temps in affected programs: 27 -> 29 (7.41%)
helped: 0
HURT: 2

total inst-and-stalls in shared programs: 123052 -> 123046 (<.01%)
inst-and-stalls in affected programs: 197 -> 191 (-3.05%)
helped: 2
HURT: 0

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17372>
This commit is contained in:
Iago Toral Quiroga
2022-07-06 11:29:41 +02:00
committed by Marge Bot
parent 84a0dca9df
commit 152fc4fd28
2 changed files with 19 additions and 6 deletions
+19 -1
View File
@@ -1263,6 +1263,18 @@ ntq_emit_cond_to_bool(struct v3d_compile *c, enum v3d_qpu_cond cond)
return result;
}
static struct qreg
ntq_emit_cond_to_int(struct v3d_compile *c, enum v3d_qpu_cond cond)
{
struct qreg result =
vir_MOV(c, vir_SEL(c, cond,
vir_uniform_ui(c, 1),
vir_uniform_ui(c, 0)));
c->flags_temp = result.index;
c->flags_cond = cond;
return result;
}
static struct qreg
f2f16_rtz(struct v3d_compile *c, struct qreg f32)
{
@@ -1713,7 +1725,13 @@ ntq_emit_alu(struct v3d_compile *c, nir_alu_instr *instr)
case nir_op_uadd_carry:
vir_set_pf(c, vir_ADD_dest(c, vir_nop_reg(), src[0], src[1]),
V3D_QPU_PF_PUSHC);
result = ntq_emit_cond_to_bool(c, V3D_QPU_COND_IFA);
result = ntq_emit_cond_to_int(c, V3D_QPU_COND_IFA);
break;
case nir_op_usub_borrow:
vir_set_pf(c, vir_SUB_dest(c, vir_nop_reg(), src[0], src[1]),
V3D_QPU_PF_PUSHC);
result = ntq_emit_cond_to_int(c, V3D_QPU_COND_IFA);
break;
case nir_op_pack_half_2x16_split:
-5
View File
@@ -214,11 +214,6 @@ const nir_shader_compiler_options v3dv_nir_options = {
.lower_pack_32_2x16 = true,
.lower_pack_32_2x16_split = true,
.lower_unpack_32_2x16_split = true,
/* FIXME: see if we can avoid the uadd_carry and usub_borrow lowering and
* get the tests to pass since it might produce slightly better code.
*/
.lower_uadd_carry = true,
.lower_usub_borrow = true,
/* FIXME: check if we can use multop + umul24 to implement mul2x32_64
* without lowering.
*/