From: Daniel Schürmann Date: Thu, 13 Jun 2019 09:34:01 +0000 (+0200) Subject: nir: introduce lowering of bitfield_insert to bfm and a new opcode bitfield_select. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a8b0b6e52b095f03c96a72394d15327c42512815;p=mesa.git nir: introduce lowering of bitfield_insert to bfm and a new opcode bitfield_select. bitfield_select is defined as: bitfield_select(mask, base, insert) = (mask & base) | (~mask & insert) matching the behavior of AMD's BFI instruction. Reviewed-by: Connor Abbott --- diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 9feed169e47..bc9122d1f25 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2288,6 +2288,8 @@ typedef struct nir_shader_compiler_options { bool lower_bitfield_insert; /** Lowers bitfield_insert to compares, and shifts. */ bool lower_bitfield_insert_to_shifts; + /** Lowers bitfield_insert to bfm/bitfield_select. */ + bool lower_bitfield_insert_to_bitfield_select; /** Lowers bitfield_reverse to shifts. */ bool lower_bitfield_reverse; /** Lowers bit_count to shifts. */ diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 8771c74b033..a12b0269e2e 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -871,6 +871,9 @@ if (mask == 0) { } """) + +triop("bitfield_select", tuint, "", "(src0 & src1) | (~src0 & src2)") + # SM5 ubfe/ibfe assembly: only the 5 least significant bits of offset and bits are used. opcode("ubfe", 0, tuint32, [0, 0, 0], [tuint32, tuint32, tuint32], False, "", """ diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 0d21696273a..4147be9c1f7 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -799,6 +799,12 @@ optimizations.extend([ ('iand', ('ishl', 'insert', 'offset'), ('ishl', ('isub', ('ishl', 1, 'bits'), 1), 'offset'))), 'options->lower_bitfield_insert_to_shifts'), + # Alternative lowering that uses bitfield_select. + (('bitfield_insert', 'base', 'insert', 'offset', 'bits'), + ('bcsel', ('ult', 31, 'bits'), 'insert', + ('bitfield_select', ('bfm', 'bits', 'offset'), ('ishl', 'insert', 'offset'), 'base')), + 'options->lower_bitfield_insert_to_bitfield_select'), + (('ibitfield_extract', 'value', 'offset', 'bits'), ('bcsel', ('ult', 31, 'bits'), 'value', ('ibfe', 'value', 'offset', 'bits')),