expmed.h 21 KB
Newer Older
1
/* Target-dependent costs for expmed.c.
2
   Copyright (C) 1987-2018 Free Software Foundation, Inc.
3 4 5 6 7

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
8
Software Foundation; either version 3, or (at your option) any later
9 10 11 12 13 14 15 16 17 18 19 20 21 22
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

#ifndef EXPMED_H
#define EXPMED_H 1

23 24
#include "insn-codes.h"

Richard Sandiford committed
25 26 27 28 29 30 31 32 33 34 35 36 37
enum alg_code {
  alg_unknown,
  alg_zero,
  alg_m, alg_shift,
  alg_add_t_m2,
  alg_sub_t_m2,
  alg_add_factor,
  alg_sub_factor,
  alg_add_t2_m,
  alg_sub_t2_m,
  alg_impossible
};

38 39 40 41 42 43 44 45 46
/* Indicates the type of fixup needed after a constant multiplication.
   BASIC_VARIANT means no fixup is needed, NEGATE_VARIANT means that
   the result should be negated, and ADD_VARIANT means that the
   multiplicand should be added to the result.  */
enum mult_variant {basic_variant, negate_variant, add_variant};

bool choose_mult_variant (machine_mode, HOST_WIDE_INT,
			  struct algorithm *, enum mult_variant *, int);

Richard Sandiford committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/* This structure holds the "cost" of a multiply sequence.  The
   "cost" field holds the total rtx_cost of every operator in the
   synthetic multiplication sequence, hence cost(a op b) is defined
   as rtx_cost(op) + cost(a) + cost(b), where cost(leaf) is zero.
   The "latency" field holds the minimum possible latency of the
   synthetic multiply, on a hypothetical infinitely parallel CPU.
   This is the critical path, or the maximum height, of the expression
   tree which is the sum of rtx_costs on the most expensive path from
   any leaf to the root.  Hence latency(a op b) is defined as zero for
   leaves and rtx_cost(op) + max(latency(a), latency(b)) otherwise.  */

struct mult_cost {
  short cost;     /* Total rtx_cost of the multiplication sequence.  */
  short latency;  /* The latency of the multiplication sequence.  */
};

/* This macro is used to compare a pointer to a mult_cost against an
   single integer "rtx_cost" value.  This is equivalent to the macro
   CHEAPER_MULT_COST(X,Z) where Z = {Y,Y}.  */
#define MULT_COST_LESS(X,Y) ((X)->cost < (Y)	\
			     || ((X)->cost == (Y) && (X)->latency < (Y)))

/* This macro is used to compare two pointers to mult_costs against
   each other.  The macro returns true if X is cheaper than Y.
   Currently, the cheaper of two mult_costs is the one with the
   lower "cost".  If "cost"s are tied, the lower latency is cheaper.  */
#define CHEAPER_MULT_COST(X,Y)  ((X)->cost < (Y)->cost		\
				 || ((X)->cost == (Y)->cost	\
				     && (X)->latency < (Y)->latency))

/* This structure records a sequence of operations.
   `ops' is the number of operations recorded.
   `cost' is their total cost.
   The operations are stored in `op' and the corresponding
   logarithms of the integer coefficients in `log'.

   These are the operations:
   alg_zero		total := 0;
   alg_m		total := multiplicand;
   alg_shift		total := total * coeff
   alg_add_t_m2		total := total + multiplicand * coeff;
   alg_sub_t_m2		total := total - multiplicand * coeff;
   alg_add_factor	total := total * coeff + total;
   alg_sub_factor	total := total * coeff - total;
   alg_add_t2_m		total := total * coeff + multiplicand;
   alg_sub_t2_m		total := total * coeff - multiplicand;

   The first operand must be either alg_zero or alg_m.  */

struct algorithm
{
  struct mult_cost cost;
  short ops;
  /* The size of the OP and LOG fields are not directly related to the
     word size, but the worst-case algorithms will be if we have few
     consecutive ones or zeros, i.e., a multiplicand like 10101010101...
     In that case we will generate shift-by-2, add, shift-by-2, add,...,
     in total wordsize operations.  */
  enum alg_code op[MAX_BITS_PER_WORD];
  char log[MAX_BITS_PER_WORD];
};

/* The entry for our multiplication cache/hash table.  */
struct alg_hash_entry {
  /* The number we are multiplying by.  */
  unsigned HOST_WIDE_INT t;

  /* The mode in which we are multiplying something by T.  */
115
  machine_mode mode;
Richard Sandiford committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

  /* The best multiplication algorithm for t.  */
  enum alg_code alg;

  /* The cost of multiplication if ALG_CODE is not alg_impossible.
     Otherwise, the cost within which multiplication by T is
     impossible.  */
  struct mult_cost cost;

  /* Optimized for speed? */
  bool speed;
};

/* The number of cache/hash entries.  */
#if HOST_BITS_PER_WIDE_INT == 64
#define NUM_ALG_HASH_ENTRIES 1031
#else
#define NUM_ALG_HASH_ENTRIES 307
#endif

136 137 138
#define NUM_MODE_INT \
  (MAX_MODE_INT - MIN_MODE_INT + 1)
#define NUM_MODE_PARTIAL_INT \
139
  (MIN_MODE_PARTIAL_INT == E_VOIDmode ? 0 \
140 141
   : MAX_MODE_PARTIAL_INT - MIN_MODE_PARTIAL_INT + 1)
#define NUM_MODE_VECTOR_INT \
142
  (MIN_MODE_VECTOR_INT == E_VOIDmode ? 0 \
143 144 145 146
   : MAX_MODE_VECTOR_INT - MIN_MODE_VECTOR_INT + 1)

#define NUM_MODE_IP_INT (NUM_MODE_INT + NUM_MODE_PARTIAL_INT)
#define NUM_MODE_IPV_INT (NUM_MODE_IP_INT + NUM_MODE_VECTOR_INT)
147 148

struct expmed_op_cheap {
149
  bool cheap[2][NUM_MODE_IPV_INT];
150 151 152
};

struct expmed_op_costs {
153
  int cost[2][NUM_MODE_IPV_INT];
154
};
155

156 157
/* Target-dependent globals.  */
struct target_expmed {
Richard Sandiford committed
158 159 160 161 162 163 164 165
  /* Each entry of ALG_HASH caches alg_code for some integer.  This is
     actually a hash table.  If we have a collision, that the older
     entry is kicked out.  */
  struct alg_hash_entry x_alg_hash[NUM_ALG_HASH_ENTRIES];

  /* True if x_alg_hash might already have been used.  */
  bool x_alg_hash_used_p;

166 167 168 169
  /* Nonzero means divides or modulus operations are relatively cheap for
     powers of two, so don't use branches; emit the operation instead.
     Usually, this will mean that the MD file will emit non-branch
     sequences.  */
170 171
  struct expmed_op_cheap x_sdiv_pow2_cheap;
  struct expmed_op_cheap x_smod_pow2_cheap;
172 173 174 175

  /* Cost of various pieces of RTL.  Note that some of these are indexed by
     shift count and some by mode.  */
  int x_zero_cost[2];
176 177 178 179 180 181 182 183 184 185 186
  struct expmed_op_costs x_add_cost;
  struct expmed_op_costs x_neg_cost;
  struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD];
  struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD];
  struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD];
  struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD];
  struct expmed_op_costs x_mul_cost;
  struct expmed_op_costs x_sdiv_cost;
  struct expmed_op_costs x_udiv_cost;
  int x_mul_widen_cost[2][NUM_MODE_INT];
  int x_mul_highpart_cost[2][NUM_MODE_INT];
187 188 189 190

  /* Conversion costs are only defined between two scalar integer modes
     of different sizes.  The first machine mode is the destination mode,
     and the second is the source mode.  */
191
  int x_convert_cost[2][NUM_MODE_IP_INT][NUM_MODE_IP_INT];
192 193 194 195 196 197 198 199 200
};

extern struct target_expmed default_target_expmed;
#if SWITCHABLE_TARGET
extern struct target_expmed *this_target_expmed;
#else
#define this_target_expmed (&default_target_expmed)
#endif

201
/* Return a pointer to the alg_hash_entry at IDX.  */
202

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
static inline struct alg_hash_entry *
alg_hash_entry_ptr (int idx)
{
  return &this_target_expmed->x_alg_hash[idx];
}

/* Return true if the x_alg_hash field might have been used.  */

static inline bool
alg_hash_used_p (void)
{
  return this_target_expmed->x_alg_hash_used_p;
}

/* Set whether the x_alg_hash field might have been used.  */

static inline void
set_alg_hash_used_p (bool usedp)
{
  this_target_expmed->x_alg_hash_used_p = usedp;
}

225 226 227
/* Compute an index into the cost arrays by mode class.  */

static inline int
228
expmed_mode_index (machine_mode mode)
229 230 231 232 233 234
{
  switch (GET_MODE_CLASS (mode))
    {
    case MODE_INT:
      return mode - MIN_MODE_INT;
    case MODE_PARTIAL_INT:
235 236 237 238 239
      /* If there are no partial integer modes, help the compiler
	 to figure out this will never happen.  See PR59934.  */
      if (MIN_MODE_PARTIAL_INT != VOIDmode)
	return mode - MIN_MODE_PARTIAL_INT + NUM_MODE_INT;
      break;
240
    case MODE_VECTOR_INT:
241 242 243 244 245
      /* If there are no vector integer modes, help the compiler
	 to figure out this will never happen.  See PR59934.  */
      if (MIN_MODE_VECTOR_INT != VOIDmode)
	return mode - MIN_MODE_VECTOR_INT + NUM_MODE_IP_INT;
      break;
246
    default:
247
      break;
248
    }
249
  gcc_unreachable ();
250 251
}

252 253 254 255 256 257
/* Return a pointer to a boolean contained in EOC indicating whether
   a particular operation performed in MODE is cheap when optimizing
   for SPEED.  */

static inline bool *
expmed_op_cheap_ptr (struct expmed_op_cheap *eoc, bool speed,
258
		     machine_mode mode)
259
{
260 261
  int idx = expmed_mode_index (mode);
  return &eoc->cheap[speed][idx];
262 263 264 265 266 267 268
}

/* Return a pointer to a cost contained in COSTS when a particular
   operation is performed in MODE when optimizing for SPEED.  */

static inline int *
expmed_op_cost_ptr (struct expmed_op_costs *costs, bool speed,
269
		    machine_mode mode)
270
{
271 272
  int idx = expmed_mode_index (mode);
  return &costs->cost[speed][idx];
273 274
}

275 276 277
/* Subroutine of {set_,}sdiv_pow2_cheap.  Not to be used otherwise.  */

static inline bool *
278
sdiv_pow2_cheap_ptr (bool speed, machine_mode mode)
279
{
280 281
  return expmed_op_cheap_ptr (&this_target_expmed->x_sdiv_pow2_cheap,
			      speed, mode);
282 283 284 285 286 287
}

/* Set whether a signed division by a power of 2 is cheap in MODE
   when optimizing for SPEED.  */

static inline void
288
set_sdiv_pow2_cheap (bool speed, machine_mode mode, bool cheap_p)
289 290 291 292 293 294 295 296
{
  *sdiv_pow2_cheap_ptr (speed, mode) = cheap_p;
}

/* Return whether a signed division by a power of 2 is cheap in MODE
   when optimizing for SPEED.  */

static inline bool
297
sdiv_pow2_cheap (bool speed, machine_mode mode)
298 299 300 301 302 303 304
{
  return *sdiv_pow2_cheap_ptr (speed, mode);
}

/* Subroutine of {set_,}smod_pow2_cheap.  Not to be used otherwise.  */

static inline bool *
305
smod_pow2_cheap_ptr (bool speed, machine_mode mode)
306
{
307 308
  return expmed_op_cheap_ptr (&this_target_expmed->x_smod_pow2_cheap,
			      speed, mode);
309 310 311 312 313 314
}

/* Set whether a signed modulo by a power of 2 is CHEAP in MODE when
   optimizing for SPEED.  */

static inline void
315
set_smod_pow2_cheap (bool speed, machine_mode mode, bool cheap)
316 317 318 319 320 321 322 323
{
  *smod_pow2_cheap_ptr (speed, mode) = cheap;
}

/* Return whether a signed modulo by a power of 2 is cheap in MODE
   when optimizing for SPEED.  */

static inline bool
324
smod_pow2_cheap (bool speed, machine_mode mode)
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
{
  return *smod_pow2_cheap_ptr (speed, mode);
}

/* Subroutine of {set_,}zero_cost.  Not to be used otherwise.  */

static inline int *
zero_cost_ptr (bool speed)
{
  return &this_target_expmed->x_zero_cost[speed];
}

/* Set the COST of loading zero when optimizing for SPEED.  */

static inline void
set_zero_cost (bool speed, int cost)
{
  *zero_cost_ptr (speed) = cost;
}

/* Return the COST of loading zero when optimizing for SPEED.  */

static inline int
zero_cost (bool speed)
{
  return *zero_cost_ptr (speed);
}

/* Subroutine of {set_,}add_cost.  Not to be used otherwise.  */

static inline int *
356
add_cost_ptr (bool speed, machine_mode mode)
357
{
358
  return expmed_op_cost_ptr (&this_target_expmed->x_add_cost, speed, mode);
359 360 361 362 363
}

/* Set the COST of computing an add in MODE when optimizing for SPEED.  */

static inline void
364
set_add_cost (bool speed, machine_mode mode, int cost)
365 366 367 368 369 370 371
{
  *add_cost_ptr (speed, mode) = cost;
}

/* Return the cost of computing an add in MODE when optimizing for SPEED.  */

static inline int
372
add_cost (bool speed, machine_mode mode)
373 374 375 376 377 378 379
{
  return *add_cost_ptr (speed, mode);
}

/* Subroutine of {set_,}neg_cost.  Not to be used otherwise.  */

static inline int *
380
neg_cost_ptr (bool speed, machine_mode mode)
381
{
382
  return expmed_op_cost_ptr (&this_target_expmed->x_neg_cost, speed, mode);
383 384 385 386 387
}

/* Set the COST of computing a negation in MODE when optimizing for SPEED.  */

static inline void
388
set_neg_cost (bool speed, machine_mode mode, int cost)
389 390 391 392 393 394 395 396
{
  *neg_cost_ptr (speed, mode) = cost;
}

/* Return the cost of computing a negation in MODE when optimizing for
   SPEED.  */

static inline int
397
neg_cost (bool speed, machine_mode mode)
398 399 400 401 402 403 404
{
  return *neg_cost_ptr (speed, mode);
}

/* Subroutine of {set_,}shift_cost.  Not to be used otherwise.  */

static inline int *
405
shift_cost_ptr (bool speed, machine_mode mode, int bits)
406
{
407 408
  return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits],
			     speed, mode);
409 410 411 412 413
}

/* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED.  */

static inline void
414
set_shift_cost (bool speed, machine_mode mode, int bits, int cost)
415 416 417 418 419 420 421 422
{
  *shift_cost_ptr (speed, mode, bits) = cost;
}

/* Return the cost of doing a shift in MODE by BITS when optimizing for
   SPEED.  */

static inline int
423
shift_cost (bool speed, machine_mode mode, int bits)
424 425 426 427 428 429 430
{
  return *shift_cost_ptr (speed, mode, bits);
}

/* Subroutine of {set_,}shiftadd_cost.  Not to be used otherwise.  */

static inline int *
431
shiftadd_cost_ptr (bool speed, machine_mode mode, int bits)
432
{
433 434
  return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits],
			     speed, mode);
435 436 437 438 439 440
}

/* Set the COST of doing a shift in MODE by BITS followed by an add when
   optimizing for SPEED.  */

static inline void
441
set_shiftadd_cost (bool speed, machine_mode mode, int bits, int cost)
442 443 444 445 446 447 448 449
{
  *shiftadd_cost_ptr (speed, mode, bits) = cost;
}

/* Return the cost of doing a shift in MODE by BITS followed by an add
   when optimizing for SPEED.  */

static inline int
450
shiftadd_cost (bool speed, machine_mode mode, int bits)
451 452 453 454 455 456 457
{
  return *shiftadd_cost_ptr (speed, mode, bits);
}

/* Subroutine of {set_,}shiftsub0_cost.  Not to be used otherwise.  */

static inline int *
458
shiftsub0_cost_ptr (bool speed, machine_mode mode, int bits)
459
{
460 461
  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits],
			     speed, mode);
462 463 464 465 466 467
}

/* Set the COST of doing a shift in MODE by BITS and then subtracting a
   value when optimizing for SPEED.  */

static inline void
468
set_shiftsub0_cost (bool speed, machine_mode mode, int bits, int cost)
469 470 471 472 473 474 475 476
{
  *shiftsub0_cost_ptr (speed, mode, bits) = cost;
}

/* Return the cost of doing a shift in MODE by BITS and then subtracting
   a value when optimizing for SPEED.  */

static inline int
477
shiftsub0_cost (bool speed, machine_mode mode, int bits)
478 479 480 481 482 483 484
{
  return *shiftsub0_cost_ptr (speed, mode, bits);
}

/* Subroutine of {set_,}shiftsub1_cost.  Not to be used otherwise.  */

static inline int *
485
shiftsub1_cost_ptr (bool speed, machine_mode mode, int bits)
486
{
487 488
  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits],
			     speed, mode);
489 490 491 492 493 494
}

/* Set the COST of subtracting a shift in MODE by BITS from a value when
   optimizing for SPEED.  */

static inline void
495
set_shiftsub1_cost (bool speed, machine_mode mode, int bits, int cost)
496 497 498 499 500 501 502 503
{
  *shiftsub1_cost_ptr (speed, mode, bits) = cost;
}

/* Return the cost of subtracting a shift in MODE by BITS from a value
   when optimizing for SPEED.  */

static inline int
504
shiftsub1_cost (bool speed, machine_mode mode, int bits)
505 506 507 508 509 510 511
{
  return *shiftsub1_cost_ptr (speed, mode, bits);
}

/* Subroutine of {set_,}mul_cost.  Not to be used otherwise.  */

static inline int *
512
mul_cost_ptr (bool speed, machine_mode mode)
513
{
514
  return expmed_op_cost_ptr (&this_target_expmed->x_mul_cost, speed, mode);
515 516 517 518 519 520
}

/* Set the COST of doing a multiplication in MODE when optimizing for
   SPEED.  */

static inline void
521
set_mul_cost (bool speed, machine_mode mode, int cost)
522 523 524 525 526 527 528 529
{
  *mul_cost_ptr (speed, mode) = cost;
}

/* Return the cost of doing a multiplication in MODE when optimizing
   for SPEED.  */

static inline int
530
mul_cost (bool speed, machine_mode mode)
531 532 533 534 535 536 537
{
  return *mul_cost_ptr (speed, mode);
}

/* Subroutine of {set_,}sdiv_cost.  Not to be used otherwise.  */

static inline int *
538
sdiv_cost_ptr (bool speed, machine_mode mode)
539
{
540
  return expmed_op_cost_ptr (&this_target_expmed->x_sdiv_cost, speed, mode);
541 542 543
}

/* Set the COST of doing a signed division in MODE when optimizing
544 545 546
   for SPEED.  */

static inline void
547
set_sdiv_cost (bool speed, machine_mode mode, int cost)
548 549 550 551 552 553 554 555
{
  *sdiv_cost_ptr (speed, mode) = cost;
}

/* Return the cost of doing a signed division in MODE when optimizing
   for SPEED.  */

static inline int
556
sdiv_cost (bool speed, machine_mode mode)
557 558 559 560 561 562 563
{
  return *sdiv_cost_ptr (speed, mode);
}

/* Subroutine of {set_,}udiv_cost.  Not to be used otherwise.  */

static inline int *
564
udiv_cost_ptr (bool speed, machine_mode mode)
565
{
566
  return expmed_op_cost_ptr (&this_target_expmed->x_udiv_cost, speed, mode);
567 568 569 570 571 572
}

/* Set the COST of doing an unsigned division in MODE when optimizing
   for SPEED.  */

static inline void
573
set_udiv_cost (bool speed, machine_mode mode, int cost)
574 575 576 577 578 579 580 581
{
  *udiv_cost_ptr (speed, mode) = cost;
}

/* Return the cost of doing an unsigned division in MODE when
   optimizing for SPEED.  */

static inline int
582
udiv_cost (bool speed, machine_mode mode)
583 584 585 586 587 588 589
{
  return *udiv_cost_ptr (speed, mode);
}

/* Subroutine of {set_,}mul_widen_cost.  Not to be used otherwise.  */

static inline int *
590
mul_widen_cost_ptr (bool speed, machine_mode mode)
591
{
592 593 594
  gcc_assert (GET_MODE_CLASS (mode) == MODE_INT);

  return &this_target_expmed->x_mul_widen_cost[speed][mode - MIN_MODE_INT];
595 596 597 598 599 600
}

/* Set the COST for computing a widening multiplication in MODE when
   optimizing for SPEED.  */

static inline void
601
set_mul_widen_cost (bool speed, machine_mode mode, int cost)
602 603 604 605 606 607 608 609
{
  *mul_widen_cost_ptr (speed, mode) = cost;
}

/* Return the cost for computing a widening multiplication in MODE when
   optimizing for SPEED.  */

static inline int
610
mul_widen_cost (bool speed, machine_mode mode)
611 612 613 614 615 616 617
{
  return *mul_widen_cost_ptr (speed, mode);
}

/* Subroutine of {set_,}mul_highpart_cost.  Not to be used otherwise.  */

static inline int *
618
mul_highpart_cost_ptr (bool speed, machine_mode mode)
619
{
620
  gcc_assert (GET_MODE_CLASS (mode) == MODE_INT);
621 622
  int m = mode - MIN_MODE_INT;
  gcc_assert (m < NUM_MODE_INT);
623

624
  return &this_target_expmed->x_mul_highpart_cost[speed][m];
625 626 627 628 629 630
}

/* Set the COST for computing the high part of a multiplication in MODE
   when optimizing for SPEED.  */

static inline void
631
set_mul_highpart_cost (bool speed, machine_mode mode, int cost)
632 633 634 635 636 637 638 639
{
  *mul_highpart_cost_ptr (speed, mode) = cost;
}

/* Return the cost for computing the high part of a multiplication in MODE
   when optimizing for SPEED.  */

static inline int
640
mul_highpart_cost (bool speed, machine_mode mode)
641 642 643 644 645 646 647
{
  return *mul_highpart_cost_ptr (speed, mode);
}

/* Subroutine of {set_,}convert_cost.  Not to be used otherwise.  */

static inline int *
648
convert_cost_ptr (machine_mode to_mode, machine_mode from_mode,
649
		  bool speed)
650
{
651 652
  int to_idx = expmed_mode_index (to_mode);
  int from_idx = expmed_mode_index (from_mode);
653

654 655
  gcc_assert (IN_RANGE (to_idx, 0, NUM_MODE_IP_INT - 1));
  gcc_assert (IN_RANGE (from_idx, 0, NUM_MODE_IP_INT - 1));
656

657 658 659 660 661 662 663
  return &this_target_expmed->x_convert_cost[speed][to_idx][from_idx];
}

/* Set the COST for converting from FROM_MODE to TO_MODE when optimizing
   for SPEED.  */

static inline void
664
set_convert_cost (machine_mode to_mode, machine_mode from_mode,
665 666 667
		  bool speed, int cost)
{
  *convert_cost_ptr (to_mode, from_mode, speed) = cost;
668 669 670 671 672 673
}

/* Return the cost for converting from FROM_MODE to TO_MODE when optimizing
   for SPEED.  */

static inline int
674
convert_cost (machine_mode to_mode, machine_mode from_mode,
675 676
	      bool speed)
{
677
  return *convert_cost_ptr (to_mode, from_mode, speed);
678 679
}

680
extern int mult_by_coeff_cost (HOST_WIDE_INT, machine_mode, bool);
681
extern rtx emit_cstore (rtx target, enum insn_code icode, enum rtx_code code,
682
			machine_mode mode, machine_mode compare_mode,
683
			int unsignedp, rtx x, rtx y, int normalizep,
684
			machine_mode target_mode);
685 686 687 688 689

/* Arguments MODE, RTX: return an rtx for the negation of that value.
   May emit insns.  */
extern rtx negate_rtx (machine_mode, rtx);

690 691
/* Arguments MODE, RTX: return an rtx for the flipping of that value.
   May emit insns.  */
692
extern rtx flip_storage_order (machine_mode, rtx);
693

694 695 696 697 698 699 700 701 702 703 704
/* Expand a logical AND operation.  */
extern rtx expand_and (machine_mode, rtx, rtx, rtx);

/* Emit a store-flag operation.  */
extern rtx emit_store_flag (rtx, enum rtx_code, rtx, rtx, machine_mode,
			    int, int);

/* Like emit_store_flag, but always succeeds.  */
extern rtx emit_store_flag_force (rtx, enum rtx_code, rtx, rtx,
				  machine_mode, int, int);

705 706
extern void canonicalize_comparison (machine_mode, enum rtx_code *, rtx *);

707 708 709 710 711 712 713 714 715 716
/* Choose a minimal N + 1 bit approximation to 1/D that can be used to
   replace division by D, and put the least significant N bits of the result
   in *MULTIPLIER_PTR and return the most significant bit.  */
extern unsigned HOST_WIDE_INT choose_multiplier (unsigned HOST_WIDE_INT, int,
						 int, unsigned HOST_WIDE_INT *,
						 int *, int *);

#ifdef TREE_CODE
extern rtx expand_variable_shift (enum tree_code, machine_mode,
				  rtx, tree, rtx, int);
717 718
extern rtx expand_shift (enum tree_code, machine_mode, rtx, poly_int64, rtx,
			 int);
719 720
extern rtx expand_divmod (int, enum tree_code, machine_mode, rtx, rtx,
			  rtx, int);
721
#endif
722

723
extern void store_bit_field (rtx, poly_uint64, poly_uint64,
724
			     poly_uint64, poly_uint64,
725
			     machine_mode, rtx, bool);
726
extern rtx extract_bit_field (rtx, poly_uint64, poly_uint64, int, rtx,
727
			      machine_mode, machine_mode, bool, rtx *);
728
extern rtx extract_low_bits (machine_mode, machine_mode, rtx);
729
extern rtx expand_mult (machine_mode, rtx, rtx, rtx, int, bool = false);
730 731
extern rtx expand_mult_highpart_adjust (scalar_int_mode, rtx, rtx, rtx,
					rtx, int);
732

733
#endif  // EXPMED_H