2003-06-19 Aldy Hernandez <aldyh@redhat.com>
[official-gcc.git] / gcc / optabs.h
blob0c04a9d1b494993449be7c26cf65333c2de512b2
1 /* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 2001, 2002, 2003 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 GTY(())
43 enum rtx_code code;
44 struct optab_handlers {
45 enum insn_code insn_code;
46 rtx libfunc;
47 } handlers [NUM_MACHINE_MODES];
49 typedef struct optab * optab;
51 /* Given an enum insn_code, access the function to construct
52 the body of that kind of insn. */
53 #define GEN_FCN(CODE) (*insn_data[(int) (CODE)].genfun)
55 /* Enumeration of valid indexes into optab_table. */
56 enum optab_index
58 OTI_add,
59 OTI_addv,
60 OTI_sub,
61 OTI_subv,
63 /* Signed and fp multiply */
64 OTI_smul,
65 OTI_smulv,
66 /* Signed multiply, return high word */
67 OTI_smul_highpart,
68 OTI_umul_highpart,
69 /* Signed multiply with result one machine mode wider than args */
70 OTI_smul_widen,
71 OTI_umul_widen,
73 /* Signed divide */
74 OTI_sdiv,
75 OTI_sdivv,
76 /* Signed divide-and-remainder in one */
77 OTI_sdivmod,
78 OTI_udiv,
79 OTI_udivmod,
80 /* Signed remainder */
81 OTI_smod,
82 OTI_umod,
83 /* Convert float to integer in float fmt */
84 OTI_ftrunc,
86 /* Logical and */
87 OTI_and,
88 /* Logical or */
89 OTI_ior,
90 /* Logical xor */
91 OTI_xor,
93 /* Arithmetic shift left */
94 OTI_ashl,
95 /* Logical shift right */
96 OTI_lshr,
97 /* Arithmetic shift right */
98 OTI_ashr,
99 /* Rotate left */
100 OTI_rotl,
101 /* Rotate right */
102 OTI_rotr,
103 /* Signed and floating-point minimum value */
104 OTI_smin,
105 /* Signed and floating-point maximum value */
106 OTI_smax,
107 /* Unsigned minimum value */
108 OTI_umin,
109 /* Unsigned maximum value */
110 OTI_umax,
111 /* Power */
112 OTI_pow,
113 /* Arc tangent of y/x */
114 OTI_atan2,
116 /* Move instruction. */
117 OTI_mov,
118 /* Move, preserving high part of register. */
119 OTI_movstrict,
121 /* Unary operations */
122 /* Negation */
123 OTI_neg,
124 OTI_negv,
125 /* Abs value */
126 OTI_abs,
127 OTI_absv,
128 /* Bitwise not */
129 OTI_one_cmpl,
130 /* Bit scanning and counting */
131 OTI_ffs,
132 OTI_clz,
133 OTI_ctz,
134 OTI_popcount,
135 OTI_parity,
136 /* Square root */
137 OTI_sqrt,
138 /* Sine */
139 OTI_sin,
140 /* Cosine */
141 OTI_cos,
142 /* Exponential */
143 OTI_exp,
144 /* Natural Logarithm */
145 OTI_log,
146 /* Rounding functions */
147 OTI_floor,
148 OTI_ceil,
149 OTI_trunc,
150 OTI_round,
151 OTI_nearbyint,
152 /* Tangent */
153 OTI_tan,
154 /* Inverse tangent */
155 OTI_atan,
157 /* Compare insn; two operands. */
158 OTI_cmp,
159 /* Used only for libcalls for unsigned comparisons. */
160 OTI_ucmp,
161 /* tst insn; compare one operand against 0 */
162 OTI_tst,
164 /* String length */
165 OTI_strlen,
167 /* Combined compare & jump/store flags/move operations. */
168 OTI_cbranch,
169 OTI_cmov,
170 OTI_cstore,
172 /* Push instruction. */
173 OTI_push,
175 /* Conditional add instruction. */
176 OTI_addcc,
178 OTI_MAX
181 extern GTY(()) optab optab_table[OTI_MAX];
183 #define add_optab (optab_table[OTI_add])
184 #define sub_optab (optab_table[OTI_sub])
185 #define smul_optab (optab_table[OTI_smul])
186 #define addv_optab (optab_table[OTI_addv])
187 #define subv_optab (optab_table[OTI_subv])
188 #define smul_highpart_optab (optab_table[OTI_smul_highpart])
189 #define umul_highpart_optab (optab_table[OTI_umul_highpart])
190 #define smul_widen_optab (optab_table[OTI_smul_widen])
191 #define umul_widen_optab (optab_table[OTI_umul_widen])
192 #define sdiv_optab (optab_table[OTI_sdiv])
193 #define smulv_optab (optab_table[OTI_smulv])
194 #define sdivv_optab (optab_table[OTI_sdivv])
195 #define sdivmod_optab (optab_table[OTI_sdivmod])
196 #define udiv_optab (optab_table[OTI_udiv])
197 #define udivmod_optab (optab_table[OTI_udivmod])
198 #define smod_optab (optab_table[OTI_smod])
199 #define umod_optab (optab_table[OTI_umod])
200 #define ftrunc_optab (optab_table[OTI_ftrunc])
201 #define and_optab (optab_table[OTI_and])
202 #define ior_optab (optab_table[OTI_ior])
203 #define xor_optab (optab_table[OTI_xor])
204 #define ashl_optab (optab_table[OTI_ashl])
205 #define lshr_optab (optab_table[OTI_lshr])
206 #define ashr_optab (optab_table[OTI_ashr])
207 #define rotl_optab (optab_table[OTI_rotl])
208 #define rotr_optab (optab_table[OTI_rotr])
209 #define smin_optab (optab_table[OTI_smin])
210 #define smax_optab (optab_table[OTI_smax])
211 #define umin_optab (optab_table[OTI_umin])
212 #define umax_optab (optab_table[OTI_umax])
213 #define pow_optab (optab_table[OTI_pow])
214 #define atan2_optab (optab_table[OTI_atan2])
216 #define mov_optab (optab_table[OTI_mov])
217 #define movstrict_optab (optab_table[OTI_movstrict])
219 #define neg_optab (optab_table[OTI_neg])
220 #define negv_optab (optab_table[OTI_negv])
221 #define abs_optab (optab_table[OTI_abs])
222 #define absv_optab (optab_table[OTI_absv])
223 #define one_cmpl_optab (optab_table[OTI_one_cmpl])
224 #define ffs_optab (optab_table[OTI_ffs])
225 #define clz_optab (optab_table[OTI_clz])
226 #define ctz_optab (optab_table[OTI_ctz])
227 #define popcount_optab (optab_table[OTI_popcount])
228 #define parity_optab (optab_table[OTI_parity])
229 #define sqrt_optab (optab_table[OTI_sqrt])
230 #define sin_optab (optab_table[OTI_sin])
231 #define cos_optab (optab_table[OTI_cos])
232 #define exp_optab (optab_table[OTI_exp])
233 #define log_optab (optab_table[OTI_log])
234 #define floor_optab (optab_table[OTI_floor])
235 #define ceil_optab (optab_table[OTI_ceil])
236 #define trunc_optab (optab_table[OTI_trunc])
237 #define round_optab (optab_table[OTI_round])
238 #define nearbyint_optab (optab_table[OTI_nearbyint])
239 #define tan_optab (optab_table[OTI_tan])
240 #define atan_optab (optab_table[OTI_atan])
242 #define cmp_optab (optab_table[OTI_cmp])
243 #define ucmp_optab (optab_table[OTI_ucmp])
244 #define tst_optab (optab_table[OTI_tst])
246 #define strlen_optab (optab_table[OTI_strlen])
248 #define cbranch_optab (optab_table[OTI_cbranch])
249 #define cmov_optab (optab_table[OTI_cmov])
250 #define cstore_optab (optab_table[OTI_cstore])
251 #define push_optab (optab_table[OTI_push])
252 #define addcc_optab (optab_table[OTI_addcc])
254 /* Tables of patterns for extending one integer mode to another. */
255 extern enum insn_code extendtab[MAX_MACHINE_MODE][MAX_MACHINE_MODE][2];
257 /* Tables of patterns for converting between fixed and floating point. */
258 extern enum insn_code fixtab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
259 extern enum insn_code fixtrunctab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
260 extern enum insn_code floattab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
262 /* These arrays record the insn_code of insns that may be needed to
263 perform input and output reloads of special objects. They provide a
264 place to pass a scratch register. */
265 extern enum insn_code reload_in_optab[NUM_MACHINE_MODES];
266 extern enum insn_code reload_out_optab[NUM_MACHINE_MODES];
268 /* Contains the optab used for each rtx code. */
269 extern GTY(()) optab code_to_optab[NUM_RTX_CODE + 1];
272 typedef rtx (*rtxfun) PARAMS ((rtx));
274 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
275 gives the gen_function to make a branch to test that condition. */
277 extern rtxfun bcc_gen_fctn[NUM_RTX_CODE];
279 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
280 gives the insn code to make a store-condition insn
281 to test that condition. */
283 extern enum insn_code setcc_gen_code[NUM_RTX_CODE];
285 #ifdef HAVE_conditional_move
286 /* Indexed by the machine mode, gives the insn code to make a conditional
287 move insn. */
289 extern enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
290 #endif
292 /* This array records the insn_code of insns to perform block moves. */
293 extern enum insn_code movstr_optab[NUM_MACHINE_MODES];
295 /* This array records the insn_code of insns to perform block clears. */
296 extern enum insn_code clrstr_optab[NUM_MACHINE_MODES];
298 /* Define functions given in optabs.c. */
300 /* Expand a binary operation given optab and rtx operands. */
301 extern rtx expand_binop PARAMS ((enum machine_mode, optab, rtx, rtx, rtx,
302 int, enum optab_methods));
304 /* Expand a binary operation with both signed and unsigned forms. */
305 extern rtx sign_expand_binop PARAMS ((enum machine_mode, optab, optab, rtx,
306 rtx, rtx, int, enum optab_methods));
308 /* Generate code to perform an operation on two operands with two results. */
309 extern int expand_twoval_binop PARAMS ((optab, rtx, rtx, rtx, rtx, int));
311 /* Expand a unary arithmetic operation given optab rtx operand. */
312 extern rtx expand_unop PARAMS ((enum machine_mode, optab, rtx, rtx, int));
314 /* Expand the absolute value operation. */
315 extern rtx expand_abs_nojump PARAMS ((enum machine_mode, rtx, rtx, int));
316 extern rtx expand_abs PARAMS ((enum machine_mode, rtx, rtx, int, int));
318 /* Expand the complex absolute value operation. */
319 extern rtx expand_complex_abs PARAMS ((enum machine_mode, rtx, rtx, int));
321 /* Generate an instruction with a given INSN_CODE with an output and
322 an input. */
323 extern void emit_unop_insn PARAMS ((int, rtx, rtx, enum rtx_code));
325 /* Emit code to perform a series of operations on a multi-word quantity, one
326 word at a time. */
327 extern rtx emit_no_conflict_block PARAMS ((rtx, rtx, rtx, rtx, rtx));
329 /* Emit one rtl instruction to store zero in specified rtx. */
330 extern void emit_clr_insn PARAMS ((rtx));
332 /* Emit one rtl insn to store 1 in specified rtx assuming it contains 0. */
333 extern void emit_0_to_1_insn PARAMS ((rtx));
335 /* Emit one rtl insn to compare two rtx's. */
336 extern void emit_cmp_insn PARAMS ((rtx, rtx, enum rtx_code, rtx,
337 enum machine_mode, int));
339 /* The various uses that a comparison can have; used by can_compare_p:
340 jumps, conditional moves, store flag operations. */
341 enum can_compare_purpose
343 ccp_jump,
344 ccp_cmov,
345 ccp_store_flag
348 /* Nonzero if a compare of mode MODE can be done straightforwardly
349 (without splitting it into pieces). */
350 extern int can_compare_p PARAMS ((enum rtx_code, enum machine_mode,
351 enum can_compare_purpose));
353 extern rtx prepare_operand PARAMS ((int, rtx, int, enum machine_mode,
354 enum machine_mode, int));
356 /* Return the INSN_CODE to use for an extend operation. */
357 extern enum insn_code can_extend_p PARAMS ((enum machine_mode,
358 enum machine_mode, int));
360 /* Generate the body of an insn to extend Y (with mode MFROM)
361 into X (with mode MTO). Do zero-extension if UNSIGNEDP is nonzero. */
362 extern rtx gen_extend_insn PARAMS ((rtx, rtx, enum machine_mode,
363 enum machine_mode, int));
365 /* Initialize the tables that control conversion between fixed and
366 floating values. */
367 extern void init_fixtab PARAMS ((void));
368 extern void init_floattab PARAMS ((void));
370 /* Generate code for a FLOAT_EXPR. */
371 extern void expand_float PARAMS ((rtx, rtx, int));
373 /* Generate code for a FIX_EXPR. */
374 extern void expand_fix PARAMS ((rtx, rtx, int));
376 #endif /* GCC_OPTABS_H */