Merge from the pain train
[official-gcc.git] / gcc / optabs.h
blobe0a7985bc15472d6ad40816d23889db5c3f6516e
1 /* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef GCC_OPTABS_H
22 #define GCC_OPTABS_H
24 #include "insn-codes.h"
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 For example, add_optab applies to addition.
31 The insn_code slot is the enum insn_code that says how to
32 generate an insn for this operation on a particular machine mode.
33 It is CODE_FOR_nothing if there is no such insn on the target machine.
35 The `lib_call' slot is the name of the library function that
36 can be used to perform the operation.
38 A few optabs, such as move_optab and cmp_optab, are used
39 by special code. */
41 struct optab_handlers GTY(())
43 enum insn_code insn_code;
44 rtx libfunc;
47 struct optab GTY(())
49 enum rtx_code code;
50 struct optab_handlers handlers[NUM_MACHINE_MODES];
52 typedef struct optab * optab;
54 /* A convert_optab is for some sort of conversion operation between
55 modes. The first array index is the destination mode, the second
56 is the source mode. */
57 struct convert_optab GTY(())
59 enum rtx_code code;
60 struct optab_handlers handlers[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
62 typedef struct convert_optab *convert_optab;
64 /* Given an enum insn_code, access the function to construct
65 the body of that kind of insn. */
66 #define GEN_FCN(CODE) (insn_data[CODE].genfun)
68 /* Enumeration of valid indexes into optab_table. */
69 enum optab_index
71 OTI_add,
72 OTI_addv,
73 OTI_sub,
74 OTI_subv,
76 /* Signed and fp multiply */
77 OTI_smul,
78 OTI_smulv,
79 /* Signed multiply, return high word */
80 OTI_smul_highpart,
81 OTI_umul_highpart,
82 /* Signed multiply with result one machine mode wider than args */
83 OTI_smul_widen,
84 OTI_umul_widen,
86 /* Signed divide */
87 OTI_sdiv,
88 OTI_sdivv,
89 /* Signed divide-and-remainder in one */
90 OTI_sdivmod,
91 OTI_udiv,
92 OTI_udivmod,
93 /* Signed remainder */
94 OTI_smod,
95 OTI_umod,
96 /* Floating point remainder functions */
97 OTI_fmod,
98 OTI_drem,
99 /* Convert float to integer in float fmt */
100 OTI_ftrunc,
102 /* Logical and */
103 OTI_and,
104 /* Logical or */
105 OTI_ior,
106 /* Logical xor */
107 OTI_xor,
109 /* Arithmetic shift left */
110 OTI_ashl,
111 /* Logical shift right */
112 OTI_lshr,
113 /* Arithmetic shift right */
114 OTI_ashr,
115 /* Rotate left */
116 OTI_rotl,
117 /* Rotate right */
118 OTI_rotr,
119 /* Signed and floating-point minimum value */
120 OTI_smin,
121 /* Signed and floating-point maximum value */
122 OTI_smax,
123 /* Unsigned minimum value */
124 OTI_umin,
125 /* Unsigned maximum value */
126 OTI_umax,
127 /* Power */
128 OTI_pow,
129 /* Arc tangent of y/x */
130 OTI_atan2,
132 /* Move instruction. */
133 OTI_mov,
134 /* Move, preserving high part of register. */
135 OTI_movstrict,
136 /* Move, with a misaligned memory. */
137 OTI_movmisalign,
139 /* Unary operations */
140 /* Negation */
141 OTI_neg,
142 OTI_negv,
143 /* Abs value */
144 OTI_abs,
145 OTI_absv,
146 /* Bitwise not */
147 OTI_one_cmpl,
148 /* Bit scanning and counting */
149 OTI_ffs,
150 OTI_clz,
151 OTI_ctz,
152 OTI_popcount,
153 OTI_parity,
154 /* Square root */
155 OTI_sqrt,
156 /* Sine-Cosine */
157 OTI_sincos,
158 /* Sine */
159 OTI_sin,
160 /* Inverse sine */
161 OTI_asin,
162 /* Cosine */
163 OTI_cos,
164 /* Inverse cosine */
165 OTI_acos,
166 /* Exponential */
167 OTI_exp,
168 /* Base-10 Exponential */
169 OTI_exp10,
170 /* Base-2 Exponential */
171 OTI_exp2,
172 /* Exponential - 1*/
173 OTI_expm1,
174 /* Load exponent of a floating point number */
175 OTI_ldexp,
176 /* Radix-independent exponent */
177 OTI_logb,
178 OTI_ilogb,
179 /* Natural Logarithm */
180 OTI_log,
181 /* Base-10 Logarithm */
182 OTI_log10,
183 /* Base-2 Logarithm */
184 OTI_log2,
185 /* logarithm of 1 plus argument */
186 OTI_log1p,
187 /* Rounding functions */
188 OTI_floor,
189 OTI_ceil,
190 OTI_btrunc,
191 OTI_round,
192 OTI_nearbyint,
193 OTI_rint,
194 /* Tangent */
195 OTI_tan,
196 /* Inverse tangent */
197 OTI_atan,
198 /* Copy sign */
199 OTI_copysign,
201 /* Compare insn; two operands. */
202 OTI_cmp,
203 /* Used only for libcalls for unsigned comparisons. */
204 OTI_ucmp,
205 /* tst insn; compare one operand against 0 */
206 OTI_tst,
208 /* Floating point comparison optabs - used primarily for libfuncs */
209 OTI_eq,
210 OTI_ne,
211 OTI_gt,
212 OTI_ge,
213 OTI_lt,
214 OTI_le,
215 OTI_unord,
217 /* String length */
218 OTI_strlen,
220 /* Combined compare & jump/store flags/move operations. */
221 OTI_cbranch,
222 OTI_cmov,
223 OTI_cstore,
225 /* Push instruction. */
226 OTI_push,
228 /* Conditional add instruction. */
229 OTI_addcc,
231 /* Set specified field of vector operand. */
232 OTI_vec_set,
233 /* Extract specified field of vector operand. */
234 OTI_vec_extract,
235 /* Initialize vector operand. */
236 OTI_vec_init,
237 /* Extract specified elements from vectors, for vector load. */
238 OTI_vec_realign_load,
240 /* Perform a raise to the power of integer. */
241 OTI_powi,
243 OTI_MAX
246 extern GTY(()) optab optab_table[OTI_MAX];
248 #define add_optab (optab_table[OTI_add])
249 #define sub_optab (optab_table[OTI_sub])
250 #define smul_optab (optab_table[OTI_smul])
251 #define addv_optab (optab_table[OTI_addv])
252 #define subv_optab (optab_table[OTI_subv])
253 #define smul_highpart_optab (optab_table[OTI_smul_highpart])
254 #define umul_highpart_optab (optab_table[OTI_umul_highpart])
255 #define smul_widen_optab (optab_table[OTI_smul_widen])
256 #define umul_widen_optab (optab_table[OTI_umul_widen])
257 #define sdiv_optab (optab_table[OTI_sdiv])
258 #define smulv_optab (optab_table[OTI_smulv])
259 #define sdivv_optab (optab_table[OTI_sdivv])
260 #define sdivmod_optab (optab_table[OTI_sdivmod])
261 #define udiv_optab (optab_table[OTI_udiv])
262 #define udivmod_optab (optab_table[OTI_udivmod])
263 #define smod_optab (optab_table[OTI_smod])
264 #define umod_optab (optab_table[OTI_umod])
265 #define fmod_optab (optab_table[OTI_fmod])
266 #define drem_optab (optab_table[OTI_drem])
267 #define ftrunc_optab (optab_table[OTI_ftrunc])
268 #define and_optab (optab_table[OTI_and])
269 #define ior_optab (optab_table[OTI_ior])
270 #define xor_optab (optab_table[OTI_xor])
271 #define ashl_optab (optab_table[OTI_ashl])
272 #define lshr_optab (optab_table[OTI_lshr])
273 #define ashr_optab (optab_table[OTI_ashr])
274 #define rotl_optab (optab_table[OTI_rotl])
275 #define rotr_optab (optab_table[OTI_rotr])
276 #define smin_optab (optab_table[OTI_smin])
277 #define smax_optab (optab_table[OTI_smax])
278 #define umin_optab (optab_table[OTI_umin])
279 #define umax_optab (optab_table[OTI_umax])
280 #define pow_optab (optab_table[OTI_pow])
281 #define atan2_optab (optab_table[OTI_atan2])
283 #define mov_optab (optab_table[OTI_mov])
284 #define movstrict_optab (optab_table[OTI_movstrict])
285 #define movmisalign_optab (optab_table[OTI_movmisalign])
287 #define neg_optab (optab_table[OTI_neg])
288 #define negv_optab (optab_table[OTI_negv])
289 #define abs_optab (optab_table[OTI_abs])
290 #define absv_optab (optab_table[OTI_absv])
291 #define one_cmpl_optab (optab_table[OTI_one_cmpl])
292 #define ffs_optab (optab_table[OTI_ffs])
293 #define clz_optab (optab_table[OTI_clz])
294 #define ctz_optab (optab_table[OTI_ctz])
295 #define popcount_optab (optab_table[OTI_popcount])
296 #define parity_optab (optab_table[OTI_parity])
297 #define sqrt_optab (optab_table[OTI_sqrt])
298 #define sincos_optab (optab_table[OTI_sincos])
299 #define sin_optab (optab_table[OTI_sin])
300 #define asin_optab (optab_table[OTI_asin])
301 #define cos_optab (optab_table[OTI_cos])
302 #define acos_optab (optab_table[OTI_acos])
303 #define exp_optab (optab_table[OTI_exp])
304 #define exp10_optab (optab_table[OTI_exp10])
305 #define exp2_optab (optab_table[OTI_exp2])
306 #define expm1_optab (optab_table[OTI_expm1])
307 #define ldexp_optab (optab_table[OTI_ldexp])
308 #define logb_optab (optab_table[OTI_logb])
309 #define ilogb_optab (optab_table[OTI_ilogb])
310 #define log_optab (optab_table[OTI_log])
311 #define log10_optab (optab_table[OTI_log10])
312 #define log2_optab (optab_table[OTI_log2])
313 #define log1p_optab (optab_table[OTI_log1p])
314 #define floor_optab (optab_table[OTI_floor])
315 #define ceil_optab (optab_table[OTI_ceil])
316 #define btrunc_optab (optab_table[OTI_btrunc])
317 #define round_optab (optab_table[OTI_round])
318 #define nearbyint_optab (optab_table[OTI_nearbyint])
319 #define rint_optab (optab_table[OTI_rint])
320 #define tan_optab (optab_table[OTI_tan])
321 #define atan_optab (optab_table[OTI_atan])
322 #define copysign_optab (optab_table[OTI_copysign])
324 #define cmp_optab (optab_table[OTI_cmp])
325 #define ucmp_optab (optab_table[OTI_ucmp])
326 #define tst_optab (optab_table[OTI_tst])
328 #define eq_optab (optab_table[OTI_eq])
329 #define ne_optab (optab_table[OTI_ne])
330 #define gt_optab (optab_table[OTI_gt])
331 #define ge_optab (optab_table[OTI_ge])
332 #define lt_optab (optab_table[OTI_lt])
333 #define le_optab (optab_table[OTI_le])
334 #define unord_optab (optab_table[OTI_unord])
336 #define strlen_optab (optab_table[OTI_strlen])
338 #define cbranch_optab (optab_table[OTI_cbranch])
339 #define cmov_optab (optab_table[OTI_cmov])
340 #define cstore_optab (optab_table[OTI_cstore])
341 #define push_optab (optab_table[OTI_push])
342 #define addcc_optab (optab_table[OTI_addcc])
344 #define vec_set_optab (optab_table[OTI_vec_set])
345 #define vec_extract_optab (optab_table[OTI_vec_extract])
346 #define vec_init_optab (optab_table[OTI_vec_init])
347 #define vec_realign_load_optab (optab_table[OTI_vec_realign_load])
349 #define powi_optab (optab_table[OTI_powi])
351 /* Conversion optabs have their own table and indexes. */
352 enum convert_optab_index
354 CTI_sext,
355 CTI_zext,
356 CTI_trunc,
358 CTI_sfix,
359 CTI_ufix,
361 CTI_sfixtrunc,
362 CTI_ufixtrunc,
364 CTI_sfloat,
365 CTI_ufloat,
367 CTI_MAX
370 extern GTY(()) convert_optab convert_optab_table[CTI_MAX];
372 #define sext_optab (convert_optab_table[CTI_sext])
373 #define zext_optab (convert_optab_table[CTI_zext])
374 #define trunc_optab (convert_optab_table[CTI_trunc])
375 #define sfix_optab (convert_optab_table[CTI_sfix])
376 #define ufix_optab (convert_optab_table[CTI_ufix])
377 #define sfixtrunc_optab (convert_optab_table[CTI_sfixtrunc])
378 #define ufixtrunc_optab (convert_optab_table[CTI_ufixtrunc])
379 #define sfloat_optab (convert_optab_table[CTI_sfloat])
380 #define ufloat_optab (convert_optab_table[CTI_ufloat])
382 /* These arrays record the insn_code of insns that may be needed to
383 perform input and output reloads of special objects. They provide a
384 place to pass a scratch register. */
385 extern enum insn_code reload_in_optab[NUM_MACHINE_MODES];
386 extern enum insn_code reload_out_optab[NUM_MACHINE_MODES];
388 /* Contains the optab used for each rtx code. */
389 extern GTY(()) optab code_to_optab[NUM_RTX_CODE + 1];
392 typedef rtx (*rtxfun) (rtx);
394 /* Indexed by the rtx-code for a conditional (e.g. EQ, LT,...)
395 gives the gen_function to make a branch to test that condition. */
397 extern rtxfun bcc_gen_fctn[NUM_RTX_CODE];
399 /* Indexed by the rtx-code for a conditional (e.g. EQ, LT,...)
400 gives the insn code to make a store-condition insn
401 to test that condition. */
403 extern enum insn_code setcc_gen_code[NUM_RTX_CODE];
405 #ifdef HAVE_conditional_move
406 /* Indexed by the machine mode, gives the insn code to make a conditional
407 move insn. */
409 extern enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
410 #endif
412 /* Indexed by the machine mode, gives the insn code for vector conditional
413 operation. */
415 extern enum insn_code vcond_gen_code[NUM_MACHINE_MODES];
416 extern enum insn_code vcondu_gen_code[NUM_MACHINE_MODES];
418 /* This array records the insn_code of insns to perform block moves. */
419 extern enum insn_code movmem_optab[NUM_MACHINE_MODES];
421 /* This array records the insn_code of insns to perform block clears. */
422 extern enum insn_code clrmem_optab[NUM_MACHINE_MODES];
424 /* These arrays record the insn_code of two different kinds of insns
425 to perform block compares. */
426 extern enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
427 extern enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
429 /* Define functions given in optabs.c. */
431 extern rtx expand_ternary_op (enum machine_mode mode, optab ternary_optab,
432 rtx op0, rtx op1, rtx op2, rtx target,
433 int unsignedp);
435 /* Expand a binary operation given optab and rtx operands. */
436 extern rtx expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
437 enum optab_methods);
439 extern bool force_expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
440 enum optab_methods);
442 /* Expand a binary operation with both signed and unsigned forms. */
443 extern rtx sign_expand_binop (enum machine_mode, optab, optab, rtx, rtx,
444 rtx, int, enum optab_methods);
446 /* Generate code to perform an operation on one operand with two results. */
447 extern int expand_twoval_unop (optab, rtx, rtx, rtx, int);
449 /* Generate code to perform an operation on two operands with two results. */
450 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
452 /* Generate code to perform an operation on two operands with two
453 results, using a library function. */
454 extern bool expand_twoval_binop_libfunc (optab, rtx, rtx, rtx, rtx,
455 enum rtx_code);
457 /* Expand a unary arithmetic operation given optab rtx operand. */
458 extern rtx expand_unop (enum machine_mode, optab, rtx, rtx, int);
460 /* Expand the absolute value operation. */
461 extern rtx expand_abs_nojump (enum machine_mode, rtx, rtx, int);
462 extern rtx expand_abs (enum machine_mode, rtx, rtx, int, int);
464 /* Expand the copysign operation. */
465 extern rtx expand_copysign (rtx, rtx, rtx);
466 extern rtx expand_copysign_absneg (enum machine_mode, rtx, rtx, rtx, int, bool);
468 /* Generate an instruction with a given INSN_CODE with an output and
469 an input. */
470 extern void emit_unop_insn (int, rtx, rtx, enum rtx_code);
472 /* Emit code to perform a series of operations on a multi-word quantity, one
473 word at a time. */
474 extern rtx emit_no_conflict_block (rtx, rtx, rtx, rtx, rtx);
476 /* Emit one rtl insn to compare two rtx's. */
477 extern void emit_cmp_insn (rtx, rtx, enum rtx_code, rtx, enum machine_mode,
478 int);
480 /* The various uses that a comparison can have; used by can_compare_p:
481 jumps, conditional moves, store flag operations. */
482 enum can_compare_purpose
484 ccp_jump,
485 ccp_cmov,
486 ccp_store_flag
489 /* Return the optab used for computing the given operation on the type
490 given by the second argument. */
491 extern optab optab_for_tree_code (enum tree_code, tree);
493 /* Nonzero if a compare of mode MODE can be done straightforwardly
494 (without splitting it into pieces). */
495 extern int can_compare_p (enum rtx_code, enum machine_mode,
496 enum can_compare_purpose);
498 /* Return the INSN_CODE to use for an extend operation. */
499 extern enum insn_code can_extend_p (enum machine_mode, enum machine_mode, int);
501 /* Generate the body of an insn to extend Y (with mode MFROM)
502 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
503 extern rtx gen_extend_insn (rtx, rtx, enum machine_mode,
504 enum machine_mode, int);
506 /* Call this to reset the function entry for one optab. */
507 extern void set_optab_libfunc (optab, enum machine_mode, const char *);
508 extern void set_conv_libfunc (convert_optab, enum machine_mode,
509 enum machine_mode, const char *);
511 /* Generate code for a FLOAT_EXPR. */
512 extern void expand_float (rtx, rtx, int);
514 /* Generate code for a FIX_EXPR. */
515 extern void expand_fix (rtx, rtx, int);
517 /* Return tree if target supports vector operations for COND_EXPR. */
518 bool expand_vec_cond_expr_p (tree, enum machine_mode);
520 /* Generate code for VEC_COND_EXPR. */
521 extern rtx expand_vec_cond_expr (tree, rtx);
523 #endif /* GCC_OPTABS_H */