#define LDEXP_TO_ARITH 0x100
#define CARRY_TO_ARITH 0x200
#define BORROW_TO_ARITH 0x400
+#define SAT_TO_CLAMP 0x800
/**
* \see class lower_packing_builtins_visitor
* - BITFIELD_INSERT_TO_BFM_BFI
* - CARRY_TO_ARITH
* - BORROW_TO_ARITH
+ * - SAT_TO_CLAMP
*
* SUB_TO_ADD_NEG:
* ---------------
* ----------------
* Converts ir_borrow into (x < y).
*
+ * SAT_TO_CLAMP:
+ * -------------
+ * Converts ir_unop_saturate into min(max(x, 0.0), 1.0)
+ *
*/
#include "main/core.h" /* for M_LOG2E */
void ldexp_to_arith(ir_expression *);
void carry_to_arith(ir_expression *);
void borrow_to_arith(ir_expression *);
+ void sat_to_clamp(ir_expression *);
};
} /* anonymous namespace */
this->progress = true;
}
+void
+lower_instructions_visitor::sat_to_clamp(ir_expression *ir)
+{
+ /* Translates
+ * ir_unop_saturate x
+ * into
+ * ir_binop_min (ir_binop_max(x, 0.0), 1.0)
+ */
+
+ ir->operation = ir_binop_min;
+ ir->operands[0] = new(ir) ir_expression(ir_binop_max, ir->operands[0]->type,
+ ir->operands[0],
+ new(ir) ir_constant(0.0f));
+ ir->operands[1] = new(ir) ir_constant(1.0f);
+
+ this->progress = true;
+}
+
ir_visitor_status
lower_instructions_visitor::visit_leave(ir_expression *ir)
{
borrow_to_arith(ir);
break;
+ case ir_unop_saturate:
+ if (lowering(SAT_TO_CLAMP))
+ sat_to_clamp(ir);
+ break;
+
default:
return visit_continue;
}