pan/mdg: improve outmod printing

Signed-off-by: Italo Nicola <italonicola@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9461>
This commit is contained in:
Italo Nicola 2021-03-02 10:53:35 +00:00 committed by Marge Bot
parent 4cc7f2d84e
commit ea3115027e
6 changed files with 70 additions and 51 deletions

View file

@ -537,7 +537,7 @@ v_mov(unsigned src, unsigned dest)
.dest = dest,
.dest_type = nir_type_uint32,
.op = midgard_alu_op_imov,
.outmod = midgard_outmod_int_wrap
.outmod = midgard_outmod_keeplo
};
return ins;

View file

@ -157,16 +157,16 @@ print_reg(FILE *fp, unsigned reg, unsigned bits)
static char *outmod_names_float[4] = {
"",
".pos",
".sat_signed",
".sat"
".clamp_0_inf",
".clamp_m1_1",
".clamp_0_1"
};
static char *outmod_names_int[4] = {
".isat",
".ssat",
".usat",
"",
".hi"
".keeplo",
".keephi"
};
static char *srcmod_names_int[4] = {
@ -180,7 +180,21 @@ static void
print_outmod(FILE *fp, unsigned outmod, bool is_int)
{
fprintf(fp, "%s", is_int ? outmod_names_int[outmod] :
outmod_names_float[outmod]);
outmod_names_float[outmod]);
}
static void
print_alu_outmod(FILE *fp, unsigned outmod, bool is_int, bool half)
{
if (is_int && !half) {
assert(outmod == midgard_outmod_keeplo);
return;
}
if (!is_int && half)
fprintf(fp, ".shrink");
print_outmod(fp, outmod, is_int);
}
static void
@ -636,10 +650,6 @@ print_vector_field(FILE *fp, const char *name, uint16_t *words, uint16_t reg_wor
if (size_ambiguous)
fprintf(fp, "%c", postfix ? postfix : 'r');
/* Print the outmod, if there is one */
print_outmod(fp, alu_field->outmod,
midgard_is_integer_out_op(alu_field->op));
fprintf(fp, " ");
/* Mask denoting status of 8-lanes */
@ -669,9 +679,12 @@ print_vector_field(FILE *fp, const char *name, uint16_t *words, uint16_t reg_wor
}
print_mask(fp, mask, bits_for_mode(mode), shrink_mode);
fprintf(fp, ", ");
/* Print output modifiers */
bool is_int = midgard_is_integer_op(alu_field->op);
print_alu_outmod(fp, alu_field->outmod, is_int, shrink_mode != midgard_shrink_mode_none);
fprintf(fp, ", ");
if (reg_info->src1_reg == 26)
print_vector_constants(fp, alu_field->src1, consts, alu_field);
@ -738,8 +751,6 @@ print_scalar_field(FILE *fp, const char *name, uint16_t *words, uint16_t reg_wor
fprintf(fp, "%s.", name);
print_alu_opcode(fp, alu_field->op);
print_outmod(fp, alu_field->outmod,
midgard_is_integer_out_op(alu_field->op));
fprintf(fp, " ");
bool full = alu_field->output_full;
@ -753,7 +764,11 @@ print_scalar_field(FILE *fp, const char *name, uint16_t *words, uint16_t reg_wor
c >>= 1;
}
fprintf(fp, ".%c, ", components[c]);
fprintf(fp, ".%c", components[c]);
print_alu_outmod(fp, alu_field->outmod, is_int, !full);
fprintf(fp, ", ");
if (reg_info->src1_reg == 26)
print_scalar_constant(fp, alu_field->src1, consts, alu_field);
@ -1430,13 +1445,15 @@ print_texture_word(FILE *fp, uint32_t *word, unsigned tabs, unsigned in_reg_base
if (texture->out_of_order)
fprintf(fp, ".ooo%u", texture->out_of_order);
/* Output modifiers are always interpreted floatly */
print_outmod(fp, texture->outmod, false);
fprintf(fp, " %sr%u", texture->out_full ? "" : "h",
out_reg_base + texture->out_reg_select);
print_mask_4(fp, texture->mask, texture->out_upper);
assert(!(texture->out_full && texture->out_upper));
/* Output modifiers are only valid for float texture operations */
if (texture->sampler_type == MALI_SAMPLER_FLOAT)
print_outmod(fp, texture->outmod, false);
fprintf(fp, ", ");
/* Depending on whether we read from textures directly or indirectly,

View file

@ -207,17 +207,19 @@ typedef enum {
} midgard_alu_op;
typedef enum {
midgard_outmod_none = 0,
midgard_outmod_pos = 1, /* max(x, 0.0) */
midgard_outmod_sat_signed = 2, /* clamp(x, -1.0, 1.0) */
midgard_outmod_sat = 3 /* clamp(x, 0.0, 1.0) */
midgard_outmod_none = 0,
midgard_outmod_clamp_0_inf = 1, /* max(x, 0.0), NaNs become +0.0 */
midgard_outmod_clamp_m1_1 = 2, /* clamp(x, -1.0, 1.0), NaNs become -1.0 */
midgard_outmod_clamp_0_1 = 3 /* clamp(x, 0.0, 1.0), NaNs become +0.0 */
} midgard_outmod_float;
/* These are applied to the resulting value that's going to be stored in the dest reg.
* This should be set to midgard_outmod_keeplo when shrink_mode is midgard_shrink_mode_none. */
typedef enum {
midgard_outmod_int_saturate = 0,
midgard_outmod_uint_saturate = 1,
midgard_outmod_int_wrap = 2,
midgard_outmod_int_high = 3, /* Overflowed portion */
midgard_outmod_ssat = 0,
midgard_outmod_usat = 1,
midgard_outmod_keeplo = 2, /* Keep low half */
midgard_outmod_keephi = 3, /* Keep high half */
} midgard_outmod_int;
typedef enum {

View file

@ -566,31 +566,31 @@ mir_accept_dest_mod(compiler_context *ctx, nir_dest **dest, nir_op op)
return false;
}
/* Look for floating point mods. We have the mods fsat, fsat_signed,
* and fpos. We also have the relations (note 3 * 2 = 6 cases):
/* Look for floating point mods. We have the mods clamp_m1_1, clamp_0_1,
* and clamp_0_inf. We also have the relations (note 3 * 2 = 6 cases):
*
* fsat_signed(fpos(x)) = fsat(x)
* fsat_signed(fsat(x)) = fsat(x)
* fpos(fsat_signed(x)) = fsat(x)
* fpos(fsat(x)) = fsat(x)
* fsat(fsat_signed(x)) = fsat(x)
* fsat(fpos(x)) = fsat(x)
* clamp_0_1(clamp_0_inf(x)) = clamp_m1_1(x)
* clamp_0_1(clamp_m1_1(x)) = clamp_m1_1(x)
* clamp_0_inf(clamp_0_1(x)) = clamp_m1_1(x)
* clamp_0_inf(clamp_m1_1(x)) = clamp_m1_1(x)
* clamp_m1_1(clamp_0_1(x)) = clamp_m1_1(x)
* clamp_m1_1(clamp_0_inf(x)) = clamp_m1_1(x)
*
* So by cases any composition of output modifiers is equivalent to
* fsat alone.
* clamp_m1_1 alone.
*/
static unsigned
mir_determine_float_outmod(compiler_context *ctx, nir_dest **dest, unsigned prior_outmod)
{
bool fpos = mir_accept_dest_mod(ctx, dest, nir_op_fclamp_pos);
bool fsat = mir_accept_dest_mod(ctx, dest, nir_op_fsat);
bool ssat = mir_accept_dest_mod(ctx, dest, nir_op_fsat_signed);
bool clamp_0_inf = mir_accept_dest_mod(ctx, dest, nir_op_fclamp_pos);
bool clamp_0_1 = mir_accept_dest_mod(ctx, dest, nir_op_fsat);
bool clamp_m1_1 = mir_accept_dest_mod(ctx, dest, nir_op_fsat_signed);
bool prior = (prior_outmod != midgard_outmod_none);
int count = (int) prior + (int) fpos + (int) ssat + (int) fsat;
int count = (int) prior + (int) clamp_0_inf + (int) clamp_0_1 + (int) clamp_m1_1;
return ((count > 1) || fsat) ? midgard_outmod_sat :
fpos ? midgard_outmod_pos :
ssat ? midgard_outmod_sat_signed :
return ((count > 1) || clamp_0_1) ? midgard_outmod_clamp_0_1 :
clamp_0_inf ? midgard_outmod_clamp_0_inf :
clamp_m1_1 ? midgard_outmod_clamp_m1_1 :
prior_outmod;
}
@ -927,15 +927,15 @@ emit_alu(compiler_context *ctx, nir_alu_instr *instr)
bool is_int = midgard_is_integer_op(op);
if (instr->op == nir_op_umul_high || instr->op == nir_op_imul_high) {
outmod = midgard_outmod_int_high;
outmod = midgard_outmod_keephi;
} else if (midgard_is_integer_out_op(op)) {
outmod = midgard_outmod_int_wrap;
outmod = midgard_outmod_keeplo;
} else if (instr->op == nir_op_fsat) {
outmod = midgard_outmod_sat;
outmod = midgard_outmod_clamp_0_1;
} else if (instr->op == nir_op_fsat_signed) {
outmod = midgard_outmod_sat_signed;
outmod = midgard_outmod_clamp_m1_1;
} else if (instr->op == nir_op_fclamp_pos) {
outmod = midgard_outmod_pos;
outmod = midgard_outmod_clamp_0_inf;
}
/* Fetch unit, quirks, etc information */
@ -2558,7 +2558,7 @@ max_bitsize_for_alu(midgard_instruction *ins)
/* High implies computing at a higher bitsize, e.g umul_high of 32-bit
* requires computing at 64-bit */
if (midgard_is_integer_out_op(ins->op) && ins->outmod == midgard_outmod_int_high) {
if (midgard_is_integer_out_op(ins->op) && ins->outmod == midgard_outmod_keephi) {
max_bitsize *= 2;
assert(max_bitsize <= 64);
}

View file

@ -243,7 +243,7 @@ mir_is_scalar(midgard_instruction *ains)
if (ains->src[1] != ~0)
could_scalar &= (sz1 == 16) || (sz1 == 32);
if (midgard_is_integer_out_op(ains->op) && ains->outmod != midgard_outmod_int_wrap)
if (midgard_is_integer_out_op(ains->op) && ains->outmod != midgard_outmod_keeplo)
return false;
return could_scalar;

View file

@ -148,7 +148,7 @@ mir_nontrivial_outmod(midgard_instruction *ins)
return true;
if (is_int)
return mod != midgard_outmod_int_wrap;
return mod != midgard_outmod_keeplo;
else
return mod != midgard_outmod_none;
}