/*
- * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
/** The bit mask, which optimizations to apply. */
static arch_dep_opts_t opts;
-/**
- * construct a Mulh: Mulh(a,b) = (a * b) >> w, w is the with in bits of a, b
- */
-static ir_node *
-new_rd_Mulh (dbg_info *db, ir_graph *irg, ir_node *block,
- ir_node *op1, ir_node *op2, ir_mode *mode) {
- ir_node *in[2];
- ir_node *res;
-
- in[0] = op1;
- in[1] = op2;
- res = new_ir_node(db, irg, block, op_Mulh, mode, 2, in);
- res = optimize_node(res);
- IRN_VRFY_IRG(res, irg);
- return res;
-}
-
void arch_dep_init(arch_dep_params_factory_t factory) {
opts = arch_dep_none;
void arch_dep_set_opts(arch_dep_opts_t the_opts) {
opts = the_opts;
-
- if (opts & arch_dep_mul_to_shift)
- set_opt_arch_dep_running(1);
}
/** check, whether a mode allows a Mulh instruction. */
* Calculate the gain when using the generalized complementary technique
*/
static int calculate_gain(unsigned char *R, int r) {
- int max_gain = -1;
- int idx, i;
+ int max_gain = 0;
+ int idx = -1, i;
int gain;
/* the gain for r == 1 */
idx = i;
}
}
- if (max_gain > 0)
- return idx;
- return -1;
+ return idx;
}
/**
assert(r == 2);
ins = env->root;
+ if (R[1] <= env->max_S) {
+ ins = emit_LEA(env, ins, ins, R[1]);
+ if (R[0] != 0) {
+ ins = emit_SHIFT(env, ins, R[0]);
+ }
+ return ins;
+ }
if (R[0] != 0) {
ins = emit_SHIFT(env, ins, R[0]);
}
- if (R[1] <= env->max_S)
- return emit_LEA(env, ins, ins, R[1]);
ins2 = emit_SHIFT(env, env->root, R[0] + R[1]);
return emit_LEA(env, ins, ins2, 0);
if (params == NULL || (opts & arch_dep_mul_to_shift) == 0)
return irn;
- if (is_Mul(irn) && mode_is_int(mode)) {
- ir_node *left = get_binop_left(irn);
- ir_node *right = get_binop_right(irn);
- tarval *tv = NULL;
- ir_node *operand = NULL;
-
- /* Look, if one operand is a constant. */
- if (is_Const(left)) {
- tv = get_Const_tarval(left);
- operand = right;
- } else if (is_Const(right)) {
- tv = get_Const_tarval(right);
- operand = left;
- }
+ set_arch_dep_running(1);
+ {
+ if (is_Mul(irn) && mode_is_int(mode)) {
+ ir_node *left = get_binop_left(irn);
+ ir_node *right = get_binop_right(irn);
+ tarval *tv = NULL;
+ ir_node *operand = NULL;
+
+ /* Look, if one operand is a constant. */
+ if (is_Const(left)) {
+ tv = get_Const_tarval(left);
+ operand = right;
+ } else if (is_Const(right)) {
+ tv = get_Const_tarval(right);
+ operand = left;
+ }
- if (tv != NULL) {
- res = do_decomposition(irn, operand, tv);
+ if (tv != NULL) {
+ res = do_decomposition(irn, operand, tv);
- if (res != irn) {
- hook_arch_dep_replace_mul_with_shifts(irn);
- exchange(irn, res);
+ if (res != irn) {
+ hook_arch_dep_replace_mul_with_shifts(irn);
+ exchange(irn, res);
+ }
}
}
}
+ //set_arch_dep_running(0);
return res;
}
tv = get_Const_tarval(c);
/* check for division by zero */
- if (classify_tarval(tv) == TV_CLASSIFY_NULL)
+ if (tarval_is_null(tv))
return irn;
left = get_Div_left(irn);
tv = get_Const_tarval(c);
/* check for division by zero */
- if (classify_tarval(tv) == TV_CLASSIFY_NULL)
+ if (tarval_is_null(tv))
return irn;
left = get_Mod_left(irn);
tv = get_Const_tarval(c);
/* check for division by zero */
- if (classify_tarval(tv) == TV_CLASSIFY_NULL)
+ if (tarval_is_null(tv))
return;
left = get_DivMod_left(irn);