Lines Matching refs:ir
86 #include "ir.h"
125 lower_instructions_visitor::sub_to_add_neg(ir_expression *ir)
127 ir->operation = ir_binop_add;
128 ir->operands[1] = new(ir) ir_expression(ir_unop_neg, ir->operands[1]->type,
129 ir->operands[1], NULL);
134 lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir)
136 assert(ir->operands[1]->type->is_float());
140 expr = new(ir) ir_expression(ir_unop_rcp,
141 ir->operands[1]->type,
142 ir->operands[1]);
145 ir->operation = ir_binop_mul;
146 ir->operands[1] = expr;
152 lower_instructions_visitor::int_div_to_mul_rcp(ir_expression *ir)
154 assert(ir->operands[1]->type->is_integer());
164 ir->operands[1]->type->vector_elements,
165 ir->operands[1]->type->matrix_columns);
167 if (ir->operands[1]->type->base_type == GLSL_TYPE_INT)
168 op1 = new(ir) ir_expression(ir_unop_i2f, vec_type, ir->operands[1], NULL);
170 op1 = new(ir) ir_expression(ir_unop_u2f, vec_type, ir->operands[1], NULL);
172 op1 = new(ir) ir_expression(ir_unop_rcp, op1->type, op1, NULL);
175 ir->operands[0]->type->vector_elements,
176 ir->operands[0]->type->matrix_columns);
178 if (ir->operands[0]->type->base_type == GLSL_TYPE_INT)
179 op0 = new(ir) ir_expression(ir_unop_i2f, vec_type, ir->operands[0], NULL);
181 op0 = new(ir) ir_expression(ir_unop_u2f, vec_type, ir->operands[0], NULL);
184 ir->type->vector_elements,
185 ir->type->matrix_columns);
187 op0 = new(ir) ir_expression(ir_binop_mul, vec_type, op0, op1);
189 if (ir->operands[1]->type->base_type == GLSL_TYPE_INT) {
190 ir->operation = ir_unop_f2i;
191 ir->operands[0] = op0;
193 ir->operation = ir_unop_i2u;
194 ir->operands[0] = new(ir) ir_expression(ir_unop_f2i, op0);
196 ir->operands[1] = NULL;
202 lower_instructions_visitor::exp_to_exp2(ir_expression *ir)
204 ir_constant *log2_e = new(ir) ir_constant(float(M_LOG2E));
206 ir->operation = ir_unop_exp2;
207 ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[0]->type,
208 ir->operands[0], log2_e);
213 lower_instructions_visitor::pow_to_exp2(ir_expression *ir)
216 new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type,
217 ir->operands[0]);
219 ir->operation = ir_unop_exp2;
220 ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[1]->type,
221 ir->operands[1], log2_x);
222 ir->operands[1] = NULL;
227 lower_instructions_visitor::log_to_log2(ir_expression *ir)
229 ir->operation = ir_binop_mul;
230 ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type,
231 ir->operands[0], NULL);
232 ir->operands[1] = new(ir) ir_constant(float(1.0 / M_LOG2E));
237 lower_instructions_visitor::mod_to_fract(ir_expression *ir)
239 ir_variable *temp = new(ir) ir_variable(ir->operands[1]->type, "mod_b",
244 new(ir) ir_assignment(new(ir) ir_dereference_variable(temp),
245 ir->operands[1], NULL);
250 new(ir) ir_expression(ir_binop_div, ir->operands[0]->type,
251 ir->operands[0],
252 new(ir) ir_dereference_variable(temp));
254 /* Don't generate new IR that would need to be lowered in an additional
260 ir_rvalue *expr = new(ir) ir_expression(ir_unop_fract,
261 ir->operands[0]->type,
265 ir->operation = ir_binop_mul;
266 ir->operands[0] = new(ir) ir_dereference_variable(temp);
267 ir->operands[1] = expr;
272 lower_instructions_visitor::visit_leave(ir_expression *ir)
274 switch (ir->operation) {
277 sub_to_add_neg(ir);
281 if (ir->operands[1]->type->is_integer() && lowering(INT_DIV_TO_MUL_RCP))
282 int_div_to_mul_rcp(ir);
283 else if (ir->operands[1]->type->is_float() && lowering(DIV_TO_MUL_RCP))
284 div_to_mul_rcp(ir);
289 exp_to_exp2(ir);
294 log_to_log2(ir);
298 if (lowering(MOD_TO_FRACT) && ir->type->is_float())
299 mod_to_fract(ir);
304 pow_to_exp2(ir);