OSDN Git Service

2004-03-10 Uros Bizjak <uros@kss-loka.si>
[pf3gnuchains/gcc-fork.git] / gcc / optabs.h
1 /* Definitions for code generation pass of GNU compiler.
2    Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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.  */
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 struct optab_handlers GTY(())
42 {
43   enum insn_code insn_code;
44   rtx libfunc;
45 };
46
47 struct optab GTY(())
48 {
49   enum rtx_code code;
50   struct optab_handlers handlers[NUM_MACHINE_MODES];
51 };
52 typedef struct optab * optab;
53
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(())
58 {
59   enum rtx_code code;
60   struct optab_handlers handlers[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
61 };
62 typedef struct convert_optab *convert_optab;
63
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)
67
68 /* Enumeration of valid indexes into optab_table.  */
69 enum optab_index
70 {
71   OTI_add,
72   OTI_addv,
73   OTI_sub,
74   OTI_subv,
75
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,
85
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,
98
99   /* Logical and */
100   OTI_and,
101   /* Logical or */
102   OTI_ior,
103   /* Logical xor */
104   OTI_xor,
105
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,
128
129   /* Move instruction.  */
130   OTI_mov,
131   /* Move, preserving high part of register.  */
132   OTI_movstrict,
133
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   /* Base-10 Exponential */
158   OTI_exp10,
159   /* Base-2 Exponential */
160   OTI_exp2,
161   /* Natural Logarithm */
162   OTI_log,
163   /* Base-10 Logarithm */
164   OTI_log10,
165   /* Base-2 Logarithm */
166   OTI_log2,
167   /* Rounding functions */
168   OTI_floor,
169   OTI_ceil,
170   OTI_trunc,
171   OTI_round,
172   OTI_nearbyint,
173   /* Tangent */
174   OTI_tan,
175   /* Inverse tangent */
176   OTI_atan,
177
178   /* Compare insn; two operands.  */
179   OTI_cmp,
180   /* Used only for libcalls for unsigned comparisons.  */
181   OTI_ucmp,
182   /* tst insn; compare one operand against 0 */
183   OTI_tst,
184
185   /* Floating point comparison optabs - used primarily for libfuncs */
186   OTI_eq,
187   OTI_ne,
188   OTI_gt,
189   OTI_ge,
190   OTI_lt,
191   OTI_le,
192   OTI_unord,
193
194   /* String length */
195   OTI_strlen,
196
197   /* Combined compare & jump/store flags/move operations.  */
198   OTI_cbranch,
199   OTI_cmov,
200   OTI_cstore,
201
202   /* Push instruction.  */
203   OTI_push,
204
205   /* Conditional add instruction.  */
206   OTI_addcc,
207
208   /* Set specified field of vector operand.  */
209   OTI_vec_set,
210   /* Extract specified field of vector operand.  */
211   OTI_vec_extract,
212   /* Initialize vector operand.  */
213   OTI_vec_init,
214
215   OTI_MAX
216 };
217
218 extern GTY(()) optab optab_table[OTI_MAX];
219
220 #define add_optab (optab_table[OTI_add])
221 #define sub_optab (optab_table[OTI_sub])
222 #define smul_optab (optab_table[OTI_smul])
223 #define addv_optab (optab_table[OTI_addv])
224 #define subv_optab (optab_table[OTI_subv])
225 #define smul_highpart_optab (optab_table[OTI_smul_highpart])
226 #define umul_highpart_optab (optab_table[OTI_umul_highpart])
227 #define smul_widen_optab (optab_table[OTI_smul_widen])
228 #define umul_widen_optab (optab_table[OTI_umul_widen])
229 #define sdiv_optab (optab_table[OTI_sdiv])
230 #define smulv_optab (optab_table[OTI_smulv])
231 #define sdivv_optab (optab_table[OTI_sdivv])
232 #define sdivmod_optab (optab_table[OTI_sdivmod])
233 #define udiv_optab (optab_table[OTI_udiv])
234 #define udivmod_optab (optab_table[OTI_udivmod])
235 #define smod_optab (optab_table[OTI_smod])
236 #define umod_optab (optab_table[OTI_umod])
237 #define ftrunc_optab (optab_table[OTI_ftrunc])
238 #define and_optab (optab_table[OTI_and])
239 #define ior_optab (optab_table[OTI_ior])
240 #define xor_optab (optab_table[OTI_xor])
241 #define ashl_optab (optab_table[OTI_ashl])
242 #define lshr_optab (optab_table[OTI_lshr])
243 #define ashr_optab (optab_table[OTI_ashr])
244 #define rotl_optab (optab_table[OTI_rotl])
245 #define rotr_optab (optab_table[OTI_rotr])
246 #define smin_optab (optab_table[OTI_smin])
247 #define smax_optab (optab_table[OTI_smax])
248 #define umin_optab (optab_table[OTI_umin])
249 #define umax_optab (optab_table[OTI_umax])
250 #define pow_optab (optab_table[OTI_pow])
251 #define atan2_optab (optab_table[OTI_atan2])
252
253 #define mov_optab (optab_table[OTI_mov])
254 #define movstrict_optab (optab_table[OTI_movstrict])
255
256 #define neg_optab (optab_table[OTI_neg])
257 #define negv_optab (optab_table[OTI_negv])
258 #define abs_optab (optab_table[OTI_abs])
259 #define absv_optab (optab_table[OTI_absv])
260 #define one_cmpl_optab (optab_table[OTI_one_cmpl])
261 #define ffs_optab (optab_table[OTI_ffs])
262 #define clz_optab (optab_table[OTI_clz])
263 #define ctz_optab (optab_table[OTI_ctz])
264 #define popcount_optab (optab_table[OTI_popcount])
265 #define parity_optab (optab_table[OTI_parity])
266 #define sqrt_optab (optab_table[OTI_sqrt])
267 #define sin_optab (optab_table[OTI_sin])
268 #define cos_optab (optab_table[OTI_cos])
269 #define exp_optab (optab_table[OTI_exp])
270 #define exp10_optab (optab_table[OTI_exp10])
271 #define exp2_optab (optab_table[OTI_exp2])
272 #define log_optab (optab_table[OTI_log])
273 #define log10_optab (optab_table[OTI_log10])
274 #define log2_optab (optab_table[OTI_log2])
275 #define floor_optab (optab_table[OTI_floor])
276 #define ceil_optab (optab_table[OTI_ceil])
277 #define btrunc_optab (optab_table[OTI_trunc])
278 #define round_optab (optab_table[OTI_round])
279 #define nearbyint_optab (optab_table[OTI_nearbyint])
280 #define tan_optab (optab_table[OTI_tan])
281 #define atan_optab (optab_table[OTI_atan])
282
283 #define cmp_optab (optab_table[OTI_cmp])
284 #define ucmp_optab (optab_table[OTI_ucmp])
285 #define tst_optab (optab_table[OTI_tst])
286
287 #define eq_optab (optab_table[OTI_eq])
288 #define ne_optab (optab_table[OTI_ne])
289 #define gt_optab (optab_table[OTI_gt])
290 #define ge_optab (optab_table[OTI_ge])
291 #define lt_optab (optab_table[OTI_lt])
292 #define le_optab (optab_table[OTI_le])
293 #define unord_optab (optab_table[OTI_unord])
294
295 #define strlen_optab (optab_table[OTI_strlen])
296
297 #define cbranch_optab (optab_table[OTI_cbranch])
298 #define cmov_optab (optab_table[OTI_cmov])
299 #define cstore_optab (optab_table[OTI_cstore])
300 #define push_optab (optab_table[OTI_push])
301 #define addcc_optab (optab_table[OTI_addcc])
302
303 #define vec_set_optab (optab_table[OTI_vec_set])
304 #define vec_extract_optab (optab_table[OTI_vec_extract])
305 #define vec_init_optab (optab_table[OTI_vec_init])
306
307 /* Conversion optabs have their own table and indexes.  */
308 enum convert_optab_index
309 {
310   CTI_sext,
311   CTI_zext,
312   CTI_trunc,
313
314   CTI_sfix,
315   CTI_ufix,
316
317   CTI_sfixtrunc,
318   CTI_ufixtrunc,
319
320   CTI_sfloat,
321   CTI_ufloat,
322
323   CTI_MAX
324 };
325
326 extern GTY(()) convert_optab convert_optab_table[CTI_MAX];
327
328 #define sext_optab (convert_optab_table[CTI_sext])
329 #define zext_optab (convert_optab_table[CTI_zext])
330 #define trunc_optab (convert_optab_table[CTI_trunc])
331 #define sfix_optab (convert_optab_table[CTI_sfix])
332 #define ufix_optab (convert_optab_table[CTI_ufix])
333 #define sfixtrunc_optab (convert_optab_table[CTI_sfixtrunc])
334 #define ufixtrunc_optab (convert_optab_table[CTI_ufixtrunc])
335 #define sfloat_optab (convert_optab_table[CTI_sfloat])
336 #define ufloat_optab (convert_optab_table[CTI_ufloat])
337
338 /* These arrays record the insn_code of insns that may be needed to
339    perform input and output reloads of special objects.  They provide a
340    place to pass a scratch register.  */
341 extern enum insn_code reload_in_optab[NUM_MACHINE_MODES];
342 extern enum insn_code reload_out_optab[NUM_MACHINE_MODES];
343
344 /* Contains the optab used for each rtx code.  */
345 extern GTY(()) optab code_to_optab[NUM_RTX_CODE + 1];
346
347 \f
348 typedef rtx (*rtxfun) (rtx);
349
350 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
351    gives the gen_function to make a branch to test that condition.  */
352
353 extern rtxfun bcc_gen_fctn[NUM_RTX_CODE];
354
355 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
356    gives the insn code to make a store-condition insn
357    to test that condition.  */
358
359 extern enum insn_code setcc_gen_code[NUM_RTX_CODE];
360
361 #ifdef HAVE_conditional_move
362 /* Indexed by the machine mode, gives the insn code to make a conditional
363    move insn.  */
364
365 extern enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
366 #endif
367
368 /* This array records the insn_code of insns to perform block moves.  */
369 extern enum insn_code movstr_optab[NUM_MACHINE_MODES];
370
371 /* This array records the insn_code of insns to perform block clears.  */
372 extern enum insn_code clrstr_optab[NUM_MACHINE_MODES];
373
374 /* These arrays record the insn_code of two different kinds of insns
375    to perform block compares.  */
376 extern enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
377 extern enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
378
379 /* Define functions given in optabs.c.  */
380
381 /* Expand a binary operation given optab and rtx operands.  */
382 extern rtx expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
383                          enum optab_methods);
384
385 /* Expand a binary operation with both signed and unsigned forms.  */
386 extern rtx sign_expand_binop (enum machine_mode, optab, optab, rtx, rtx,
387                               rtx, int, enum optab_methods);
388
389 /* Generate code to perform an operation on two operands with two results.  */
390 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
391
392 /* Expand a unary arithmetic operation given optab rtx operand.  */
393 extern rtx expand_unop (enum machine_mode, optab, rtx, rtx, int);
394
395 /* Expand the absolute value operation.  */
396 extern rtx expand_abs_nojump (enum machine_mode, rtx, rtx, int);
397 extern rtx expand_abs (enum machine_mode, rtx, rtx, int, int);
398
399 /* Expand the complex absolute value operation.  */
400 extern rtx expand_complex_abs (enum machine_mode, rtx, rtx, int);
401
402 /* Generate an instruction with a given INSN_CODE with an output and
403    an input.  */
404 extern void emit_unop_insn (int, rtx, rtx, enum rtx_code);
405
406 /* Emit code to perform a series of operations on a multi-word quantity, one
407    word at a time.  */
408 extern rtx emit_no_conflict_block (rtx, rtx, rtx, rtx, rtx);
409
410 /* Emit one rtl instruction to store zero in specified rtx.  */
411 extern void emit_clr_insn (rtx);
412
413 /* Emit one rtl insn to store 1 in specified rtx assuming it contains 0.  */
414 extern void emit_0_to_1_insn (rtx);
415
416 /* Emit one rtl insn to compare two rtx's.  */
417 extern void emit_cmp_insn (rtx, rtx, enum rtx_code, rtx, enum machine_mode,
418                            int);
419
420 /* The various uses that a comparison can have; used by can_compare_p:
421    jumps, conditional moves, store flag operations.  */
422 enum can_compare_purpose
423 {
424   ccp_jump,
425   ccp_cmov,
426   ccp_store_flag
427 };
428
429 /* Nonzero if a compare of mode MODE can be done straightforwardly
430    (without splitting it into pieces).  */
431 extern int can_compare_p (enum rtx_code, enum machine_mode,
432                           enum can_compare_purpose);
433
434 extern rtx prepare_operand (int, rtx, int, enum machine_mode,
435                             enum machine_mode, int);
436
437 /* Return the INSN_CODE to use for an extend operation.  */
438 extern enum insn_code can_extend_p (enum machine_mode, enum machine_mode, int);
439
440 /* Generate the body of an insn to extend Y (with mode MFROM)
441    into X (with mode MTO).  Do zero-extension if UNSIGNEDP is nonzero.  */
442 extern rtx gen_extend_insn (rtx, rtx, enum machine_mode,
443                             enum machine_mode, int);
444
445 /* Initialize the tables that control conversion between fixed and
446    floating values.  */
447 extern void init_fixtab (void);
448 extern void init_floattab (void);
449
450 /* Call this to reset the function entry for one optab.  */
451 extern void set_optab_libfunc (optab, enum machine_mode, const char *);
452 extern void set_conv_libfunc (convert_optab, enum machine_mode,
453                               enum machine_mode, const char *);
454
455 /* Generate code for a FLOAT_EXPR.  */
456 extern void expand_float (rtx, rtx, int);
457
458 /* Generate code for a FIX_EXPR.  */
459 extern void expand_fix (rtx, rtx, int);
460
461 #endif /* GCC_OPTABS_H */