i965/vec4/tcs: Return NULL instead of false in brw_compile_tcs()
[mesa.git] / src / glsl / lower_mat_op_to_vec.cpp
index 9d593f9dd0efbf7891ecbd78ca4753d907a4bd25..e96cda216dda595cf24b7595fb6fdaad82e300dd 100644 (file)
@@ -35,6 +35,8 @@
 #include "ir_expression_flattening.h"
 #include "glsl_types.h"
 
+namespace {
+
 class ir_mat_op_to_vec_visitor : public ir_hierarchical_visitor {
 public:
    ir_mat_op_to_vec_visitor()
@@ -63,6 +65,8 @@ public:
    bool made_progress;
 };
 
+} /* anonymous namespace */
+
 static bool
 mat_op_to_vec_predicate(ir_instruction *ir)
 {
@@ -122,7 +126,7 @@ ir_mat_op_to_vec_visitor::do_mul_mat_mat(ir_dereference *result,
                                         ir_dereference *a,
                                         ir_dereference *b)
 {
-   int b_col, i;
+   unsigned b_col, i;
    ir_assignment *assign;
    ir_expression *expr;
 
@@ -144,9 +148,7 @@ ir_mat_op_to_vec_visitor::do_mul_mat_mat(ir_dereference *result,
                                           mul_expr);
       }
 
-      assign = new(mem_ctx) ir_assignment(get_column(result, b_col),
-                                         expr,
-                                         NULL);
+      assign = new(mem_ctx) ir_assignment(get_column(result, b_col), expr);
       base_ir->insert_before(assign);
    }
 }
@@ -156,7 +158,7 @@ ir_mat_op_to_vec_visitor::do_mul_mat_vec(ir_dereference *result,
                                         ir_dereference *a,
                                         ir_dereference *b)
 {
-   int i;
+   unsigned i;
    ir_assignment *assign;
    ir_expression *expr;
 
@@ -176,9 +178,7 @@ ir_mat_op_to_vec_visitor::do_mul_mat_vec(ir_dereference *result,
    }
 
    result = result->clone(mem_ctx, NULL);
-   assign = new(mem_ctx) ir_assignment(result,
-                                      expr,
-                                      NULL);
+   assign = new(mem_ctx) ir_assignment(result, expr);
    base_ir->insert_before(assign);
 }
 
@@ -187,7 +187,7 @@ ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_dereference *result,
                                         ir_dereference *a,
                                         ir_dereference *b)
 {
-   int i;
+   unsigned i;
 
    for (i = 0; i < b->type->matrix_columns; i++) {
       ir_rvalue *column_result;
@@ -202,8 +202,7 @@ ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_dereference *result,
                                               get_column(b, i));
 
       column_assign = new(mem_ctx) ir_assignment(column_result,
-                                                column_expr,
-                                                NULL);
+                                                column_expr);
       base_ir->insert_before(column_assign);
    }
 }
@@ -213,7 +212,7 @@ ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_dereference *result,
                                            ir_dereference *a,
                                            ir_dereference *b)
 {
-   int i;
+   unsigned i;
 
    for (i = 0; i < a->type->matrix_columns; i++) {
       ir_expression *column_expr;
@@ -224,8 +223,7 @@ ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_dereference *result,
                                               b->clone(mem_ctx, NULL));
 
       column_assign = new(mem_ctx) ir_assignment(get_column(result, i),
-                                                column_expr,
-                                                NULL);
+                                                column_expr);
       base_ir->insert_before(column_assign);
    }
 }
@@ -279,13 +277,17 @@ ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_dereference *result,
    }
 
    ir_rvalue *const val = new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
-   ir_expression *any = new(this->mem_ctx) ir_expression(ir_unop_any, val);
+   uint8_t vec_elems = val->type->vector_elements;
+   ir_expression *any =
+      new(this->mem_ctx) ir_expression(ir_binop_any_nequal, val,
+                                       new(this->mem_ctx) ir_constant(false,
+                                                                      vec_elems));
 
    if (test_equal)
       any = new(this->mem_ctx) ir_expression(ir_unop_logic_not, any);
 
    ir_assignment *const assign =
-      new(mem_ctx) ir_assignment(result->clone(mem_ctx, NULL), any, NULL);
+      new(mem_ctx) ir_assignment(result->clone(mem_ctx, NULL), any);
    base_ir->insert_before(assign);
 }
 
@@ -350,17 +352,15 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
        * that others that want to use op[i] have to clone the deref.
        */
       op[i] = new(mem_ctx) ir_dereference_variable(var);
-      assign = new(mem_ctx) ir_assignment(op[i],
-                                         orig_expr->operands[i],
-                                         NULL);
+      assign = new(mem_ctx) ir_assignment(op[i], orig_expr->operands[i]);
       base_ir->insert_before(assign);
    }
 
    /* OK, time to break down this matrix operation. */
    switch (orig_expr->operation) {
+   case ir_unop_d2f:
+   case ir_unop_f2d:
    case ir_unop_neg: {
-      const unsigned mask = (1U << result->type->vector_elements) - 1;
-
       /* Apply the operation to each column.*/
       for (i = 0; i < matrix_columns; i++) {
         ir_expression *column_expr;
@@ -370,9 +370,7 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
                                                  get_column(op[0], i));
 
         column_assign = new(mem_ctx) ir_assignment(get_column(result, i),
-                                                   column_expr,
-                                                   NULL,
-                                                   mask);
+                                                   column_expr);
         assert(column_assign->write_mask != 0);
         base_ir->insert_before(column_assign);
       }
@@ -382,8 +380,6 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
    case ir_binop_sub:
    case ir_binop_div:
    case ir_binop_mod: {
-      const unsigned mask = (1U << result->type->vector_elements) - 1;
-
       /* For most operations, the matrix version is just going
        * column-wise through and applying the operation to each column
        * if available.
@@ -397,9 +393,7 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
                                                  get_column(op[1], i));
 
         column_assign = new(mem_ctx) ir_assignment(get_column(result, i),
-                                                   column_expr,
-                                                   NULL,
-                                                   mask);
+                                                   column_expr);
         assert(column_assign->write_mask != 0);
         base_ir->insert_before(column_assign);
       }