optabs.h revision 259563
1/* Definitions for code generation pass of GNU compiler.
2   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
3   Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING.  If not, write to
19the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA.  */
21
22#ifndef GCC_OPTABS_H
23#define GCC_OPTABS_H
24
25#include "insn-codes.h"
26
27/* Optabs are tables saying how to generate insn bodies
28   for various machine modes and numbers of operands.
29   Each optab applies to one operation.
30   For example, add_optab applies to addition.
31
32   The insn_code slot is the enum insn_code that says how to
33   generate an insn for this operation on a particular machine mode.
34   It is CODE_FOR_nothing if there is no such insn on the target machine.
35
36   The `lib_call' slot is the name of the library function that
37   can be used to perform the operation.
38
39   A few optabs, such as move_optab and cmp_optab, are used
40   by special code.  */
41
42struct optab_handlers GTY(())
43{
44  enum insn_code insn_code;
45  rtx libfunc;
46};
47
48struct optab GTY(())
49{
50  enum rtx_code code;
51  struct optab_handlers handlers[NUM_MACHINE_MODES];
52};
53typedef struct optab * optab;
54
55/* A convert_optab is for some sort of conversion operation between
56   modes.  The first array index is the destination mode, the second
57   is the source mode.  */
58struct convert_optab GTY(())
59{
60  enum rtx_code code;
61  struct optab_handlers handlers[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
62};
63typedef struct convert_optab *convert_optab;
64
65/* Given an enum insn_code, access the function to construct
66   the body of that kind of insn.  */
67#define GEN_FCN(CODE) (insn_data[CODE].genfun)
68
69/* Enumeration of valid indexes into optab_table.  */
70enum optab_index
71{
72  OTI_add,
73  OTI_addv,
74  OTI_sub,
75  OTI_subv,
76
77  /* Signed and fp multiply */
78  OTI_smul,
79  OTI_smulv,
80  /* Signed multiply, return high word */
81  OTI_smul_highpart,
82  OTI_umul_highpart,
83  /* Signed multiply with result one machine mode wider than args */
84  OTI_smul_widen,
85  OTI_umul_widen,
86  /* Widening multiply of one unsigned and one signed operand.  */
87  OTI_usmul_widen,
88
89  /* Signed divide */
90  OTI_sdiv,
91  OTI_sdivv,
92  /* Signed divide-and-remainder in one */
93  OTI_sdivmod,
94  OTI_udiv,
95  OTI_udivmod,
96  /* Signed remainder */
97  OTI_smod,
98  OTI_umod,
99  /* Floating point remainder functions */
100  OTI_fmod,
101  OTI_drem,
102  /* Convert float to integer in float fmt */
103  OTI_ftrunc,
104
105  /* Logical and */
106  OTI_and,
107  /* Logical or */
108  OTI_ior,
109  /* Logical xor */
110  OTI_xor,
111
112  /* Arithmetic shift left */
113  OTI_ashl,
114  /* Logical shift right */
115  OTI_lshr,
116  /* Arithmetic shift right */
117  OTI_ashr,
118  /* Rotate left */
119  OTI_rotl,
120  /* Rotate right */
121  OTI_rotr,
122  /* Signed and floating-point minimum value */
123  OTI_smin,
124  /* Signed and floating-point maximum value */
125  OTI_smax,
126  /* Unsigned minimum value */
127  OTI_umin,
128  /* Unsigned maximum value */
129  OTI_umax,
130  /* Power */
131  OTI_pow,
132  /* Arc tangent of y/x */
133  OTI_atan2,
134
135  /* Move instruction.  */
136  OTI_mov,
137  /* Move, preserving high part of register.  */
138  OTI_movstrict,
139  /* Move, with a misaligned memory.  */
140  OTI_movmisalign,
141
142  /* Unary operations */
143  /* Negation */
144  OTI_neg,
145  OTI_negv,
146  /* Abs value */
147  OTI_abs,
148  OTI_absv,
149  /* Byteswap */
150  OTI_bswap,
151  /* Bitwise not */
152  OTI_one_cmpl,
153  /* Bit scanning and counting */
154  OTI_ffs,
155  OTI_clz,
156  OTI_ctz,
157  OTI_popcount,
158  OTI_parity,
159  /* Square root */
160  OTI_sqrt,
161  /* Sine-Cosine */
162  OTI_sincos,
163  /* Sine */
164  OTI_sin,
165  /* Inverse sine */
166  OTI_asin,
167  /* Cosine */
168  OTI_cos,
169  /* Inverse cosine */
170  OTI_acos,
171  /* Exponential */
172  OTI_exp,
173  /* Base-10 Exponential */
174  OTI_exp10,
175  /* Base-2 Exponential */
176  OTI_exp2,
177  /* Exponential - 1*/
178  OTI_expm1,
179  /* Load exponent of a floating point number */
180  OTI_ldexp,
181  /* Radix-independent exponent */
182  OTI_logb,
183  OTI_ilogb,
184  /* Natural Logarithm */
185  OTI_log,
186  /* Base-10 Logarithm */
187  OTI_log10,
188  /* Base-2 Logarithm */
189  OTI_log2,
190  /* logarithm of 1 plus argument */
191  OTI_log1p,
192  /* Rounding functions */
193  OTI_floor,
194  OTI_lfloor,
195  OTI_ceil,
196  OTI_lceil,
197  OTI_btrunc,
198  OTI_round,
199  OTI_nearbyint,
200  OTI_rint,
201  OTI_lrint,
202  /* Tangent */
203  OTI_tan,
204  /* Inverse tangent */
205  OTI_atan,
206  /* Copy sign */
207  OTI_copysign,
208
209  /* Compare insn; two operands.  */
210  OTI_cmp,
211  /* Used only for libcalls for unsigned comparisons.  */
212  OTI_ucmp,
213  /* tst insn; compare one operand against 0 */
214  OTI_tst,
215
216  /* Floating point comparison optabs - used primarily for libfuncs */
217  OTI_eq,
218  OTI_ne,
219  OTI_gt,
220  OTI_ge,
221  OTI_lt,
222  OTI_le,
223  OTI_unord,
224
225  /* String length */
226  OTI_strlen,
227
228  /* Combined compare & jump/store flags/move operations.  */
229  OTI_cbranch,
230  OTI_cmov,
231  OTI_cstore,
232
233  /* Push instruction.  */
234  OTI_push,
235
236  /* Conditional add instruction.  */
237  OTI_addcc,
238
239  /* Reduction operations on a vector operand.  */
240  OTI_reduc_smax,
241  OTI_reduc_umax,
242  OTI_reduc_smin,
243  OTI_reduc_umin,
244  OTI_reduc_splus,
245  OTI_reduc_uplus,
246
247  /* Summation, with result machine mode one or more wider than args.  */
248  OTI_ssum_widen,
249  OTI_usum_widen,
250
251  /* Dot product, with result machine mode one or more wider than args.  */
252  OTI_sdot_prod,
253  OTI_udot_prod,
254
255  /* Set specified field of vector operand.  */
256  OTI_vec_set,
257  /* Extract specified field of vector operand.  */
258  OTI_vec_extract,
259  /* Initialize vector operand.  */
260  OTI_vec_init,
261  /* Whole vector shift. The shift amount is in bits.  */
262  OTI_vec_shl,
263  OTI_vec_shr,
264  /* Extract specified elements from vectors, for vector load.  */
265  OTI_vec_realign_load,
266
267  /* Perform a raise to the power of integer.  */
268  OTI_powi,
269
270  OTI_MAX
271};
272
273extern GTY(()) optab optab_table[OTI_MAX];
274
275#define add_optab (optab_table[OTI_add])
276#define sub_optab (optab_table[OTI_sub])
277#define smul_optab (optab_table[OTI_smul])
278#define addv_optab (optab_table[OTI_addv])
279#define subv_optab (optab_table[OTI_subv])
280#define smul_highpart_optab (optab_table[OTI_smul_highpart])
281#define umul_highpart_optab (optab_table[OTI_umul_highpart])
282#define smul_widen_optab (optab_table[OTI_smul_widen])
283#define umul_widen_optab (optab_table[OTI_umul_widen])
284#define usmul_widen_optab (optab_table[OTI_usmul_widen])
285#define sdiv_optab (optab_table[OTI_sdiv])
286#define smulv_optab (optab_table[OTI_smulv])
287#define sdivv_optab (optab_table[OTI_sdivv])
288#define sdivmod_optab (optab_table[OTI_sdivmod])
289#define udiv_optab (optab_table[OTI_udiv])
290#define udivmod_optab (optab_table[OTI_udivmod])
291#define smod_optab (optab_table[OTI_smod])
292#define umod_optab (optab_table[OTI_umod])
293#define fmod_optab (optab_table[OTI_fmod])
294#define drem_optab (optab_table[OTI_drem])
295#define ftrunc_optab (optab_table[OTI_ftrunc])
296#define and_optab (optab_table[OTI_and])
297#define ior_optab (optab_table[OTI_ior])
298#define xor_optab (optab_table[OTI_xor])
299#define ashl_optab (optab_table[OTI_ashl])
300#define lshr_optab (optab_table[OTI_lshr])
301#define ashr_optab (optab_table[OTI_ashr])
302#define rotl_optab (optab_table[OTI_rotl])
303#define rotr_optab (optab_table[OTI_rotr])
304#define smin_optab (optab_table[OTI_smin])
305#define smax_optab (optab_table[OTI_smax])
306#define umin_optab (optab_table[OTI_umin])
307#define umax_optab (optab_table[OTI_umax])
308#define pow_optab (optab_table[OTI_pow])
309#define atan2_optab (optab_table[OTI_atan2])
310
311#define mov_optab (optab_table[OTI_mov])
312#define movstrict_optab (optab_table[OTI_movstrict])
313#define movmisalign_optab (optab_table[OTI_movmisalign])
314
315#define neg_optab (optab_table[OTI_neg])
316#define negv_optab (optab_table[OTI_negv])
317#define abs_optab (optab_table[OTI_abs])
318#define absv_optab (optab_table[OTI_absv])
319#define one_cmpl_optab (optab_table[OTI_one_cmpl])
320#define bswap_optab (optab_table[OTI_bswap])
321#define ffs_optab (optab_table[OTI_ffs])
322#define clz_optab (optab_table[OTI_clz])
323#define ctz_optab (optab_table[OTI_ctz])
324#define popcount_optab (optab_table[OTI_popcount])
325#define parity_optab (optab_table[OTI_parity])
326#define sqrt_optab (optab_table[OTI_sqrt])
327#define sincos_optab (optab_table[OTI_sincos])
328#define sin_optab (optab_table[OTI_sin])
329#define asin_optab (optab_table[OTI_asin])
330#define cos_optab (optab_table[OTI_cos])
331#define acos_optab (optab_table[OTI_acos])
332#define exp_optab (optab_table[OTI_exp])
333#define exp10_optab (optab_table[OTI_exp10])
334#define exp2_optab (optab_table[OTI_exp2])
335#define expm1_optab (optab_table[OTI_expm1])
336#define ldexp_optab (optab_table[OTI_ldexp])
337#define logb_optab (optab_table[OTI_logb])
338#define ilogb_optab (optab_table[OTI_ilogb])
339#define log_optab (optab_table[OTI_log])
340#define log10_optab (optab_table[OTI_log10])
341#define log2_optab (optab_table[OTI_log2])
342#define log1p_optab (optab_table[OTI_log1p])
343#define floor_optab (optab_table[OTI_floor])
344#define lfloor_optab (optab_table[OTI_lfloor])
345#define ceil_optab (optab_table[OTI_ceil])
346#define lceil_optab (optab_table[OTI_lceil])
347#define btrunc_optab (optab_table[OTI_btrunc])
348#define round_optab (optab_table[OTI_round])
349#define nearbyint_optab (optab_table[OTI_nearbyint])
350#define rint_optab (optab_table[OTI_rint])
351#define lrint_optab (optab_table[OTI_lrint])
352#define tan_optab (optab_table[OTI_tan])
353#define atan_optab (optab_table[OTI_atan])
354#define copysign_optab (optab_table[OTI_copysign])
355
356#define cmp_optab (optab_table[OTI_cmp])
357#define ucmp_optab (optab_table[OTI_ucmp])
358#define tst_optab (optab_table[OTI_tst])
359
360#define eq_optab (optab_table[OTI_eq])
361#define ne_optab (optab_table[OTI_ne])
362#define gt_optab (optab_table[OTI_gt])
363#define ge_optab (optab_table[OTI_ge])
364#define lt_optab (optab_table[OTI_lt])
365#define le_optab (optab_table[OTI_le])
366#define unord_optab (optab_table[OTI_unord])
367
368#define strlen_optab (optab_table[OTI_strlen])
369
370#define cbranch_optab (optab_table[OTI_cbranch])
371#define cmov_optab (optab_table[OTI_cmov])
372#define cstore_optab (optab_table[OTI_cstore])
373#define push_optab (optab_table[OTI_push])
374#define addcc_optab (optab_table[OTI_addcc])
375
376#define reduc_smax_optab (optab_table[OTI_reduc_smax])
377#define reduc_umax_optab (optab_table[OTI_reduc_umax])
378#define reduc_smin_optab (optab_table[OTI_reduc_smin])
379#define reduc_umin_optab (optab_table[OTI_reduc_umin])
380#define reduc_splus_optab (optab_table[OTI_reduc_splus])
381#define reduc_uplus_optab (optab_table[OTI_reduc_uplus])
382
383#define ssum_widen_optab (optab_table[OTI_ssum_widen])
384#define usum_widen_optab (optab_table[OTI_usum_widen])
385#define sdot_prod_optab (optab_table[OTI_sdot_prod])
386#define udot_prod_optab (optab_table[OTI_udot_prod])
387
388#define vec_set_optab (optab_table[OTI_vec_set])
389#define vec_extract_optab (optab_table[OTI_vec_extract])
390#define vec_init_optab (optab_table[OTI_vec_init])
391#define vec_shl_optab (optab_table[OTI_vec_shl])
392#define vec_shr_optab (optab_table[OTI_vec_shr])
393#define vec_realign_load_optab (optab_table[OTI_vec_realign_load])
394
395#define powi_optab (optab_table[OTI_powi])
396
397/* Conversion optabs have their own table and indexes.  */
398enum convert_optab_index
399{
400  COI_sext,
401  COI_zext,
402  COI_trunc,
403
404  COI_sfix,
405  COI_ufix,
406
407  COI_sfixtrunc,
408  COI_ufixtrunc,
409
410  COI_sfloat,
411  COI_ufloat,
412
413  COI_MAX
414};
415
416extern GTY(()) convert_optab convert_optab_table[COI_MAX];
417
418#define sext_optab (convert_optab_table[COI_sext])
419#define zext_optab (convert_optab_table[COI_zext])
420#define trunc_optab (convert_optab_table[COI_trunc])
421#define sfix_optab (convert_optab_table[COI_sfix])
422#define ufix_optab (convert_optab_table[COI_ufix])
423#define sfixtrunc_optab (convert_optab_table[COI_sfixtrunc])
424#define ufixtrunc_optab (convert_optab_table[COI_ufixtrunc])
425#define sfloat_optab (convert_optab_table[COI_sfloat])
426#define ufloat_optab (convert_optab_table[COI_ufloat])
427
428/* These arrays record the insn_code of insns that may be needed to
429   perform input and output reloads of special objects.  They provide a
430   place to pass a scratch register.  */
431extern enum insn_code reload_in_optab[NUM_MACHINE_MODES];
432extern enum insn_code reload_out_optab[NUM_MACHINE_MODES];
433
434/* Contains the optab used for each rtx code.  */
435extern GTY(()) optab code_to_optab[NUM_RTX_CODE + 1];
436
437
438typedef rtx (*rtxfun) (rtx);
439
440/* Indexed by the rtx-code for a conditional (e.g. EQ, LT,...)
441   gives the gen_function to make a branch to test that condition.  */
442
443extern rtxfun bcc_gen_fctn[NUM_RTX_CODE];
444
445/* Indexed by the rtx-code for a conditional (e.g. EQ, LT,...)
446   gives the insn code to make a store-condition insn
447   to test that condition.  */
448
449extern enum insn_code setcc_gen_code[NUM_RTX_CODE];
450
451#ifdef HAVE_conditional_move
452/* Indexed by the machine mode, gives the insn code to make a conditional
453   move insn.  */
454
455extern enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
456#endif
457
458/* Indexed by the machine mode, gives the insn code for vector conditional
459   operation.  */
460
461extern enum insn_code vcond_gen_code[NUM_MACHINE_MODES];
462extern enum insn_code vcondu_gen_code[NUM_MACHINE_MODES];
463
464/* This array records the insn_code of insns to perform block moves.  */
465extern enum insn_code movmem_optab[NUM_MACHINE_MODES];
466
467/* This array records the insn_code of insns to perform block sets.  */
468extern enum insn_code setmem_optab[NUM_MACHINE_MODES];
469
470/* These arrays record the insn_code of two different kinds of insns
471   to perform block compares.  */
472extern enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
473extern enum insn_code cmpstrn_optab[NUM_MACHINE_MODES];
474extern enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
475
476/* Synchronization primitives.  This first set is atomic operation for
477   which we don't care about the resulting value.  */
478extern enum insn_code sync_add_optab[NUM_MACHINE_MODES];
479extern enum insn_code sync_sub_optab[NUM_MACHINE_MODES];
480extern enum insn_code sync_ior_optab[NUM_MACHINE_MODES];
481extern enum insn_code sync_and_optab[NUM_MACHINE_MODES];
482extern enum insn_code sync_xor_optab[NUM_MACHINE_MODES];
483extern enum insn_code sync_nand_optab[NUM_MACHINE_MODES];
484
485/* This second set is atomic operations in which we return the value
486   that existed in memory before the operation.  */
487extern enum insn_code sync_old_add_optab[NUM_MACHINE_MODES];
488extern enum insn_code sync_old_sub_optab[NUM_MACHINE_MODES];
489extern enum insn_code sync_old_ior_optab[NUM_MACHINE_MODES];
490extern enum insn_code sync_old_and_optab[NUM_MACHINE_MODES];
491extern enum insn_code sync_old_xor_optab[NUM_MACHINE_MODES];
492extern enum insn_code sync_old_nand_optab[NUM_MACHINE_MODES];
493
494/* This third set is atomic operations in which we return the value
495   that resulted after performing the operation.  */
496extern enum insn_code sync_new_add_optab[NUM_MACHINE_MODES];
497extern enum insn_code sync_new_sub_optab[NUM_MACHINE_MODES];
498extern enum insn_code sync_new_ior_optab[NUM_MACHINE_MODES];
499extern enum insn_code sync_new_and_optab[NUM_MACHINE_MODES];
500extern enum insn_code sync_new_xor_optab[NUM_MACHINE_MODES];
501extern enum insn_code sync_new_nand_optab[NUM_MACHINE_MODES];
502
503/* Atomic compare and swap.  */
504extern enum insn_code sync_compare_and_swap[NUM_MACHINE_MODES];
505extern enum insn_code sync_compare_and_swap_cc[NUM_MACHINE_MODES];
506
507/* Atomic exchange with acquire semantics.  */
508extern enum insn_code sync_lock_test_and_set[NUM_MACHINE_MODES];
509
510/* Atomic clear with release semantics.  */
511extern enum insn_code sync_lock_release[NUM_MACHINE_MODES];
512
513/* Define functions given in optabs.c.  */
514
515extern rtx expand_widen_pattern_expr (tree exp, rtx op0, rtx op1, rtx wide_op,
516                                      rtx target, int unsignedp);
517
518extern rtx expand_ternary_op (enum machine_mode mode, optab ternary_optab,
519			      rtx op0, rtx op1, rtx op2, rtx target,
520			      int unsignedp);
521
522/* Expand a binary operation given optab and rtx operands.  */
523extern rtx expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
524			 enum optab_methods);
525
526extern bool force_expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
527				enum optab_methods);
528
529/* Expand a binary operation with both signed and unsigned forms.  */
530extern rtx sign_expand_binop (enum machine_mode, optab, optab, rtx, rtx,
531			      rtx, int, enum optab_methods);
532
533/* Generate code to perform an operation on one operand with two results.  */
534extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
535
536/* Generate code to perform an operation on two operands with two results.  */
537extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
538
539/* Generate code to perform an operation on two operands with two
540   results, using a library function.  */
541extern bool expand_twoval_binop_libfunc (optab, rtx, rtx, rtx, rtx,
542					 enum rtx_code);
543
544/* Expand a unary arithmetic operation given optab rtx operand.  */
545extern rtx expand_unop (enum machine_mode, optab, rtx, rtx, int);
546
547/* Expand the absolute value operation.  */
548extern rtx expand_abs_nojump (enum machine_mode, rtx, rtx, int);
549extern rtx expand_abs (enum machine_mode, rtx, rtx, int, int);
550
551/* Expand the copysign operation.  */
552extern rtx expand_copysign (rtx, rtx, rtx);
553
554/* Generate an instruction with a given INSN_CODE with an output and
555   an input.  */
556extern void emit_unop_insn (int, rtx, rtx, enum rtx_code);
557
558/* Emit code to perform a series of operations on a multi-word quantity, one
559   word at a time.  */
560extern rtx emit_no_conflict_block (rtx, rtx, rtx, rtx, rtx);
561
562/* Emit one rtl insn to compare two rtx's.  */
563extern void emit_cmp_insn (rtx, rtx, enum rtx_code, rtx, enum machine_mode,
564			   int);
565
566/* The various uses that a comparison can have; used by can_compare_p:
567   jumps, conditional moves, store flag operations.  */
568enum can_compare_purpose
569{
570  ccp_jump,
571  ccp_cmov,
572  ccp_store_flag
573};
574
575/* Return the optab used for computing the given operation on the type
576   given by the second argument.  */
577extern optab optab_for_tree_code (enum tree_code, tree);
578
579/* Nonzero if a compare of mode MODE can be done straightforwardly
580   (without splitting it into pieces).  */
581extern int can_compare_p (enum rtx_code, enum machine_mode,
582			  enum can_compare_purpose);
583
584/* Return the INSN_CODE to use for an extend operation.  */
585extern enum insn_code can_extend_p (enum machine_mode, enum machine_mode, int);
586
587/* Generate the body of an insn to extend Y (with mode MFROM)
588   into X (with mode MTO).  Do zero-extension if UNSIGNEDP is nonzero.  */
589extern rtx gen_extend_insn (rtx, rtx, enum machine_mode,
590			    enum machine_mode, int);
591
592/* Call this to reset the function entry for one optab.  */
593extern void set_optab_libfunc (optab, enum machine_mode, const char *);
594extern void set_conv_libfunc (convert_optab, enum machine_mode,
595			      enum machine_mode, const char *);
596
597/* Generate code for a FLOAT_EXPR.  */
598extern void expand_float (rtx, rtx, int);
599
600/* Generate code for a FIX_EXPR.  */
601extern void expand_fix (rtx, rtx, int);
602
603/* Return tree if target supports vector operations for COND_EXPR.  */
604bool expand_vec_cond_expr_p (tree, enum machine_mode);
605
606/* Generate code for VEC_COND_EXPR.  */
607extern rtx expand_vec_cond_expr (tree, rtx);
608
609/* Generate code for VEC_LSHIFT_EXPR and VEC_RSHIFT_EXPR.  */
610extern rtx expand_vec_shift_expr (tree, rtx);
611
612#endif /* GCC_OPTABS_H */
613