/*
- * 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.
*
* 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;
}
/**
ir_node *k_node;
ir_node *curr = left;
- if (k != 1) {
- k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k - 1);
- curr = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode);
- }
+ /* create the correction code for signed values only if there might be a remainder */
+ if (! is_Div_remainderless(irn)) {
+ if (k != 1) {
+ k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k - 1);
+ curr = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode);
+ }
- k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, bits - k);
- curr = new_rd_Shr(dbg, current_ir_graph, block, curr, k_node, mode);
+ k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, bits - k);
+ curr = new_rd_Shr(dbg, current_ir_graph, block, curr, k_node, mode);
- curr = new_rd_Add(dbg, current_ir_graph, block, left, curr, mode);
+ curr = new_rd_Add(dbg, current_ir_graph, block, left, curr, mode);
+ } else {
+ k_node = left;
+ }
k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k);
res = new_rd_Shrs(dbg, current_ir_graph, block, curr, k_node, mode);