expr.c (expand_expr_real_2): Use widening_optab_handler.
[gcc.git] / gcc / optabs.h
1 /* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #ifndef GCC_OPTABS_H
22 #define GCC_OPTABS_H
23
24 #include "insn-codes.h"
25
26 /* Optabs are tables saying how to generate insn bodies
27 for various machine modes and numbers of operands.
28 Each optab applies to one operation.
29
30 For example, add_optab applies to addition.
31
32 The `lib_call' slot is the name of the library function that
33 can be used to perform the operation.
34
35 A few optabs, such as move_optab, are used by special code. */
36
37 struct optab_handlers
38 {
39 /* I - CODE_FOR_nothing, where I is either the insn code of the
40 associated insn generator or CODE_FOR_nothing if there is no such
41 insn on the target machine. */
42 int insn_code;
43 };
44
45 struct widening_optab_handlers
46 {
47 struct optab_handlers handlers[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
48 };
49
50 struct optab_d
51 {
52 enum rtx_code code;
53 char libcall_suffix;
54 const char *libcall_basename;
55 void (*libcall_gen)(struct optab_d *, const char *name, char suffix,
56 enum machine_mode);
57 struct optab_handlers handlers[NUM_MACHINE_MODES];
58 struct widening_optab_handlers *widening;
59 };
60 typedef struct optab_d * optab;
61
62 /* A convert_optab is for some sort of conversion operation between
63 modes. The first array index is the destination mode, the second
64 is the source mode. */
65 struct convert_optab_d
66 {
67 enum rtx_code code;
68 const char *libcall_basename;
69 void (*libcall_gen)(struct convert_optab_d *, const char *name,
70 enum machine_mode,
71 enum machine_mode);
72 struct optab_handlers handlers[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
73 };
74 typedef struct convert_optab_d *convert_optab;
75
76 /* Given an enum insn_code, access the function to construct
77 the body of that kind of insn. */
78 #define GEN_FCN(CODE) (insn_data[CODE].genfun)
79
80 /* Enumeration of valid indexes into optab_table. */
81 enum optab_index
82 {
83 /* Fixed-point operators with signed/unsigned saturation */
84 OTI_ssadd,
85 OTI_usadd,
86 OTI_sssub,
87 OTI_ussub,
88 OTI_ssmul,
89 OTI_usmul,
90 OTI_ssdiv,
91 OTI_usdiv,
92 OTI_ssneg,
93 OTI_usneg,
94 OTI_ssashl,
95 OTI_usashl,
96
97 OTI_add,
98 OTI_addv,
99 OTI_sub,
100 OTI_subv,
101
102 /* Signed and fp multiply */
103 OTI_smul,
104 OTI_smulv,
105 /* Signed multiply, return high word */
106 OTI_smul_highpart,
107 OTI_umul_highpart,
108 /* Signed multiply with result one machine mode wider than args */
109 OTI_smul_widen,
110 OTI_umul_widen,
111 /* Widening multiply of one unsigned and one signed operand. */
112 OTI_usmul_widen,
113 /* Signed multiply and add with the result and addend one machine mode
114 wider than the multiplicand and multiplier. */
115 OTI_smadd_widen,
116 /* Unsigned multiply and add with the result and addend one machine mode
117 wider than the multiplicand and multiplier. */
118 OTI_umadd_widen,
119 /* Signed multiply and add with the result and addend one machine mode
120 wider than the multiplicand and multiplier.
121 All involved operations are saturating. */
122 OTI_ssmadd_widen,
123 /* Unsigned multiply and add with the result and addend one machine mode
124 wider than the multiplicand and multiplier.
125 All involved operations are saturating. */
126 OTI_usmadd_widen,
127 /* Signed multiply and subtract the result and minuend one machine mode
128 wider than the multiplicand and multiplier. */
129 OTI_smsub_widen,
130 /* Unsigned multiply and subtract the result and minuend one machine mode
131 wider than the multiplicand and multiplier. */
132 OTI_umsub_widen,
133 /* Signed multiply and subtract the result and minuend one machine mode
134 wider than the multiplicand and multiplier.
135 All involved operations are saturating. */
136 OTI_ssmsub_widen,
137 /* Unsigned multiply and subtract the result and minuend one machine mode
138 wider than the multiplicand and multiplier.
139 All involved operations are saturating. */
140 OTI_usmsub_widen,
141
142 /* Signed divide */
143 OTI_sdiv,
144 OTI_sdivv,
145 /* Signed divide-and-remainder in one */
146 OTI_sdivmod,
147 OTI_udiv,
148 OTI_udivmod,
149 /* Signed remainder */
150 OTI_smod,
151 OTI_umod,
152 /* Floating point remainder functions */
153 OTI_fmod,
154 OTI_remainder,
155 /* Convert float to integer in float fmt */
156 OTI_ftrunc,
157
158 /* Logical and */
159 OTI_and,
160 /* Logical or */
161 OTI_ior,
162 /* Logical xor */
163 OTI_xor,
164
165 /* Arithmetic shift left */
166 OTI_ashl,
167 /* Logical shift right */
168 OTI_lshr,
169 /* Arithmetic shift right */
170 OTI_ashr,
171 /* Rotate left */
172 OTI_rotl,
173 /* Rotate right */
174 OTI_rotr,
175
176 /* Arithmetic shift left of vector by vector */
177 OTI_vashl,
178 /* Logical shift right of vector by vector */
179 OTI_vlshr,
180 /* Arithmetic shift right of vector by vector */
181 OTI_vashr,
182 /* Rotate left of vector by vector */
183 OTI_vrotl,
184 /* Rotate right of vector by vector */
185 OTI_vrotr,
186
187 /* Signed and floating-point minimum value */
188 OTI_smin,
189 /* Signed and floating-point maximum value */
190 OTI_smax,
191 /* Unsigned minimum value */
192 OTI_umin,
193 /* Unsigned maximum value */
194 OTI_umax,
195 /* Power */
196 OTI_pow,
197 /* Arc tangent of y/x */
198 OTI_atan2,
199 /* Floating multiply/add */
200 OTI_fma,
201 OTI_fms,
202 OTI_fnma,
203 OTI_fnms,
204
205 /* Move instruction. */
206 OTI_mov,
207 /* Move, preserving high part of register. */
208 OTI_movstrict,
209 /* Move, with a misaligned memory. */
210 OTI_movmisalign,
211 /* Nontemporal store. */
212 OTI_storent,
213
214 /* Unary operations */
215 /* Negation */
216 OTI_neg,
217 OTI_negv,
218 /* Abs value */
219 OTI_abs,
220 OTI_absv,
221 /* Byteswap */
222 OTI_bswap,
223 /* Bitwise not */
224 OTI_one_cmpl,
225 /* Bit scanning and counting */
226 OTI_ffs,
227 OTI_clz,
228 OTI_ctz,
229 OTI_clrsb,
230 OTI_popcount,
231 OTI_parity,
232 /* Square root */
233 OTI_sqrt,
234 /* Sine-Cosine */
235 OTI_sincos,
236 /* Sine */
237 OTI_sin,
238 /* Inverse sine */
239 OTI_asin,
240 /* Cosine */
241 OTI_cos,
242 /* Inverse cosine */
243 OTI_acos,
244 /* Exponential */
245 OTI_exp,
246 /* Base-10 Exponential */
247 OTI_exp10,
248 /* Base-2 Exponential */
249 OTI_exp2,
250 /* Exponential - 1*/
251 OTI_expm1,
252 /* Load exponent of a floating point number */
253 OTI_ldexp,
254 /* Multiply floating-point number by integral power of radix */
255 OTI_scalb,
256 /* Mantissa of a floating-point number */
257 OTI_significand,
258 /* Radix-independent exponent */
259 OTI_logb,
260 OTI_ilogb,
261 /* Natural Logarithm */
262 OTI_log,
263 /* Base-10 Logarithm */
264 OTI_log10,
265 /* Base-2 Logarithm */
266 OTI_log2,
267 /* logarithm of 1 plus argument */
268 OTI_log1p,
269 /* Rounding functions */
270 OTI_floor,
271 OTI_ceil,
272 OTI_btrunc,
273 OTI_round,
274 OTI_nearbyint,
275 OTI_rint,
276 /* Tangent */
277 OTI_tan,
278 /* Inverse tangent */
279 OTI_atan,
280 /* Copy sign */
281 OTI_copysign,
282 /* Signbit */
283 OTI_signbit,
284 /* Test for infinite value */
285 OTI_isinf,
286
287 /* Compare insn; two operands. Used only for libcalls. */
288 OTI_cmp,
289 OTI_ucmp,
290
291 /* Floating point comparison optabs - used primarily for libfuncs */
292 OTI_eq,
293 OTI_ne,
294 OTI_gt,
295 OTI_ge,
296 OTI_lt,
297 OTI_le,
298 OTI_unord,
299
300 /* String length */
301 OTI_strlen,
302
303 /* Combined compare & jump/move/store flags/trap operations. */
304 OTI_cbranch,
305 OTI_cmov,
306 OTI_cstore,
307 OTI_ctrap,
308
309 /* Push instruction. */
310 OTI_push,
311
312 /* Conditional add instruction. */
313 OTI_addcc,
314
315 /* Reduction operations on a vector operand. */
316 OTI_reduc_smax,
317 OTI_reduc_umax,
318 OTI_reduc_smin,
319 OTI_reduc_umin,
320 OTI_reduc_splus,
321 OTI_reduc_uplus,
322
323 /* Summation, with result machine mode one or more wider than args. */
324 OTI_ssum_widen,
325 OTI_usum_widen,
326
327 /* Dot product, with result machine mode one or more wider than args. */
328 OTI_sdot_prod,
329 OTI_udot_prod,
330
331 /* Set specified field of vector operand. */
332 OTI_vec_set,
333 /* Extract specified field of vector operand. */
334 OTI_vec_extract,
335 /* Extract even/odd fields of vector operands. */
336 OTI_vec_extract_even,
337 OTI_vec_extract_odd,
338 /* Interleave fields of vector operands. */
339 OTI_vec_interleave_high,
340 OTI_vec_interleave_low,
341 /* Initialize vector operand. */
342 OTI_vec_init,
343 /* Whole vector shift. The shift amount is in bits. */
344 OTI_vec_shl,
345 OTI_vec_shr,
346 /* Extract specified elements from vectors, for vector load. */
347 OTI_vec_realign_load,
348 /* Widening multiplication.
349 The high/low part of the resulting vector of products is returned. */
350 OTI_vec_widen_umult_hi,
351 OTI_vec_widen_umult_lo,
352 OTI_vec_widen_smult_hi,
353 OTI_vec_widen_smult_lo,
354 /* Extract and widen the high/low part of a vector of signed or
355 floating point elements. */
356 OTI_vec_unpacks_hi,
357 OTI_vec_unpacks_lo,
358 /* Extract and widen the high/low part of a vector of unsigned
359 elements. */
360 OTI_vec_unpacku_hi,
361 OTI_vec_unpacku_lo,
362
363 /* Extract, convert to floating point and widen the high/low part of
364 a vector of signed or unsigned integer elements. */
365 OTI_vec_unpacks_float_hi,
366 OTI_vec_unpacks_float_lo,
367 OTI_vec_unpacku_float_hi,
368 OTI_vec_unpacku_float_lo,
369
370 /* Narrow (demote) and merge the elements of two vectors. */
371 OTI_vec_pack_trunc,
372 OTI_vec_pack_usat,
373 OTI_vec_pack_ssat,
374
375 /* Convert to signed/unsigned integer, narrow and merge elements
376 of two vectors of floating point elements. */
377 OTI_vec_pack_sfix_trunc,
378 OTI_vec_pack_ufix_trunc,
379
380 /* Perform a raise to the power of integer. */
381 OTI_powi,
382
383 OTI_MAX
384 };
385
386 #define ssadd_optab (&optab_table[OTI_ssadd])
387 #define usadd_optab (&optab_table[OTI_usadd])
388 #define sssub_optab (&optab_table[OTI_sssub])
389 #define ussub_optab (&optab_table[OTI_ussub])
390 #define ssmul_optab (&optab_table[OTI_ssmul])
391 #define usmul_optab (&optab_table[OTI_usmul])
392 #define ssdiv_optab (&optab_table[OTI_ssdiv])
393 #define usdiv_optab (&optab_table[OTI_usdiv])
394 #define ssneg_optab (&optab_table[OTI_ssneg])
395 #define usneg_optab (&optab_table[OTI_usneg])
396 #define ssashl_optab (&optab_table[OTI_ssashl])
397 #define usashl_optab (&optab_table[OTI_usashl])
398
399 #define add_optab (&optab_table[OTI_add])
400 #define sub_optab (&optab_table[OTI_sub])
401 #define smul_optab (&optab_table[OTI_smul])
402 #define addv_optab (&optab_table[OTI_addv])
403 #define subv_optab (&optab_table[OTI_subv])
404 #define smul_highpart_optab (&optab_table[OTI_smul_highpart])
405 #define umul_highpart_optab (&optab_table[OTI_umul_highpart])
406 #define smul_widen_optab (&optab_table[OTI_smul_widen])
407 #define umul_widen_optab (&optab_table[OTI_umul_widen])
408 #define usmul_widen_optab (&optab_table[OTI_usmul_widen])
409 #define smadd_widen_optab (&optab_table[OTI_smadd_widen])
410 #define umadd_widen_optab (&optab_table[OTI_umadd_widen])
411 #define ssmadd_widen_optab (&optab_table[OTI_ssmadd_widen])
412 #define usmadd_widen_optab (&optab_table[OTI_usmadd_widen])
413 #define smsub_widen_optab (&optab_table[OTI_smsub_widen])
414 #define umsub_widen_optab (&optab_table[OTI_umsub_widen])
415 #define ssmsub_widen_optab (&optab_table[OTI_ssmsub_widen])
416 #define usmsub_widen_optab (&optab_table[OTI_usmsub_widen])
417 #define sdiv_optab (&optab_table[OTI_sdiv])
418 #define smulv_optab (&optab_table[OTI_smulv])
419 #define sdivv_optab (&optab_table[OTI_sdivv])
420 #define sdivmod_optab (&optab_table[OTI_sdivmod])
421 #define udiv_optab (&optab_table[OTI_udiv])
422 #define udivmod_optab (&optab_table[OTI_udivmod])
423 #define smod_optab (&optab_table[OTI_smod])
424 #define umod_optab (&optab_table[OTI_umod])
425 #define fmod_optab (&optab_table[OTI_fmod])
426 #define remainder_optab (&optab_table[OTI_remainder])
427 #define ftrunc_optab (&optab_table[OTI_ftrunc])
428 #define and_optab (&optab_table[OTI_and])
429 #define ior_optab (&optab_table[OTI_ior])
430 #define xor_optab (&optab_table[OTI_xor])
431 #define ashl_optab (&optab_table[OTI_ashl])
432 #define lshr_optab (&optab_table[OTI_lshr])
433 #define ashr_optab (&optab_table[OTI_ashr])
434 #define rotl_optab (&optab_table[OTI_rotl])
435 #define rotr_optab (&optab_table[OTI_rotr])
436 #define vashl_optab (&optab_table[OTI_vashl])
437 #define vlshr_optab (&optab_table[OTI_vlshr])
438 #define vashr_optab (&optab_table[OTI_vashr])
439 #define vrotl_optab (&optab_table[OTI_vrotl])
440 #define vrotr_optab (&optab_table[OTI_vrotr])
441 #define smin_optab (&optab_table[OTI_smin])
442 #define smax_optab (&optab_table[OTI_smax])
443 #define umin_optab (&optab_table[OTI_umin])
444 #define umax_optab (&optab_table[OTI_umax])
445 #define pow_optab (&optab_table[OTI_pow])
446 #define atan2_optab (&optab_table[OTI_atan2])
447 #define fma_optab (&optab_table[OTI_fma])
448 #define fms_optab (&optab_table[OTI_fms])
449 #define fnma_optab (&optab_table[OTI_fnma])
450 #define fnms_optab (&optab_table[OTI_fnms])
451
452 #define mov_optab (&optab_table[OTI_mov])
453 #define movstrict_optab (&optab_table[OTI_movstrict])
454 #define movmisalign_optab (&optab_table[OTI_movmisalign])
455 #define storent_optab (&optab_table[OTI_storent])
456
457 #define neg_optab (&optab_table[OTI_neg])
458 #define negv_optab (&optab_table[OTI_negv])
459 #define abs_optab (&optab_table[OTI_abs])
460 #define absv_optab (&optab_table[OTI_absv])
461 #define one_cmpl_optab (&optab_table[OTI_one_cmpl])
462 #define bswap_optab (&optab_table[OTI_bswap])
463 #define ffs_optab (&optab_table[OTI_ffs])
464 #define clz_optab (&optab_table[OTI_clz])
465 #define ctz_optab (&optab_table[OTI_ctz])
466 #define clrsb_optab (&optab_table[OTI_clrsb])
467 #define popcount_optab (&optab_table[OTI_popcount])
468 #define parity_optab (&optab_table[OTI_parity])
469 #define sqrt_optab (&optab_table[OTI_sqrt])
470 #define sincos_optab (&optab_table[OTI_sincos])
471 #define sin_optab (&optab_table[OTI_sin])
472 #define asin_optab (&optab_table[OTI_asin])
473 #define cos_optab (&optab_table[OTI_cos])
474 #define acos_optab (&optab_table[OTI_acos])
475 #define exp_optab (&optab_table[OTI_exp])
476 #define exp10_optab (&optab_table[OTI_exp10])
477 #define exp2_optab (&optab_table[OTI_exp2])
478 #define expm1_optab (&optab_table[OTI_expm1])
479 #define ldexp_optab (&optab_table[OTI_ldexp])
480 #define scalb_optab (&optab_table[OTI_scalb])
481 #define significand_optab (&optab_table[OTI_significand])
482 #define logb_optab (&optab_table[OTI_logb])
483 #define ilogb_optab (&optab_table[OTI_ilogb])
484 #define log_optab (&optab_table[OTI_log])
485 #define log10_optab (&optab_table[OTI_log10])
486 #define log2_optab (&optab_table[OTI_log2])
487 #define log1p_optab (&optab_table[OTI_log1p])
488 #define floor_optab (&optab_table[OTI_floor])
489 #define ceil_optab (&optab_table[OTI_ceil])
490 #define btrunc_optab (&optab_table[OTI_btrunc])
491 #define round_optab (&optab_table[OTI_round])
492 #define nearbyint_optab (&optab_table[OTI_nearbyint])
493 #define rint_optab (&optab_table[OTI_rint])
494 #define tan_optab (&optab_table[OTI_tan])
495 #define atan_optab (&optab_table[OTI_atan])
496 #define copysign_optab (&optab_table[OTI_copysign])
497 #define signbit_optab (&optab_table[OTI_signbit])
498 #define isinf_optab (&optab_table[OTI_isinf])
499
500 #define cmp_optab (&optab_table[OTI_cmp])
501 #define ucmp_optab (&optab_table[OTI_ucmp])
502
503 #define eq_optab (&optab_table[OTI_eq])
504 #define ne_optab (&optab_table[OTI_ne])
505 #define gt_optab (&optab_table[OTI_gt])
506 #define ge_optab (&optab_table[OTI_ge])
507 #define lt_optab (&optab_table[OTI_lt])
508 #define le_optab (&optab_table[OTI_le])
509 #define unord_optab (&optab_table[OTI_unord])
510
511 #define strlen_optab (&optab_table[OTI_strlen])
512
513 #define cbranch_optab (&optab_table[OTI_cbranch])
514 #define cmov_optab (&optab_table[OTI_cmov])
515 #define cstore_optab (&optab_table[OTI_cstore])
516 #define ctrap_optab (&optab_table[OTI_ctrap])
517
518 #define push_optab (&optab_table[OTI_push])
519 #define addcc_optab (&optab_table[OTI_addcc])
520
521 #define reduc_smax_optab (&optab_table[OTI_reduc_smax])
522 #define reduc_umax_optab (&optab_table[OTI_reduc_umax])
523 #define reduc_smin_optab (&optab_table[OTI_reduc_smin])
524 #define reduc_umin_optab (&optab_table[OTI_reduc_umin])
525 #define reduc_splus_optab (&optab_table[OTI_reduc_splus])
526 #define reduc_uplus_optab (&optab_table[OTI_reduc_uplus])
527
528 #define ssum_widen_optab (&optab_table[OTI_ssum_widen])
529 #define usum_widen_optab (&optab_table[OTI_usum_widen])
530 #define sdot_prod_optab (&optab_table[OTI_sdot_prod])
531 #define udot_prod_optab (&optab_table[OTI_udot_prod])
532
533 #define vec_set_optab (&optab_table[OTI_vec_set])
534 #define vec_extract_optab (&optab_table[OTI_vec_extract])
535 #define vec_extract_even_optab (&optab_table[OTI_vec_extract_even])
536 #define vec_extract_odd_optab (&optab_table[OTI_vec_extract_odd])
537 #define vec_interleave_high_optab (&optab_table[OTI_vec_interleave_high])
538 #define vec_interleave_low_optab (&optab_table[OTI_vec_interleave_low])
539 #define vec_init_optab (&optab_table[OTI_vec_init])
540 #define vec_shl_optab (&optab_table[OTI_vec_shl])
541 #define vec_shr_optab (&optab_table[OTI_vec_shr])
542 #define vec_realign_load_optab (&optab_table[OTI_vec_realign_load])
543 #define vec_widen_umult_hi_optab (&optab_table[OTI_vec_widen_umult_hi])
544 #define vec_widen_umult_lo_optab (&optab_table[OTI_vec_widen_umult_lo])
545 #define vec_widen_smult_hi_optab (&optab_table[OTI_vec_widen_smult_hi])
546 #define vec_widen_smult_lo_optab (&optab_table[OTI_vec_widen_smult_lo])
547 #define vec_unpacks_hi_optab (&optab_table[OTI_vec_unpacks_hi])
548 #define vec_unpacks_lo_optab (&optab_table[OTI_vec_unpacks_lo])
549 #define vec_unpacku_hi_optab (&optab_table[OTI_vec_unpacku_hi])
550 #define vec_unpacku_lo_optab (&optab_table[OTI_vec_unpacku_lo])
551 #define vec_unpacks_float_hi_optab (&optab_table[OTI_vec_unpacks_float_hi])
552 #define vec_unpacks_float_lo_optab (&optab_table[OTI_vec_unpacks_float_lo])
553 #define vec_unpacku_float_hi_optab (&optab_table[OTI_vec_unpacku_float_hi])
554 #define vec_unpacku_float_lo_optab (&optab_table[OTI_vec_unpacku_float_lo])
555 #define vec_pack_trunc_optab (&optab_table[OTI_vec_pack_trunc])
556 #define vec_pack_ssat_optab (&optab_table[OTI_vec_pack_ssat])
557 #define vec_pack_usat_optab (&optab_table[OTI_vec_pack_usat])
558 #define vec_pack_sfix_trunc_optab (&optab_table[OTI_vec_pack_sfix_trunc])
559 #define vec_pack_ufix_trunc_optab (&optab_table[OTI_vec_pack_ufix_trunc])
560
561 #define powi_optab (&optab_table[OTI_powi])
562
563 /* Conversion optabs have their own table and indexes. */
564 enum convert_optab_index
565 {
566 COI_sext,
567 COI_zext,
568 COI_trunc,
569
570 COI_sfix,
571 COI_ufix,
572
573 COI_sfixtrunc,
574 COI_ufixtrunc,
575
576 COI_sfloat,
577 COI_ufloat,
578
579 COI_lrint,
580 COI_lround,
581 COI_lfloor,
582 COI_lceil,
583
584 COI_fract,
585 COI_fractuns,
586 COI_satfract,
587 COI_satfractuns,
588
589 COI_vec_load_lanes,
590 COI_vec_store_lanes,
591
592 COI_MAX
593 };
594
595 #define sext_optab (&convert_optab_table[COI_sext])
596 #define zext_optab (&convert_optab_table[COI_zext])
597 #define trunc_optab (&convert_optab_table[COI_trunc])
598 #define sfix_optab (&convert_optab_table[COI_sfix])
599 #define ufix_optab (&convert_optab_table[COI_ufix])
600 #define sfixtrunc_optab (&convert_optab_table[COI_sfixtrunc])
601 #define ufixtrunc_optab (&convert_optab_table[COI_ufixtrunc])
602 #define sfloat_optab (&convert_optab_table[COI_sfloat])
603 #define ufloat_optab (&convert_optab_table[COI_ufloat])
604 #define lrint_optab (&convert_optab_table[COI_lrint])
605 #define lround_optab (&convert_optab_table[COI_lround])
606 #define lfloor_optab (&convert_optab_table[COI_lfloor])
607 #define lceil_optab (&convert_optab_table[COI_lceil])
608 #define fract_optab (&convert_optab_table[COI_fract])
609 #define fractuns_optab (&convert_optab_table[COI_fractuns])
610 #define satfract_optab (&convert_optab_table[COI_satfract])
611 #define satfractuns_optab (&convert_optab_table[COI_satfractuns])
612 #define vec_load_lanes_optab (&convert_optab_table[COI_vec_load_lanes])
613 #define vec_store_lanes_optab (&convert_optab_table[COI_vec_store_lanes])
614
615 /* Contains the optab used for each rtx code. */
616 extern optab code_to_optab[NUM_RTX_CODE + 1];
617
618 \f
619 typedef rtx (*rtxfun) (rtx);
620
621 /* Enumerates operations that have a named .md pattern associated
622 with them, but which are not implemented as library functions. */
623 enum direct_optab_index
624 {
625 #ifdef HAVE_conditional_move
626 /* Conditional move operations. */
627 DOI_movcc,
628 #endif
629
630 /* Operations that use a scratch register to perform input and output
631 reloads of special objects. */
632 DOI_reload_in,
633 DOI_reload_out,
634
635 /* Vector conditional operations. */
636 DOI_vcond,
637 DOI_vcondu,
638
639 /* Block move operation. */
640 DOI_movmem,
641
642 /* Block set operation. */
643 DOI_setmem,
644
645 /* Various types of block compare operation. */
646 DOI_cmpstr,
647 DOI_cmpstrn,
648 DOI_cmpmem,
649
650 /* Synchronization primitives. This first set is atomic operation for
651 which we don't care about the resulting value. */
652 DOI_sync_add,
653 DOI_sync_sub,
654 DOI_sync_ior,
655 DOI_sync_and,
656 DOI_sync_xor,
657 DOI_sync_nand,
658
659 /* This second set is atomic operations in which we return the value
660 that existed in memory before the operation. */
661 DOI_sync_old_add,
662 DOI_sync_old_sub,
663 DOI_sync_old_ior,
664 DOI_sync_old_and,
665 DOI_sync_old_xor,
666 DOI_sync_old_nand,
667
668 /* This third set is atomic operations in which we return the value
669 that resulted after performing the operation. */
670 DOI_sync_new_add,
671 DOI_sync_new_sub,
672 DOI_sync_new_ior,
673 DOI_sync_new_and,
674 DOI_sync_new_xor,
675 DOI_sync_new_nand,
676
677 /* Atomic compare and swap. */
678 DOI_sync_compare_and_swap,
679
680 /* Atomic exchange with acquire semantics. */
681 DOI_sync_lock_test_and_set,
682
683 /* Atomic clear with release semantics. */
684 DOI_sync_lock_release,
685
686 DOI_MAX
687 };
688
689 /* A structure that says which insn should be used to perform an operation
690 in a particular mode. */
691 struct direct_optab_d
692 {
693 struct optab_handlers handlers[NUM_MACHINE_MODES];
694 };
695 typedef struct direct_optab_d *direct_optab;
696
697 #ifdef HAVE_conditional_move
698 #define movcc_optab (&direct_optab_table[(int) DOI_movcc])
699 #endif
700 #define reload_in_optab (&direct_optab_table[(int) DOI_reload_in])
701 #define reload_out_optab (&direct_optab_table[(int) DOI_reload_out])
702 #define vcond_optab (&direct_optab_table[(int) DOI_vcond])
703 #define vcondu_optab (&direct_optab_table[(int) DOI_vcondu])
704 #define movmem_optab (&direct_optab_table[(int) DOI_movmem])
705 #define setmem_optab (&direct_optab_table[(int) DOI_setmem])
706 #define cmpstr_optab (&direct_optab_table[(int) DOI_cmpstr])
707 #define cmpstrn_optab (&direct_optab_table[(int) DOI_cmpstrn])
708 #define cmpmem_optab (&direct_optab_table[(int) DOI_cmpmem])
709 #define sync_add_optab (&direct_optab_table[(int) DOI_sync_add])
710 #define sync_sub_optab (&direct_optab_table[(int) DOI_sync_sub])
711 #define sync_ior_optab (&direct_optab_table[(int) DOI_sync_ior])
712 #define sync_and_optab (&direct_optab_table[(int) DOI_sync_and])
713 #define sync_xor_optab (&direct_optab_table[(int) DOI_sync_xor])
714 #define sync_nand_optab (&direct_optab_table[(int) DOI_sync_nand])
715 #define sync_old_add_optab (&direct_optab_table[(int) DOI_sync_old_add])
716 #define sync_old_sub_optab (&direct_optab_table[(int) DOI_sync_old_sub])
717 #define sync_old_ior_optab (&direct_optab_table[(int) DOI_sync_old_ior])
718 #define sync_old_and_optab (&direct_optab_table[(int) DOI_sync_old_and])
719 #define sync_old_xor_optab (&direct_optab_table[(int) DOI_sync_old_xor])
720 #define sync_old_nand_optab (&direct_optab_table[(int) DOI_sync_old_nand])
721 #define sync_new_add_optab (&direct_optab_table[(int) DOI_sync_new_add])
722 #define sync_new_sub_optab (&direct_optab_table[(int) DOI_sync_new_sub])
723 #define sync_new_ior_optab (&direct_optab_table[(int) DOI_sync_new_ior])
724 #define sync_new_and_optab (&direct_optab_table[(int) DOI_sync_new_and])
725 #define sync_new_xor_optab (&direct_optab_table[(int) DOI_sync_new_xor])
726 #define sync_new_nand_optab (&direct_optab_table[(int) DOI_sync_new_nand])
727 #define sync_compare_and_swap_optab \
728 (&direct_optab_table[(int) DOI_sync_compare_and_swap])
729 #define sync_lock_test_and_set_optab \
730 (&direct_optab_table[(int) DOI_sync_lock_test_and_set])
731 #define sync_lock_release_optab \
732 (&direct_optab_table[(int) DOI_sync_lock_release])
733 \f
734 /* Target-dependent globals. */
735 struct target_optabs {
736 /* Tables of patterns that may have an associated libcall. */
737 struct optab_d x_optab_table[(int) OTI_MAX];
738
739 /* Tables of patterns for converting one mode to another. */
740 struct convert_optab_d x_convert_optab_table[(int) COI_MAX];
741
742 /* Tables of patterns for direct optabs (i.e. those which cannot be
743 implemented using a libcall). */
744 struct direct_optab_d x_direct_optab_table[(int) DOI_MAX];
745 };
746
747 extern struct target_optabs default_target_optabs;
748 #if SWITCHABLE_TARGET
749 extern struct target_optabs *this_target_optabs;
750 #else
751 #define this_target_optabs (&default_target_optabs)
752 #endif
753
754 #define optab_table \
755 (this_target_optabs->x_optab_table)
756 #define convert_optab_table \
757 (this_target_optabs->x_convert_optab_table)
758 #define direct_optab_table \
759 (this_target_optabs->x_direct_optab_table)
760 \f
761 /* Define functions given in optabs.c. */
762
763 extern rtx expand_widen_pattern_expr (sepops ops, rtx op0, rtx op1, rtx wide_op,
764 rtx target, int unsignedp);
765
766 extern rtx expand_ternary_op (enum machine_mode mode, optab ternary_optab,
767 rtx op0, rtx op1, rtx op2, rtx target,
768 int unsignedp);
769
770 /* Expand a binary operation given optab and rtx operands. */
771 extern rtx expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
772 enum optab_methods);
773
774 extern bool force_expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
775 enum optab_methods);
776
777 /* Expand a binary operation with both signed and unsigned forms. */
778 extern rtx sign_expand_binop (enum machine_mode, optab, optab, rtx, rtx,
779 rtx, int, enum optab_methods);
780
781 /* Generate code to perform an operation on one operand with two results. */
782 extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
783
784 /* Generate code to perform an operation on two operands with two results. */
785 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
786
787 /* Generate code to perform an operation on two operands with two
788 results, using a library function. */
789 extern bool expand_twoval_binop_libfunc (optab, rtx, rtx, rtx, rtx,
790 enum rtx_code);
791
792 /* Expand a unary arithmetic operation given optab rtx operand. */
793 extern rtx expand_unop (enum machine_mode, optab, rtx, rtx, int);
794
795 /* Expand the absolute value operation. */
796 extern rtx expand_abs_nojump (enum machine_mode, rtx, rtx, int);
797 extern rtx expand_abs (enum machine_mode, rtx, rtx, int, int);
798
799 /* Expand the one's complement absolute value operation. */
800 extern rtx expand_one_cmpl_abs_nojump (enum machine_mode, rtx, rtx);
801
802 /* Expand the copysign operation. */
803 extern rtx expand_copysign (rtx, rtx, rtx);
804
805 /* Generate an instruction with a given INSN_CODE with an output and
806 an input. */
807 extern void emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
808 extern bool maybe_emit_unop_insn (enum insn_code, rtx, rtx, enum rtx_code);
809
810 /* An extra flag to control optab_for_tree_code's behavior. This is needed to
811 distinguish between machines with a vector shift that takes a scalar for the
812 shift amount vs. machines that take a vector for the shift amount. */
813 enum optab_subtype
814 {
815 optab_default,
816 optab_scalar,
817 optab_vector
818 };
819
820 /* Return the optab used for computing the given operation on the type given by
821 the second argument. The third argument distinguishes between the types of
822 vector shifts and rotates */
823 extern optab optab_for_tree_code (enum tree_code, const_tree, enum optab_subtype);
824
825 /* The various uses that a comparison can have; used by can_compare_p:
826 jumps, conditional moves, store flag operations. */
827 enum can_compare_purpose
828 {
829 ccp_jump,
830 ccp_cmov,
831 ccp_store_flag
832 };
833
834 /* Nonzero if a compare of mode MODE can be done straightforwardly
835 (without splitting it into pieces). */
836 extern int can_compare_p (enum rtx_code, enum machine_mode,
837 enum can_compare_purpose);
838
839 /* Return the INSN_CODE to use for an extend operation. */
840 extern enum insn_code can_extend_p (enum machine_mode, enum machine_mode, int);
841
842 /* Generate the body of an insn to extend Y (with mode MFROM)
843 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
844 extern rtx gen_extend_insn (rtx, rtx, enum machine_mode,
845 enum machine_mode, int);
846
847 /* Call this to reset the function entry for one optab. */
848 extern void set_optab_libfunc (optab, enum machine_mode, const char *);
849 extern void set_conv_libfunc (convert_optab, enum machine_mode,
850 enum machine_mode, const char *);
851
852 /* Generate code for a FIXED_CONVERT_EXPR. */
853 extern void expand_fixed_convert (rtx, rtx, int, int);
854
855 /* Generate code for a FLOAT_EXPR. */
856 extern void expand_float (rtx, rtx, int);
857
858 /* Return the insn_code for a FLOAT_EXPR. */
859 enum insn_code can_float_p (enum machine_mode, enum machine_mode, int);
860
861 /* Generate code for a FIX_EXPR. */
862 extern void expand_fix (rtx, rtx, int);
863
864 /* Generate code for float to integral conversion. */
865 extern bool expand_sfix_optab (rtx, rtx, convert_optab);
866
867 /* Generate code for a widening multiply. */
868 extern rtx expand_widening_mult (enum machine_mode, rtx, rtx, rtx, int, optab);
869
870 /* Return tree if target supports vector operations for COND_EXPR. */
871 bool expand_vec_cond_expr_p (tree, enum machine_mode);
872
873 /* Generate code for VEC_COND_EXPR. */
874 extern rtx expand_vec_cond_expr (tree, tree, tree, tree, rtx);
875 /* Generate code for VEC_LSHIFT_EXPR and VEC_RSHIFT_EXPR. */
876 extern rtx expand_vec_shift_expr (sepops, rtx);
877
878 /* Return the insn used to implement mode MODE of OP, or CODE_FOR_nothing
879 if the target does not have such an insn. */
880
881 static inline enum insn_code
882 optab_handler (optab op, enum machine_mode mode)
883 {
884 return (enum insn_code) (op->handlers[(int) mode].insn_code
885 + (int) CODE_FOR_nothing);
886 }
887
888 /* Like optab_handler, but for widening_operations that have a TO_MODE and
889 a FROM_MODE. */
890
891 static inline enum insn_code
892 widening_optab_handler (optab op, enum machine_mode to_mode,
893 enum machine_mode from_mode)
894 {
895 if (to_mode == from_mode || from_mode == VOIDmode)
896 return optab_handler (op, to_mode);
897
898 if (op->widening)
899 return (enum insn_code) (op->widening->handlers[(int) to_mode][(int) from_mode].insn_code
900 + (int) CODE_FOR_nothing);
901
902 return CODE_FOR_nothing;
903 }
904
905 /* Record that insn CODE should be used to implement mode MODE of OP. */
906
907 static inline void
908 set_optab_handler (optab op, enum machine_mode mode, enum insn_code code)
909 {
910 op->handlers[(int) mode].insn_code = (int) code - (int) CODE_FOR_nothing;
911 }
912
913 /* Like set_optab_handler, but for widening operations that have a TO_MODE
914 and a FROM_MODE. */
915
916 static inline void
917 set_widening_optab_handler (optab op, enum machine_mode to_mode,
918 enum machine_mode from_mode, enum insn_code code)
919 {
920 if (to_mode == from_mode)
921 set_optab_handler (op, to_mode, code);
922 else
923 {
924 if (op->widening == NULL)
925 op->widening = (struct widening_optab_handlers *)
926 xcalloc (1, sizeof (struct widening_optab_handlers));
927
928 op->widening->handlers[(int) to_mode][(int) from_mode].insn_code
929 = (int) code - (int) CODE_FOR_nothing;
930 }
931 }
932
933 /* Return the insn used to perform conversion OP from mode FROM_MODE
934 to mode TO_MODE; return CODE_FOR_nothing if the target does not have
935 such an insn. */
936
937 static inline enum insn_code
938 convert_optab_handler (convert_optab op, enum machine_mode to_mode,
939 enum machine_mode from_mode)
940 {
941 return ((enum insn_code)
942 (op->handlers[(int) to_mode][(int) from_mode].insn_code
943 + (int) CODE_FOR_nothing));
944 }
945
946 /* Record that insn CODE should be used to perform conversion OP
947 from mode FROM_MODE to mode TO_MODE. */
948
949 static inline void
950 set_convert_optab_handler (convert_optab op, enum machine_mode to_mode,
951 enum machine_mode from_mode, enum insn_code code)
952 {
953 op->handlers[(int) to_mode][(int) from_mode].insn_code
954 = (int) code - (int) CODE_FOR_nothing;
955 }
956
957 /* Return the insn used to implement mode MODE of OP, or CODE_FOR_nothing
958 if the target does not have such an insn. */
959
960 static inline enum insn_code
961 direct_optab_handler (direct_optab op, enum machine_mode mode)
962 {
963 return (enum insn_code) (op->handlers[(int) mode].insn_code
964 + (int) CODE_FOR_nothing);
965 }
966
967 /* Record that insn CODE should be used to implement mode MODE of OP. */
968
969 static inline void
970 set_direct_optab_handler (direct_optab op, enum machine_mode mode,
971 enum insn_code code)
972 {
973 op->handlers[(int) mode].insn_code = (int) code - (int) CODE_FOR_nothing;
974 }
975
976 extern rtx optab_libfunc (optab optab, enum machine_mode mode);
977 extern rtx convert_optab_libfunc (convert_optab optab, enum machine_mode mode1,
978 enum machine_mode mode2);
979
980 extern bool insn_operand_matches (enum insn_code icode, unsigned int opno,
981 rtx operand);
982
983 /* Describes the type of an expand_operand. Each value is associated
984 with a create_*_operand function; see the comments above those
985 functions for details. */
986 enum expand_operand_type {
987 EXPAND_FIXED,
988 EXPAND_OUTPUT,
989 EXPAND_INPUT,
990 EXPAND_CONVERT_TO,
991 EXPAND_CONVERT_FROM,
992 EXPAND_ADDRESS,
993 EXPAND_INTEGER
994 };
995
996 /* Information about an operand for instruction expansion. */
997 struct expand_operand {
998 /* The type of operand. */
999 ENUM_BITFIELD (expand_operand_type) type : 8;
1000
1001 /* True if any conversion should treat VALUE as being unsigned
1002 rather than signed. Only meaningful for certain types. */
1003 unsigned int unsigned_p : 1;
1004
1005 /* Unused; available for future use. */
1006 unsigned int unused : 7;
1007
1008 /* The mode passed to the convert_*_operand function. It has a
1009 type-dependent meaning. */
1010 ENUM_BITFIELD (machine_mode) mode : 16;
1011
1012 /* The value of the operand. */
1013 rtx value;
1014 };
1015
1016 /* Initialize OP with the given fields. Initialise the other fields
1017 to their default values. */
1018
1019 static inline void
1020 create_expand_operand (struct expand_operand *op,
1021 enum expand_operand_type type,
1022 rtx value, enum machine_mode mode,
1023 bool unsigned_p)
1024 {
1025 op->type = type;
1026 op->unsigned_p = unsigned_p;
1027 op->unused = 0;
1028 op->mode = mode;
1029 op->value = value;
1030 }
1031
1032 /* Make OP describe an operand that must use rtx X, even if X is volatile. */
1033
1034 static inline void
1035 create_fixed_operand (struct expand_operand *op, rtx x)
1036 {
1037 create_expand_operand (op, EXPAND_FIXED, x, VOIDmode, false);
1038 }
1039
1040 /* Make OP describe an output operand that must have mode MODE.
1041 X, if nonnull, is a suggestion for where the output should be stored.
1042 It is OK for VALUE to be inconsistent with MODE, although it will just
1043 be ignored in that case. */
1044
1045 static inline void
1046 create_output_operand (struct expand_operand *op, rtx x,
1047 enum machine_mode mode)
1048 {
1049 create_expand_operand (op, EXPAND_OUTPUT, x, mode, false);
1050 }
1051
1052 /* Make OP describe an input operand that must have mode MODE and
1053 value VALUE; MODE cannot be VOIDmode. The backend may request that
1054 VALUE be copied into a different kind of rtx before being passed
1055 as an operand. */
1056
1057 static inline void
1058 create_input_operand (struct expand_operand *op, rtx value,
1059 enum machine_mode mode)
1060 {
1061 create_expand_operand (op, EXPAND_INPUT, value, mode, false);
1062 }
1063
1064 /* Like create_input_operand, except that VALUE must first be converted
1065 to mode MODE. UNSIGNED_P says whether VALUE is unsigned. */
1066
1067 static inline void
1068 create_convert_operand_to (struct expand_operand *op, rtx value,
1069 enum machine_mode mode, bool unsigned_p)
1070 {
1071 create_expand_operand (op, EXPAND_CONVERT_TO, value, mode, unsigned_p);
1072 }
1073
1074 /* Make OP describe an input operand that should have the same value
1075 as VALUE, after any mode conversion that the backend might request.
1076 If VALUE is a CONST_INT, it should be treated as having mode MODE.
1077 UNSIGNED_P says whether VALUE is unsigned. */
1078
1079 static inline void
1080 create_convert_operand_from (struct expand_operand *op, rtx value,
1081 enum machine_mode mode, bool unsigned_p)
1082 {
1083 create_expand_operand (op, EXPAND_CONVERT_FROM, value, mode, unsigned_p);
1084 }
1085
1086 extern void create_convert_operand_from_type (struct expand_operand *op,
1087 rtx value, tree type);
1088
1089 /* Make OP describe an input Pmode address operand. VALUE is the value
1090 of the address, but it may need to be converted to Pmode first. */
1091
1092 static inline void
1093 create_address_operand (struct expand_operand *op, rtx value)
1094 {
1095 create_expand_operand (op, EXPAND_ADDRESS, value, Pmode, false);
1096 }
1097
1098 /* Make OP describe an input operand that has value INTVAL and that has
1099 no inherent mode. This function should only be used for operands that
1100 are always expand-time constants. The backend may request that INTVAL
1101 be copied into a different kind of rtx, but it must specify the mode
1102 of that rtx if so. */
1103
1104 static inline void
1105 create_integer_operand (struct expand_operand *op, HOST_WIDE_INT intval)
1106 {
1107 create_expand_operand (op, EXPAND_INTEGER, GEN_INT (intval), VOIDmode, false);
1108 }
1109
1110 extern bool valid_multiword_target_p (rtx);
1111
1112 extern bool maybe_legitimize_operands (enum insn_code icode,
1113 unsigned int opno, unsigned int nops,
1114 struct expand_operand *ops);
1115 extern rtx maybe_gen_insn (enum insn_code icode, unsigned int nops,
1116 struct expand_operand *ops);
1117 extern bool maybe_expand_insn (enum insn_code icode, unsigned int nops,
1118 struct expand_operand *ops);
1119 extern bool maybe_expand_jump_insn (enum insn_code icode, unsigned int nops,
1120 struct expand_operand *ops);
1121 extern void expand_insn (enum insn_code icode, unsigned int nops,
1122 struct expand_operand *ops);
1123 extern void expand_jump_insn (enum insn_code icode, unsigned int nops,
1124 struct expand_operand *ops);
1125
1126 extern rtx prepare_operand (enum insn_code, rtx, int, enum machine_mode,
1127 enum machine_mode, int);
1128
1129 #endif /* GCC_OPTABS_H */