[Mesa-dev] [PATCH 4/8] nir: Add lowering for find_lsb.

Ian Romanick idr at freedesktop.org
Thu May 31 17:51:42 UTC 2018


On 05/08/2018 01:13 PM, Eric Anholt wrote:
> There is a fairly simple relation to turn this into ufind_msb.
> ---
>  src/compiler/nir/nir.h                | 2 ++
>  src/compiler/nir/nir_opt_algebraic.py | 4 ++++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index ee45b0709636..53ac1598dfc9 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -1891,6 +1891,8 @@ typedef struct nir_shader_compiler_options {
>     bool lower_bfm;
>     /** Lowers ifind_msb to compare and ufind_msb */
>     bool lower_ifind_msb;
> +   /** Lowers find_lsb to ufind_msb and logic ops */
> +   bool lower_find_lsb;
>     bool lower_uadd_carry;
>     bool lower_usub_borrow;
>     /** lowers fneg and ineg to fsub and isub. */
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index 616f734ac9b2..46de62eea0b5 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -536,6 +536,10 @@ optimizations = [
>      ('ufind_msb', ('bcsel', ('ilt', 'value', 0), ('inot', 'value'), 'value')),
>      'options->lower_ifind_msb'),
>  
> +   (('find_lsb', 'value'),
> +    ('ufind_msb', ('iand', 'value', ('ineg', 'value'))),
> +    'options->lower_find_lsb'),
> +

I did something pretty similar in 3e7cebc8da5c9, but I did it in the
backend code generator.  I like this.  After this lands, I think i965
will use this for Gen < 7, and I'll delete that other code.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

>     (('extract_i8', a, 'b at 32'),
>      ('ishr', ('ishl', a, ('imul', ('isub', 3, b), 8)), 24),
>      'options->lower_extract_byte'),


More information about the mesa-dev mailing list