aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-11-04 12:11:17 +0100
committermarha <marha@users.sourceforge.net>2013-11-04 12:11:17 +0100
commitd79b6645eb21ca82d506ef038b8ea71a1e431f3f (patch)
tree8f96f2c0492c134147a32e124ea5d0a7337b2242 /mesalib/src/glsl/opt_algebraic.cpp
parentfeb35c5e0724010fc4431e4e4fb24720fcdffe80 (diff)
parente4ef724e06621be9325fc41ed886fd404467fdc0 (diff)
downloadvcxsrv-d79b6645eb21ca82d506ef038b8ea71a1e431f3f.tar.gz
vcxsrv-d79b6645eb21ca82d506ef038b8ea71a1e431f3f.tar.bz2
vcxsrv-d79b6645eb21ca82d506ef038b8ea71a1e431f3f.zip
Merge remote-tracking branch 'origin/released'
* origin/released: fontconfig glproto libX11 mesa xserver xkeyboard-config git update 31 oct 2013 Conflicts: xorg-server/glx/dispatch.h xorg-server/glx/glapi.c xorg-server/glx/glapi.h xorg-server/glx/glapi_gentable.c xorg-server/glx/glapitable.h xorg-server/glx/glprocs.h xorg-server/glx/glxcmdsswap.c xorg-server/glx/glxdri.c xorg-server/glx/glxext.c xorg-server/glx/glxext.h xorg-server/glx/indirect_dispatch.c xorg-server/glx/indirect_dispatch.h xorg-server/glx/indirect_dispatch_swap.c xorg-server/glx/indirect_reqsize.c xorg-server/glx/indirect_reqsize.h xorg-server/glx/indirect_size.h xorg-server/glx/indirect_size_get.c xorg-server/glx/indirect_size_get.h xorg-server/glx/indirect_table.c xorg-server/glx/indirect_texture_compression.c xorg-server/glx/render2.c xorg-server/glx/render2swap.c
Diffstat (limited to 'mesalib/src/glsl/opt_algebraic.cpp')
-rw-r--r--mesalib/src/glsl/opt_algebraic.cpp166
1 files changed, 69 insertions, 97 deletions
diff --git a/mesalib/src/glsl/opt_algebraic.cpp b/mesalib/src/glsl/opt_algebraic.cpp
index 37b2f02c6..a07e153ae 100644
--- a/mesalib/src/glsl/opt_algebraic.cpp
+++ b/mesalib/src/glsl/opt_algebraic.cpp
@@ -32,8 +32,11 @@
#include "ir_visitor.h"
#include "ir_rvalue_visitor.h"
#include "ir_optimization.h"
+#include "ir_builder.h"
#include "glsl_types.h"
+using namespace ir_builder;
+
namespace {
/**
@@ -194,7 +197,6 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
{
ir_constant *op_const[4] = {NULL, NULL, NULL, NULL};
ir_expression *op_expr[4] = {NULL, NULL, NULL, NULL};
- ir_expression *temp;
unsigned int i;
assert(ir->get_num_operands() <= 4);
@@ -217,12 +219,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
switch (op_expr[0]->operation) {
case ir_unop_abs:
case ir_unop_neg:
- this->progress = true;
- temp = new(mem_ctx) ir_expression(ir_unop_abs,
- ir->type,
- op_expr[0]->operands[0],
- NULL);
- return swizzle_if_required(ir, temp);
+ return abs(op_expr[0]->operands[0]);
default:
break;
}
@@ -233,8 +230,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
break;
if (op_expr[0]->operation == ir_unop_neg) {
- this->progress = true;
- return swizzle_if_required(ir, op_expr[0]->operands[0]);
+ return op_expr[0]->operands[0];
}
break;
@@ -261,7 +257,6 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
}
if (new_op != ir_unop_logic_not) {
- this->progress = true;
return new(mem_ctx) ir_expression(new_op,
ir->type,
op_expr[0]->operands[0],
@@ -272,14 +267,10 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
}
case ir_binop_add:
- if (is_vec_zero(op_const[0])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[1]);
- }
- if (is_vec_zero(op_const[1])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[0]);
- }
+ if (is_vec_zero(op_const[0]))
+ return ir->operands[1];
+ if (is_vec_zero(op_const[1]))
+ return ir->operands[0];
/* Reassociate addition of constants so that we can do constant
* folding.
@@ -291,50 +282,25 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
break;
case ir_binop_sub:
- if (is_vec_zero(op_const[0])) {
- this->progress = true;
- temp = new(mem_ctx) ir_expression(ir_unop_neg,
- ir->operands[1]->type,
- ir->operands[1],
- NULL);
- return swizzle_if_required(ir, temp);
- }
- if (is_vec_zero(op_const[1])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[0]);
- }
+ if (is_vec_zero(op_const[0]))
+ return neg(ir->operands[1]);
+ if (is_vec_zero(op_const[1]))
+ return ir->operands[0];
break;
case ir_binop_mul:
- if (is_vec_one(op_const[0])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[1]);
- }
- if (is_vec_one(op_const[1])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[0]);
- }
+ if (is_vec_one(op_const[0]))
+ return ir->operands[1];
+ if (is_vec_one(op_const[1]))
+ return ir->operands[0];
- if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) {
- this->progress = true;
+ if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1]))
return ir_constant::zero(ir, ir->type);
- }
- if (is_vec_negative_one(op_const[0])) {
- this->progress = true;
- temp = new(mem_ctx) ir_expression(ir_unop_neg,
- ir->operands[1]->type,
- ir->operands[1],
- NULL);
- return swizzle_if_required(ir, temp);
- }
- if (is_vec_negative_one(op_const[1])) {
- this->progress = true;
- temp = new(mem_ctx) ir_expression(ir_unop_neg,
- ir->operands[0]->type,
- ir->operands[0],
- NULL);
- return swizzle_if_required(ir, temp);
- }
+
+ if (is_vec_negative_one(op_const[0]))
+ return neg(ir->operands[1]);
+ if (is_vec_negative_one(op_const[1]))
+ return neg(ir->operands[0]);
/* Reassociate multiplication of constants so that we can do
@@ -349,26 +315,20 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
case ir_binop_div:
if (is_vec_one(op_const[0]) && ir->type->base_type == GLSL_TYPE_FLOAT) {
- this->progress = true;
- temp = new(mem_ctx) ir_expression(ir_unop_rcp,
+ return new(mem_ctx) ir_expression(ir_unop_rcp,
ir->operands[1]->type,
ir->operands[1],
NULL);
- return swizzle_if_required(ir, temp);
- }
- if (is_vec_one(op_const[1])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[0]);
}
+ if (is_vec_one(op_const[1]))
+ return ir->operands[0];
break;
case ir_binop_dot:
- if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) {
- this->progress = true;
+ if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1]))
return ir_constant::zero(mem_ctx, ir->type);
- }
+
if (is_vec_basis(op_const[0])) {
- this->progress = true;
unsigned component = 0;
for (unsigned c = 0; c < op_const[0]->type->vector_elements; c++) {
if (op_const[0]->value.f[c] == 1.0)
@@ -377,7 +337,6 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
return new(mem_ctx) ir_swizzle(ir->operands[1], component, 0, 0, 0, 1);
}
if (is_vec_basis(op_const[1])) {
- this->progress = true;
unsigned component = 0;
for (unsigned c = 0; c < op_const[1]->type->vector_elements; c++) {
if (op_const[1]->value.f[c] == 1.0)
@@ -387,46 +346,52 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
}
break;
+ case ir_binop_rshift:
+ case ir_binop_lshift:
+ /* 0 >> x == 0 */
+ if (is_vec_zero(op_const[0]))
+ return ir->operands[0];
+ /* x >> 0 == x */
+ if (is_vec_zero(op_const[1]))
+ return ir->operands[0];
+ break;
+
case ir_binop_logic_and:
/* FINISHME: Also simplify (a && a) to (a). */
if (is_vec_one(op_const[0])) {
- this->progress = true;
return ir->operands[1];
} else if (is_vec_one(op_const[1])) {
- this->progress = true;
return ir->operands[0];
} else if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) {
- this->progress = true;
return ir_constant::zero(mem_ctx, ir->type);
+ } else if (op_expr[0] && op_expr[0]->operation == ir_unop_logic_not &&
+ op_expr[1] && op_expr[1]->operation == ir_unop_logic_not) {
+ /* De Morgan's Law:
+ * (not A) and (not B) === not (A or B)
+ */
+ return logic_not(logic_or(op_expr[0]->operands[0],
+ op_expr[1]->operands[0]));
}
break;
case ir_binop_logic_xor:
/* FINISHME: Also simplify (a ^^ a) to (false). */
if (is_vec_zero(op_const[0])) {
- this->progress = true;
return ir->operands[1];
} else if (is_vec_zero(op_const[1])) {
- this->progress = true;
return ir->operands[0];
} else if (is_vec_one(op_const[0])) {
- this->progress = true;
- return new(mem_ctx) ir_expression(ir_unop_logic_not, ir->type,
- ir->operands[1], NULL);
+ return logic_not(ir->operands[1]);
} else if (is_vec_one(op_const[1])) {
- this->progress = true;
- return new(mem_ctx) ir_expression(ir_unop_logic_not, ir->type,
- ir->operands[0], NULL);
+ return logic_not(ir->operands[0]);
}
break;
case ir_binop_logic_or:
/* FINISHME: Also simplify (a || a) to (a). */
if (is_vec_zero(op_const[0])) {
- this->progress = true;
return ir->operands[1];
} else if (is_vec_zero(op_const[1])) {
- this->progress = true;
return ir->operands[0];
} else if (is_vec_one(op_const[0]) || is_vec_one(op_const[1])) {
ir_constant_data data;
@@ -434,16 +399,20 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
for (unsigned i = 0; i < 16; i++)
data.b[i] = true;
- this->progress = true;
return new(mem_ctx) ir_constant(ir->type, &data);
+ } else if (op_expr[0] && op_expr[0]->operation == ir_unop_logic_not &&
+ op_expr[1] && op_expr[1]->operation == ir_unop_logic_not) {
+ /* De Morgan's Law:
+ * (not A) or (not B) === not (A and B)
+ */
+ return logic_not(logic_and(op_expr[0]->operands[0],
+ op_expr[1]->operands[0]));
}
break;
case ir_unop_rcp:
- if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp) {
- this->progress = true;
+ if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp)
return op_expr[0]->operands[0];
- }
/* FINISHME: We should do rcp(rsq(x)) -> sqrt(x) for some
* backends, except that some backends will have done sqrt ->
@@ -452,12 +421,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
/* As far as we know, all backends are OK with rsq. */
if (op_expr[0] && op_expr[0]->operation == ir_unop_sqrt) {
- this->progress = true;
- temp = new(mem_ctx) ir_expression(ir_unop_rsq,
- op_expr[0]->operands[0]->type,
- op_expr[0]->operands[0],
- NULL);
- return swizzle_if_required(ir, temp);
+ return rsq(op_expr[0]->operands[0]);
}
break;
@@ -465,11 +429,9 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
case ir_triop_lrp:
/* Operands are (x, y, a). */
if (is_vec_zero(op_const[2])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[0]);
+ return ir->operands[0];
} else if (is_vec_one(op_const[2])) {
- this->progress = true;
- return swizzle_if_required(ir, ir->operands[1]);
+ return ir->operands[1];
}
break;
@@ -490,7 +452,17 @@ ir_algebraic_visitor::handle_rvalue(ir_rvalue **rvalue)
if (!expr || expr->operation == ir_quadop_vector)
return;
- *rvalue = handle_expression(expr);
+ ir_rvalue *new_rvalue = handle_expression(expr);
+ if (new_rvalue == *rvalue)
+ return;
+
+ /* If the expr used to be some vec OP scalar returning a vector, and the
+ * optimization gave us back a scalar, we still need to turn it into a
+ * vector.
+ */
+ *rvalue = swizzle_if_required(expr, new_rvalue);
+
+ this->progress = true;
}
bool