<p dir="ltr">In general, I think I like this.  The CPP was fine and I in general prefer it when practical but this is probably justified in light of the constant folding stuff.  Good work on making of look very similar to the old nir_opcodes.h.  Only 1 comment below.</p>
<p dir="ltr">On Jan 16, 2015 3:46 PM, "Connor Abbott" <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>> wrote:<br>
><br>
> Before, we used a system where a file, nir_opcodes.h, defined some macros that<br>
> were included to generate the enum values and the nir_op_infos structure. This<br>
> worked pretty well, but for development the error messages were never very<br>
> useful, Python tools couldn't understand the opcode list, and it was difficult<br>
> to use nir_opcodes.h to do other things like autogenerate a builder API. Now, we<br>
> store opcode information in nir_opcodes.py, and we have nir_opcodes_c.py to<br>
> generate the old nir_opcodes.c and nir_opcodes_h.py to generate nir_opcodes.h,<br>
> which contains all the enum names and gets included into nir.h like before.  In<br>
> addition to solving the above problems, using Python and Mako to generate<br>
> everything means that it's much easier to add keep information centralized as we<br>
> add new things like constant propagation that require per-opcode information.<br>
><br>
> Signed-off-by: Connor Abbott <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>><br>
> ---<br>
>  src/glsl/Makefile.am          |  15 +-<br>
>  src/glsl/Makefile.sources     |   6 +-<br>
>  src/glsl/nir/.gitignore       |   2 +<br>
>  src/glsl/nir/nir.h            |   9 -<br>
>  src/glsl/nir/nir_opcodes.c    |  46 ------<br>
>  src/glsl/nir/nir_opcodes.h    | 366 ----------------------------------------<br>
>  src/glsl/nir/nir_opcodes.py   | 377 ++++++++++++++++++++++++++++++++++++++++++<br>
>  src/glsl/nir/nir_opcodes_c.py |  56 +++++++<br>
>  src/glsl/nir/nir_opcodes_h.py |  39 +++++<br>
>  9 files changed, 491 insertions(+), 425 deletions(-)<br>
>  delete mode 100644 src/glsl/nir/nir_opcodes.c<br>
>  delete mode 100644 src/glsl/nir/nir_opcodes.h<br>
>  create mode 100644 src/glsl/nir/nir_opcodes.py<br>
>  create mode 100644 src/glsl/nir/nir_opcodes_c.py<br>
>  create mode 100644 src/glsl/nir/nir_opcodes_h.py<br>
><br>
> diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am<br>
> index b2b74a9..b2fe16a 100644<br>
> --- a/src/glsl/Makefile.am<br>
> +++ b/src/glsl/Makefile.am<br>
> @@ -27,6 +27,7 @@ AM_CPPFLAGS = \<br>
>         -I$(top_srcdir)/src/glsl/glcpp \<br>
>         -I$(top_srcdir)/src/glsl/nir \<br>
>         -I$(top_srcdir)/src/gtest/include \<br>
> +       -I$(top_builddir)/src/glsl/nir \<br>
>         $(DEFINES)<br>
>  AM_CFLAGS = $(VISIBILITY_CFLAGS)<br>
>  AM_CXXFLAGS = $(VISIBILITY_CXXFLAGS)<br>
> @@ -207,7 +208,9 @@ BUILT_SOURCES =                                             \<br>
>         glsl_lexer.cpp                                  \<br>
>         glcpp/glcpp-parse.c                             \<br>
>         glcpp/glcpp-lex.c                               \<br>
> -       nir/nir_opt_algebraic.c<br>
> +       nir/nir_opt_algebraic.c                         \<br>
> +       nir/nir_opcodes.h                               \<br>
> +       nir/nir_opcodes.c<br>
>  CLEANFILES =                                           \<br>
>         glcpp/glcpp-parse.h                             \<br>
>         glsl_parser.h                                   \<br>
> @@ -223,3 +226,13 @@ dist-hook:<br>
>  nir/nir_opt_algebraic.c: nir/nir_opt_algebraic.py nir/nir_algebraic.py<br>
>         $(MKDIR_P) nir;                                                 \<br>
>         $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/nir/nir_opt_algebraic.py > $@<br>
> +<br>
> +nir/nir_opcodes.h: nir/nir_opcodes.py nir/nir_opcodes_h.py<br>
> +       $(MKDIR_P) nir;                                                 \<br>
> +       $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/nir/nir_opcodes_h.py > $@<br>
> +<br>
> +nir/nir_opcodes.c: nir/nir_opcodes.py nir/nir_opcodes_c.py<br>
> +       $(MKDIR_P) nir;                                                 \<br>
> +       $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/nir/nir_opcodes_c.py > $@<br>
> +<br>
> +nir/nir.h: nir/nir_opcodes.h<br>
> diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources<br>
> index a951ca7..03b4f2e 100644<br>
> --- a/src/glsl/Makefile.sources<br>
> +++ b/src/glsl/Makefile.sources<br>
> @@ -14,7 +14,9 @@ LIBGLCPP_GENERATED_FILES = \<br>
>         $(GLSL_BUILDDIR)/glcpp/glcpp-parse.c<br>
><br>
>  NIR_GENERATED_FILES = \<br>
> -       $(GLSL_BUILDDIR)/nir/nir_opt_algebraic.c<br>
> +       $(GLSL_BUILDDIR)/nir/nir_opt_algebraic.c \<br>
> +       $(GLSL_BUILDDIR)/nir/nir_opcodes.h \<br>
> +       $(GLSL_BUILDDIR)/nir/nir_opcodes.c<br>
><br>
>  NIR_FILES = \<br>
>         $(GLSL_SRCDIR)/nir/nir.c \<br>
> @@ -35,8 +37,6 @@ NIR_FILES = \<br>
>         $(GLSL_SRCDIR)/nir/nir_lower_var_copies.c \<br>
>         $(GLSL_SRCDIR)/nir/nir_lower_vec_to_movs.c \<br>
>         $(GLSL_SRCDIR)/nir/nir_metadata.c \<br>
> -       $(GLSL_SRCDIR)/nir/nir_opcodes.c \<br>
> -       $(GLSL_SRCDIR)/nir/nir_opcodes.h \<br>
>         $(GLSL_SRCDIR)/nir/nir_opt_constant_folding.c \<br>
>         $(GLSL_SRCDIR)/nir/nir_opt_copy_propagate.c \<br>
>         $(GLSL_SRCDIR)/nir/nir_opt_cse.c \<br>
> diff --git a/src/glsl/nir/.gitignore b/src/glsl/nir/.gitignore<br>
> index 6d954fe..4c28193 100644<br>
> --- a/src/glsl/nir/.gitignore<br>
> +++ b/src/glsl/nir/.gitignore<br>
> @@ -1 +1,3 @@<br>
>  nir_opt_algebraic.c<br>
> +nir_opcodes.c<br>
> +nir_opcodes.h<br>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h<br>
> index d5fa0e3..890113c 100644<br>
> --- a/src/glsl/nir/nir.h<br>
> +++ b/src/glsl/nir/nir.h<br>
> @@ -532,20 +532,11 @@ typedef struct {<br>
>     unsigned write_mask : 4; /* ignored if dest.is_ssa is true */<br>
>  } nir_alu_dest;<br>
><br>
> -#define OPCODE(name, num_inputs, output_size, output_type, \<br>
> -               input_sizes, input_types, algebraic_props) \<br>
> -   nir_op_##name,<br>
> -<br>
> -#define LAST_OPCODE(name) nir_last_opcode = nir_op_##name,<br>
> -<br>
>  typedef enum {<br>
>  #include "nir_opcodes.h"<br>
>     nir_num_opcodes = nir_last_opcode + 1<br>
>  } nir_op;<br>
><br>
> -#undef OPCODE<br>
> -#undef LAST_OPCODE<br>
> -<br>
>  typedef enum {<br>
>     nir_type_float,<br>
>     nir_type_int,<br>
> diff --git a/src/glsl/nir/nir_opcodes.c b/src/glsl/nir/nir_opcodes.c<br>
> deleted file mode 100644<br>
> index 1e66c55..0000000<br>
> --- a/src/glsl/nir/nir_opcodes.c<br>
> +++ /dev/null<br>
> @@ -1,46 +0,0 @@<br>
> -/*<br>
> - * Copyright © 2014 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>
> - * Authors:<br>
> - *    Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
> - *<br>
> - */<br>
> -<br>
> -#include "nir.h"<br>
> -<br>
> -#define OPCODE(_name, _num_inputs, _output_size, _output_type, \<br>
> -               _input_sizes, _input_types, _algebraic_props) \<br>
> -{ \<br>
> -   .name = #_name, \<br>
> -   .num_inputs = _num_inputs, \<br>
> -   .output_size = _output_size, \<br>
> -   .output_type = _output_type, \<br>
> -   .input_sizes = _input_sizes, \<br>
> -   .input_types = _input_types, \<br>
> -   .algebraic_properties = _algebraic_props, \<br>
> -},<br>
> -<br>
> -#define LAST_OPCODE(name)<br>
> -<br>
> -const nir_op_info nir_op_infos[nir_num_opcodes] = {<br>
> -#include "nir_opcodes.h"<br>
> -};<br>
> diff --git a/src/glsl/nir/nir_opcodes.h b/src/glsl/nir/nir_opcodes.h<br>
> deleted file mode 100644<br>
> index c16b7fe..0000000<br>
> --- a/src/glsl/nir/nir_opcodes.h<br>
> +++ /dev/null<br>
> @@ -1,366 +0,0 @@<br>
> -/*<br>
> - * Copyright © 2014 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>
> - * Authors:<br>
> - *    Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
> - *<br>
> - */<br>
> -<br>
> -/**<br>
> - * This header file defines all the available opcodes in one place. It expands<br>
> - * to a list of macros of the form:<br>
> - *<br>
> - * OPCODE(name, num_inputs, output_size, output_type,<br>
> - *        input_sizes, input_types, algebraic_properties)<br>
> - *<br>
> - * Which should correspond one-to-one with the nir_op_info structure. It is<br>
> - * included in both ir.h to create the nir_op enum (with members of the form<br>
> - * nir_op_(name)) and and in opcodes.c to create nir_op_infos, which is a<br>
> - * const array of nir_op_info structures for each opcode.<br>
> - */<br>
> -<br>
> -#define ARR(...) { __VA_ARGS__ }<br>
> -<br>
> -#define UNOP(name, type) OPCODE(name, 1, 0, type, ARR(0), ARR(type), 0)<br>
> -#define UNOP_CONVERT(name, in_type, out_type) \<br>
> -   OPCODE(name, 1, 0, out_type, ARR(0), ARR(in_type), 0)<br>
> -#define UNOP_HORIZ(name, output_size, output_type, input_size, input_type) \<br>
> -   OPCODE(name, 1, output_size, output_type, ARR(input_size), \<br>
> -          ARR(input_type), 0)<br>
> -<br>
> -#define UNOP_REDUCE(name, output_size, output_type, input_type) \<br>
> -   UNOP_HORIZ(name##2, output_size, output_type, 2, input_type) \<br>
> -   UNOP_HORIZ(name##3, output_size, output_type, 3, input_type) \<br>
> -   UNOP_HORIZ(name##4, output_size, output_type, 4, input_type)<br>
> -<br>
> -/**<br>
> - * These two move instructions differ in what modifiers they support and what<br>
> - * the negate modifier means. Otherwise, they are identical.<br>
> - */<br>
> -UNOP(fmov, nir_type_float)<br>
> -UNOP(imov, nir_type_int)<br>
> -<br>
> -UNOP(ineg, nir_type_int)<br>
> -UNOP(fneg, nir_type_float)<br>
> -UNOP(inot, nir_type_int) /* invert every bit of the integer */<br>
> -UNOP(fnot, nir_type_float) /* (src == 0.0) ? 1.0 : 0.0 */<br>
> -UNOP(fsign, nir_type_float)<br>
> -UNOP(isign, nir_type_int)<br>
> -UNOP(iabs, nir_type_int)<br>
> -UNOP(fabs, nir_type_float)<br>
> -UNOP(fsat, nir_type_float)<br>
> -UNOP(frcp, nir_type_float)<br>
> -UNOP(frsq, nir_type_float)<br>
> -UNOP(fsqrt, nir_type_float)<br>
> -UNOP(fexp, nir_type_float) /* < e^x */<br>
> -UNOP(flog, nir_type_float) /* log base e */<br>
> -UNOP(fexp2, nir_type_float)<br>
> -UNOP(flog2, nir_type_float)<br>
> -UNOP_CONVERT(f2i, nir_type_float, nir_type_int)       /**< Float-to-integer conversion. */<br>
> -UNOP_CONVERT(f2u, nir_type_float, nir_type_unsigned)  /**< Float-to-unsigned conversion. */<br>
> -UNOP_CONVERT(i2f, nir_type_int, nir_type_float)       /**< Integer-to-float conversion. */<br>
> -UNOP_CONVERT(f2b, nir_type_float, nir_type_bool)      /**< Float-to-boolean conversion */<br>
> -UNOP_CONVERT(b2f, nir_type_bool, nir_type_float)      /**< Boolean-to-float conversion */<br>
> -UNOP_CONVERT(i2b, nir_type_int, nir_type_bool)        /**< int-to-boolean conversion */<br>
> -UNOP_CONVERT(b2i, nir_type_bool, nir_type_int)        /**< Boolean-to-int conversion */<br>
> -UNOP_CONVERT(u2f, nir_type_unsigned, nir_type_float)  /**< Unsigned-to-float conversion. */<br>
> -<br>
> -UNOP_REDUCE(bany, 1, nir_type_bool, nir_type_bool) /* returns ~0 if any component of src[0] != 0 */<br>
> -UNOP_REDUCE(ball, 1, nir_type_bool, nir_type_bool) /* returns ~0 if all components of src[0] != 0 */<br>
> -UNOP_REDUCE(fany, 1, nir_type_float, nir_type_float) /* returns 1.0 if any component of src[0] != 0 */<br>
> -UNOP_REDUCE(fall, 1, nir_type_float, nir_type_float) /* returns 1.0 if all components of src[0] != 0 */<br>
> -<br>
> -/**<br>
> - * \name Unary floating-point rounding operations.<br>
> - */<br>
> -/*@{*/<br>
> -UNOP(ftrunc, nir_type_float)<br>
> -UNOP(fceil, nir_type_float)<br>
> -UNOP(ffloor, nir_type_float)<br>
> -UNOP(ffract, nir_type_float)<br>
> -UNOP(fround_even, nir_type_float)<br>
> -/*@}*/<br>
> -<br>
> -/**<br>
> - * \name Trigonometric operations.<br>
> - */<br>
> -/*@{*/<br>
> -UNOP(fsin, nir_type_float)<br>
> -UNOP(fcos, nir_type_float)<br>
> -UNOP(fsin_reduced, nir_type_float)<br>
> -UNOP(fcos_reduced, nir_type_float)<br>
> -/*@}*/<br>
> -<br>
> -/**<br>
> - * \name Partial derivatives.<br>
> - */<br>
> -/*@{*/<br>
> -UNOP(fddx, nir_type_float)<br>
> -UNOP(fddy, nir_type_float)<br>
> -UNOP(fddx_fine, nir_type_float)<br>
> -UNOP(fddy_fine, nir_type_float)<br>
> -UNOP(fddx_coarse, nir_type_float)<br>
> -UNOP(fddy_coarse, nir_type_float)<br>
> -/*@}*/<br>
> -<br>
> -/**<br>
> - * \name Floating point pack and unpack operations.<br>
> - */<br>
> -/*@{*/<br>
> -UNOP_HORIZ(pack_snorm_2x16, 1, nir_type_unsigned, 2, nir_type_float)<br>
> -UNOP_HORIZ(pack_snorm_4x8, 1, nir_type_unsigned, 4, nir_type_float)<br>
> -UNOP_HORIZ(pack_unorm_2x16, 1, nir_type_unsigned, 2, nir_type_float)<br>
> -UNOP_HORIZ(pack_unorm_4x8, 1, nir_type_unsigned, 4, nir_type_float)<br>
> -UNOP_HORIZ(pack_half_2x16, 1, nir_type_unsigned, 2, nir_type_float)<br>
> -UNOP_HORIZ(unpack_snorm_2x16, 2, nir_type_float, 1, nir_type_unsigned)<br>
> -UNOP_HORIZ(unpack_snorm_4x8, 4, nir_type_float, 1, nir_type_unsigned)<br>
> -UNOP_HORIZ(unpack_unorm_2x16, 2, nir_type_float, 1, nir_type_unsigned)<br>
> -UNOP_HORIZ(unpack_unorm_4x8, 4, nir_type_float, 1, nir_type_unsigned)<br>
> -UNOP_HORIZ(unpack_half_2x16, 2, nir_type_float, 1, nir_type_unsigned)<br>
> -/*@}*/<br>
> -<br>
> -/**<br>
> - * \name Lowered floating point unpacking operations.<br>
> - */<br>
> -/*@{*/<br>
> -UNOP_HORIZ(unpack_half_2x16_split_x, 1, nir_type_float, 1, nir_type_unsigned)<br>
> -UNOP_HORIZ(unpack_half_2x16_split_y, 1, nir_type_float, 1, nir_type_unsigned)<br>
> -/*@}*/<br>
> -<br>
> -/**<br>
> - * \name Bit operations, part of ARB_gpu_shader5.<br>
> - */<br>
> -/*@{*/<br>
> -UNOP(bitfield_reverse, nir_type_unsigned)<br>
> -UNOP(bit_count, nir_type_unsigned)<br>
> -UNOP_CONVERT(ufind_msb, nir_type_unsigned, nir_type_int)<br>
> -UNOP(ifind_msb, nir_type_int)<br>
> -UNOP(find_lsb, nir_type_int)<br>
> -/*@}*/<br>
> -<br>
> -UNOP_HORIZ(fnoise1_1, 1, nir_type_float, 1, nir_type_float)<br>
> -UNOP_HORIZ(fnoise1_2, 1, nir_type_float, 2, nir_type_float)<br>
> -UNOP_HORIZ(fnoise1_3, 1, nir_type_float, 3, nir_type_float)<br>
> -UNOP_HORIZ(fnoise1_4, 1, nir_type_float, 4, nir_type_float)<br>
> -UNOP_HORIZ(fnoise2_1, 2, nir_type_float, 1, nir_type_float)<br>
> -UNOP_HORIZ(fnoise2_2, 2, nir_type_float, 2, nir_type_float)<br>
> -UNOP_HORIZ(fnoise2_3, 2, nir_type_float, 3, nir_type_float)<br>
> -UNOP_HORIZ(fnoise2_4, 2, nir_type_float, 4, nir_type_float)<br>
> -UNOP_HORIZ(fnoise3_1, 3, nir_type_float, 1, nir_type_float)<br>
> -UNOP_HORIZ(fnoise3_2, 3, nir_type_float, 2, nir_type_float)<br>
> -UNOP_HORIZ(fnoise3_3, 3, nir_type_float, 3, nir_type_float)<br>
> -UNOP_HORIZ(fnoise3_4, 3, nir_type_float, 4, nir_type_float)<br>
> -UNOP_HORIZ(fnoise4_1, 4, nir_type_float, 1, nir_type_float)<br>
> -UNOP_HORIZ(fnoise4_2, 4, nir_type_float, 2, nir_type_float)<br>
> -UNOP_HORIZ(fnoise4_3, 4, nir_type_float, 3, nir_type_float)<br>
> -UNOP_HORIZ(fnoise4_4, 4, nir_type_float, 4, nir_type_float)<br>
> -<br>
> -#define BINOP(name, type, alg_props) \<br>
> -   OPCODE(name, 2, 0, type, ARR(0, 0), ARR(type, type), alg_props)<br>
> -#define BINOP_CONVERT(name, out_type, in_type, alg_props) \<br>
> -   OPCODE(name, 2, 0, out_type, ARR(0, 0), ARR(in_type, in_type), alg_props)<br>
> -#define BINOP_COMPARE(name, type, alg_props) \<br>
> -   OPCODE(name, 2, 0, nir_type_bool, ARR(0, 0), ARR(type, type), alg_props)<br>
> -#define BINOP_HORIZ(name, output_size, output_type, src1_size, src1_type, \<br>
> -                    src2_size, src2_type) \<br>
> -   OPCODE(name, 2, output_size, output_type, ARR(src1_size, src2_size), \<br>
> -          ARR(src1_type, src2_type), 0)<br>
> -#define BINOP_REDUCE(name, output_size, output_type, src_type) \<br>
> -   OPCODE(name##2, 2, output_size, output_type, \<br>
> -          ARR(2, 2), ARR(src_type, src_type), NIR_OP_IS_COMMUTATIVE) \<br>
> -   OPCODE(name##3, 2, output_size, output_type, \<br>
> -          ARR(3, 3), ARR(src_type, src_type), NIR_OP_IS_COMMUTATIVE) \<br>
> -   OPCODE(name##4, 2, output_size, output_type, \<br>
> -          ARR(4, 4), ARR(src_type, src_type), NIR_OP_IS_COMMUTATIVE)<br>
> -<br>
> -BINOP(fadd, nir_type_float, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -BINOP(iadd, nir_type_int, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -BINOP(fsub, nir_type_float, 0)<br>
> -BINOP(isub, nir_type_int, 0)<br>
> -<br>
> -BINOP(fmul, nir_type_float, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -/* low 32-bits of signed/unsigned integer multiply */<br>
> -BINOP(imul, nir_type_int, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -/* high 32-bits of signed integer multiply */<br>
> -BINOP(imul_high, nir_type_int, NIR_OP_IS_COMMUTATIVE)<br>
> -/* high 32-bits of unsigned integer multiply */<br>
> -BINOP(umul_high, nir_type_unsigned, NIR_OP_IS_COMMUTATIVE)<br>
> -<br>
> -BINOP(fdiv, nir_type_float, 0)<br>
> -BINOP(idiv, nir_type_int, 0)<br>
> -BINOP(udiv, nir_type_unsigned, 0)<br>
> -<br>
> -/**<br>
> - * returns a boolean representing the carry resulting from the addition of<br>
> - * the two unsigned arguments.<br>
> - */<br>
> -BINOP_CONVERT(uadd_carry, nir_type_bool, nir_type_unsigned,<br>
> -              NIR_OP_IS_COMMUTATIVE)<br>
> -<br>
> -/**<br>
> - * returns a boolean representing the borrow resulting from the subtraction<br>
> - * of the two unsigned arguments.<br>
> - */<br>
> -BINOP_CONVERT(usub_borrow, nir_type_bool, nir_type_unsigned, 0)<br>
> -<br>
> -BINOP(fmod, nir_type_float, 0)<br>
> -BINOP(umod, nir_type_unsigned, 0)<br>
> -<br>
> -/**<br>
> - * \name comparisons<br>
> - */<br>
> -/*@{*/<br>
> -<br>
> -/**<br>
> - * these integer-aware comparisons return a boolean (0 or ~0)<br>
> - */<br>
> -BINOP_COMPARE(flt, nir_type_float, 0)<br>
> -BINOP_COMPARE(fge, nir_type_float, 0)<br>
> -BINOP_COMPARE(feq, nir_type_float, NIR_OP_IS_COMMUTATIVE)<br>
> -BINOP_COMPARE(fne, nir_type_float, NIR_OP_IS_COMMUTATIVE)<br>
> -BINOP_COMPARE(ilt, nir_type_int, 0)<br>
> -BINOP_COMPARE(ige, nir_type_int, 0)<br>
> -BINOP_COMPARE(ieq, nir_type_int, NIR_OP_IS_COMMUTATIVE)<br>
> -BINOP_COMPARE(ine, nir_type_int, NIR_OP_IS_COMMUTATIVE)<br>
> -BINOP_COMPARE(ult, nir_type_unsigned, 0)<br>
> -BINOP_COMPARE(uge, nir_type_unsigned, 0)<br>
> -<br>
> -/** integer-aware GLSL-style comparisons that compare floats and ints */<br>
> -BINOP_REDUCE(ball_fequal,  1, nir_type_bool, nir_type_float)<br>
> -BINOP_REDUCE(bany_fnequal, 1, nir_type_bool, nir_type_float)<br>
> -BINOP_REDUCE(ball_iequal,  1, nir_type_bool, nir_type_int)<br>
> -BINOP_REDUCE(bany_inequal, 1, nir_type_bool, nir_type_int)<br>
> -<br>
> -/** non-integer-aware GLSL-style comparisons that return 0.0 or 1.0 */<br>
> -BINOP_REDUCE(fall_equal,  1, nir_type_float, nir_type_float)<br>
> -BINOP_REDUCE(fany_nequal, 1, nir_type_float, nir_type_float)<br>
> -<br>
> -/**<br>
> - * These comparisons for integer-less hardware return 1.0 and 0.0 for true<br>
> - * and false respectively<br>
> - */<br>
> -BINOP(slt, nir_type_float, 0) /* Set on Less Than */<br>
> -BINOP(sge, nir_type_float, 0) /* Set on Greater Than or Equal */<br>
> -BINOP(seq, nir_type_float, NIR_OP_IS_COMMUTATIVE) /* Set on Equal */<br>
> -BINOP(sne, nir_type_float, NIR_OP_IS_COMMUTATIVE) /* Set on Not Equal */<br>
> -<br>
> -/*@}*/<br>
> -<br>
> -BINOP(ishl, nir_type_int, 0)<br>
> -BINOP(ishr, nir_type_int, 0)<br>
> -BINOP(ushr, nir_type_unsigned, 0)<br>
> -<br>
> -/**<br>
> - * \name bitwise logic operators<br>
> - *<br>
> - * These are also used as boolean and, or, xor for hardware supporting<br>
> - * integers.<br>
> - */<br>
> -/*@{*/<br>
> -BINOP(iand, nir_type_unsigned, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -BINOP(ior, nir_type_unsigned, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -BINOP(ixor, nir_type_unsigned, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -/*@{*/<br>
> -<br>
> -/**<br>
> - * \name floating point logic operators<br>
> - *<br>
> - * These use (src != 0.0) for testing the truth of the input, and output 1.0<br>
> - * for true and 0.0 for false<br>
> - */<br>
> -BINOP(fand, nir_type_float, NIR_OP_IS_COMMUTATIVE)<br>
> -BINOP(for, nir_type_float, NIR_OP_IS_COMMUTATIVE)<br>
> -BINOP(fxor, nir_type_float, NIR_OP_IS_COMMUTATIVE)<br>
> -<br>
> -BINOP_REDUCE(fdot, 1, nir_type_float, nir_type_float)<br>
> -<br>
> -BINOP(fmin, nir_type_float, 0)<br>
> -BINOP(imin, nir_type_int, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -BINOP(umin, nir_type_unsigned, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -BINOP(fmax, nir_type_float, 0)<br>
> -BINOP(imax, nir_type_int, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -BINOP(umax, nir_type_unsigned, NIR_OP_IS_COMMUTATIVE | NIR_OP_IS_ASSOCIATIVE)<br>
> -<br>
> -BINOP(fpow, nir_type_float, 0)<br>
> -<br>
> -BINOP_HORIZ(pack_half_2x16_split, 1, nir_type_unsigned, 1, nir_type_float, 1, nir_type_float)<br>
> -<br>
> -BINOP(bfm, nir_type_unsigned, 0)<br>
> -<br>
> -BINOP(ldexp, nir_type_unsigned, 0)<br>
> -<br>
> -/**<br>
> - * Combines the first component of each input to make a 2-component vector.<br>
> - */<br>
> -BINOP_HORIZ(vec2, 2, nir_type_unsigned, 1, nir_type_unsigned, 1, nir_type_unsigned)<br>
> -<br>
> -#define TRIOP(name, type) \<br>
> -   OPCODE(name, 3, 0, type, ARR(0, 0, 0), ARR(type, type, type), 0)<br>
> -#define TRIOP_HORIZ(name, output_size, src1_size, src2_size, src3_size) \<br>
> -   OPCODE(name, 3, output_size, nir_type_unsigned, \<br>
> -   ARR(src1_size, src2_size, src3_size), \<br>
> -   ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned), 0)<br>
> -<br>
> -/* fma(a, b, c) = (a * b) + c */<br>
> -TRIOP(ffma, nir_type_float)<br>
> -<br>
> -TRIOP(flrp, nir_type_float)<br>
> -<br>
> -/**<br>
> - * \name Conditional Select<br>
> - *<br>
> - * A vector conditional select instruction (like ?:, but operating per-<br>
> - * component on vectors). There are two versions, one for floating point<br>
> - * bools (0.0 vs 1.0) and one for integer bools (0 vs ~0).<br>
> - */<br>
> -<br>
> -TRIOP(fcsel, nir_type_float)<br>
> -OPCODE(bcsel, 3, 0, nir_type_unsigned, ARR(0, 0, 0),<br>
> -       ARR(nir_type_bool, nir_type_unsigned, nir_type_unsigned), 0)<br>
> -<br>
> -TRIOP(bfi, nir_type_unsigned)<br>
> -<br>
> -TRIOP(ubitfield_extract, nir_type_unsigned)<br>
> -OPCODE(ibitfield_extract, 3, 0, nir_type_int, ARR(0, 0, 0),<br>
> -       ARR(nir_type_int, nir_type_unsigned, nir_type_unsigned), 0)<br>
> -<br>
> -/**<br>
> - * Combines the first component of each input to make a 3-component vector.<br>
> - */<br>
> -TRIOP_HORIZ(vec3, 3, 1, 1, 1)<br>
> -<br>
> -#define QUADOP(name) \<br>
> -   OPCODE(name, 4, 0, nir_type_unsigned, ARR(0, 0, 0, 0), \<br>
> -          ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned, nir_type_unsigned), \<br>
> -          0)<br>
> -#define QUADOP_HORIZ(name, output_size, src1_size, src2_size, src3_size, \<br>
> -                     src4_size) \<br>
> -   OPCODE(name, 4, output_size, nir_type_unsigned, \<br>
> -          ARR(src1_size, src2_size, src3_size, src4_size), \<br>
> -          ARR(nir_type_unsigned, nir_type_unsigned, nir_type_unsigned, nir_type_unsigned), \<br>
> -          0)<br>
> -<br>
> -QUADOP(bitfield_insert)<br>
> -<br>
> -QUADOP_HORIZ(vec4, 4, 1, 1, 1, 1)<br>
> -<br>
> -LAST_OPCODE(vec4)<br>
> diff --git a/src/glsl/nir/nir_opcodes.py b/src/glsl/nir/nir_opcodes.py<br>
> new file mode 100644<br>
> index 0000000..fa2f563<br>
> --- /dev/null<br>
> +++ b/src/glsl/nir/nir_opcodes.py<br>
> @@ -0,0 +1,377 @@<br>
> +#! /usr/bin/env python<br>
> +#<br>
> +# Copyright (C) 2014 Connor Abbott<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>
> +# Authors:<br>
> +#    Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
> +<br>
> +# Class that represents all the information we have about the opcode<br>
> +# NOTE: this must be kept in sync with nir_op_info<br>
> +<br>
> +class Opcode:<br>
> +   # name is the name of the opcode (prepend nir_op_ for the enum name)<br>
> +   # all types are strings that get nir_type_ prepended to them<br>
> +   # input_types is a list of types<br>
> +   # algebraic_properties is a space-seperated string,<br>
> +   # where nir_op_is_ is prepended before each entry</p>
<p dir="ltr">Python uses triple quotes for comments like this. Pydoc can pick up on them that way.</p>
<p dir="ltr">> +   def __init__(self, name, output_size, output_type, input_sizes,<br>
> +                input_types, algebraic_properties):<br>
> +      assert(isinstance(name, str))<br>
> +      assert(isinstance(output_size, int))<br>
> +      assert(isinstance(output_type, str))<br>
> +      assert(isinstance(input_sizes, list))<br>
> +      assert(isinstance(input_sizes[0], int))<br>
> +      assert(isinstance(input_types, list))<br>
> +      assert(isinstance(input_types[0], str))<br>
> +      assert(isinstance(algebraic_properties, str))<br>
> +      assert(len(input_sizes) == len(input_types))<br>
> +      assert(0 <= output_size <= 4)<br>
> +      for size in input_sizes:<br>
> +         assert(0 <= size <= 4)<br>
> +         if output_size != 0:<br>
> +            assert size != 0<br>
> +      <a href="http://self.name">self.name</a> = name<br>
> +      self.num_inputs = len(input_sizes)<br>
> +      self.output_size = output_size<br>
> +      self.output_type = output_type<br>
> +      self.input_sizes = input_sizes<br>
> +      self.input_types = input_types<br>
> +      self.algebraic_properties = algebraic_properties<br>
> +<br>
> +# helper variables for strings<br>
> +tfloat = "float"<br>
> +tint = "int"<br>
> +tbool = "bool"<br>
> +tunsigned = "unsigned"<br>
> +<br>
> +commutative = "commutative "<br>
> +associative = "associative "</p>
<p dir="ltr">Your concatenation of these strings below seems odd.  I suppose the spaces make it OK, but I'm not sure I like it.  We can change that easily enough later so I won't block on that.</p>
<p dir="ltr">> +<br>
> +# global dictionary of opcodes<br>
> +opcodes = {}<br>
> +<br>
> +def opcode(name, output_size, output_type, input_sizes, input_types,<br>
> +           algebraic_properties):<br>
> +   assert(name not in opcodes)<br>
> +   opcodes[name] = Opcode(name, output_size, output_type, input_sizes,<br>
> +                          input_types, algebraic_properties)<br>
> +<br>
> +def unop_convert(name, in_type, out_type):<br>
> +   opcode(name, 0, out_type, [0], [in_type], "")<br>
> +<br>
> +def unop(name, ty):<br>
> +   opcode(name, 0, ty, [0], [ty], "")<br>
> +<br>
> +def unop_horiz(name, output_size, output_type, input_size, input_type):<br>
> +   opcode(name, output_size, output_type, [input_size], [input_type], "")<br>
> +<br>
> +def unop_reduce(name, output_size, output_type, input_type):<br>
> +   unop_horiz(name + "2", output_size, output_type, 2, input_type)<br>
> +   unop_horiz(name + "3", output_size, output_type, 3, input_type)<br>
> +   unop_horiz(name + "4", output_size, output_type, 4, input_type)<br>
> +<br>
> +<br>
> +# These two move instructions differ in what modifiers they support and what<br>
> +# the negate modifier means. Otherwise, they are identical.<br>
> +unop("fmov", tfloat)<br>
> +unop("imov", tint)<br>
> +<br>
> +unop("ineg", tint)<br>
> +unop("fneg", tfloat)<br>
> +unop("inot", tint) # invert every bit of the integer<br>
> +unop("fnot", tfloat) # (src == 0.0) ? 1.0 : 0.0<br>
> +unop("fsign", tfloat)<br>
> +unop("isign", tint)<br>
> +unop("iabs", tint)<br>
> +unop("fabs", tfloat)<br>
> +unop("fsat", tfloat)<br>
> +unop("frcp", tfloat)<br>
> +unop("frsq", tfloat)<br>
> +unop("fsqrt", tfloat)<br>
> +unop("fexp", tfloat) # < e^x<br>
> +unop("flog", tfloat) # log base e<br>
> +unop("fexp2", tfloat)<br>
> +unop("flog2", tfloat)<br>
> +unop_convert("f2i", tfloat, tint) # Float-to-integer conversion.<br>
> +unop_convert("f2u", tfloat, tunsigned) # Float-to-unsigned conversion<br>
> +unop_convert("i2f", tint, tfloat) # Integer-to-float conversion.<br>
> +unop_convert("f2b", tfloat, tbool) # Float-to-boolean conversion<br>
> +unop_convert("b2f", tbool, tfloat) # Boolean-to-float conversion<br>
> +unop_convert("i2b", tint, tbool) # int-to-boolean conversion<br>
> +unop_convert("b2i", tbool, tint) # Boolean-to-int conversion<br>
> +unop_convert("u2f", tunsigned, tfloat) #Unsigned-to-float conversion.<br>
> +<br>
> +unop_reduce("bany", 1, tbool, tbool) # returns ~0 if any component of src[0] != 0<br>
> +unop_reduce("ball", 1, tbool, tbool) # returns ~0 if all components of src[0] != 0<br>
> +unop_reduce("fany", 1, tfloat, tfloat) # returns 1.0 if any component of src[0] != 0<br>
> +unop_reduce("fall", 1, tfloat, tfloat) # returns 1.0 if all components of src[0] != 0<br>
> +<br>
> +# Unary floating-point rounding operations.<br>
> +<br>
> +<br>
> +unop("ftrunc", tfloat)<br>
> +unop("fceil", tfloat)<br>
> +unop("ffloor", tfloat)<br>
> +unop("ffract", tfloat)<br>
> +unop("fround_even", tfloat)<br>
> +<br>
> +<br>
> +# Trigonometric operations.<br>
> +<br>
> +<br>
> +unop("fsin", tfloat)<br>
> +unop("fcos", tfloat)<br>
> +unop("fsin_reduced", tfloat)<br>
> +unop("fcos_reduced", tfloat)<br>
> +<br>
> +<br>
> +# Partial derivatives.<br>
> +<br>
> +<br>
> +unop("fddx", tfloat)<br>
> +unop("fddy", tfloat)<br>
> +unop("fddx_fine", tfloat)<br>
> +unop("fddy_fine", tfloat)<br>
> +unop("fddx_coarse", tfloat)<br>
> +unop("fddy_coarse", tfloat)<br>
> +<br>
> +<br>
> +# Floating point pack and unpack operations.<br>
> +<br>
> +<br>
> +unop_horiz("pack_snorm_2x16", 1, tunsigned, 2, tfloat)<br>
> +unop_horiz("pack_snorm_4x8", 1, tunsigned, 4, tfloat)<br>
> +unop_horiz("pack_unorm_2x16", 1, tunsigned, 2, tfloat)<br>
> +unop_horiz("pack_unorm_4x8", 1, tunsigned, 4, tfloat)<br>
> +unop_horiz("pack_half_2x16", 1, tunsigned, 2, tfloat)<br>
> +unop_horiz("unpack_snorm_2x16", 2, tfloat, 1, tunsigned)<br>
> +unop_horiz("unpack_snorm_4x8", 4, tfloat, 1, tunsigned)<br>
> +unop_horiz("unpack_unorm_2x16", 2, tfloat, 1, tunsigned)<br>
> +unop_horiz("unpack_unorm_4x8", 4, tfloat, 1, tunsigned)<br>
> +unop_horiz("unpack_half_2x16", 2, tfloat, 1, tunsigned)<br>
> +<br>
> +<br>
> +# Lowered floating point unpacking operations.<br>
> +<br>
> +<br>
> +unop_horiz("unpack_half_2x16_split_x", 1, tfloat, 1, tunsigned)<br>
> +unop_horiz("unpack_half_2x16_split_y", 1, tfloat, 1, tunsigned)<br>
> +<br>
> +<br>
> +# Bit operations, part of ARB_gpu_shader5.<br>
> +<br>
> +<br>
> +unop("bitfield_reverse", tunsigned)<br>
> +unop("bit_count", tunsigned)<br>
> +unop_convert("ufind_msb", tunsigned, tint)<br>
> +unop("ifind_msb", tint)<br>
> +unop("find_lsb", tint)<br>
> +<br>
> +<br>
> +for i in range(1, 5):<br>
> +   for j in range(1, 5):<br>
> +      unop_horiz("fnoise" + str(i) + "_" + str(j), i, tfloat, j, tfloat)<br>
> +<br>
> +def binop_convert(name, out_type, in_type, alg_props):<br>
> +   opcode(name, 0, out_type, [0, 0], [in_type, in_type], alg_props)<br>
> +<br>
> +def binop(name, ty, alg_props):<br>
> +   binop_convert(name, ty, ty, alg_props)<br>
> +<br>
> +def binop_compare(name, ty, alg_props):<br>
> +   binop_convert(name, ty, tbool, alg_props)<br>
> +<br>
> +def binop_horiz(name, out_size, out_type, src1_size, src1_type, src2_size,<br>
> +                src2_type):<br>
> +   opcode(name, out_size, out_type, [src1_size, src2_size], [src1_type, src2_type], "")<br>
> +<br>
> +def binop_reduce(name, output_size, output_type, src_type):<br>
> +   opcode(name + "2",output_size, output_type,<br>
> +          [2, 2], [src_type, src_type], commutative)<br>
> +   opcode(name + "3", output_size, output_type,<br>
> +          [3, 3], [src_type, src_type], commutative)<br>
> +   opcode(name + "4", output_size, output_type,<br>
> +          [4, 4], [src_type, src_type], commutative)<br>
> +<br>
> +binop("fadd", tfloat, commutative + associative)<br>
> +binop("iadd", tint, commutative + associative)<br>
> +binop("fsub", tfloat, "")<br>
> +binop("isub", tint, "")<br>
> +<br>
> +binop("fmul", tfloat, commutative + associative)<br>
> +# low 32-bits of signed/unsigned integer multiply<br>
> +binop("imul", tint, commutative + associative)<br>
> +# high 32-bits of signed integer multiply<br>
> +binop("imul_high", tint, commutative)<br>
> +# high 32-bits of unsigned integer multiply<br>
> +binop("umul_high", tunsigned, commutative)<br>
> +<br>
> +binop("fdiv", tfloat, "")<br>
> +binop("idiv", tint, "")<br>
> +binop("udiv", tunsigned, "")<br>
> +<br>
> +# returns a boolean representing the carry resulting from the addition of<br>
> +# the two unsigned arguments.<br>
> +<br>
> +binop_convert("uadd_carry", tbool, tunsigned,<br>
> +              commutative)<br>
> +<br>
> +# returns a boolean representing the borrow resulting from the subtraction<br>
> +# of the two unsigned arguments.<br>
> +<br>
> +binop_convert("usub_borrow", tbool, tunsigned, "")<br>
> +<br>
> +binop("fmod", tfloat, "")<br>
> +binop("umod", tunsigned, "")<br>
> +<br>
> +#<br>
> +# Comparisons<br>
> +#<br>
> +<br>
> +<br>
> +# these integer-aware comparisons return a boolean (0 or ~0)<br>
> +<br>
> +binop_compare("flt", tfloat, "")<br>
> +binop_compare("fge", tfloat, "")<br>
> +binop_compare("feq", tfloat, commutative)<br>
> +binop_compare("fne", tfloat, commutative)<br>
> +binop_compare("ilt", tint, "")<br>
> +binop_compare("ige", tint, "")<br>
> +binop_compare("ieq", tint, commutative)<br>
> +binop_compare("ine", tint, commutative)<br>
> +binop_compare("ult", tunsigned, "")<br>
> +binop_compare("uge", tunsigned, "")<br>
> +<br>
> +# integer-aware GLSL-style comparisons that compare floats and ints<br>
> +<br>
> +binop_reduce("ball_fequal",  1, tbool, tfloat)<br>
> +binop_reduce("bany_fnequal", 1, tbool, tfloat)<br>
> +binop_reduce("ball_iequal",  1, tbool, tint)<br>
> +binop_reduce("bany_inequal", 1, tbool, tint)<br>
> +<br>
> +# non-integer-aware GLSL-style comparisons that return 0.0 or 1.0<br>
> +<br>
> +binop_reduce("fall_equal",  1, tfloat, tfloat)<br>
> +binop_reduce("fany_nequal", 1, tfloat, tfloat)<br>
> +<br>
> +# These comparisons for integer-less hardware return 1.0 and 0.0 for true<br>
> +# and false respectively<br>
> +<br>
> +binop("slt", tfloat, "") # Set on Less Than<br>
> +binop("sge", tfloat, "") # Set on Greater Than or Equal<br>
> +binop("seq", tfloat, commutative) # Set on Equal<br>
> +binop("sne", tfloat, commutative) # Set on Not Equal<br>
> +<br>
> +<br>
> +binop("ishl", tint, "")<br>
> +binop("ishr", tint, "")<br>
> +binop("ushr", tunsigned, "")<br>
> +<br>
> +# bitwise logic operators<br>
> +#<br>
> +# These are also used as boolean and, or, xor for hardware supporting<br>
> +# integers.<br>
> +<br>
> +<br>
> +binop("iand", tunsigned, commutative + associative)<br>
> +binop("ior", tunsigned, commutative + associative)<br>
> +binop("ixor", tunsigned, commutative + associative)<br>
> +<br>
> +<br>
> +# floating point logic operators<br>
> +#<br>
> +# These use (src != 0.0) for testing the truth of the input, and output 1.0<br>
> +# for true and 0.0 for false<br>
> +<br>
> +binop("fand", tfloat, commutative)<br>
> +binop("for", tfloat, commutative)<br>
> +binop("fxor", tfloat, commutative)<br>
> +<br>
> +binop_reduce("fdot", 1, tfloat, tfloat)<br>
> +<br>
> +binop("fmin", tfloat, commutative + associative)</p>
<p dir="ltr">This is a functional change.  When I pushed the code to add algebraic properties, I left these non commutative as I think that discussion is still ongoing.  Since none of this is turned on yet, it probably doesn't matter whether we mark it or not.    That said, it should be a separate patch and not hidden behind deleting and recreating a file.</p>
<p dir="ltr">> +binop("imin", tint, commutative + associative)<br>
> +binop("umin", tunsigned, commutative + associative)<br>
> +binop("fmax", tfloat, commutative + associative)</p>
<p dir="ltr">Here too</p>
<p dir="ltr">> +binop("imax", tint, commutative + associative)<br>
> +binop("umax", tunsigned, commutative + associative)<br>
> +<br>
> +binop("fpow", tfloat, "")<br>
> +<br>
> +binop_horiz("pack_half_2x16_split", 1, tunsigned, 1, tfloat, 1, tfloat)<br>
> +<br>
> +binop("bfm", tunsigned, "")<br>
> +<br>
> +binop("ldexp", tunsigned, "")<br>
> +<br>
> +# Combines the first component of each input to make a 2-component vector.<br>
> +<br>
> +binop_horiz("vec2", 2, tunsigned, 1, tunsigned, 1, tunsigned)<br>
> +<br>
> +def triop(name, ty):<br>
> +   opcode(name, 0, ty, [0, 0, 0], [ty, ty, ty], "")<br>
> +def triop_horiz(name, output_size, src1_size, src2_size, src3_size):<br>
> +   opcode(name, output_size, tunsigned,<br>
> +   [src1_size, src2_size, src3_size],<br>
> +   [tunsigned, tunsigned, tunsigned], "")<br>
> +<br>
> +# fma(a, b, c) = (a# b) + c<br>
> +triop("ffma", tfloat)<br>
> +<br>
> +triop("flrp", tfloat)<br>
> +<br>
> +# Conditional Select<br>
> +#<br>
> +# A vector conditional select instruction (like ?:, but operating per-<br>
> +# component on vectors). There are two versions, one for floating point<br>
> +# bools (0.0 vs 1.0) and one for integer bools (0 vs ~0).<br>
> +<br>
> +<br>
> +triop("fcsel", tfloat)<br>
> +opcode("bcsel", 0, tunsigned, [0, 0, 0],<br>
> +       [tbool, tunsigned, tunsigned], "")<br>
> +<br>
> +triop("bfi", tunsigned)<br>
> +<br>
> +triop("ubitfield_extract", tunsigned)<br>
> +opcode("ibitfield_extract", 0, tint, [0, 0, 0],<br>
> +       [tint, tunsigned, tunsigned], "")<br>
> +<br>
> +# Combines the first component of each input to make a 3-component vector.<br>
> +<br>
> +triop_horiz("vec3", 3, 1, 1, 1)<br>
> +<br>
> +def quadop(name):<br>
> +   opcode(name, 0, tunsigned, [0, 0, 0, 0],<br>
> +          [tunsigned, tunsigned, tunsigned, tunsigned],<br>
> +          "")<br>
> +def quadop_horiz(name, output_size, src1_size, src2_size, src3_size, src4_size):<br>
> +   opcode(name, output_size, tunsigned,<br>
> +          [src1_size, src2_size, src3_size, src4_size],<br>
> +          [tunsigned, tunsigned, tunsigned, tunsigned],<br>
> +          "")<br>
> +<br>
> +quadop("bitfield_insert")<br>
> +<br>
> +quadop_horiz("vec4", 4, 1, 1, 1, 1)<br>
> +<br>
> +<br>
> diff --git a/src/glsl/nir/nir_opcodes_c.py b/src/glsl/nir/nir_opcodes_c.py<br>
> new file mode 100644<br>
> index 0000000..04a22b5<br>
> --- /dev/null<br>
> +++ b/src/glsl/nir/nir_opcodes_c.py<br>
> @@ -0,0 +1,56 @@<br>
> +#! /usr/bin/env python<br>
> +#<br>
> +# Copyright (C) 2014 Connor Abbott<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>
> +# Authors:<br>
> +#    Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
> +<br>
> +from nir_opcodes import opcodes<br>
> +from mako.template import Template<br>
> +<br>
> +template = Template("""<br>
> +#include "nir.h"<br>
> +<br>
> +const nir_op_info nir_op_infos[nir_num_opcodes] = {<br>
> +% for name, opcode in sorted(opcodes.iteritems()):<br>
> +{<br>
> +   .name = "${name}",<br>
> +   .num_inputs = ${opcode.num_inputs},<br>
> +   .output_size = ${opcode.output_size},<br>
> +   .output_type = ${"nir_type_" + opcode.output_type},<br>
> +   .input_sizes = {<br>
> +      ${ ", ".join(str(size) for size in opcode.input_sizes) }<br>
> +   },<br>
> +   .input_types = {<br>
> +      ${ ", ".join("nir_type_" + type for type in opcode.input_types) }<br>
> +   },<br>
> +   .algebraic_properties =<br>
> +      ${ "0" if opcode.algebraic_properties == "" else " | ".join(<br>
> +            "NIR_OP_IS_" + prop.upper() for prop in<br>
> +               opcode.algebraic_properties.strip().split(" ")) }<br>
> +},<br>
> +% endfor<br>
> +};<br>
> +""")<br>
> +<br>
> +print template.render(opcodes=opcodes)<br>
> +<br>
> diff --git a/src/glsl/nir/nir_opcodes_h.py b/src/glsl/nir/nir_opcodes_h.py<br>
> new file mode 100644<br>
> index 0000000..84d004c<br>
> --- /dev/null<br>
> +++ b/src/glsl/nir/nir_opcodes_h.py<br>
> @@ -0,0 +1,39 @@<br>
> +#! /usr/bin/env python<br>
> +#<br>
> +# Copyright (C) 2014 Connor Abbott<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>
> +# Authors:<br>
> +#    Connor Abbott (<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>)<br>
> +<br>
> +from nir_opcodes import opcodes<br>
> +from mako.template import Template<br>
> +<br>
> +<br>
> +template = Template("""<br>
> +% for name in sorted(opcodes):<br>
> +nir_op_${name},<br>
> +% endfor<br>
> +nir_last_opcode = nir_op_${sorted(opcodes)[-1]},<br>
> +""")<br>
> +<br>
> +print template.render(opcodes=opcodes)<br>
> +<br>
> --<br>
> 2.1.0<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>