* A Callback for evaluating the costs of an instruction.
*
* @param kind the instruction
+ * @param mode the mode of the instruction
* @param tv for MUL instruction, the multiplication constant
*
* @return the costs of this instruction
*/
-typedef int (*evaluate_costs_func)(insn_kind kind, ir_tarval *tv);
+typedef int (*evaluate_costs_func)(insn_kind kind, const ir_mode *mode, ir_tarval *tv);
/**
* A parameter structure that drives the machine dependent Firm
static const ir_settings_arch_dep_t ad = {
1, /* also use subs */
4, /* maximum shifts */
- 31, /* maximum shift amount */
+ 63, /* maximum shift amount */
ia32_evaluate_insn, /* evaluate the instruction sequence */
1, /* allow Mulhs */
}
/* Evaluate the costs of an instruction. */
-int ia32_evaluate_insn(insn_kind kind, ir_tarval *tv)
+int ia32_evaluate_insn(insn_kind kind, const ir_mode *mode, ir_tarval *tv)
{
int cost;
switch (kind) {
case MUL:
- cost = arch_costs->cost_mul_start;
+ cost = arch_costs->cost_mul_start;
if (arch_costs->cost_mul_bit > 0) {
char *bitstr = get_tarval_bitpattern(tv);
int i;
}
free(bitstr);
}
- return cost;
+ if (get_mode_size_bits(mode) <= 32)
+ return cost;
+ /* 64bit mul supported, approx 4times of a 32bit mul*/
+ return 4 * cost;
case LEA:
- return arch_costs->lea_cost;
+ /* lea is only supported for 32 bit */
+ if (get_mode_size_bits(mode) <= 32)
+ return arch_costs->lea_cost;
+ return 0x10000;
case ADD:
case SUB:
- return arch_costs->add_cost;
+ if (get_mode_size_bits(mode) <= 32)
+ return arch_costs->add_cost;
+ /* 64bit add/sub supported, double the cost */
+ return 2 * arch_costs->add_cost;
case SHIFT:
- return arch_costs->const_shf_cost;
+ if (get_mode_size_bits(mode) <= 32)
+ return arch_costs->const_shf_cost;
+ /* 64bit shift supported, double the cost */
+ return 2 * arch_costs->const_shf_cost;
case ZERO:
return arch_costs->add_cost;
default:
* lowerer.
*
* @param kind the instruction
+ * @param mode the mode of the instruction
* @param tv for MUL instruction, the multiplication constant
*
* @return the cost
*/
-int ia32_evaluate_insn(insn_kind kind, ir_tarval *tv);
+int ia32_evaluate_insn(insn_kind kind, const ir_mode *mode, ir_tarval *tv);
#endif
* Some kind of default evaluator. Return the cost of
* instructions.
*/
-static int default_evaluate(insn_kind kind, ir_tarval *tv)
+static int default_evaluate(insn_kind kind, const ir_mode *mode, ir_tarval *tv)
{
+ (void) mode;
(void) tv;
if (kind == MUL)
case ADD:
costs = evaluate_insn(env, inst->in[0]);
costs += evaluate_insn(env, inst->in[1]);
- costs += env->evaluate(inst->kind, NULL);
+ costs += env->evaluate(inst->kind, env->mode, NULL);
inst->costs = costs;
return costs;
case SHIFT:
else
--env->n_shift;
costs = evaluate_insn(env, inst->in[0]);
- costs += env->evaluate(inst->kind, NULL);
+ costs += env->evaluate(inst->kind, env->mode, NULL);
inst->costs = costs;
return costs;
case ZERO:
- inst->costs = costs = env->evaluate(inst->kind, NULL);
+ inst->costs = costs = env->evaluate(inst->kind, env->mode, NULL);
return costs;
case MUL:
case ROOT:
inst = decompose_mul(&env, R, r, tv);
/* the paper suggests 70% here */
- mul_costs = (env.evaluate(MUL, tv) * 7 + 5) / 10;
+ mul_costs = (env.evaluate(MUL, env.mode, tv) * 7 + 5) / 10;
if (evaluate_insn(&env, inst) <= mul_costs && !env.fail) {
env.op = operand;
env.blk = get_nodes_block(irn);