Change opt_algebraic to use the new macro. Remove the old less than / greater than functions. --- src/glsl/ir_constant_util.h | 49 ++++++++++++++++++--------------------------- src/glsl/opt_algebraic.cpp | 8 ++++---- 2 files changed, 23 insertions(+), 34 deletions(-)
diff --git a/src/glsl/ir_constant_util.h b/src/glsl/ir_constant_util.h index d4048f3..4a54898 100644 --- a/src/glsl/ir_constant_util.h +++ b/src/glsl/ir_constant_util.h @@ -33,6 +33,25 @@ #include "main/macros.h" #include "program/prog_instruction.h" +#define IS_CONSTANT(ir, operator, operand) \ + (is_valid_vec_const(ir) ? \ + ((ir->type->vector_elements == 4) ? \ + ir->get_float_component(0) operator operand && \ + ir->get_float_component(1) operator operand && \ + ir->get_float_component(2) operator operand && \ + ir->get_float_component(3) operator operand : \ + ((ir->type->vector_elements == 3) ? \ + ir->get_float_component(0) operator operand && \ + ir->get_float_component(1) operator operand && \ + ir->get_float_component(2) operator operand : \ + ((ir->type->vector_elements == 2) ? \ + ir->get_float_component(0) operator operand && \ + ir->get_float_component(1) operator operand : \ + ((ir->type->vector_elements == 1) ? \ + ir->get_float_component(0) operator operand : \ + false)))) \ + : false) + /* When eliminating an expression and just returning one of its operands, * we may need to swizzle that operand out to a vector if the expression was * vector type. @@ -88,34 +107,4 @@ is_valid_vec_const(ir_constant *ir) return true; } -static inline bool -is_less_than_one(ir_constant *ir) -{ - if (!is_valid_vec_const(ir)) - return false; - - unsigned component = 0; - for (int c = 0; c < ir->type->vector_elements; c++) { - if (ir->get_float_component(c) < 1.0f) - component++; - } - - return (component == ir->type->vector_elements); -} - -static inline bool -is_greater_than_zero(ir_constant *ir) -{ - if (!is_valid_vec_const(ir)) - return false; - - unsigned component = 0; - for (int c = 0; c < ir->type->vector_elements; c++) { - if (ir->get_float_component(c) > 0.0f) - component++; - } - - return (component == ir->type->vector_elements); -} - #endif /* IR_CONSTANT_UTIL_H_ */ diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp index b1243c2..9ee6c9a 100644 --- a/src/glsl/opt_algebraic.cpp +++ b/src/glsl/opt_algebraic.cpp @@ -639,21 +639,21 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) /* Found a {min|max} ({max|min} (x, 0.0), b) where b < 1.0 * and its variations */ - if (is_less_than_one(outer_const) && inner_val_b->is_zero()) + if (IS_CONSTANT(outer_const, <, 1.0f) && inner_val_b->is_zero()) return expr(ir_binop_min, saturate(inner_val_a), outer_const); if (!inner_val_b->as_constant()) continue; - if (is_less_than_one(inner_val_b->as_constant()) && outer_const->is_zero()) + if (IS_CONSTANT(inner_val_b->as_constant(), <, 1.0f) && outer_const->is_zero()) return expr(ir_binop_min, saturate(inner_val_a), inner_val_b); /* Found a {min|max} ({max|min} (x, b), 1.0), where b > 0.0 * and its variations */ - if (outer_const->is_one() && is_greater_than_zero(inner_val_b->as_constant())) + if (outer_const->is_one() && IS_CONSTANT(inner_val_b->as_constant(), >, 0.0f)) return expr(ir_binop_max, saturate(inner_val_a), inner_val_b); - if (inner_val_b->as_constant()->is_one() && is_greater_than_zero(outer_const)) + if (inner_val_b->as_constant()->is_one() && IS_CONSTANT(outer_const, >, 0.0f)) return expr(ir_binop_max, saturate(inner_val_a), outer_const); } } -- 2.2.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev