[Mesa-dev] [PATCH 04/12] nir/algebraic: Allow for flagging operations as being inexact

Francisco Jerez currojerez at riseup.net
Thu Mar 24 02:55:42 UTC 2016


Jason Ekstrand <jason at jlekstrand.net> writes:

> ---
>  src/compiler/nir/nir_algebraic.py     | 9 ++++++++-
>  src/compiler/nir/nir_opt_algebraic.py | 9 ++++++++-
>  src/compiler/nir/nir_search.c         | 4 ++++
>  src/compiler/nir/nir_search.h         | 6 ++++++
>  4 files changed, 26 insertions(+), 2 deletions(-)
>
> diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
> index 2357b57..5356228 100644
> --- a/src/compiler/nir/nir_algebraic.py
> +++ b/src/compiler/nir/nir_algebraic.py
> @@ -69,6 +69,7 @@ static const ${val.c_type} ${val.name} = {
>     ${'true' if val.is_constant else 'false'},
>     nir_type_${ val.required_type or 'invalid' },
>  % elif isinstance(val, Expression):
> +   ${'true' if val.inexact else 'false'},
>     nir_op_${val.opcode},
>     { ${', '.join(src.c_ptr for src in val.sources)} },
>  % endif
> @@ -129,12 +130,18 @@ class Variable(Value):
>  
>        self.index = varset[self.var_name]
>  
> +_opcode_re = re.compile(r"(?P<inexact>~)?(?P<opcode>\w+)")
> +
>  class Expression(Value):
>     def __init__(self, expr, name_base, varset):
>        Value.__init__(self, name_base, "expression")
>        assert isinstance(expr, tuple)
>  
> -      self.opcode = expr[0]
> +      m = _opcode_re.match(expr[0])
> +      assert m and m.group('opcode') is not None
> +
> +      self.opcode = m.group('opcode')
> +      self.inexact = m.group('inexact') is not None
>        self.sources = [ Value.create(src, "{0}_{1}".format(name_base, i), varset)
>                         for (i, src) in enumerate(expr[1:]) ]
>  
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index 2a3eb32..3e7ea06 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -34,10 +34,17 @@ d = 'd'
>  
>  # Written in the form (<search>, <replace>) where <search> is an expression
>  # and <replace> is either an expression or a value.  An expression is
> -# defined as a tuple of the form (<op>, <src0>, <src1>, <src2>, <src3>)
> +# defined as a tuple of the form ([~]<op>, <src0>, <src1>, <src2>, <src3>)
>  # where each source is either an expression or a value.  A value can be
>  # either a numeric constant or a string representing a variable name.
>  #
> +# If the opcode in a search expression is prefixed by a '~' character, this
> +# indicates that the operation is inexact.  Such operations will only get
> +# applied to SSA values that do not have the exact bit set.  This should be
> +# used by by any optimizations that are not bit-for-bit exact.  It should not,
> +# however, be used for backend-requested lowering operations as those need to
> +# happen regardless of precision.
> +#
>  # Variable names are specified as "[#]name[@type]" where "#" inicates that
>  # the given variable will only match constants and the type indicates that
>  # the given variable will only match values from ALU instructions with the
> diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
> index 4cb2d4d..b0c9328 100644
> --- a/src/compiler/nir/nir_search.c
> +++ b/src/compiler/nir/nir_search.c
> @@ -191,6 +191,10 @@ match_expression(const nir_search_expression *expr, nir_alu_instr *instr,
>     if (instr->op != expr->opcode)
>        return false;
>  
> +   assert(instr->dest.dest.is_ssa);
> +   if (expr->inexact && instr->exact)
> +      return false;
> +
>     assert(!instr->dest.saturate);
>     assert(nir_op_infos[instr->op].num_inputs > 0);
>  
> diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h
> index 7d47792..a8246a1 100644
> --- a/src/compiler/nir/nir_search.h
> +++ b/src/compiler/nir/nir_search.h
> @@ -81,6 +81,12 @@ typedef struct {
>  typedef struct {
>     nir_search_value value;
>  
> +   /* When set on a search expression, the expression will only match an SSA
> +    * value that does *not* have the exact bit set.  If unset, the exact bit
> +    * on the SSA value is ignored.
> +    */
> +   bool inexact;
> +
>     nir_op opcode;
>     const nir_search_value *srcs[4];
>  } nir_search_expression;

Looks okay to me:

Reviewed-by: Francisco Jerez <currojerez at riseup.net>

> -- 
> 2.5.0.400.gff86faf
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160323/2c1fb854/attachment.sig>


More information about the mesa-dev mailing list