From 312a2849807f577f0bbdf10b4e5e5fd1c3546b02 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 15 Oct 2021 16:39:35 +0100 Subject: [PATCH] nir/algebraic: add ignore_exact() wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rhys Perry Reviewed-by: Timur Kristóf Part-of: --- src/compiler/nir/nir_algebraic.py | 40 +++++++++++++++++++++++---- src/compiler/nir/nir_opt_algebraic.py | 2 ++ src/compiler/nir/nir_search.c | 2 +- src/compiler/nir/nir_search.h | 5 +++- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index bfe00d6ed85..9a4e8054345 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -98,13 +98,33 @@ class VarSet(object): def lock(self): self.immutable = True +class SearchExpression(object): + def __init__(self, expr): + self.opcode = expr[0] + self.sources = expr[1:] + self.ignore_exact = False + + @staticmethod + def create(val): + if isinstance(val, tuple): + return SearchExpression(val) + else: + assert(isinstance(val, SearchExpression)) + return val + + def __repr__(self): + l = [self.opcode, *self.sources] + if self.ignore_exact: + l.append('ignore_exact') + return repr((*l,)) + class Value(object): @staticmethod def create(val, name_base, varset, algebraic_pass): if isinstance(val, bytes): val = val.decode('utf-8') - if isinstance(val, tuple): + if isinstance(val, tuple) or isinstance(val, SearchExpression): return Expression(val, name_base, varset, algebraic_pass) elif isinstance(val, Expression): return val @@ -185,7 +205,9 @@ class Value(object): ${val.cond_index}, ${val.swizzle()}, % elif isinstance(val, Expression): - ${'true' if val.inexact else 'false'}, ${'true' if val.exact else 'false'}, + ${'true' if val.inexact else 'false'}, + ${'true' if val.exact else 'false'}, + ${'true' if val.ignore_exact else 'false'}, ${val.c_opcode()}, ${val.comm_expr_idx}, ${val.comm_exprs}, { ${', '.join(src.array_index for src in val.sources)} }, @@ -339,15 +361,17 @@ _opcode_re = re.compile(r"(?P~)?(?P!)?(?P\w+)(?:@(?P, ) where is an expression # and is either an expression or a value. An expression is # defined as a tuple of the form ([~], , , , ) diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index 3246d13ec8a..4fd7ad66143 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -408,7 +408,7 @@ match_expression(const nir_algebraic_table *table, const nir_search_expression * return false; state->inexact_match = expr->inexact || state->inexact_match; - state->has_exact_alu = instr->exact || state->has_exact_alu; + state->has_exact_alu = (instr->exact && !expr->ignore_exact) || state->has_exact_alu; if (state->inexact_match && state->has_exact_alu) return false; diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h index 2a7e9a2f0fe..fb56592cdd4 100644 --- a/src/compiler/nir/nir_search.h +++ b/src/compiler/nir/nir_search.h @@ -142,8 +142,11 @@ typedef struct { /** In a replacement, requests that the instruction be marked exact. */ bool exact : 1; + /** Don't make the replacement exact if the search expression is exact. */ + bool ignore_exact : 1; + /* One of nir_op or nir_search_op */ - uint16_t opcode : 14; + uint16_t opcode : 13; /* Commutative expression index. This is assigned by opt_algebraic.py when * search structures are constructed and is a unique (to this structure)