nir/builder: Add rounding mode parameter to nir_type_convert

Later changes will use this.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15121>
This commit is contained in:
Ian Romanick 2022-11-01 16:38:26 -07:00 committed by Marge Bot
parent 43da822312
commit 9f86d18b2d
3 changed files with 24 additions and 14 deletions

View file

@ -436,7 +436,8 @@ nir_ssa_def *
nir_type_convert(nir_builder *b,
nir_ssa_def *src,
nir_alu_type src_type,
nir_alu_type dest_type)
nir_alu_type dest_type,
nir_rounding_mode rnd)
{
assert(nir_alu_type_get_type_size(src_type) == 0 ||
nir_alu_type_get_type_size(src_type) == src->bit_size);
@ -444,7 +445,7 @@ nir_type_convert(nir_builder *b,
src_type = (nir_alu_type) (src_type | src->bit_size);
nir_op opcode =
nir_type_conversion_op(src_type, dest_type, nir_rounding_mode_undef);
nir_type_conversion_op(src_type, dest_type, rnd);
if (opcode == nir_op_mov)
return src;

View file

@ -369,7 +369,8 @@ nir_ssa_def *
nir_type_convert(nir_builder *b,
nir_ssa_def *src,
nir_alu_type src_type,
nir_alu_type dest_type);
nir_alu_type dest_type,
nir_rounding_mode rnd);
static inline nir_ssa_def *
nir_convert_to_bit_size(nir_builder *b,
@ -377,7 +378,8 @@ nir_convert_to_bit_size(nir_builder *b,
nir_alu_type type,
unsigned bit_size)
{
return nir_type_convert(b, src, type, (nir_alu_type) (type | bit_size));
return nir_type_convert(b, src, type, (nir_alu_type) (type | bit_size),
nir_rounding_mode_undef);
}
static inline nir_ssa_def *
@ -407,7 +409,8 @@ nir_f2fN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
static inline nir_ssa_def *
nir_f2b(nir_builder *b, nir_ssa_def *src)
{
return nir_type_convert(b, src, nir_type_float, nir_type_bool1);
return nir_type_convert(b, src, nir_type_float, nir_type_bool1,
nir_rounding_mode_undef);
}
static inline nir_ssa_def *
@ -420,42 +423,48 @@ static inline nir_ssa_def *
nir_b2iN(nir_builder *b, nir_ssa_def *src, uint32_t bit_size)
{
return nir_type_convert(b, src, nir_type_bool,
(nir_alu_type) (nir_type_int | bit_size));
(nir_alu_type) (nir_type_int | bit_size),
nir_rounding_mode_undef);
}
static inline nir_ssa_def *
nir_b2fN(nir_builder *b, nir_ssa_def *src, uint32_t bit_size)
{
return nir_type_convert(b, src, nir_type_bool,
(nir_alu_type) (nir_type_float | bit_size));
(nir_alu_type) (nir_type_float | bit_size),
nir_rounding_mode_undef);
}
static inline nir_ssa_def *
nir_i2fN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_int,
(nir_alu_type) (nir_type_float | bit_size));
(nir_alu_type) (nir_type_float | bit_size),
nir_rounding_mode_undef);
}
static inline nir_ssa_def *
nir_u2fN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_uint,
(nir_alu_type) (nir_type_float | bit_size));
(nir_alu_type) (nir_type_float | bit_size),
nir_rounding_mode_undef);
}
static inline nir_ssa_def *
nir_f2uN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_float,
(nir_alu_type) (nir_type_uint | bit_size));
(nir_alu_type) (nir_type_uint | bit_size),
nir_rounding_mode_undef);
}
static inline nir_ssa_def *
nir_f2iN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_float,
(nir_alu_type) (nir_type_int | bit_size));
(nir_alu_type) (nir_type_int | bit_size),
nir_rounding_mode_undef);
}
static inline nir_ssa_def *

View file

@ -99,8 +99,8 @@ convert_instr_small(nir_builder *b, nir_op op,
nir_alu_type int_type = nir_op_infos[op].output_type | sz;
nir_alu_type float_type = nir_type_float | (options->allow_fp16 ? sz * 2 : 32);
nir_ssa_def *p = nir_type_convert(b, numer, int_type, float_type);
nir_ssa_def *q = nir_type_convert(b, denom, int_type, float_type);
nir_ssa_def *p = nir_type_convert(b, numer, int_type, float_type, nir_rounding_mode_undef);
nir_ssa_def *q = nir_type_convert(b, denom, int_type, float_type, nir_rounding_mode_undef);
/* Take 1/q but offset mantissa by 1 to correct for rounding. This is
* needed for correct results and has been checked exhaustively for
@ -111,7 +111,7 @@ convert_instr_small(nir_builder *b, nir_op op,
nir_ssa_def *res = nir_fmul(b, p, rcp);
/* Convert back to integer space with rounding inferred by type */
res = nir_type_convert(b, res, float_type, int_type);
res = nir_type_convert(b, res, float_type, int_type, nir_rounding_mode_undef);
/* Get remainder given the quotient */
if (op == nir_op_umod || op == nir_op_imod || op == nir_op_irem)