]>
Commit | Line | Data |
---|---|---|
462f85ce | 1 | /* Target-dependent costs for expmed.c. |
23a5b65a | 2 | Copyright (C) 1987-2014 Free Software Foundation, Inc. |
462f85ce RS |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | 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 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef EXPMED_H | |
21 | #define EXPMED_H 1 | |
22 | ||
c371bb73 RS |
23 | enum alg_code { |
24 | alg_unknown, | |
25 | alg_zero, | |
26 | alg_m, alg_shift, | |
27 | alg_add_t_m2, | |
28 | alg_sub_t_m2, | |
29 | alg_add_factor, | |
30 | alg_sub_factor, | |
31 | alg_add_t2_m, | |
32 | alg_sub_t2_m, | |
33 | alg_impossible | |
34 | }; | |
35 | ||
36 | /* This structure holds the "cost" of a multiply sequence. The | |
37 | "cost" field holds the total rtx_cost of every operator in the | |
38 | synthetic multiplication sequence, hence cost(a op b) is defined | |
39 | as rtx_cost(op) + cost(a) + cost(b), where cost(leaf) is zero. | |
40 | The "latency" field holds the minimum possible latency of the | |
41 | synthetic multiply, on a hypothetical infinitely parallel CPU. | |
42 | This is the critical path, or the maximum height, of the expression | |
43 | tree which is the sum of rtx_costs on the most expensive path from | |
44 | any leaf to the root. Hence latency(a op b) is defined as zero for | |
45 | leaves and rtx_cost(op) + max(latency(a), latency(b)) otherwise. */ | |
46 | ||
47 | struct mult_cost { | |
48 | short cost; /* Total rtx_cost of the multiplication sequence. */ | |
49 | short latency; /* The latency of the multiplication sequence. */ | |
50 | }; | |
51 | ||
52 | /* This macro is used to compare a pointer to a mult_cost against an | |
53 | single integer "rtx_cost" value. This is equivalent to the macro | |
54 | CHEAPER_MULT_COST(X,Z) where Z = {Y,Y}. */ | |
55 | #define MULT_COST_LESS(X,Y) ((X)->cost < (Y) \ | |
56 | || ((X)->cost == (Y) && (X)->latency < (Y))) | |
57 | ||
58 | /* This macro is used to compare two pointers to mult_costs against | |
59 | each other. The macro returns true if X is cheaper than Y. | |
60 | Currently, the cheaper of two mult_costs is the one with the | |
61 | lower "cost". If "cost"s are tied, the lower latency is cheaper. */ | |
62 | #define CHEAPER_MULT_COST(X,Y) ((X)->cost < (Y)->cost \ | |
63 | || ((X)->cost == (Y)->cost \ | |
64 | && (X)->latency < (Y)->latency)) | |
65 | ||
66 | /* This structure records a sequence of operations. | |
67 | `ops' is the number of operations recorded. | |
68 | `cost' is their total cost. | |
69 | The operations are stored in `op' and the corresponding | |
70 | logarithms of the integer coefficients in `log'. | |
71 | ||
72 | These are the operations: | |
73 | alg_zero total := 0; | |
74 | alg_m total := multiplicand; | |
75 | alg_shift total := total * coeff | |
76 | alg_add_t_m2 total := total + multiplicand * coeff; | |
77 | alg_sub_t_m2 total := total - multiplicand * coeff; | |
78 | alg_add_factor total := total * coeff + total; | |
79 | alg_sub_factor total := total * coeff - total; | |
80 | alg_add_t2_m total := total * coeff + multiplicand; | |
81 | alg_sub_t2_m total := total * coeff - multiplicand; | |
82 | ||
83 | The first operand must be either alg_zero or alg_m. */ | |
84 | ||
85 | struct algorithm | |
86 | { | |
87 | struct mult_cost cost; | |
88 | short ops; | |
89 | /* The size of the OP and LOG fields are not directly related to the | |
90 | word size, but the worst-case algorithms will be if we have few | |
91 | consecutive ones or zeros, i.e., a multiplicand like 10101010101... | |
92 | In that case we will generate shift-by-2, add, shift-by-2, add,..., | |
93 | in total wordsize operations. */ | |
94 | enum alg_code op[MAX_BITS_PER_WORD]; | |
95 | char log[MAX_BITS_PER_WORD]; | |
96 | }; | |
97 | ||
98 | /* The entry for our multiplication cache/hash table. */ | |
99 | struct alg_hash_entry { | |
100 | /* The number we are multiplying by. */ | |
101 | unsigned HOST_WIDE_INT t; | |
102 | ||
103 | /* The mode in which we are multiplying something by T. */ | |
104 | enum machine_mode mode; | |
105 | ||
106 | /* The best multiplication algorithm for t. */ | |
107 | enum alg_code alg; | |
108 | ||
109 | /* The cost of multiplication if ALG_CODE is not alg_impossible. | |
110 | Otherwise, the cost within which multiplication by T is | |
111 | impossible. */ | |
112 | struct mult_cost cost; | |
113 | ||
114 | /* Optimized for speed? */ | |
115 | bool speed; | |
116 | }; | |
117 | ||
118 | /* The number of cache/hash entries. */ | |
119 | #if HOST_BITS_PER_WIDE_INT == 64 | |
120 | #define NUM_ALG_HASH_ENTRIES 1031 | |
121 | #else | |
122 | #define NUM_ALG_HASH_ENTRIES 307 | |
123 | #endif | |
124 | ||
91f8035e RH |
125 | #define NUM_MODE_INT \ |
126 | (MAX_MODE_INT - MIN_MODE_INT + 1) | |
127 | #define NUM_MODE_PARTIAL_INT \ | |
128 | (MIN_MODE_PARTIAL_INT == VOIDmode ? 0 \ | |
129 | : MAX_MODE_PARTIAL_INT - MIN_MODE_PARTIAL_INT + 1) | |
130 | #define NUM_MODE_VECTOR_INT \ | |
131 | (MIN_MODE_VECTOR_INT == VOIDmode ? 0 \ | |
132 | : MAX_MODE_VECTOR_INT - MIN_MODE_VECTOR_INT + 1) | |
133 | ||
134 | #define NUM_MODE_IP_INT (NUM_MODE_INT + NUM_MODE_PARTIAL_INT) | |
135 | #define NUM_MODE_IPV_INT (NUM_MODE_IP_INT + NUM_MODE_VECTOR_INT) | |
2a261cd3 NF |
136 | |
137 | struct expmed_op_cheap { | |
91f8035e | 138 | bool cheap[2][NUM_MODE_IPV_INT]; |
2a261cd3 NF |
139 | }; |
140 | ||
141 | struct expmed_op_costs { | |
91f8035e | 142 | int cost[2][NUM_MODE_IPV_INT]; |
2a261cd3 | 143 | }; |
6dd8f4bb | 144 | |
462f85ce RS |
145 | /* Target-dependent globals. */ |
146 | struct target_expmed { | |
c371bb73 RS |
147 | /* Each entry of ALG_HASH caches alg_code for some integer. This is |
148 | actually a hash table. If we have a collision, that the older | |
149 | entry is kicked out. */ | |
150 | struct alg_hash_entry x_alg_hash[NUM_ALG_HASH_ENTRIES]; | |
151 | ||
152 | /* True if x_alg_hash might already have been used. */ | |
153 | bool x_alg_hash_used_p; | |
154 | ||
462f85ce RS |
155 | /* Nonzero means divides or modulus operations are relatively cheap for |
156 | powers of two, so don't use branches; emit the operation instead. | |
157 | Usually, this will mean that the MD file will emit non-branch | |
158 | sequences. */ | |
2a261cd3 NF |
159 | struct expmed_op_cheap x_sdiv_pow2_cheap; |
160 | struct expmed_op_cheap x_smod_pow2_cheap; | |
462f85ce RS |
161 | |
162 | /* Cost of various pieces of RTL. Note that some of these are indexed by | |
163 | shift count and some by mode. */ | |
164 | int x_zero_cost[2]; | |
2a261cd3 NF |
165 | struct expmed_op_costs x_add_cost; |
166 | struct expmed_op_costs x_neg_cost; | |
167 | struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD]; | |
168 | struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD]; | |
169 | struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD]; | |
170 | struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD]; | |
171 | struct expmed_op_costs x_mul_cost; | |
172 | struct expmed_op_costs x_sdiv_cost; | |
173 | struct expmed_op_costs x_udiv_cost; | |
174 | int x_mul_widen_cost[2][NUM_MODE_INT]; | |
175 | int x_mul_highpart_cost[2][NUM_MODE_INT]; | |
6dd8f4bb BS |
176 | |
177 | /* Conversion costs are only defined between two scalar integer modes | |
178 | of different sizes. The first machine mode is the destination mode, | |
179 | and the second is the source mode. */ | |
91f8035e | 180 | int x_convert_cost[2][NUM_MODE_IP_INT][NUM_MODE_IP_INT]; |
462f85ce RS |
181 | }; |
182 | ||
183 | extern struct target_expmed default_target_expmed; | |
184 | #if SWITCHABLE_TARGET | |
185 | extern struct target_expmed *this_target_expmed; | |
186 | #else | |
187 | #define this_target_expmed (&default_target_expmed) | |
188 | #endif | |
189 | ||
5322d07e | 190 | /* Return a pointer to the alg_hash_entry at IDX. */ |
462f85ce | 191 | |
5322d07e NF |
192 | static inline struct alg_hash_entry * |
193 | alg_hash_entry_ptr (int idx) | |
194 | { | |
195 | return &this_target_expmed->x_alg_hash[idx]; | |
196 | } | |
197 | ||
198 | /* Return true if the x_alg_hash field might have been used. */ | |
199 | ||
200 | static inline bool | |
201 | alg_hash_used_p (void) | |
202 | { | |
203 | return this_target_expmed->x_alg_hash_used_p; | |
204 | } | |
205 | ||
206 | /* Set whether the x_alg_hash field might have been used. */ | |
207 | ||
208 | static inline void | |
209 | set_alg_hash_used_p (bool usedp) | |
210 | { | |
211 | this_target_expmed->x_alg_hash_used_p = usedp; | |
212 | } | |
213 | ||
91f8035e RH |
214 | /* Compute an index into the cost arrays by mode class. */ |
215 | ||
216 | static inline int | |
217 | expmed_mode_index (enum machine_mode mode) | |
218 | { | |
219 | switch (GET_MODE_CLASS (mode)) | |
220 | { | |
221 | case MODE_INT: | |
222 | return mode - MIN_MODE_INT; | |
223 | case MODE_PARTIAL_INT: | |
904e5ccd JJ |
224 | /* If there are no partial integer modes, help the compiler |
225 | to figure out this will never happen. See PR59934. */ | |
226 | if (MIN_MODE_PARTIAL_INT != VOIDmode) | |
227 | return mode - MIN_MODE_PARTIAL_INT + NUM_MODE_INT; | |
228 | break; | |
91f8035e | 229 | case MODE_VECTOR_INT: |
904e5ccd JJ |
230 | /* If there are no vector integer modes, help the compiler |
231 | to figure out this will never happen. See PR59934. */ | |
232 | if (MIN_MODE_VECTOR_INT != VOIDmode) | |
233 | return mode - MIN_MODE_VECTOR_INT + NUM_MODE_IP_INT; | |
234 | break; | |
91f8035e | 235 | default: |
904e5ccd | 236 | break; |
91f8035e | 237 | } |
904e5ccd | 238 | gcc_unreachable (); |
91f8035e RH |
239 | } |
240 | ||
2a261cd3 NF |
241 | /* Return a pointer to a boolean contained in EOC indicating whether |
242 | a particular operation performed in MODE is cheap when optimizing | |
243 | for SPEED. */ | |
244 | ||
245 | static inline bool * | |
246 | expmed_op_cheap_ptr (struct expmed_op_cheap *eoc, bool speed, | |
247 | enum machine_mode mode) | |
248 | { | |
91f8035e RH |
249 | int idx = expmed_mode_index (mode); |
250 | return &eoc->cheap[speed][idx]; | |
2a261cd3 NF |
251 | } |
252 | ||
253 | /* Return a pointer to a cost contained in COSTS when a particular | |
254 | operation is performed in MODE when optimizing for SPEED. */ | |
255 | ||
256 | static inline int * | |
257 | expmed_op_cost_ptr (struct expmed_op_costs *costs, bool speed, | |
258 | enum machine_mode mode) | |
259 | { | |
91f8035e RH |
260 | int idx = expmed_mode_index (mode); |
261 | return &costs->cost[speed][idx]; | |
2a261cd3 NF |
262 | } |
263 | ||
5322d07e NF |
264 | /* Subroutine of {set_,}sdiv_pow2_cheap. Not to be used otherwise. */ |
265 | ||
266 | static inline bool * | |
267 | sdiv_pow2_cheap_ptr (bool speed, enum machine_mode mode) | |
268 | { | |
2a261cd3 NF |
269 | return expmed_op_cheap_ptr (&this_target_expmed->x_sdiv_pow2_cheap, |
270 | speed, mode); | |
5322d07e NF |
271 | } |
272 | ||
273 | /* Set whether a signed division by a power of 2 is cheap in MODE | |
274 | when optimizing for SPEED. */ | |
275 | ||
276 | static inline void | |
277 | set_sdiv_pow2_cheap (bool speed, enum machine_mode mode, bool cheap_p) | |
278 | { | |
279 | *sdiv_pow2_cheap_ptr (speed, mode) = cheap_p; | |
280 | } | |
281 | ||
282 | /* Return whether a signed division by a power of 2 is cheap in MODE | |
283 | when optimizing for SPEED. */ | |
284 | ||
285 | static inline bool | |
286 | sdiv_pow2_cheap (bool speed, enum machine_mode mode) | |
287 | { | |
288 | return *sdiv_pow2_cheap_ptr (speed, mode); | |
289 | } | |
290 | ||
291 | /* Subroutine of {set_,}smod_pow2_cheap. Not to be used otherwise. */ | |
292 | ||
293 | static inline bool * | |
294 | smod_pow2_cheap_ptr (bool speed, enum machine_mode mode) | |
295 | { | |
2a261cd3 NF |
296 | return expmed_op_cheap_ptr (&this_target_expmed->x_smod_pow2_cheap, |
297 | speed, mode); | |
5322d07e NF |
298 | } |
299 | ||
300 | /* Set whether a signed modulo by a power of 2 is CHEAP in MODE when | |
301 | optimizing for SPEED. */ | |
302 | ||
303 | static inline void | |
304 | set_smod_pow2_cheap (bool speed, enum machine_mode mode, bool cheap) | |
305 | { | |
306 | *smod_pow2_cheap_ptr (speed, mode) = cheap; | |
307 | } | |
308 | ||
309 | /* Return whether a signed modulo by a power of 2 is cheap in MODE | |
310 | when optimizing for SPEED. */ | |
311 | ||
312 | static inline bool | |
313 | smod_pow2_cheap (bool speed, enum machine_mode mode) | |
314 | { | |
315 | return *smod_pow2_cheap_ptr (speed, mode); | |
316 | } | |
317 | ||
318 | /* Subroutine of {set_,}zero_cost. Not to be used otherwise. */ | |
319 | ||
320 | static inline int * | |
321 | zero_cost_ptr (bool speed) | |
322 | { | |
323 | return &this_target_expmed->x_zero_cost[speed]; | |
324 | } | |
325 | ||
326 | /* Set the COST of loading zero when optimizing for SPEED. */ | |
327 | ||
328 | static inline void | |
329 | set_zero_cost (bool speed, int cost) | |
330 | { | |
331 | *zero_cost_ptr (speed) = cost; | |
332 | } | |
333 | ||
334 | /* Return the COST of loading zero when optimizing for SPEED. */ | |
335 | ||
336 | static inline int | |
337 | zero_cost (bool speed) | |
338 | { | |
339 | return *zero_cost_ptr (speed); | |
340 | } | |
341 | ||
342 | /* Subroutine of {set_,}add_cost. Not to be used otherwise. */ | |
343 | ||
344 | static inline int * | |
345 | add_cost_ptr (bool speed, enum machine_mode mode) | |
346 | { | |
2a261cd3 | 347 | return expmed_op_cost_ptr (&this_target_expmed->x_add_cost, speed, mode); |
5322d07e NF |
348 | } |
349 | ||
350 | /* Set the COST of computing an add in MODE when optimizing for SPEED. */ | |
351 | ||
352 | static inline void | |
353 | set_add_cost (bool speed, enum machine_mode mode, int cost) | |
354 | { | |
355 | *add_cost_ptr (speed, mode) = cost; | |
356 | } | |
357 | ||
358 | /* Return the cost of computing an add in MODE when optimizing for SPEED. */ | |
359 | ||
360 | static inline int | |
361 | add_cost (bool speed, enum machine_mode mode) | |
362 | { | |
363 | return *add_cost_ptr (speed, mode); | |
364 | } | |
365 | ||
366 | /* Subroutine of {set_,}neg_cost. Not to be used otherwise. */ | |
367 | ||
368 | static inline int * | |
369 | neg_cost_ptr (bool speed, enum machine_mode mode) | |
370 | { | |
2a261cd3 | 371 | return expmed_op_cost_ptr (&this_target_expmed->x_neg_cost, speed, mode); |
5322d07e NF |
372 | } |
373 | ||
374 | /* Set the COST of computing a negation in MODE when optimizing for SPEED. */ | |
375 | ||
376 | static inline void | |
377 | set_neg_cost (bool speed, enum machine_mode mode, int cost) | |
378 | { | |
379 | *neg_cost_ptr (speed, mode) = cost; | |
380 | } | |
381 | ||
382 | /* Return the cost of computing a negation in MODE when optimizing for | |
383 | SPEED. */ | |
384 | ||
385 | static inline int | |
386 | neg_cost (bool speed, enum machine_mode mode) | |
387 | { | |
388 | return *neg_cost_ptr (speed, mode); | |
389 | } | |
390 | ||
391 | /* Subroutine of {set_,}shift_cost. Not to be used otherwise. */ | |
392 | ||
393 | static inline int * | |
394 | shift_cost_ptr (bool speed, enum machine_mode mode, int bits) | |
395 | { | |
2a261cd3 NF |
396 | return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits], |
397 | speed, mode); | |
5322d07e NF |
398 | } |
399 | ||
400 | /* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED. */ | |
401 | ||
402 | static inline void | |
403 | set_shift_cost (bool speed, enum machine_mode mode, int bits, int cost) | |
404 | { | |
405 | *shift_cost_ptr (speed, mode, bits) = cost; | |
406 | } | |
407 | ||
408 | /* Return the cost of doing a shift in MODE by BITS when optimizing for | |
409 | SPEED. */ | |
410 | ||
411 | static inline int | |
412 | shift_cost (bool speed, enum machine_mode mode, int bits) | |
413 | { | |
414 | return *shift_cost_ptr (speed, mode, bits); | |
415 | } | |
416 | ||
417 | /* Subroutine of {set_,}shiftadd_cost. Not to be used otherwise. */ | |
418 | ||
419 | static inline int * | |
420 | shiftadd_cost_ptr (bool speed, enum machine_mode mode, int bits) | |
421 | { | |
2a261cd3 NF |
422 | return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits], |
423 | speed, mode); | |
5322d07e NF |
424 | } |
425 | ||
426 | /* Set the COST of doing a shift in MODE by BITS followed by an add when | |
427 | optimizing for SPEED. */ | |
428 | ||
429 | static inline void | |
430 | set_shiftadd_cost (bool speed, enum machine_mode mode, int bits, int cost) | |
431 | { | |
432 | *shiftadd_cost_ptr (speed, mode, bits) = cost; | |
433 | } | |
434 | ||
435 | /* Return the cost of doing a shift in MODE by BITS followed by an add | |
436 | when optimizing for SPEED. */ | |
437 | ||
438 | static inline int | |
439 | shiftadd_cost (bool speed, enum machine_mode mode, int bits) | |
440 | { | |
441 | return *shiftadd_cost_ptr (speed, mode, bits); | |
442 | } | |
443 | ||
444 | /* Subroutine of {set_,}shiftsub0_cost. Not to be used otherwise. */ | |
445 | ||
446 | static inline int * | |
447 | shiftsub0_cost_ptr (bool speed, enum machine_mode mode, int bits) | |
448 | { | |
2a261cd3 NF |
449 | return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits], |
450 | speed, mode); | |
5322d07e NF |
451 | } |
452 | ||
453 | /* Set the COST of doing a shift in MODE by BITS and then subtracting a | |
454 | value when optimizing for SPEED. */ | |
455 | ||
456 | static inline void | |
457 | set_shiftsub0_cost (bool speed, enum machine_mode mode, int bits, int cost) | |
458 | { | |
459 | *shiftsub0_cost_ptr (speed, mode, bits) = cost; | |
460 | } | |
461 | ||
462 | /* Return the cost of doing a shift in MODE by BITS and then subtracting | |
463 | a value when optimizing for SPEED. */ | |
464 | ||
465 | static inline int | |
466 | shiftsub0_cost (bool speed, enum machine_mode mode, int bits) | |
467 | { | |
468 | return *shiftsub0_cost_ptr (speed, mode, bits); | |
469 | } | |
470 | ||
471 | /* Subroutine of {set_,}shiftsub1_cost. Not to be used otherwise. */ | |
472 | ||
473 | static inline int * | |
474 | shiftsub1_cost_ptr (bool speed, enum machine_mode mode, int bits) | |
475 | { | |
2a261cd3 NF |
476 | return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits], |
477 | speed, mode); | |
5322d07e NF |
478 | } |
479 | ||
480 | /* Set the COST of subtracting a shift in MODE by BITS from a value when | |
481 | optimizing for SPEED. */ | |
482 | ||
483 | static inline void | |
484 | set_shiftsub1_cost (bool speed, enum machine_mode mode, int bits, int cost) | |
485 | { | |
486 | *shiftsub1_cost_ptr (speed, mode, bits) = cost; | |
487 | } | |
488 | ||
489 | /* Return the cost of subtracting a shift in MODE by BITS from a value | |
490 | when optimizing for SPEED. */ | |
491 | ||
492 | static inline int | |
493 | shiftsub1_cost (bool speed, enum machine_mode mode, int bits) | |
494 | { | |
495 | return *shiftsub1_cost_ptr (speed, mode, bits); | |
496 | } | |
497 | ||
498 | /* Subroutine of {set_,}mul_cost. Not to be used otherwise. */ | |
499 | ||
500 | static inline int * | |
501 | mul_cost_ptr (bool speed, enum machine_mode mode) | |
502 | { | |
2a261cd3 | 503 | return expmed_op_cost_ptr (&this_target_expmed->x_mul_cost, speed, mode); |
5322d07e NF |
504 | } |
505 | ||
506 | /* Set the COST of doing a multiplication in MODE when optimizing for | |
507 | SPEED. */ | |
508 | ||
509 | static inline void | |
510 | set_mul_cost (bool speed, enum machine_mode mode, int cost) | |
511 | { | |
512 | *mul_cost_ptr (speed, mode) = cost; | |
513 | } | |
514 | ||
515 | /* Return the cost of doing a multiplication in MODE when optimizing | |
516 | for SPEED. */ | |
517 | ||
518 | static inline int | |
519 | mul_cost (bool speed, enum machine_mode mode) | |
520 | { | |
521 | return *mul_cost_ptr (speed, mode); | |
522 | } | |
523 | ||
524 | /* Subroutine of {set_,}sdiv_cost. Not to be used otherwise. */ | |
525 | ||
526 | static inline int * | |
527 | sdiv_cost_ptr (bool speed, enum machine_mode mode) | |
528 | { | |
2a261cd3 | 529 | return expmed_op_cost_ptr (&this_target_expmed->x_sdiv_cost, speed, mode); |
5322d07e NF |
530 | } |
531 | ||
532 | /* Set the COST of doing a signed division in MODE when optimizing | |
6dd8f4bb BS |
533 | for SPEED. */ |
534 | ||
535 | static inline void | |
5322d07e NF |
536 | set_sdiv_cost (bool speed, enum machine_mode mode, int cost) |
537 | { | |
538 | *sdiv_cost_ptr (speed, mode) = cost; | |
539 | } | |
540 | ||
541 | /* Return the cost of doing a signed division in MODE when optimizing | |
542 | for SPEED. */ | |
543 | ||
544 | static inline int | |
545 | sdiv_cost (bool speed, enum machine_mode mode) | |
546 | { | |
547 | return *sdiv_cost_ptr (speed, mode); | |
548 | } | |
549 | ||
550 | /* Subroutine of {set_,}udiv_cost. Not to be used otherwise. */ | |
551 | ||
552 | static inline int * | |
553 | udiv_cost_ptr (bool speed, enum machine_mode mode) | |
554 | { | |
2a261cd3 | 555 | return expmed_op_cost_ptr (&this_target_expmed->x_udiv_cost, speed, mode); |
5322d07e NF |
556 | } |
557 | ||
558 | /* Set the COST of doing an unsigned division in MODE when optimizing | |
559 | for SPEED. */ | |
560 | ||
561 | static inline void | |
562 | set_udiv_cost (bool speed, enum machine_mode mode, int cost) | |
563 | { | |
564 | *udiv_cost_ptr (speed, mode) = cost; | |
565 | } | |
566 | ||
567 | /* Return the cost of doing an unsigned division in MODE when | |
568 | optimizing for SPEED. */ | |
569 | ||
570 | static inline int | |
571 | udiv_cost (bool speed, enum machine_mode mode) | |
572 | { | |
573 | return *udiv_cost_ptr (speed, mode); | |
574 | } | |
575 | ||
576 | /* Subroutine of {set_,}mul_widen_cost. Not to be used otherwise. */ | |
577 | ||
578 | static inline int * | |
579 | mul_widen_cost_ptr (bool speed, enum machine_mode mode) | |
580 | { | |
2a261cd3 NF |
581 | gcc_assert (GET_MODE_CLASS (mode) == MODE_INT); |
582 | ||
583 | return &this_target_expmed->x_mul_widen_cost[speed][mode - MIN_MODE_INT]; | |
5322d07e NF |
584 | } |
585 | ||
586 | /* Set the COST for computing a widening multiplication in MODE when | |
587 | optimizing for SPEED. */ | |
588 | ||
589 | static inline void | |
590 | set_mul_widen_cost (bool speed, enum machine_mode mode, int cost) | |
591 | { | |
592 | *mul_widen_cost_ptr (speed, mode) = cost; | |
593 | } | |
594 | ||
595 | /* Return the cost for computing a widening multiplication in MODE when | |
596 | optimizing for SPEED. */ | |
597 | ||
598 | static inline int | |
599 | mul_widen_cost (bool speed, enum machine_mode mode) | |
600 | { | |
601 | return *mul_widen_cost_ptr (speed, mode); | |
602 | } | |
603 | ||
604 | /* Subroutine of {set_,}mul_highpart_cost. Not to be used otherwise. */ | |
605 | ||
606 | static inline int * | |
607 | mul_highpart_cost_ptr (bool speed, enum machine_mode mode) | |
608 | { | |
2a261cd3 NF |
609 | gcc_assert (GET_MODE_CLASS (mode) == MODE_INT); |
610 | ||
611 | return &this_target_expmed->x_mul_highpart_cost[speed][mode - MIN_MODE_INT]; | |
5322d07e NF |
612 | } |
613 | ||
614 | /* Set the COST for computing the high part of a multiplication in MODE | |
615 | when optimizing for SPEED. */ | |
616 | ||
617 | static inline void | |
618 | set_mul_highpart_cost (bool speed, enum machine_mode mode, int cost) | |
619 | { | |
620 | *mul_highpart_cost_ptr (speed, mode) = cost; | |
621 | } | |
622 | ||
623 | /* Return the cost for computing the high part of a multiplication in MODE | |
624 | when optimizing for SPEED. */ | |
625 | ||
626 | static inline int | |
627 | mul_highpart_cost (bool speed, enum machine_mode mode) | |
628 | { | |
629 | return *mul_highpart_cost_ptr (speed, mode); | |
630 | } | |
631 | ||
632 | /* Subroutine of {set_,}convert_cost. Not to be used otherwise. */ | |
633 | ||
634 | static inline int * | |
635 | convert_cost_ptr (enum machine_mode to_mode, enum machine_mode from_mode, | |
636 | bool speed) | |
6dd8f4bb | 637 | { |
91f8035e RH |
638 | int to_idx = expmed_mode_index (to_mode); |
639 | int from_idx = expmed_mode_index (from_mode); | |
6dd8f4bb | 640 | |
91f8035e RH |
641 | gcc_assert (IN_RANGE (to_idx, 0, NUM_MODE_IP_INT - 1)); |
642 | gcc_assert (IN_RANGE (from_idx, 0, NUM_MODE_IP_INT - 1)); | |
6dd8f4bb | 643 | |
5322d07e NF |
644 | return &this_target_expmed->x_convert_cost[speed][to_idx][from_idx]; |
645 | } | |
646 | ||
647 | /* Set the COST for converting from FROM_MODE to TO_MODE when optimizing | |
648 | for SPEED. */ | |
649 | ||
650 | static inline void | |
651 | set_convert_cost (enum machine_mode to_mode, enum machine_mode from_mode, | |
652 | bool speed, int cost) | |
653 | { | |
654 | *convert_cost_ptr (to_mode, from_mode, speed) = cost; | |
6dd8f4bb BS |
655 | } |
656 | ||
657 | /* Return the cost for converting from FROM_MODE to TO_MODE when optimizing | |
658 | for SPEED. */ | |
659 | ||
660 | static inline int | |
661 | convert_cost (enum machine_mode to_mode, enum machine_mode from_mode, | |
662 | bool speed) | |
663 | { | |
5322d07e | 664 | return *convert_cost_ptr (to_mode, from_mode, speed); |
6dd8f4bb BS |
665 | } |
666 | ||
667 | extern int mult_by_coeff_cost (HOST_WIDE_INT, enum machine_mode, bool); | |
462f85ce | 668 | #endif |