OSDN Git Service

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