* [PATCH] Add machine mode argument to synth_mult
@ 2004-06-10 19:30 Roger Sayle
2004-06-10 22:18 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2004-06-10 19:30 UTC (permalink / raw)
To: gcc-patches
The following patch adds a "mode" argument to expmed.c's synth_mult
so that the costs of primitive operations use the appropriate values
for the mode/width of the multiplication.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with
a top-level "make -k check" with no new failures.
Ok for mainline?
2004-06-10 Roger Sayle <roger@eyesopen.com>
* expmed.c (synth_mult): Add an additional MODE argument for the
machine mode of the multiplication. Update recursive calls. Use
mode instead of word_mode for determining operation costs.
(choose_mult_variant): Update calls to synth_mult with "mode".
Index: expmed.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expmed.c,v
retrieving revision 1.163
diff -c -3 -p -r1.163 expmed.c
*** expmed.c 9 Jun 2004 21:00:35 -0000 1.163
--- expmed.c 10 Jun 2004 14:11:59 -0000
*************** struct algorithm
*** 2153,2159 ****
multiplicand should be added to the result. */
enum mult_variant {basic_variant, negate_variant, add_variant};
! static void synth_mult (struct algorithm *, unsigned HOST_WIDE_INT, int);
static bool choose_mult_variant (enum machine_mode, HOST_WIDE_INT,
struct algorithm *, enum mult_variant *, int);
static rtx expand_mult_const (enum machine_mode, rtx, HOST_WIDE_INT, rtx,
--- 2153,2160 ----
multiplicand should be added to the result. */
enum mult_variant {basic_variant, negate_variant, add_variant};
! static void synth_mult (struct algorithm *, unsigned HOST_WIDE_INT,
! int, enum machine_mode mode);
static bool choose_mult_variant (enum machine_mode, HOST_WIDE_INT,
struct algorithm *, enum mult_variant *, int);
static rtx expand_mult_const (enum machine_mode, rtx, HOST_WIDE_INT, rtx,
*************** static rtx expand_mult_highpart_optab (e
*** 2168,2178 ****
/* Compute and return the best algorithm for multiplying by T.
The algorithm must cost less than cost_limit
If retval.cost >= COST_LIMIT, no algorithm was found and all
! other field of the returned struct are undefined. */
static void
synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t,
! int cost_limit)
{
int m;
struct algorithm *alg_in, *best_alg;
--- 2169,2180 ----
/* Compute and return the best algorithm for multiplying by T.
The algorithm must cost less than cost_limit
If retval.cost >= COST_LIMIT, no algorithm was found and all
! other field of the returned struct are undefined.
! MODE is the machine mode of the multiplication. */
static void
synth_mult (struct algorithm *alg_out, unsigned HOST_WIDE_INT t,
! int cost_limit, enum machine_mode mode)
{
int m;
struct algorithm *alg_in, *best_alg;
*************** synth_mult (struct algorithm *alg_out, u
*** 2225,2231 ****
{
q = t >> m;
cost = shift_cost[m];
! synth_mult (alg_in, q, cost_limit - cost);
cost += alg_in->cost;
if (cost < cost_limit)
--- 2227,2233 ----
{
q = t >> m;
cost = shift_cost[m];
! synth_mult (alg_in, q, cost_limit - cost, mode);
cost += alg_in->cost;
if (cost < cost_limit)
*************** synth_mult (struct algorithm *alg_out, u
*** 2259,2266 ****
{
/* T ends with ...111. Multiply by (T + 1) and subtract 1. */
! cost = add_cost[word_mode];
! synth_mult (alg_in, t + 1, cost_limit - cost);
cost += alg_in->cost;
if (cost < cost_limit)
--- 2261,2268 ----
{
/* T ends with ...111. Multiply by (T + 1) and subtract 1. */
! cost = add_cost[mode];
! synth_mult (alg_in, t + 1, cost_limit - cost, mode);
cost += alg_in->cost;
if (cost < cost_limit)
*************** synth_mult (struct algorithm *alg_out, u
*** 2276,2283 ****
{
/* T ends with ...01 or ...011. Multiply by (T - 1) and add 1. */
! cost = add_cost[word_mode];
! synth_mult (alg_in, t - 1, cost_limit - cost);
cost += alg_in->cost;
if (cost < cost_limit)
--- 2278,2285 ----
{
/* T ends with ...01 or ...011. Multiply by (T - 1) and add 1. */
! cost = add_cost[mode];
! synth_mult (alg_in, t - 1, cost_limit - cost, mode);
cost += alg_in->cost;
if (cost < cost_limit)
*************** synth_mult (struct algorithm *alg_out, u
*** 2308,2317 ****
d = ((unsigned HOST_WIDE_INT) 1 << m) + 1;
if (t % d == 0 && t > d && m < BITS_PER_WORD)
{
! cost = add_cost[word_mode] + shift_cost[m];
if (shiftadd_cost[m] < cost)
cost = shiftadd_cost[m];
! synth_mult (alg_in, t / d, cost_limit - cost);
cost += alg_in->cost;
if (cost < cost_limit)
--- 2310,2319 ----
d = ((unsigned HOST_WIDE_INT) 1 << m) + 1;
if (t % d == 0 && t > d && m < BITS_PER_WORD)
{
! cost = add_cost[mode] + shift_cost[m];
if (shiftadd_cost[m] < cost)
cost = shiftadd_cost[m];
! synth_mult (alg_in, t / d, cost_limit - cost, mode);
cost += alg_in->cost;
if (cost < cost_limit)
*************** synth_mult (struct algorithm *alg_out, u
*** 2329,2338 ****
d = ((unsigned HOST_WIDE_INT) 1 << m) - 1;
if (t % d == 0 && t > d && m < BITS_PER_WORD)
{
! cost = add_cost[word_mode] + shift_cost[m];
if (shiftsub_cost[m] < cost)
cost = shiftsub_cost[m];
! synth_mult (alg_in, t / d, cost_limit - cost);
cost += alg_in->cost;
if (cost < cost_limit)
--- 2331,2340 ----
d = ((unsigned HOST_WIDE_INT) 1 << m) - 1;
if (t % d == 0 && t > d && m < BITS_PER_WORD)
{
! cost = add_cost[mode] + shift_cost[m];
if (shiftsub_cost[m] < cost)
cost = shiftsub_cost[m];
! synth_mult (alg_in, t / d, cost_limit - cost, mode);
cost += alg_in->cost;
if (cost < cost_limit)
*************** synth_mult (struct algorithm *alg_out, u
*** 2357,2363 ****
if (m >= 0 && m < BITS_PER_WORD)
{
cost = shiftadd_cost[m];
! synth_mult (alg_in, (t - 1) >> m, cost_limit - cost);
cost += alg_in->cost;
if (cost < cost_limit)
--- 2359,2365 ----
if (m >= 0 && m < BITS_PER_WORD)
{
cost = shiftadd_cost[m];
! synth_mult (alg_in, (t - 1) >> m, cost_limit - cost, mode);
cost += alg_in->cost;
if (cost < cost_limit)
*************** synth_mult (struct algorithm *alg_out, u
*** 2376,2382 ****
if (m >= 0 && m < BITS_PER_WORD)
{
cost = shiftsub_cost[m];
! synth_mult (alg_in, (t + 1) >> m, cost_limit - cost);
cost += alg_in->cost;
if (cost < cost_limit)
--- 2378,2384 ----
if (m >= 0 && m < BITS_PER_WORD)
{
cost = shiftsub_cost[m];
! synth_mult (alg_in, (t + 1) >> m, cost_limit - cost, mode);
cost += alg_in->cost;
if (cost < cost_limit)
*************** choose_mult_variant (enum machine_mode m
*** 2429,2450 ****
struct algorithm alg2;
*variant = basic_variant;
! synth_mult (alg, val, mult_cost);
/* This works only if the inverted value actually fits in an
`unsigned int' */
if (HOST_BITS_PER_INT >= GET_MODE_BITSIZE (mode))
{
! synth_mult (&alg2, -val, MIN (alg->cost, mult_cost)
! - neg_cost[mode]);
alg2.cost += neg_cost[mode];
if (alg2.cost < alg->cost)
*alg = alg2, *variant = negate_variant;
}
/* This proves very useful for division-by-constant. */
! synth_mult (&alg2, val - 1, MIN (alg->cost, mult_cost)
! - add_cost[mode]);
alg2.cost += add_cost[mode];
if (alg2.cost < alg->cost)
*alg = alg2, *variant = add_variant;
--- 2431,2452 ----
struct algorithm alg2;
*variant = basic_variant;
! synth_mult (alg, val, mult_cost, mode);
/* This works only if the inverted value actually fits in an
`unsigned int' */
if (HOST_BITS_PER_INT >= GET_MODE_BITSIZE (mode))
{
! synth_mult (&alg2, -val, MIN (alg->cost, mult_cost) - neg_cost[mode],
! mode);
alg2.cost += neg_cost[mode];
if (alg2.cost < alg->cost)
*alg = alg2, *variant = negate_variant;
}
/* This proves very useful for division-by-constant. */
! synth_mult (&alg2, val - 1, MIN (alg->cost, mult_cost) - add_cost[mode],
! mode);
alg2.cost += add_cost[mode];
if (alg2.cost < alg->cost)
*alg = alg2, *variant = add_variant;
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Add machine mode argument to synth_mult
2004-06-10 19:30 [PATCH] Add machine mode argument to synth_mult Roger Sayle
@ 2004-06-10 22:18 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2004-06-10 22:18 UTC (permalink / raw)
To: Roger Sayle; +Cc: gcc-patches
On Thu, Jun 10, 2004 at 12:05:52PM -0600, Roger Sayle wrote:
> * expmed.c (synth_mult): Add an additional MODE argument for the
> machine mode of the multiplication. Update recursive calls. Use
> mode instead of word_mode for determining operation costs.
> (choose_mult_variant): Update calls to synth_mult with "mode".
Ok.
r~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-06-10 21:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-10 19:30 [PATCH] Add machine mode argument to synth_mult Roger Sayle
2004-06-10 22:18 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).