<p dir="ltr"><br>
On Jan 11, 2016 2:47 PM, "Matt Turner" <<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a>> wrote:<br>
><br>
> The OpenGL specifications for bitfieldInsert() and bitfieldExtract() says:<br>
><br>
>    The result will be undefined if <offset> or <bits> is negative, or if<br>
>    the sum of <offset> and <bits> is greater than the number of bits<br>
>    used to store the operand.<br>
><br>
> Therefore passing bits=32, offset=0 is legal and defined in GLSL.<br>
><br>
> But the earlier DX11/SM5 bfi/ibfe/ubfe opcodes are specified to accept a<br>
> bitfield width ranging from 0-31. As such, Intel and AMD instructions<br>
> read only the low 5 bits of the width operand, making them not able to<br>
> implement the GLSL-specified behavior directly.<br>
><br>
> This commit adds a pass that inserts code to implement the trivial cases<br>
> of <bits> = 32 as<br>
><br>
>    bitfieldInsert:<br>
>       bits > 31 ? insert : bitfieldInsert(base, insert, offset, bits)<br>
><br>
>    bitfieldExtract:<br>
>       bits > 31 ? value : bitfieldExtract(value, offset, bits)</p>
<p dir="ltr">Why not just add this to nir_opt_algebraic with a flag in nir_compiler_options?  That's the way we've done a bunch of other lowering.</p>
<p dir="ltr">> ---<br>
>  src/glsl/Makefile.am                              |  5 +++<br>
>  src/glsl/Makefile.sources                         |  1 +<br>
>  src/glsl/nir/nir.h                                |  2 ++<br>
>  src/glsl/nir/nir_fixup_bitfield_insert_extract.py | 40 +++++++++++++++++++++++<br>
>  4 files changed, 48 insertions(+)<br>
>  create mode 100644 src/glsl/nir/nir_fixup_bitfield_insert_extract.py<br>
><br>
> diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am<br>
> index ba7af7c..33d28ec 100644<br>
> --- a/src/glsl/Makefile.am<br>
> +++ b/src/glsl/Makefile.am<br>
> @@ -46,6 +46,7 @@ EXTRA_DIST = tests glcpp/tests README TODO glcpp/README       \<br>
>         nir/nir_algebraic.py                            \<br>
>         nir/nir_builder_opcodes_h.py                    \<br>
>         nir/nir_constant_expressions.py                 \<br>
> +       nir/nir_fixup_bitfield_insert_extract.py        \<br>
>         nir/nir_opcodes.py                              \<br>
>         nir/nir_opcodes_c.py                            \<br>
>         nir/nir_opcodes_h.py                            \<br>
> @@ -265,6 +266,10 @@ nir/nir_opt_algebraic.c: nir/nir_opt_algebraic.py nir/nir_algebraic.py<br>
>         $(MKDIR_GEN)<br>
>         $(PYTHON_GEN) $(srcdir)/nir/nir_opt_algebraic.py > $@ || ($(RM) $@; false)<br>
><br>
> +nir/nir_fixup_bitfield_insert_extract.c: nir/nir_fixup_bitfield_insert_extract.py nir/nir_algebraic.py<br>
> +       $(MKDIR_GEN)<br>
> +       $(PYTHON_GEN) $(srcdir)/nir/nir_fixup_bitfield_insert_extract.py > $@ || ($(RM) $@; false)<br>
> +<br>
>  nir_tests_control_flow_tests_SOURCES =                 \<br>
>         nir/tests/control_flow_tests.cpp<br>
>  nir_tests_control_flow_tests_CFLAGS =                  \<br>
> diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources<br>
> index fd28f5c..bb79d84 100644<br>
> --- a/src/glsl/Makefile.sources<br>
> +++ b/src/glsl/Makefile.sources<br>
> @@ -13,6 +13,7 @@ LIBGLCPP_GENERATED_FILES = \<br>
>  NIR_GENERATED_FILES = \<br>
>         nir/nir_builder_opcodes.h \<br>
>         nir/nir_constant_expressions.c \<br>
> +       nir/nir_fixup_bitfield_insert_extract.c \<br>
>         nir/nir_opcodes.c \<br>
>         nir/nir_opcodes.h \<br>
>         nir/nir_opt_algebraic.c<br>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h<br>
> index 23aec69..4b97b5e 100644<br>
> --- a/src/glsl/nir/nir.h<br>
> +++ b/src/glsl/nir/nir.h<br>
> @@ -2064,6 +2064,8 @@ void nir_lower_to_source_mods(nir_shader *shader);<br>
><br>
>  bool nir_lower_gs_intrinsics(nir_shader *shader);<br>
><br>
> +bool nir_fixup_bitfield_insert_extract(nir_shader *shader);<br>
> +<br>
>  bool nir_normalize_cubemap_coords(nir_shader *shader);<br>
><br>
>  void nir_live_ssa_defs_impl(nir_function_impl *impl);<br>
> diff --git a/src/glsl/nir/nir_fixup_bitfield_insert_extract.py b/src/glsl/nir/nir_fixup_bitfield_insert_extract.py<br>
> new file mode 100644<br>
> index 0000000..21ff47c<br>
> --- /dev/null<br>
> +++ b/src/glsl/nir/nir_fixup_bitfield_insert_extract.py<br>
> @@ -0,0 +1,40 @@<br>
> +#! /usr/bin/env python<br>
> +#<br>
> +# Copyright (C) 2015 Intel Corporation<br>
> +#<br>
> +# Permission is hereby granted, free of charge, to any person obtaining a<br>
> +# copy of this software and associated documentation files (the "Software"),<br>
> +# to deal in the Software without restriction, including without limitation<br>
> +# the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> +# and/or sell copies of the Software, and to permit persons to whom the<br>
> +# Software is furnished to do so, subject to the following conditions:<br>
> +#<br>
> +# The above copyright notice and this permission notice (including the next<br>
> +# paragraph) shall be included in all copies or substantial portions of the<br>
> +# Software.<br>
> +#<br>
> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
> +# IN THE SOFTWARE.<br>
> +<br>
> +import nir_algebraic<br>
> +<br>
> +fixup = [<br>
> +   (('bitfield_insert', 'base', 'insert', 'offset', 'bits'),<br>
> +    ('bcsel', ('ilt', 31, 'bits'), 'insert',<br>
> +              ('bitfield_insert', 'base', 'insert', 'offset', 'bits'))),<br>
> +<br>
> +   (('ibitfield_extract', 'value', 'offset', 'bits'),<br>
> +    ('bcsel', ('ilt', 31, 'bits'), 'value',<br>
> +              ('ibitfield_extract', 'value', 'offset', 'bits'))),<br>
> +<br>
> +   (('ubitfield_extract', 'value', 'offset', 'bits'),<br>
> +    ('bcsel', ('ult', 31, 'bits'), 'value',<br>
> +              ('ubitfield_extract', 'value', 'offset', 'bits'))),<br>
> +]<br>
> +<br>
> +print nir_algebraic.AlgebraicPass("nir_fixup_bitfield_insert_extract", fixup).render()<br>
> --<br>
> 2.4.9<br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>