OSDN Git Service

* expr.h: Split out optab- and libfunc-related code to...
[pf3gnuchains/gcc-fork.git] / gcc / optabs.h
1 /* Definitions for code generation pass of GNU compiler.
2    Copyright (C) 2001 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC 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.
10
11 GNU CC 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.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
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    For example, add_optab applies to addition.
30
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.
34
35    The `lib_call' slot is the name of the library function that
36    can be used to perform the operation.
37
38    A few optabs, such as move_optab and cmp_optab, are used
39    by special code.  */
40
41 typedef struct optab
42 {
43   enum rtx_code code;
44   struct {
45     enum insn_code insn_code;
46     rtx libfunc;
47   } handlers [NUM_MACHINE_MODES];
48 } * optab;
49
50 /* Given an enum insn_code, access the function to construct
51    the body of that kind of insn.  */
52 #define GEN_FCN(CODE) (*insn_data[(int) (CODE)].genfun)
53
54 /* Enumeration of valid indexes into optab_table.  */
55 enum optab_index
56 {
57   OTI_add,
58   OTI_addv,
59   OTI_sub,
60   OTI_subv,
61
62   /* Signed and fp multiply */
63   OTI_smul,
64   OTI_smulv,
65   /* Signed multiply, return high word */
66   OTI_smul_highpart,
67   OTI_umul_highpart,
68   /* Signed multiply with result one machine mode wider than args */
69   OTI_smul_widen,
70   OTI_umul_widen,
71
72   /* Signed divide */
73   OTI_sdiv,
74   OTI_sdivv,
75   /* Signed divide-and-remainder in one */
76   OTI_sdivmod,
77   OTI_udiv,
78   OTI_udivmod,
79   /* Signed remainder */
80   OTI_smod,
81   OTI_umod,
82   /* Optab for floating divide. */
83   OTI_flodiv,
84   /* Convert float to integer in float fmt */
85   OTI_ftrunc,
86
87   /* Logical and */
88   OTI_and,
89   /* Logical or */
90   OTI_ior,
91   /* Logical xor */
92   OTI_xor,
93
94   /* Arithmetic shift left */
95   OTI_ashl,
96   /* Logical shift right */
97   OTI_lshr,  
98   /* Arithmetic shift right */
99   OTI_ashr,
100   /* Rotate left */
101   OTI_rotl,
102   /* Rotate right */
103   OTI_rotr,
104   /* Signed and floating-point minimum value */
105   OTI_smin,
106   /* Signed and floating-point maximum value */
107   OTI_smax,
108   /* Unsigned minimum value */
109   OTI_umin,
110   /* Unsigned maximum value */
111   OTI_umax,
112
113   /* Move instruction.  */
114   OTI_mov,
115   /* Move, preserving high part of register.  */
116   OTI_movstrict,
117
118   /* Unary operations */
119   /* Negation */
120   OTI_neg,
121   OTI_negv,
122   /* Abs value */
123   OTI_abs,
124   OTI_absv,
125   /* Bitwise not */
126   OTI_one_cmpl,
127   /* Find first bit set */
128   OTI_ffs,
129   /* Square root */
130   OTI_sqrt,
131   /* Sine */
132   OTI_sin,
133   /* Cosine */
134   OTI_cos,
135
136   /* Compare insn; two operands.  */
137   OTI_cmp,
138   /* Used only for libcalls for unsigned comparisons.  */
139   OTI_ucmp,
140   /* tst insn; compare one operand against 0 */
141   OTI_tst,
142
143   /* String length */
144   OTI_strlen,
145
146   /* Combined compare & jump/store flags/move operations.  */
147   OTI_cbranch,
148   OTI_cmov,
149   OTI_cstore,
150     
151   /* Push instruction.  */
152   OTI_push,
153
154   OTI_MAX
155 };
156
157 extern optab optab_table[OTI_MAX];
158
159 #define add_optab (optab_table[OTI_add])
160 #define sub_optab (optab_table[OTI_sub])
161 #define smul_optab (optab_table[OTI_smul])
162 #define addv_optab (optab_table[OTI_addv])
163 #define subv_optab (optab_table[OTI_subv])
164 #define smul_highpart_optab (optab_table[OTI_smul_highpart])
165 #define umul_highpart_optab (optab_table[OTI_umul_highpart])
166 #define smul_widen_optab (optab_table[OTI_smul_widen])
167 #define umul_widen_optab (optab_table[OTI_umul_widen])
168 #define sdiv_optab (optab_table[OTI_sdiv])
169 #define smulv_optab (optab_table[OTI_smulv])
170 #define sdivv_optab (optab_table[OTI_sdivv])
171 #define sdivmod_optab (optab_table[OTI_sdivmod])
172 #define udiv_optab (optab_table[OTI_udiv])
173 #define udivmod_optab (optab_table[OTI_udivmod])
174 #define smod_optab (optab_table[OTI_smod])
175 #define umod_optab (optab_table[OTI_umod])
176 #define flodiv_optab (optab_table[OTI_flodiv])
177 #define ftrunc_optab (optab_table[OTI_ftrunc])
178 #define and_optab (optab_table[OTI_and])
179 #define ior_optab (optab_table[OTI_ior])
180 #define xor_optab (optab_table[OTI_xor])
181 #define ashl_optab (optab_table[OTI_ashl])
182 #define lshr_optab (optab_table[OTI_lshr])
183 #define ashr_optab (optab_table[OTI_ashr])
184 #define rotl_optab (optab_table[OTI_rotl])
185 #define rotr_optab (optab_table[OTI_rotr])
186 #define smin_optab (optab_table[OTI_smin])
187 #define smax_optab (optab_table[OTI_smax])
188 #define umin_optab (optab_table[OTI_umin])
189 #define umax_optab (optab_table[OTI_umax])
190
191 #define mov_optab (optab_table[OTI_mov])
192 #define movstrict_optab (optab_table[OTI_movstrict])
193
194 #define neg_optab (optab_table[OTI_neg])
195 #define negv_optab (optab_table[OTI_negv])
196 #define abs_optab (optab_table[OTI_abs])
197 #define absv_optab (optab_table[OTI_absv])
198 #define one_cmpl_optab (optab_table[OTI_one_cmpl])
199 #define ffs_optab (optab_table[OTI_ffs])
200 #define sqrt_optab (optab_table[OTI_sqrt])
201 #define sin_optab (optab_table[OTI_sin])
202 #define cos_optab (optab_table[OTI_cos])
203
204 #define cmp_optab (optab_table[OTI_cmp])
205 #define ucmp_optab (optab_table[OTI_ucmp])
206 #define tst_optab (optab_table[OTI_tst])
207
208 #define strlen_optab (optab_table[OTI_strlen])
209
210 #define cbranch_optab (optab_table[OTI_cbranch])
211 #define cmov_optab (optab_table[OTI_cmov])
212 #define cstore_optab (optab_table[OTI_cstore])
213 #define push_optab (optab_table[OTI_push])
214
215 /* Tables of patterns for extending one integer mode to another.  */
216 extern enum insn_code extendtab[MAX_MACHINE_MODE][MAX_MACHINE_MODE][2];
217
218 /* Tables of patterns for converting between fixed and floating point. */
219 extern enum insn_code fixtab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
220 extern enum insn_code fixtrunctab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
221 extern enum insn_code floattab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
222
223 /* These arrays record the insn_code of insns that may be needed to
224    perform input and output reloads of special objects.  They provide a
225    place to pass a scratch register.  */
226 extern enum insn_code reload_in_optab[NUM_MACHINE_MODES];
227 extern enum insn_code reload_out_optab[NUM_MACHINE_MODES];
228
229 /* Contains the optab used for each rtx code.  */
230 extern optab code_to_optab[NUM_RTX_CODE + 1];
231
232 /* Passed to expand_binop and expand_unop to say which options to try to use
233    if the requested operation can't be open-coded on the requisite mode.
234    Either OPTAB_LIB or OPTAB_LIB_WIDEN says try using a library call.
235    Either OPTAB_WIDEN or OPTAB_LIB_WIDEN says try using a wider mode.
236    OPTAB_MUST_WIDEN says try widening and don't try anything else.  */
237
238 enum optab_methods
239 {
240   OPTAB_DIRECT,
241   OPTAB_LIB,
242   OPTAB_WIDEN,
243   OPTAB_LIB_WIDEN,
244   OPTAB_MUST_WIDEN
245 };
246
247 \f
248 typedef rtx (*rtxfun) PARAMS ((rtx));
249
250 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
251    gives the gen_function to make a branch to test that condition.  */
252
253 extern rtxfun bcc_gen_fctn[NUM_RTX_CODE];
254
255 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
256    gives the insn code to make a store-condition insn
257    to test that condition.  */
258
259 extern enum insn_code setcc_gen_code[NUM_RTX_CODE];
260
261 #ifdef HAVE_conditional_move
262 /* Indexed by the machine mode, gives the insn code to make a conditional
263    move insn.  */
264
265 extern enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
266 #endif
267
268 /* This array records the insn_code of insns to perform block moves.  */
269 extern enum insn_code movstr_optab[NUM_MACHINE_MODES];
270
271 /* This array records the insn_code of insns to perform block clears.  */
272 extern enum insn_code clrstr_optab[NUM_MACHINE_MODES];
273
274 /* Define functions given in optabs.c.  */
275
276 /* Expand a binary operation given optab and rtx operands.  */
277 extern rtx expand_binop PARAMS ((enum machine_mode, optab, rtx, rtx, rtx,
278                                  int, enum optab_methods));
279
280 /* Expand a binary operation with both signed and unsigned forms.  */
281 extern rtx sign_expand_binop PARAMS ((enum machine_mode, optab, optab, rtx,
282                                       rtx, rtx, int, enum optab_methods));
283
284 /* Generate code to perform an operation on two operands with two results.  */
285 extern int expand_twoval_binop PARAMS ((optab, rtx, rtx, rtx, rtx, int));
286
287 /* Expand a unary arithmetic operation given optab rtx operand.  */
288 extern rtx expand_unop PARAMS ((enum machine_mode, optab, rtx, rtx, int));
289
290 /* Expand the absolute value operation.  */
291 extern rtx expand_abs PARAMS ((enum machine_mode, rtx, rtx, int, int));
292
293 /* Expand the complex absolute value operation.  */
294 extern rtx expand_complex_abs PARAMS ((enum machine_mode, rtx, rtx, int));
295
296 /* Generate an instruction with a given INSN_CODE with an output and
297    an input.  */
298 extern void emit_unop_insn PARAMS ((int, rtx, rtx, enum rtx_code));
299
300 /* Emit code to perform a series of operations on a multi-word quantity, one
301    word at a time.  */
302 extern rtx emit_no_conflict_block PARAMS ((rtx, rtx, rtx, rtx, rtx));
303
304 /* Emit one rtl instruction to store zero in specified rtx.  */
305 extern void emit_clr_insn PARAMS ((rtx));
306
307 /* Emit one rtl insn to store 1 in specified rtx assuming it contains 0.  */
308 extern void emit_0_to_1_insn PARAMS ((rtx));
309
310 /* Emit one rtl insn to compare two rtx's.  */
311 extern void emit_cmp_insn PARAMS ((rtx, rtx, enum rtx_code, rtx,
312                                    enum machine_mode, int, unsigned int));
313
314 /* The various uses that a comparison can have; used by can_compare_p:
315    jumps, conditional moves, store flag operations.  */
316 enum can_compare_purpose
317 {
318   ccp_jump,
319   ccp_cmov,
320   ccp_store_flag
321 };
322
323 /* Nonzero if a compare of mode MODE can be done straightforwardly
324    (without splitting it into pieces).  */
325 extern int can_compare_p PARAMS ((enum rtx_code, enum machine_mode,
326                                   enum can_compare_purpose));
327
328 extern void prepare_cmp_insn PARAMS ((rtx *, rtx *, enum rtx_code *, rtx,
329                                       enum machine_mode *, int *, int,
330                                       enum can_compare_purpose));
331
332 extern rtx prepare_operand PARAMS ((int, rtx, int, enum machine_mode,
333                                     enum machine_mode, int));
334
335 /* Return the INSN_CODE to use for an extend operation.  */
336 extern enum insn_code can_extend_p PARAMS ((enum machine_mode,
337                                             enum machine_mode, int));
338
339 /* Generate the body of an insn to extend Y (with mode MFROM)
340    into X (with mode MTO).  Do zero-extension if UNSIGNEDP is nonzero.  */
341 extern rtx gen_extend_insn PARAMS ((rtx, rtx, enum machine_mode,
342                                     enum machine_mode, int));
343
344 /* Initialize the tables that control conversion between fixed and
345    floating values.  */
346 extern void init_fixtab PARAMS ((void));
347 extern void init_floattab PARAMS ((void));
348
349 /* Generate code for a FLOAT_EXPR.  */
350 extern void expand_float PARAMS ((rtx, rtx, int));
351
352 /* Generate code for a FIX_EXPR.  */
353 extern void expand_fix PARAMS ((rtx, rtx, int));
354
355 #endif /* GCC_OPTABS_H */