[Mesa-dev] [PATCH 1/8] nir: Add lowering for bitfieldInsert without using bfi.

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


There are GLSL IR lowering passes for a lot (all?) of this that I added
when I did GL_MESA_shader_integer_functions.  Is there a reason to not
use those?

On 05/08/2018 01:13 PM, Eric Anholt wrote:
> If you don't have HW to do bfi, then lowering bitfieldInsert to bfi makes
> things harder than keeping the "bits" argument around.
> 
> This still uses bfm, but I've added the obvious lowering of bfm if you
> need it.
> ---
>  src/compiler/nir/nir.h                |  5 +++++
>  src/compiler/nir/nir_opt_algebraic.py | 14 ++++++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index a379928cdcd9..ed95dbf955d8 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -1880,7 +1880,12 @@ typedef struct nir_shader_compiler_options {
>     bool lower_fmod32;
>     bool lower_fmod64;
>     bool lower_bitfield_extract;
> +   /** Lowers bitfield_insert to bfi/bfm */
>     bool lower_bitfield_insert;
> +   /** Lowers bitfield_insert to bfm, compares, and shifts. */
> +   bool lower_bitfield_insert_to_shifts;
> +   /** Lowers bfm to shifts and subtracts. */
> +   bool lower_bfm;
>     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 96232f0e549c..2824dcebb81b 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -492,6 +492,20 @@ optimizations = [
>                ('bfi', ('bfm', 'bits', 'offset'), 'insert', 'base')),
>      'options->lower_bitfield_insert'),
>  
> +   # Alternative lowering that doesn't rely on bfi.
> +   (('bitfield_insert', 'base', 'insert', 'offset', 'bits'),
> +    ('bcsel', ('ilt', 31, 'bits'),
> +     'insert',
> +     ('ior',
> +      ('iand', 'base', ('inot', ('bfm', 'bits', 'offset'))),
> +      ('iand', ('ishl', 'insert', 'offset'), ('bfm', 'bits', 'offset')))),
> +    'options->lower_bitfield_insert_to_shifts'),
> +
> +   # bfm lowering -- note that the NIR opcode is undefined if either arg is 32.
> +   (('bfm', 'bits', 'offset'),
> +    ('ishl', ('isub', ('ishl', 1, 'bits'), 1), 'offset'),
> +    'options->lower_bfm'),
> +
>     (('ibitfield_extract', 'value', 'offset', 'bits'),
>      ('bcsel', ('ilt', 31, 'bits'), 'value',
>                ('ibfe', 'value', 'offset', 'bits')),
> 



More information about the mesa-dev mailing list