2010-07-12 11:04:07 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-17 10:43:10 -08:00
|
|
|
* \file lower_mat_op_to_vec.cpp
|
2010-07-12 11:04:07 -07:00
|
|
|
*
|
|
|
|
|
* Breaks matrix operation expressions down to a series of vector operations.
|
|
|
|
|
*
|
|
|
|
|
* Generally this is how we have to codegen matrix operations for a
|
|
|
|
|
* GPU, so this gives us the chance to constant fold operations on a
|
|
|
|
|
* column or row.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ir.h"
|
|
|
|
|
#include "ir_expression_flattening.h"
|
|
|
|
|
#include "glsl_types.h"
|
|
|
|
|
|
|
|
|
|
class ir_mat_op_to_vec_visitor : public ir_hierarchical_visitor {
|
|
|
|
|
public:
|
|
|
|
|
ir_mat_op_to_vec_visitor()
|
|
|
|
|
{
|
|
|
|
|
this->made_progress = false;
|
2010-08-27 15:32:59 -07:00
|
|
|
this->mem_ctx = NULL;
|
2010-07-12 11:04:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_visitor_status visit_leave(ir_assignment *);
|
|
|
|
|
|
2010-08-04 16:27:55 -07:00
|
|
|
ir_dereference *get_column(ir_variable *var, int col);
|
2010-07-12 17:34:17 -07:00
|
|
|
ir_rvalue *get_element(ir_variable *var, int col, int row);
|
|
|
|
|
|
|
|
|
|
void do_mul_mat_mat(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var, ir_variable *b_var);
|
|
|
|
|
void do_mul_mat_vec(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var, ir_variable *b_var);
|
|
|
|
|
void do_mul_vec_mat(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var, ir_variable *b_var);
|
|
|
|
|
void do_mul_mat_scalar(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var, ir_variable *b_var);
|
2010-08-18 17:53:47 -07:00
|
|
|
void do_equal_mat_mat(ir_variable *result_var, ir_variable *a_var,
|
|
|
|
|
ir_variable *b_var, bool test_equal);
|
2010-07-12 11:04:07 -07:00
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
void *mem_ctx;
|
2010-07-12 11:04:07 -07:00
|
|
|
bool made_progress;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
mat_op_to_vec_predicate(ir_instruction *ir)
|
|
|
|
|
{
|
|
|
|
|
ir_expression *expr = ir->as_expression();
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
if (!expr)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < expr->get_num_operands(); i++) {
|
|
|
|
|
if (expr->operands[i]->type->is_matrix())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
do_mat_op_to_vec(exec_list *instructions)
|
|
|
|
|
{
|
|
|
|
|
ir_mat_op_to_vec_visitor v;
|
|
|
|
|
|
|
|
|
|
/* Pull out any matrix expression to a separate assignment to a
|
|
|
|
|
* temp. This will make our handling of the breakdown to
|
|
|
|
|
* operations on the matrix's vector components much easier.
|
|
|
|
|
*/
|
|
|
|
|
do_expression_flattening(instructions, mat_op_to_vec_predicate);
|
|
|
|
|
|
|
|
|
|
visit_list_elements(&v, instructions);
|
|
|
|
|
|
|
|
|
|
return v.made_progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_rvalue *
|
2010-07-12 17:34:17 -07:00
|
|
|
ir_mat_op_to_vec_visitor::get_element(ir_variable *var, int col, int row)
|
|
|
|
|
{
|
|
|
|
|
ir_dereference *deref;
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
deref = new(mem_ctx) ir_dereference_variable(var);
|
2010-07-12 17:34:17 -07:00
|
|
|
|
|
|
|
|
if (var->type->is_matrix()) {
|
2010-08-27 15:32:59 -07:00
|
|
|
deref = new(mem_ctx) ir_dereference_array(var,
|
|
|
|
|
new(mem_ctx) ir_constant(col));
|
2010-07-12 17:34:17 -07:00
|
|
|
} else {
|
|
|
|
|
assert(col == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
return new(mem_ctx) ir_swizzle(deref, row, 0, 0, 0, 1);
|
2010-07-12 17:34:17 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-04 16:27:55 -07:00
|
|
|
ir_dereference *
|
2010-07-12 17:34:17 -07:00
|
|
|
ir_mat_op_to_vec_visitor::get_column(ir_variable *var, int row)
|
2010-07-12 11:04:07 -07:00
|
|
|
{
|
|
|
|
|
ir_dereference *deref;
|
|
|
|
|
|
|
|
|
|
if (!var->type->is_matrix()) {
|
2010-08-27 15:32:59 -07:00
|
|
|
deref = new(mem_ctx) ir_dereference_variable(var);
|
2010-07-12 11:04:07 -07:00
|
|
|
} else {
|
2010-08-27 15:32:59 -07:00
|
|
|
deref = new(mem_ctx) ir_dereference_variable(var);
|
|
|
|
|
deref = new(mem_ctx) ir_dereference_array(deref,
|
|
|
|
|
new(mem_ctx) ir_constant(row));
|
2010-07-12 11:04:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return deref;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 17:34:17 -07:00
|
|
|
void
|
|
|
|
|
ir_mat_op_to_vec_visitor::do_mul_mat_mat(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var,
|
|
|
|
|
ir_variable *b_var)
|
|
|
|
|
{
|
|
|
|
|
int b_col, i;
|
|
|
|
|
ir_assignment *assign;
|
|
|
|
|
ir_expression *expr;
|
|
|
|
|
|
|
|
|
|
for (b_col = 0; b_col < b_var->type->matrix_columns; b_col++) {
|
|
|
|
|
ir_rvalue *a = get_column(a_var, 0);
|
|
|
|
|
ir_rvalue *b = get_element(b_var, b_col, 0);
|
|
|
|
|
|
|
|
|
|
/* first column */
|
2010-08-27 15:32:59 -07:00
|
|
|
expr = new(mem_ctx) ir_expression(ir_binop_mul,
|
2010-07-12 17:34:17 -07:00
|
|
|
a,
|
|
|
|
|
b);
|
|
|
|
|
|
|
|
|
|
/* following columns */
|
|
|
|
|
for (i = 1; i < a_var->type->matrix_columns; i++) {
|
|
|
|
|
ir_expression *mul_expr;
|
|
|
|
|
|
|
|
|
|
a = get_column(a_var, i);
|
|
|
|
|
b = get_element(b_var, b_col, i);
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
|
2010-07-12 17:34:17 -07:00
|
|
|
a,
|
|
|
|
|
b);
|
2010-08-27 15:32:59 -07:00
|
|
|
expr = new(mem_ctx) ir_expression(ir_binop_add,
|
2010-07-12 17:34:17 -07:00
|
|
|
expr,
|
|
|
|
|
mul_expr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ir_rvalue *result = get_column(result_var, b_col);
|
2010-08-27 15:32:59 -07:00
|
|
|
assign = new(mem_ctx) ir_assignment(result,
|
2010-07-12 17:34:17 -07:00
|
|
|
expr,
|
|
|
|
|
NULL);
|
|
|
|
|
base_ir->insert_before(assign);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ir_mat_op_to_vec_visitor::do_mul_mat_vec(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var,
|
|
|
|
|
ir_variable *b_var)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
ir_rvalue *a = get_column(a_var, 0);
|
|
|
|
|
ir_rvalue *b = get_element(b_var, 0, 0);
|
|
|
|
|
ir_assignment *assign;
|
|
|
|
|
ir_expression *expr;
|
|
|
|
|
|
|
|
|
|
/* first column */
|
2010-08-27 15:32:59 -07:00
|
|
|
expr = new(mem_ctx) ir_expression(ir_binop_mul,
|
2010-07-12 17:34:17 -07:00
|
|
|
a,
|
|
|
|
|
b);
|
|
|
|
|
|
|
|
|
|
/* following columns */
|
|
|
|
|
for (i = 1; i < a_var->type->matrix_columns; i++) {
|
|
|
|
|
ir_expression *mul_expr;
|
|
|
|
|
|
|
|
|
|
a = get_column(a_var, i);
|
|
|
|
|
b = get_element(b_var, 0, i);
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
|
2010-07-12 17:34:17 -07:00
|
|
|
a,
|
|
|
|
|
b);
|
2011-06-24 12:11:35 -07:00
|
|
|
expr = new(mem_ctx) ir_expression(ir_binop_add, expr, mul_expr);
|
2010-07-12 17:34:17 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
ir_rvalue *result = new(mem_ctx) ir_dereference_variable(result_var);
|
|
|
|
|
assign = new(mem_ctx) ir_assignment(result,
|
2010-07-12 17:34:17 -07:00
|
|
|
expr,
|
|
|
|
|
NULL);
|
|
|
|
|
base_ir->insert_before(assign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var,
|
|
|
|
|
ir_variable *b_var)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < b_var->type->matrix_columns; i++) {
|
2010-08-27 15:32:59 -07:00
|
|
|
ir_rvalue *a = new(mem_ctx) ir_dereference_variable(a_var);
|
2010-07-12 17:34:17 -07:00
|
|
|
ir_rvalue *b = get_column(b_var, i);
|
|
|
|
|
ir_rvalue *result;
|
|
|
|
|
ir_expression *column_expr;
|
|
|
|
|
ir_assignment *column_assign;
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
result = new(mem_ctx) ir_dereference_variable(result_var);
|
|
|
|
|
result = new(mem_ctx) ir_swizzle(result, i, 0, 0, 0, 1);
|
2010-07-12 17:34:17 -07:00
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
column_expr = new(mem_ctx) ir_expression(ir_binop_dot,
|
2010-07-12 17:34:17 -07:00
|
|
|
a,
|
|
|
|
|
b);
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
column_assign = new(mem_ctx) ir_assignment(result,
|
2010-07-12 17:34:17 -07:00
|
|
|
column_expr,
|
|
|
|
|
NULL);
|
|
|
|
|
base_ir->insert_before(column_assign);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var,
|
|
|
|
|
ir_variable *b_var)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < a_var->type->matrix_columns; i++) {
|
|
|
|
|
ir_rvalue *a = get_column(a_var, i);
|
2010-08-27 15:32:59 -07:00
|
|
|
ir_rvalue *b = new(mem_ctx) ir_dereference_variable(b_var);
|
2010-07-12 17:34:17 -07:00
|
|
|
ir_rvalue *result = get_column(result_var, i);
|
|
|
|
|
ir_expression *column_expr;
|
|
|
|
|
ir_assignment *column_assign;
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
column_expr = new(mem_ctx) ir_expression(ir_binop_mul,
|
2010-07-12 17:34:17 -07:00
|
|
|
a,
|
|
|
|
|
b);
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
column_assign = new(mem_ctx) ir_assignment(result,
|
2010-07-12 17:34:17 -07:00
|
|
|
column_expr,
|
|
|
|
|
NULL);
|
|
|
|
|
base_ir->insert_before(column_assign);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 17:53:47 -07:00
|
|
|
void
|
|
|
|
|
ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_variable *result_var,
|
|
|
|
|
ir_variable *a_var,
|
|
|
|
|
ir_variable *b_var,
|
|
|
|
|
bool test_equal)
|
|
|
|
|
{
|
|
|
|
|
/* This essentially implements the following GLSL:
|
|
|
|
|
*
|
|
|
|
|
* bool equal(mat4 a, mat4 b)
|
|
|
|
|
* {
|
|
|
|
|
* return !any(bvec4(a[0] != b[0],
|
|
|
|
|
* a[1] != b[1],
|
|
|
|
|
* a[2] != b[2],
|
|
|
|
|
* a[3] != b[3]);
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* bool nequal(mat4 a, mat4 b)
|
|
|
|
|
* {
|
|
|
|
|
* return any(bvec4(a[0] != b[0],
|
|
|
|
|
* a[1] != b[1],
|
|
|
|
|
* a[2] != b[2],
|
|
|
|
|
* a[3] != b[3]);
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
const unsigned columns = a_var->type->matrix_columns;
|
|
|
|
|
const glsl_type *const bvec_type =
|
|
|
|
|
glsl_type::get_instance(GLSL_TYPE_BOOL, columns, 1);
|
|
|
|
|
|
|
|
|
|
ir_variable *const tmp_bvec =
|
|
|
|
|
new(this->mem_ctx) ir_variable(bvec_type, "mat_cmp_bvec",
|
|
|
|
|
ir_var_temporary);
|
|
|
|
|
this->base_ir->insert_before(tmp_bvec);
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < columns; i++) {
|
|
|
|
|
ir_dereference *const op0 = get_column(a_var, i);
|
|
|
|
|
ir_dereference *const op1 = get_column(b_var, i);
|
|
|
|
|
|
|
|
|
|
ir_expression *const cmp =
|
2011-06-24 12:11:35 -07:00
|
|
|
new(this->mem_ctx) ir_expression(ir_binop_any_nequal, op0, op1);
|
2010-08-18 17:53:47 -07:00
|
|
|
|
|
|
|
|
ir_dereference *const lhs =
|
|
|
|
|
new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
|
|
|
|
|
|
|
|
|
|
ir_assignment *const assign =
|
2010-09-22 11:47:03 -07:00
|
|
|
new(this->mem_ctx) ir_assignment(lhs, cmp, NULL, (1U << i));
|
2010-08-18 17:53:47 -07:00
|
|
|
|
|
|
|
|
this->base_ir->insert_before(assign);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-24 12:11:35 -07:00
|
|
|
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);
|
2010-08-18 17:53:47 -07:00
|
|
|
|
|
|
|
|
if (test_equal)
|
2011-06-24 12:11:35 -07:00
|
|
|
any = new(this->mem_ctx) ir_expression(ir_unop_logic_not, any);
|
2010-08-18 17:53:47 -07:00
|
|
|
|
|
|
|
|
ir_rvalue *const result =
|
|
|
|
|
new(this->mem_ctx) ir_dereference_variable(result_var);
|
|
|
|
|
|
|
|
|
|
ir_assignment *const assign =
|
|
|
|
|
new(mem_ctx) ir_assignment(result, any, NULL);
|
|
|
|
|
base_ir->insert_before(assign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
has_matrix_operand(const ir_expression *expr, unsigned &columns)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned i = 0; i < expr->get_num_operands(); i++) {
|
|
|
|
|
if (expr->operands[i]->type->is_matrix()) {
|
|
|
|
|
columns = expr->operands[i]->type->matrix_columns;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-07-12 11:04:07 -07:00
|
|
|
ir_visitor_status
|
2010-08-27 15:34:42 -07:00
|
|
|
ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
|
2010-07-12 11:04:07 -07:00
|
|
|
{
|
2010-08-27 15:34:42 -07:00
|
|
|
ir_expression *orig_expr = orig_assign->rhs->as_expression();
|
2010-07-12 11:04:07 -07:00
|
|
|
unsigned int i, matrix_columns = 1;
|
|
|
|
|
ir_variable *op_var[2];
|
|
|
|
|
|
2010-08-27 15:34:42 -07:00
|
|
|
if (!orig_expr)
|
2010-07-12 11:04:07 -07:00
|
|
|
return visit_continue;
|
|
|
|
|
|
2010-08-18 17:53:47 -07:00
|
|
|
if (!has_matrix_operand(orig_expr, matrix_columns))
|
2010-07-12 11:04:07 -07:00
|
|
|
return visit_continue;
|
|
|
|
|
|
2010-11-10 16:33:10 -08:00
|
|
|
assert(orig_expr->get_num_operands() <= 2);
|
|
|
|
|
|
2011-01-21 14:32:31 -08:00
|
|
|
mem_ctx = ralloc_parent(orig_assign);
|
2010-08-27 15:32:59 -07:00
|
|
|
|
2010-08-27 15:34:42 -07:00
|
|
|
ir_dereference_variable *lhs_deref =
|
|
|
|
|
orig_assign->lhs->as_dereference_variable();
|
2010-07-12 11:04:07 -07:00
|
|
|
assert(lhs_deref);
|
|
|
|
|
|
|
|
|
|
ir_variable *result_var = lhs_deref->var;
|
|
|
|
|
|
|
|
|
|
/* Store the expression operands in temps so we can use them
|
|
|
|
|
* multiple times.
|
|
|
|
|
*/
|
2010-08-27 15:34:42 -07:00
|
|
|
for (i = 0; i < orig_expr->get_num_operands(); i++) {
|
2010-07-12 11:04:07 -07:00
|
|
|
ir_assignment *assign;
|
|
|
|
|
|
2010-08-27 15:34:42 -07:00
|
|
|
op_var[i] = new(mem_ctx) ir_variable(orig_expr->operands[i]->type,
|
2010-07-19 17:12:42 -07:00
|
|
|
"mat_op_to_vec",
|
|
|
|
|
ir_var_temporary);
|
2010-07-12 11:04:07 -07:00
|
|
|
base_ir->insert_before(op_var[i]);
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
lhs_deref = new(mem_ctx) ir_dereference_variable(op_var[i]);
|
|
|
|
|
assign = new(mem_ctx) ir_assignment(lhs_deref,
|
2010-08-27 15:34:42 -07:00
|
|
|
orig_expr->operands[i],
|
2010-07-12 11:04:07 -07:00
|
|
|
NULL);
|
|
|
|
|
base_ir->insert_before(assign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* OK, time to break down this matrix operation. */
|
2010-08-27 15:34:42 -07:00
|
|
|
switch (orig_expr->operation) {
|
2010-08-10 19:52:02 -07:00
|
|
|
case ir_unop_neg: {
|
|
|
|
|
const unsigned mask = (1U << result_var->type->vector_elements) - 1;
|
|
|
|
|
|
|
|
|
|
/* Apply the operation to each column.*/
|
|
|
|
|
for (i = 0; i < matrix_columns; i++) {
|
|
|
|
|
ir_rvalue *op0 = get_column(op_var[0], i);
|
|
|
|
|
ir_dereference *result = get_column(result_var, i);
|
|
|
|
|
ir_expression *column_expr;
|
|
|
|
|
ir_assignment *column_assign;
|
|
|
|
|
|
2011-06-24 12:11:35 -07:00
|
|
|
column_expr = new(mem_ctx) ir_expression(orig_expr->operation, op0);
|
2010-08-10 19:52:02 -07:00
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
column_assign = new(mem_ctx) ir_assignment(result,
|
2010-08-10 19:52:02 -07:00
|
|
|
column_expr,
|
|
|
|
|
NULL,
|
|
|
|
|
mask);
|
|
|
|
|
assert(column_assign->write_mask != 0);
|
|
|
|
|
base_ir->insert_before(column_assign);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-07-12 11:04:07 -07:00
|
|
|
case ir_binop_add:
|
|
|
|
|
case ir_binop_sub:
|
|
|
|
|
case ir_binop_div:
|
2010-08-04 16:27:55 -07:00
|
|
|
case ir_binop_mod: {
|
|
|
|
|
const unsigned mask = (1U << result_var->type->vector_elements) - 1;
|
|
|
|
|
|
2010-07-12 11:04:07 -07:00
|
|
|
/* For most operations, the matrix version is just going
|
|
|
|
|
* column-wise through and applying the operation to each column
|
|
|
|
|
* if available.
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < matrix_columns; i++) {
|
|
|
|
|
ir_rvalue *op0 = get_column(op_var[0], i);
|
|
|
|
|
ir_rvalue *op1 = get_column(op_var[1], i);
|
2010-08-04 16:27:55 -07:00
|
|
|
ir_dereference *result = get_column(result_var, i);
|
2010-07-12 11:04:07 -07:00
|
|
|
ir_expression *column_expr;
|
|
|
|
|
ir_assignment *column_assign;
|
|
|
|
|
|
2010-08-27 15:34:42 -07:00
|
|
|
column_expr = new(mem_ctx) ir_expression(orig_expr->operation,
|
2010-07-12 11:04:07 -07:00
|
|
|
op0,
|
|
|
|
|
op1);
|
|
|
|
|
|
2010-08-27 15:32:59 -07:00
|
|
|
column_assign = new(mem_ctx) ir_assignment(result,
|
2010-07-12 11:04:07 -07:00
|
|
|
column_expr,
|
2010-08-04 16:27:55 -07:00
|
|
|
NULL,
|
|
|
|
|
mask);
|
|
|
|
|
assert(column_assign->write_mask != 0);
|
2010-07-12 11:04:07 -07:00
|
|
|
base_ir->insert_before(column_assign);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-08-04 16:27:55 -07:00
|
|
|
}
|
2010-07-12 11:04:07 -07:00
|
|
|
case ir_binop_mul:
|
2010-07-12 17:34:17 -07:00
|
|
|
if (op_var[0]->type->is_matrix()) {
|
|
|
|
|
if (op_var[1]->type->is_matrix()) {
|
|
|
|
|
do_mul_mat_mat(result_var, op_var[0], op_var[1]);
|
|
|
|
|
} else if (op_var[1]->type->is_vector()) {
|
|
|
|
|
do_mul_mat_vec(result_var, op_var[0], op_var[1]);
|
|
|
|
|
} else {
|
|
|
|
|
assert(op_var[1]->type->is_scalar());
|
|
|
|
|
do_mul_mat_scalar(result_var, op_var[0], op_var[1]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
assert(op_var[1]->type->is_matrix());
|
|
|
|
|
if (op_var[0]->type->is_vector()) {
|
|
|
|
|
do_mul_vec_mat(result_var, op_var[0], op_var[1]);
|
|
|
|
|
} else {
|
|
|
|
|
assert(op_var[0]->type->is_scalar());
|
|
|
|
|
do_mul_mat_scalar(result_var, op_var[1], op_var[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-12 11:04:07 -07:00
|
|
|
break;
|
2010-08-18 17:53:47 -07:00
|
|
|
|
2010-09-08 01:31:39 +02:00
|
|
|
case ir_binop_all_equal:
|
|
|
|
|
case ir_binop_any_nequal:
|
2010-08-18 17:53:47 -07:00
|
|
|
do_equal_mat_mat(result_var, op_var[1], op_var[0],
|
2010-09-08 01:31:39 +02:00
|
|
|
(orig_expr->operation == ir_binop_all_equal));
|
2010-08-18 17:53:47 -07:00
|
|
|
break;
|
|
|
|
|
|
2010-07-12 11:04:07 -07:00
|
|
|
default:
|
2010-08-27 15:34:42 -07:00
|
|
|
printf("FINISHME: Handle matrix operation for %s\n",
|
|
|
|
|
orig_expr->operator_string());
|
2010-07-12 11:04:07 -07:00
|
|
|
abort();
|
|
|
|
|
}
|
2010-08-27 15:34:42 -07:00
|
|
|
orig_assign->remove();
|
2010-07-12 11:04:07 -07:00
|
|
|
this->made_progress = true;
|
|
|
|
|
|
|
|
|
|
return visit_continue;
|
|
|
|
|
}
|