re PR c++/14369 (errenous reject of well-formed code)
[official-gcc.git] / gcc / optabs.h
blob496ba1a6fc8e21a41a2beb034a726df1b160941f
1 /* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 2001, 2002, 2003, 2004 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 /* Convert float to integer in float fmt */
97 OTI_ftrunc,
99 /* Logical and */
100 OTI_and,
101 /* Logical or */
102 OTI_ior,
103 /* Logical xor */
104 OTI_xor,
106 /* Arithmetic shift left */
107 OTI_ashl,
108 /* Logical shift right */
109 OTI_lshr,
110 /* Arithmetic shift right */
111 OTI_ashr,
112 /* Rotate left */
113 OTI_rotl,
114 /* Rotate right */
115 OTI_rotr,
116 /* Signed and floating-point minimum value */
117 OTI_smin,
118 /* Signed and floating-point maximum value */
119 OTI_smax,
120 /* Unsigned minimum value */
121 OTI_umin,
122 /* Unsigned maximum value */
123 OTI_umax,
124 /* Power */
125 OTI_pow,
126 /* Arc tangent of y/x */
127 OTI_atan2,
129 /* Move instruction. */
130 OTI_mov,
131 /* Move, preserving high part of register. */
132 OTI_movstrict,
134 /* Unary operations */
135 /* Negation */
136 OTI_neg,
137 OTI_negv,
138 /* Abs value */
139 OTI_abs,
140 OTI_absv,
141 /* Bitwise not */
142 OTI_one_cmpl,
143 /* Bit scanning and counting */
144 OTI_ffs,
145 OTI_clz,
146 OTI_ctz,
147 OTI_popcount,
148 OTI_parity,
149 /* Square root */
150 OTI_sqrt,
151 /* Sine */
152 OTI_sin,
153 /* Cosine */
154 OTI_cos,
155 /* Exponential */
156 OTI_exp,
157 /* Natural Logarithm */
158 OTI_log,
159 /* Base-10 Logarithm */
160 OTI_log10,
161 /* Base-2 Logarithm */
162 OTI_log2,
163 /* Rounding functions */
164 OTI_floor,
165 OTI_ceil,
166 OTI_trunc,
167 OTI_round,
168 OTI_nearbyint,
169 /* Tangent */
170 OTI_tan,
171 /* Inverse tangent */
172 OTI_atan,
174 /* Compare insn; two operands. */
175 OTI_cmp,
176 /* Used only for libcalls for unsigned comparisons. */
177 OTI_ucmp,
178 /* tst insn; compare one operand against 0 */
179 OTI_tst,
181 /* Floating point comparison optabs - used primarily for libfuncs */
182 OTI_eq,
183 OTI_ne,
184 OTI_gt,
185 OTI_ge,
186 OTI_lt,
187 OTI_le,
188 OTI_unord,
190 /* String length */
191 OTI_strlen,
193 /* Combined compare & jump/store flags/move operations. */
194 OTI_cbranch,
195 OTI_cmov,
196 OTI_cstore,
198 /* Push instruction. */
199 OTI_push,
201 /* Conditional add instruction. */
202 OTI_addcc,
204 /* Set specified field of vector operand. */
205 OTI_vec_set,
206 /* Extract specified field of vector operand. */
207 OTI_vec_extract,
208 /* Initialize vector operand. */
209 OTI_vec_init,
211 OTI_MAX
214 extern GTY(()) optab optab_table[OTI_MAX];
216 #define add_optab (optab_table[OTI_add])
217 #define sub_optab (optab_table[OTI_sub])
218 #define smul_optab (optab_table[OTI_smul])
219 #define addv_optab (optab_table[OTI_addv])
220 #define subv_optab (optab_table[OTI_subv])
221 #define smul_highpart_optab (optab_table[OTI_smul_highpart])
222 #define umul_highpart_optab (optab_table[OTI_umul_highpart])
223 #define smul_widen_optab (optab_table[OTI_smul_widen])
224 #define umul_widen_optab (optab_table[OTI_umul_widen])
225 #define sdiv_optab (optab_table[OTI_sdiv])
226 #define smulv_optab (optab_table[OTI_smulv])
227 #define sdivv_optab (optab_table[OTI_sdivv])
228 #define sdivmod_optab (optab_table[OTI_sdivmod])
229 #define udiv_optab (optab_table[OTI_udiv])
230 #define udivmod_optab (optab_table[OTI_udivmod])
231 #define smod_optab (optab_table[OTI_smod])
232 #define umod_optab (optab_table[OTI_umod])
233 #define ftrunc_optab (optab_table[OTI_ftrunc])
234 #define and_optab (optab_table[OTI_and])
235 #define ior_optab (optab_table[OTI_ior])
236 #define xor_optab (optab_table[OTI_xor])
237 #define ashl_optab (optab_table[OTI_ashl])
238 #define lshr_optab (optab_table[OTI_lshr])
239 #define ashr_optab (optab_table[OTI_ashr])
240 #define rotl_optab (optab_table[OTI_rotl])
241 #define rotr_optab (optab_table[OTI_rotr])
242 #define smin_optab (optab_table[OTI_smin])
243 #define smax_optab (optab_table[OTI_smax])
244 #define umin_optab (optab_table[OTI_umin])
245 #define umax_optab (optab_table[OTI_umax])
246 #define pow_optab (optab_table[OTI_pow])
247 #define atan2_optab (optab_table[OTI_atan2])
249 #define mov_optab (optab_table[OTI_mov])
250 #define movstrict_optab (optab_table[OTI_movstrict])
252 #define neg_optab (optab_table[OTI_neg])
253 #define negv_optab (optab_table[OTI_negv])
254 #define abs_optab (optab_table[OTI_abs])
255 #define absv_optab (optab_table[OTI_absv])
256 #define one_cmpl_optab (optab_table[OTI_one_cmpl])
257 #define ffs_optab (optab_table[OTI_ffs])
258 #define clz_optab (optab_table[OTI_clz])
259 #define ctz_optab (optab_table[OTI_ctz])
260 #define popcount_optab (optab_table[OTI_popcount])
261 #define parity_optab (optab_table[OTI_parity])
262 #define sqrt_optab (optab_table[OTI_sqrt])
263 #define sin_optab (optab_table[OTI_sin])
264 #define cos_optab (optab_table[OTI_cos])
265 #define exp_optab (optab_table[OTI_exp])
266 #define log_optab (optab_table[OTI_log])
267 #define log10_optab (optab_table[OTI_log10])
268 #define log2_optab (optab_table[OTI_log2])
269 #define floor_optab (optab_table[OTI_floor])
270 #define ceil_optab (optab_table[OTI_ceil])
271 #define btrunc_optab (optab_table[OTI_trunc])
272 #define round_optab (optab_table[OTI_round])
273 #define nearbyint_optab (optab_table[OTI_nearbyint])
274 #define tan_optab (optab_table[OTI_tan])
275 #define atan_optab (optab_table[OTI_atan])
277 #define cmp_optab (optab_table[OTI_cmp])
278 #define ucmp_optab (optab_table[OTI_ucmp])
279 #define tst_optab (optab_table[OTI_tst])
281 #define eq_optab (optab_table[OTI_eq])
282 #define ne_optab (optab_table[OTI_ne])
283 #define gt_optab (optab_table[OTI_gt])
284 #define ge_optab (optab_table[OTI_ge])
285 #define lt_optab (optab_table[OTI_lt])
286 #define le_optab (optab_table[OTI_le])
287 #define unord_optab (optab_table[OTI_unord])
289 #define strlen_optab (optab_table[OTI_strlen])
291 #define cbranch_optab (optab_table[OTI_cbranch])
292 #define cmov_optab (optab_table[OTI_cmov])
293 #define cstore_optab (optab_table[OTI_cstore])
294 #define push_optab (optab_table[OTI_push])
295 #define addcc_optab (optab_table[OTI_addcc])
297 #define vec_set_optab (optab_table[OTI_vec_set])
298 #define vec_extract_optab (optab_table[OTI_vec_extract])
299 #define vec_init_optab (optab_table[OTI_vec_init])
301 /* Conversion optabs have their own table and indexes. */
302 enum convert_optab_index
304 CTI_sext,
305 CTI_zext,
306 CTI_trunc,
308 CTI_sfix,
309 CTI_ufix,
311 CTI_sfixtrunc,
312 CTI_ufixtrunc,
314 CTI_sfloat,
315 CTI_ufloat,
317 CTI_MAX
320 extern GTY(()) convert_optab convert_optab_table[CTI_MAX];
322 #define sext_optab (convert_optab_table[CTI_sext])
323 #define zext_optab (convert_optab_table[CTI_zext])
324 #define trunc_optab (convert_optab_table[CTI_trunc])
325 #define sfix_optab (convert_optab_table[CTI_sfix])
326 #define ufix_optab (convert_optab_table[CTI_ufix])
327 #define sfixtrunc_optab (convert_optab_table[CTI_sfixtrunc])
328 #define ufixtrunc_optab (convert_optab_table[CTI_ufixtrunc])
329 #define sfloat_optab (convert_optab_table[CTI_sfloat])
330 #define ufloat_optab (convert_optab_table[CTI_ufloat])
332 /* These arrays record the insn_code of insns that may be needed to
333 perform input and output reloads of special objects. They provide a
334 place to pass a scratch register. */
335 extern enum insn_code reload_in_optab[NUM_MACHINE_MODES];
336 extern enum insn_code reload_out_optab[NUM_MACHINE_MODES];
338 /* Contains the optab used for each rtx code. */
339 extern GTY(()) optab code_to_optab[NUM_RTX_CODE + 1];
342 typedef rtx (*rtxfun) (rtx);
344 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
345 gives the gen_function to make a branch to test that condition. */
347 extern rtxfun bcc_gen_fctn[NUM_RTX_CODE];
349 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
350 gives the insn code to make a store-condition insn
351 to test that condition. */
353 extern enum insn_code setcc_gen_code[NUM_RTX_CODE];
355 #ifdef HAVE_conditional_move
356 /* Indexed by the machine mode, gives the insn code to make a conditional
357 move insn. */
359 extern enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
360 #endif
362 /* This array records the insn_code of insns to perform block moves. */
363 extern enum insn_code movstr_optab[NUM_MACHINE_MODES];
365 /* This array records the insn_code of insns to perform block clears. */
366 extern enum insn_code clrstr_optab[NUM_MACHINE_MODES];
368 /* These arrays record the insn_code of two different kinds of insns
369 to perform block compares. */
370 extern enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
371 extern enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
373 /* Define functions given in optabs.c. */
375 /* Expand a binary operation given optab and rtx operands. */
376 extern rtx expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
377 enum optab_methods);
379 /* Expand a binary operation with both signed and unsigned forms. */
380 extern rtx sign_expand_binop (enum machine_mode, optab, optab, rtx, rtx,
381 rtx, int, enum optab_methods);
383 /* Generate code to perform an operation on two operands with two results. */
384 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
386 /* Expand a unary arithmetic operation given optab rtx operand. */
387 extern rtx expand_unop (enum machine_mode, optab, rtx, rtx, int);
389 /* Expand the absolute value operation. */
390 extern rtx expand_abs_nojump (enum machine_mode, rtx, rtx, int);
391 extern rtx expand_abs (enum machine_mode, rtx, rtx, int, int);
393 /* Expand the complex absolute value operation. */
394 extern rtx expand_complex_abs (enum machine_mode, rtx, rtx, int);
396 /* Generate an instruction with a given INSN_CODE with an output and
397 an input. */
398 extern void emit_unop_insn (int, rtx, rtx, enum rtx_code);
400 /* Emit code to perform a series of operations on a multi-word quantity, one
401 word at a time. */
402 extern rtx emit_no_conflict_block (rtx, rtx, rtx, rtx, rtx);
404 /* Emit one rtl instruction to store zero in specified rtx. */
405 extern void emit_clr_insn (rtx);
407 /* Emit one rtl insn to store 1 in specified rtx assuming it contains 0. */
408 extern void emit_0_to_1_insn (rtx);
410 /* Emit one rtl insn to compare two rtx's. */
411 extern void emit_cmp_insn (rtx, rtx, enum rtx_code, rtx, enum machine_mode,
412 int);
414 /* The various uses that a comparison can have; used by can_compare_p:
415 jumps, conditional moves, store flag operations. */
416 enum can_compare_purpose
418 ccp_jump,
419 ccp_cmov,
420 ccp_store_flag
423 /* Nonzero if a compare of mode MODE can be done straightforwardly
424 (without splitting it into pieces). */
425 extern int can_compare_p (enum rtx_code, enum machine_mode,
426 enum can_compare_purpose);
428 extern rtx prepare_operand (int, rtx, int, enum machine_mode,
429 enum machine_mode, int);
431 /* Return the INSN_CODE to use for an extend operation. */
432 extern enum insn_code can_extend_p (enum machine_mode, enum machine_mode, int);
434 /* Generate the body of an insn to extend Y (with mode MFROM)
435 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
436 extern rtx gen_extend_insn (rtx, rtx, enum machine_mode,
437 enum machine_mode, int);
439 /* Initialize the tables that control conversion between fixed and
440 floating values. */
441 extern void init_fixtab (void);
442 extern void init_floattab (void);
444 /* Call this to reset the function entry for one optab. */
445 extern void set_optab_libfunc (optab, enum machine_mode, const char *);
446 extern void set_conv_libfunc (convert_optab, enum machine_mode,
447 enum machine_mode, const char *);
449 /* Generate code for a FLOAT_EXPR. */
450 extern void expand_float (rtx, rtx, int);
452 /* Generate code for a FIX_EXPR. */
453 extern void expand_fix (rtx, rtx, int);
455 #endif /* GCC_OPTABS_H */