ir_binop_lshift,
ir_binop_rshift,
ir_binop_less,
- ir_binop_greater,
- ir_binop_lequal,
+ ir_binop_less, /* This is correct. See the ast_greater case below. */
+ ir_binop_gequal, /* This is correct. See the ast_lequal case below. */
ir_binop_gequal,
ir_binop_all_equal,
ir_binop_any_nequal,
assert(type->is_error()
|| (type->is_boolean() && type->is_scalar()));
+ /* Like NIR, GLSL IR does not have opcodes for > or <=. Instead, swap
+ * the arguments and use < or >=.
+ */
+ if (this->oper == ast_greater || this->oper == ast_lequal) {
+ ir_rvalue *const tmp = op[0];
+ op[0] = op[1];
+ op[1] = tmp;
+ }
+
result = new(ctx) ir_expression(operations[this->oper], type,
op[0], op[1]);
error_emitted = type->is_error();
ir_expression_operation opcode,
const glsl_type *return_type,
const glsl_type *param0_type,
- const glsl_type *param1_type);
+ const glsl_type *param1_type,
+ bool swap_operands = false);
#define B0(X) ir_function_signature *_##X();
#define B1(X) ir_function_signature *_##X(const glsl_type *);
ir_expression_operation opcode,
const glsl_type *return_type,
const glsl_type *param0_type,
- const glsl_type *param1_type)
+ const glsl_type *param1_type,
+ bool swap_operands)
{
ir_variable *x = in_var(param0_type, "x");
ir_variable *y = in_var(param1_type, "y");
MAKE_SIG(return_type, avail, 2, x, y);
- body.emit(ret(expr(opcode, x, y)));
+
+ if (swap_operands)
+ body.emit(ret(expr(opcode, y, x)));
+ else
+ body.emit(ret(expr(opcode, x, y)));
+
return sig;
}
builtin_builder::_lessThanEqual(builtin_available_predicate avail,
const glsl_type *type)
{
- return binop(avail, ir_binop_lequal,
- glsl_type::bvec(type->vector_elements), type, type);
+ return binop(avail, ir_binop_gequal,
+ glsl_type::bvec(type->vector_elements), type, type,
+ true);
}
ir_function_signature *
builtin_builder::_greaterThan(builtin_available_predicate avail,
const glsl_type *type)
{
- return binop(avail, ir_binop_greater,
- glsl_type::bvec(type->vector_elements), type, type);
+ return binop(avail, ir_binop_less,
+ glsl_type::bvec(type->vector_elements), type, type,
+ true);
}
ir_function_signature *
result = nir_slt(&b, srcs[0], srcs[1]);
}
break;
- case ir_binop_greater:
- if (supports_ints) {
- if (type_is_float(types[0]))
- result = nir_flt(&b, srcs[1], srcs[0]);
- else if (type_is_signed(types[0]))
- result = nir_ilt(&b, srcs[1], srcs[0]);
- else
- result = nir_ult(&b, srcs[1], srcs[0]);
- } else {
- result = nir_slt(&b, srcs[1], srcs[0]);
- }
- break;
- case ir_binop_lequal:
- if (supports_ints) {
- if (type_is_float(types[0]))
- result = nir_fge(&b, srcs[1], srcs[0]);
- else if (type_is_signed(types[0]))
- result = nir_ige(&b, srcs[1], srcs[0]);
- else
- result = nir_uge(&b, srcs[1], srcs[0]);
- } else {
- result = nir_slt(&b, srcs[1], srcs[0]);
- }
- break;
case ir_binop_gequal:
if (supports_ints) {
if (type_is_float(types[0]))
case ir_binop_equal:
case ir_binop_nequal:
- case ir_binop_lequal:
case ir_binop_gequal:
case ir_binop_less:
- case ir_binop_greater:
assert(op0->type == op1->type);
this->type = glsl_type::get_instance(GLSL_TYPE_BOOL,
op0->type->vector_elements, 1);
ir_expression*
greater(operand a, operand b)
{
- return expr(ir_binop_greater, a, b);
+ return expr(ir_binop_less, b, a);
}
ir_expression*
lequal(operand a, operand b)
{
- return expr(ir_binop_lequal, a, b);
+ return expr(ir_binop_gequal, b, a);
}
ir_expression*
case ir_binop_mul:
case ir_binop_imul_high:
case ir_binop_less:
- case ir_binop_greater:
- case ir_binop_lequal:
case ir_binop_gequal:
case ir_binop_equal:
case ir_binop_nequal:
# Binary comparison operators which return a boolean vector.
# The type of both operands must be equal.
operation("less", 2, printable_name="<", source_types=numeric_types, dest_type=bool_type, c_expression="{src0} < {src1}"),
- operation("greater", 2, printable_name=">", source_types=numeric_types, dest_type=bool_type, c_expression="{src0} > {src1}"),
- operation("lequal", 2, printable_name="<=", source_types=numeric_types, dest_type=bool_type, c_expression="{src0} <= {src1}"),
operation("gequal", 2, printable_name=">=", source_types=numeric_types, dest_type=bool_type, c_expression="{src0} >= {src1}"),
operation("equal", 2, printable_name="==", source_types=all_types, dest_type=bool_type, c_expression="{src0} == {src1}"),
operation("nequal", 2, printable_name="!=", source_types=all_types, dest_type=bool_type, c_expression="{src0} != {src1}"),
break;
case ir_binop_less:
- case ir_binop_greater:
- case ir_binop_lequal:
case ir_binop_gequal:
case ir_binop_equal:
case ir_binop_nequal:
static int
calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
- enum ir_expression_operation op, bool continue_from_then)
+ enum ir_expression_operation op, bool continue_from_then,
+ bool swap_compare_operands)
{
if (from == NULL || to == NULL || increment == NULL)
return -1;
ir_expression *const add =
new(mem_ctx) ir_expression(ir_binop_add, mul->type, mul, from);
- ir_expression *cmp =
- new(mem_ctx) ir_expression(op, glsl_type::bool_type, add, to);
+ ir_expression *cmp = swap_compare_operands
+ ? new(mem_ctx) ir_expression(op, glsl_type::bool_type, to, add)
+ : new(mem_ctx) ir_expression(op, glsl_type::bool_type, add, to);
if (continue_from_then)
cmp = new(mem_ctx) ir_expression(ir_unop_logic_not, cmp);
switch (cond->operation) {
case ir_binop_less:
- case ir_binop_greater:
- case ir_binop_lequal:
case ir_binop_gequal: {
/* The expressions that we care about will either be of the form
* 'counter < limit' or 'limit < counter'. Figure out which is
ir_rvalue *counter = cond->operands[0]->as_dereference_variable();
ir_constant *limit = cond->operands[1]->as_constant();
enum ir_expression_operation cmp = cond->operation;
+ bool swap_compare_operands = false;
if (limit == NULL) {
counter = cond->operands[1]->as_dereference_variable();
limit = cond->operands[0]->as_constant();
-
- switch (cmp) {
- case ir_binop_less: cmp = ir_binop_greater; break;
- case ir_binop_greater: cmp = ir_binop_less; break;
- case ir_binop_lequal: cmp = ir_binop_gequal; break;
- case ir_binop_gequal: cmp = ir_binop_lequal; break;
- default: assert(!"Should not get here.");
- }
+ swap_compare_operands = true;
}
if ((counter == NULL) || (limit == NULL))
loop_variable *lv = ls->get(var);
if (lv != NULL && lv->is_induction_var()) {
t->iterations = calculate_iterations(init, limit, lv->increment,
- cmp, t->continue_from_then);
+ cmp, t->continue_from_then,
+ swap_compare_operands);
if (incremented_before_terminator(ir, var, t->ir)) {
t->iterations--;
switch (op_expr[0]->operation) {
case ir_binop_less: new_op = ir_binop_gequal; break;
- case ir_binop_greater: new_op = ir_binop_lequal; break;
- case ir_binop_lequal: new_op = ir_binop_greater; break;
case ir_binop_gequal: new_op = ir_binop_less; break;
case ir_binop_equal: new_op = ir_binop_nequal; break;
case ir_binop_nequal: new_op = ir_binop_equal; break;
break;
case ir_binop_less:
- case ir_binop_lequal:
- case ir_binop_greater:
case ir_binop_gequal:
case ir_binop_equal:
case ir_binop_nequal:
def gt_zero(var_name):
"""Create Construct the expression var_name > 0"""
- return ['expression', 'bool', '>', ['var_ref', var_name], const_float(0)]
+ return ['expression', 'bool', '<', const_float(0), ['var_ref', var_name]]
# The following functions can be used to build complex control flow
switch (op) {
case ir_binop_less:
return BRW_CONDITIONAL_L;
- case ir_binop_greater:
- return BRW_CONDITIONAL_G;
- case ir_binop_lequal:
- return BRW_CONDITIONAL_LE;
case ir_binop_gequal:
return BRW_CONDITIONAL_GE;
case ir_binop_equal:
case ir_binop_less:
emit(ir, OPCODE_SLT, result_dst, op[0], op[1]);
break;
- case ir_binop_greater:
- /* Negating the operands (as opposed to switching the order of the
- * operands) produces the correct result when both are +/-Inf.
- */
- op[0].negate = ~op[0].negate;
- op[1].negate = ~op[1].negate;
- emit(ir, OPCODE_SLT, result_dst, op[0], op[1]);
- break;
- case ir_binop_lequal:
- /* Negating the operands (as opposed to switching the order of the
- * operands) produces the correct result when both are +/-Inf.
- */
- op[0].negate = ~op[0].negate;
- op[1].negate = ~op[1].negate;
- emit(ir, OPCODE_SGE, result_dst, op[0], op[1]);
- break;
case ir_binop_gequal:
emit(ir, OPCODE_SGE, result_dst, op[0], op[1]);
break;
/* a is - 0 + - 0 +
* (a < 0) T F F ( a < 0) T F F
* (0 < a) F F T (-a < 0) F F T
- * (a <= 0) T T F (-a < 0) F F T (swap order of other operands)
- * (0 <= a) F T T ( a < 0) T F F (swap order of other operands)
- * (a > 0) F F T (-a < 0) F F T
- * (0 > a) T F F ( a < 0) T F F
* (a >= 0) F T T ( a < 0) T F F (swap order of other operands)
* (0 >= a) T T F (-a < 0) F F T (swap order of other operands)
*
negate = zero_on_left;
break;
- case ir_binop_greater:
- switch_order = false;
- negate = !zero_on_left;
- break;
-
- case ir_binop_lequal:
- switch_order = true;
- negate = !zero_on_left;
- break;
-
case ir_binop_gequal:
switch_order = true;
negate = zero_on_left;
case ir_binop_less:
emit_asm(ir, TGSI_OPCODE_SLT, result_dst, op[0], op[1]);
break;
- case ir_binop_greater:
- emit_asm(ir, TGSI_OPCODE_SLT, result_dst, op[1], op[0]);
- break;
- case ir_binop_lequal:
- emit_asm(ir, TGSI_OPCODE_SGE, result_dst, op[1], op[0]);
- break;
case ir_binop_gequal:
emit_asm(ir, TGSI_OPCODE_SGE, result_dst, op[0], op[1]);
break;
/* a is - 0 + - 0 +
* (a < 0) T F F ( a < 0) T F F
* (0 < a) F F T (-a < 0) F F T
- * (a <= 0) T T F (-a < 0) F F T (swap order of other operands)
- * (0 <= a) F T T ( a < 0) T F F (swap order of other operands)
- * (a > 0) F F T (-a < 0) F F T
- * (0 > a) T F F ( a < 0) T F F
* (a >= 0) F T T ( a < 0) T F F (swap order of other operands)
* (0 >= a) T T F (-a < 0) F F T (swap order of other operands)
*
negate = zero_on_left;
break;
- case ir_binop_greater:
- switch_order = false;
- negate = !zero_on_left;
- break;
-
- case ir_binop_lequal:
- switch_order = true;
- negate = !zero_on_left;
- break;
-
case ir_binop_gequal:
switch_order = true;
negate = zero_on_left;