diff options
author | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-06-15 15:06:14 +0000 |
---|---|---|
committer | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-06-15 15:06:14 +0000 |
commit | 83df06d03db9695a45ccafea225a8342ecbe3d73 (patch) | |
tree | e04a2fe3bce10855bce0dcd51b05d25bf50ce7ff /gcc/expmed.c | |
parent | ebf99822991d7fd1408ff6bc616abd83a35a80c3 (diff) | |
download | gcc-83df06d03db9695a45ccafea225a8342ecbe3d73.tar.gz |
* expmed.c (synth_mult): Mask bits of the multiplier to the
machine mode of the multiplication. Don't consider shifts
by more than (or equal to) the width of the operation's mode.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@83187 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/expmed.c')
-rw-r--r-- | gcc/expmed.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/expmed.c b/gcc/expmed.c index f45de5d56cc..bebdbe86dec 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -2191,6 +2191,7 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t, struct algorithm *alg_in, *best_alg; int cost; unsigned HOST_WIDE_INT q; + int maxm = MIN (BITS_PER_WORD, GET_MODE_BITSIZE (mode)); /* Indicate that no algorithm is yet found. If no algorithm is found, this value will be returned and indicate failure. */ @@ -2199,6 +2200,9 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t, if (cost_limit <= 0) return; + /* Restrict the bits of "t" to the multiplication's mode. */ + t &= GET_MODE_MASK (mode); + /* t == 1 can be done in zero cost. */ if (t == 1) { @@ -2234,7 +2238,7 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t, if ((t & 1) == 0) { m = floor_log2 (t & -t); /* m = number of low zero bits */ - if (m < BITS_PER_WORD) + if (m < maxm) { q = t >> m; cost = shift_cost[mode][m]; @@ -2319,7 +2323,7 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t, unsigned HOST_WIDE_INT d; d = ((unsigned HOST_WIDE_INT) 1 << m) + 1; - if (t % d == 0 && t > d && m < BITS_PER_WORD) + if (t % d == 0 && t > d && m < maxm) { cost = add_cost[mode] + shift_cost[mode][m]; if (shiftadd_cost[mode][m] < cost) @@ -2340,7 +2344,7 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t, } d = ((unsigned HOST_WIDE_INT) 1 << m) - 1; - if (t % d == 0 && t > d && m < BITS_PER_WORD) + if (t % d == 0 && t > d && m < maxm) { cost = add_cost[mode] + shift_cost[mode][m]; if (shiftsub_cost[mode][m] < cost) @@ -2367,7 +2371,7 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t, q = t - 1; q = q & -q; m = exact_log2 (q); - if (m >= 0 && m < BITS_PER_WORD) + if (m >= 0 && m < maxm) { cost = shiftadd_cost[mode][m]; synth_mult (alg_in, (t - 1) >> m, cost_limit - cost, mode); @@ -2386,7 +2390,7 @@ synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t, q = t + 1; q = q & -q; m = exact_log2 (q); - if (m >= 0 && m < BITS_PER_WORD) + if (m >= 0 && m < maxm) { cost = shiftsub_cost[mode][m]; synth_mult (alg_in, (t + 1) >> m, cost_limit - cost, mode); |