Re: [Mesa-dev] [PATCH v2 09/29] nir: Make boolean conversions sized just like the others

2018-12-14 Thread Iago Toral
On Thu, 2018-12-13 at 07:02 -0600, Jason Ekstrand wrote:
> On December 13, 2018 04:07:56 Iago Toral  wrote:
> 
> > On Thu, 2018-12-06 at 13:45 -0600, Jason Ekstrand wrote:
> > (...)
> > > diff --git a/src/compiler/nir/nir_builder.h
> > > b/src/compiler/nir/nir_builder.h
> > > index 30fa1d7ec8b..e0cdcd4ba23 100644
> > > --- a/src/compiler/nir/nir_builder.h
> > > +++ b/src/compiler/nir/nir_builder.h
> > > @@ -963,6 +963,18 @@ nir_load_param(nir_builder *build, uint32_t
> > > param_idx)
> > > 
> > > #include "nir_builder_opcodes.h"
> > > 
> > > +static inline nir_ssa_def *
> > > +nir_f2b(nir_builder *build, nir_ssa_def *f)
> > > +{
> > > +   return nir_f2b32(build, f);
> > > +}
> > > +
> > > +static inline nir_ssa_def *
> > > +nir_i2b(nir_builder *build, nir_ssa_def *i)
> > > +{
> > > +   return nir_i2b32(build, i);
> > > +}
> > > +
> > 
> > any particular reason why wanted these instead of just calling the
> > 32-
> > bit opcode directly from the caller?
> 
> In my 1-bit booleans series, it lets me switch most of NIR without
> having 
> to manually edit every single place we do a x2b conversion.
> 
> > I need to do b2f conversions in a couple of places where the
> > destination can be 16, 32 or 64 and I think it is more convenient
> > to
> > have helpers that take the destination bit-size as parameter and
> > then
> > emit the appropriate opcode instead. What do you think?
> 
> For b2f, I totally agree.  In fact, I've considered adding a small
> bit of 
> codegen to nir_builder to add such a pole of helpers. One of my
> patch 
> series (I don't remember which at this point) adds i2i and u2u
> helpers that 
> take a bit size like you suggest.

Great, I'll add that helper then.

I was wondering: do we want to add b2u and b2i helpers that take a bit-
size as well for completion? They would be trivial to add but I have
not come across any place where we need them at the moment since I
think we usually handle all the cases we have through
nir_type_conversion_op().

Iago

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2 09/29] nir: Make boolean conversions sized just like the others

2018-12-13 Thread Jason Ekstrand

On December 13, 2018 04:07:56 Iago Toral  wrote:


On Thu, 2018-12-06 at 13:45 -0600, Jason Ekstrand wrote:
(...)

diff --git a/src/compiler/nir/nir_builder.h
b/src/compiler/nir/nir_builder.h
index 30fa1d7ec8b..e0cdcd4ba23 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -963,6 +963,18 @@ nir_load_param(nir_builder *build, uint32_t
param_idx)

#include "nir_builder_opcodes.h"

+static inline nir_ssa_def *
+nir_f2b(nir_builder *build, nir_ssa_def *f)
+{
+   return nir_f2b32(build, f);
+}
+
+static inline nir_ssa_def *
+nir_i2b(nir_builder *build, nir_ssa_def *i)
+{
+   return nir_i2b32(build, i);
+}
+


any particular reason why wanted these instead of just calling the 32-
bit opcode directly from the caller?


In my 1-bit booleans series, it lets me switch most of NIR without having 
to manually edit every single place we do a x2b conversion.



I need to do b2f conversions in a couple of places where the
destination can be 16, 32 or 64 and I think it is more convenient to
have helpers that take the destination bit-size as parameter and then
emit the appropriate opcode instead. What do you think?


For b2f, I totally agree.  In fact, I've considered adding a small bit of 
codegen to nir_builder to add such a pole of helpers. One of my patch 
series (I don't remember which at this point) adds i2i and u2u helpers that 
take a bit size like you suggest.



--Jason



___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2 09/29] nir: Make boolean conversions sized just like the others

2018-12-13 Thread Iago Toral
On Thu, 2018-12-06 at 13:45 -0600, Jason Ekstrand wrote:
(...)
> diff --git a/src/compiler/nir/nir_builder.h
> b/src/compiler/nir/nir_builder.h
> index 30fa1d7ec8b..e0cdcd4ba23 100644
> --- a/src/compiler/nir/nir_builder.h
> +++ b/src/compiler/nir/nir_builder.h
> @@ -963,6 +963,18 @@ nir_load_param(nir_builder *build, uint32_t
> param_idx)
>  
>  #include "nir_builder_opcodes.h"
>  
> +static inline nir_ssa_def *
> +nir_f2b(nir_builder *build, nir_ssa_def *f)
> +{
> +   return nir_f2b32(build, f);
> +}
> +
> +static inline nir_ssa_def *
> +nir_i2b(nir_builder *build, nir_ssa_def *i)
> +{
> +   return nir_i2b32(build, i);
> +}
> +

any particular reason why wanted these instead of just calling the 32-
bit opcode directly from the caller?

I need to do b2f conversions in a couple of places where the
destination can be 16, 32 or 64 and I think it is more convenient to
have helpers that take the destination bit-size as parameter and then
emit the appropriate opcode instead. What do you think?

Iago

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 09/29] nir: Make boolean conversions sized just like the others

2018-12-06 Thread Jason Ekstrand
Instead of a single i2b and b2i, we now have i2b32 and b2iN where N is
one if 8, 16, 32, or 64.  This leads to having a few more opcodes but
now everything is consistent and booleans aren't a weird special case
anymore.

Reviewed-by: Connor Abbott 
---
 src/amd/common/ac_nir_to_llvm.c   | 12 +++
 src/broadcom/compiler/nir_to_vir.c|  8 +++
 src/compiler/glsl/glsl_to_nir.cpp |  2 +-
 src/compiler/nir/nir.h|  4 ++--
 src/compiler/nir/nir_algebraic.py |  4 
 src/compiler/nir/nir_builder.h| 12 +++
 src/compiler/nir/nir_lower_idiv.c |  2 +-
 src/compiler/nir/nir_lower_int64.c|  2 +-
 src/compiler/nir/nir_opcodes.py   | 25 +++---
 src/compiler/nir/nir_opcodes_c.py | 30 +++
 src/compiler/nir/nir_opt_algebraic.py | 14 ++---
 src/compiler/nir/nir_opt_if.c |  2 +-
 src/compiler/nir/nir_search.c | 19 +
 src/compiler/nir/nir_search.h |  4 
 src/compiler/spirv/vtn_glsl450.c  |  4 ++--
 src/freedreno/ir3/ir3_compiler_nir.c  | 11 ++
 src/gallium/drivers/vc4/vc4_program.c |  8 +++
 src/intel/compiler/brw_fs_nir.cpp | 19 ++---
 src/intel/compiler/brw_vec4_nir.cpp   |  9 
 src/mesa/program/prog_to_nir.c|  4 ++--
 20 files changed, 121 insertions(+), 74 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index a109f5a8156..fe65dfff8f3 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -941,16 +941,20 @@ static void visit_alu(struct ac_nir_context *ctx, const 
nir_alu_instr *instr)
src[1] = ac_to_integer(>ac, src[1]);
result = emit_uint_carry(>ac, 
"llvm.usub.with.overflow.i32", src[0], src[1]);
break;
-   case nir_op_b2f:
+   case nir_op_b2f16:
+   case nir_op_b2f32:
+   case nir_op_b2f64:
result = emit_b2f(>ac, src[0], 
instr->dest.dest.ssa.bit_size);
break;
-   case nir_op_f2b:
+   case nir_op_f2b32:
result = emit_f2b(>ac, src[0]);
break;
-   case nir_op_b2i:
+   case nir_op_b2i16:
+   case nir_op_b2i32:
+   case nir_op_b2i64:
result = emit_b2i(>ac, src[0], 
instr->dest.dest.ssa.bit_size);
break;
-   case nir_op_i2b:
+   case nir_op_i2b32:
src[0] = ac_to_integer(>ac, src[0]);
result = emit_i2b(>ac, src[0]);
break;
diff --git a/src/broadcom/compiler/nir_to_vir.c 
b/src/broadcom/compiler/nir_to_vir.c
index 57be43d7245..fbe8af376a7 100644
--- a/src/broadcom/compiler/nir_to_vir.c
+++ b/src/broadcom/compiler/nir_to_vir.c
@@ -682,14 +682,14 @@ ntq_emit_alu(struct v3d_compile *c, nir_alu_instr *instr)
 case nir_op_u2f32:
 result = vir_UTOF(c, src[0]);
 break;
-case nir_op_b2f:
+case nir_op_b2f32:
 result = vir_AND(c, src[0], vir_uniform_f(c, 1.0));
 break;
-case nir_op_b2i:
+case nir_op_b2i32:
 result = vir_AND(c, src[0], vir_uniform_ui(c, 1));
 break;
-case nir_op_i2b:
-case nir_op_f2b:
+case nir_op_i2b32:
+case nir_op_f2b32:
 vir_PF(c, src[0], V3D_QPU_PF_PUSHZ);
 result = vir_MOV(c, vir_SEL(c, V3D_QPU_COND_IFNA,
 vir_uniform_ui(c, ~0),
diff --git a/src/compiler/glsl/glsl_to_nir.cpp 
b/src/compiler/glsl/glsl_to_nir.cpp
index 5e70d230550..2ab03069672 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -1527,7 +1527,7 @@ nir_visitor::visit(ir_expression *ir)
   result = supports_ints ? nir_u2f32(, srcs[0]) : nir_fmov(, srcs[0]);
   break;
case ir_unop_b2f:
-  result = supports_ints ? nir_b2f(, srcs[0]) : nir_fmov(, srcs[0]);
+  result = supports_ints ? nir_b2f32(, srcs[0]) : nir_fmov(, srcs[0]);
   break;
case ir_unop_f2i:
case ir_unop_f2u:
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index db935c8496b..cb8122def8a 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1568,8 +1568,8 @@ nir_alu_instr_is_comparison(const nir_alu_instr *instr)
case nir_op_uge:
case nir_op_ieq:
case nir_op_ine:
-   case nir_op_i2b:
-   case nir_op_f2b:
+   case nir_op_i2b32:
+   case nir_op_f2b32:
case nir_op_inot:
case nir_op_fnot:
   return true;
diff --git a/src/compiler/nir/nir_algebraic.py 
b/src/compiler/nir/nir_algebraic.py
index 66ee0ad6402..c16cadbdc58 100644
--- a/src/compiler/nir/nir_algebraic.py
+++ b/src/compiler/nir/nir_algebraic.py
@@ -45,6 +45,10 @@ conv_opcode_types = {
 'f2i' : 'int',
 'u2u' : 'uint',
 'i2i' : 'int',
+'b2f' : 'float',
+'b2i' : 'int',
+'i2b' : 'bool',
+'f2b' : 'bool',
 }
 
 if sys.version_info < (3, 0):