* libfuncs.h
[platform/upstream/gcc.git] / gcc / optabs.h
1 /* Definitions for code generation pass of GNU compiler.
2    Copyright (C) 2001, 2002, 2003 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 GTY(())
42 {
43   enum rtx_code code;
44   struct optab_handlers {
45     enum insn_code insn_code;
46     rtx libfunc;
47   } handlers [NUM_MACHINE_MODES];
48 };
49 typedef struct optab * optab;
50
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)
54
55 /* Enumeration of valid indexes into optab_table.  */
56 enum optab_index
57 {
58   OTI_add,
59   OTI_addv,
60   OTI_sub,
61   OTI_subv,
62
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,
72
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,
85
86   /* Logical and */
87   OTI_and,
88   /* Logical or */
89   OTI_ior,
90   /* Logical xor */
91   OTI_xor,
92
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,
115
116   /* Move instruction.  */
117   OTI_mov,
118   /* Move, preserving high part of register.  */
119   OTI_movstrict,
120
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,
156
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,
163
164   /* Floating point comparison optabs - used primarily for libfuncs */
165   OTI_eq,
166   OTI_ne,
167   OTI_gt,
168   OTI_ge,
169   OTI_lt,
170   OTI_le,
171   OTI_unord,
172
173   /* String length */
174   OTI_strlen,
175
176   /* Combined compare & jump/store flags/move operations.  */
177   OTI_cbranch,
178   OTI_cmov,
179   OTI_cstore,
180
181   /* Push instruction.  */
182   OTI_push,
183
184   /* Conditional add instruction.  */
185   OTI_addcc,
186
187   OTI_MAX
188 };
189
190 extern GTY(()) optab optab_table[OTI_MAX];
191
192 #define add_optab (optab_table[OTI_add])
193 #define sub_optab (optab_table[OTI_sub])
194 #define smul_optab (optab_table[OTI_smul])
195 #define addv_optab (optab_table[OTI_addv])
196 #define subv_optab (optab_table[OTI_subv])
197 #define smul_highpart_optab (optab_table[OTI_smul_highpart])
198 #define umul_highpart_optab (optab_table[OTI_umul_highpart])
199 #define smul_widen_optab (optab_table[OTI_smul_widen])
200 #define umul_widen_optab (optab_table[OTI_umul_widen])
201 #define sdiv_optab (optab_table[OTI_sdiv])
202 #define smulv_optab (optab_table[OTI_smulv])
203 #define sdivv_optab (optab_table[OTI_sdivv])
204 #define sdivmod_optab (optab_table[OTI_sdivmod])
205 #define udiv_optab (optab_table[OTI_udiv])
206 #define udivmod_optab (optab_table[OTI_udivmod])
207 #define smod_optab (optab_table[OTI_smod])
208 #define umod_optab (optab_table[OTI_umod])
209 #define ftrunc_optab (optab_table[OTI_ftrunc])
210 #define and_optab (optab_table[OTI_and])
211 #define ior_optab (optab_table[OTI_ior])
212 #define xor_optab (optab_table[OTI_xor])
213 #define ashl_optab (optab_table[OTI_ashl])
214 #define lshr_optab (optab_table[OTI_lshr])
215 #define ashr_optab (optab_table[OTI_ashr])
216 #define rotl_optab (optab_table[OTI_rotl])
217 #define rotr_optab (optab_table[OTI_rotr])
218 #define smin_optab (optab_table[OTI_smin])
219 #define smax_optab (optab_table[OTI_smax])
220 #define umin_optab (optab_table[OTI_umin])
221 #define umax_optab (optab_table[OTI_umax])
222 #define pow_optab (optab_table[OTI_pow])
223 #define atan2_optab (optab_table[OTI_atan2])
224
225 #define mov_optab (optab_table[OTI_mov])
226 #define movstrict_optab (optab_table[OTI_movstrict])
227
228 #define neg_optab (optab_table[OTI_neg])
229 #define negv_optab (optab_table[OTI_negv])
230 #define abs_optab (optab_table[OTI_abs])
231 #define absv_optab (optab_table[OTI_absv])
232 #define one_cmpl_optab (optab_table[OTI_one_cmpl])
233 #define ffs_optab (optab_table[OTI_ffs])
234 #define clz_optab (optab_table[OTI_clz])
235 #define ctz_optab (optab_table[OTI_ctz])
236 #define popcount_optab (optab_table[OTI_popcount])
237 #define parity_optab (optab_table[OTI_parity])
238 #define sqrt_optab (optab_table[OTI_sqrt])
239 #define sin_optab (optab_table[OTI_sin])
240 #define cos_optab (optab_table[OTI_cos])
241 #define exp_optab (optab_table[OTI_exp])
242 #define log_optab (optab_table[OTI_log])
243 #define floor_optab (optab_table[OTI_floor])
244 #define ceil_optab (optab_table[OTI_ceil])
245 #define trunc_optab (optab_table[OTI_trunc])
246 #define round_optab (optab_table[OTI_round])
247 #define nearbyint_optab (optab_table[OTI_nearbyint])
248 #define tan_optab (optab_table[OTI_tan])
249 #define atan_optab (optab_table[OTI_atan])
250
251 #define cmp_optab (optab_table[OTI_cmp])
252 #define ucmp_optab (optab_table[OTI_ucmp])
253 #define tst_optab (optab_table[OTI_tst])
254
255 #define eq_optab (optab_table[OTI_eq])
256 #define ne_optab (optab_table[OTI_ne])
257 #define gt_optab (optab_table[OTI_gt])
258 #define ge_optab (optab_table[OTI_ge])
259 #define lt_optab (optab_table[OTI_lt])
260 #define le_optab (optab_table[OTI_le])
261 #define unord_optab (optab_table[OTI_unord])
262
263 #define strlen_optab (optab_table[OTI_strlen])
264
265 #define cbranch_optab (optab_table[OTI_cbranch])
266 #define cmov_optab (optab_table[OTI_cmov])
267 #define cstore_optab (optab_table[OTI_cstore])
268 #define push_optab (optab_table[OTI_push])
269 #define addcc_optab (optab_table[OTI_addcc])
270
271 /* Tables of patterns for extending one integer mode to another.  */
272 extern enum insn_code extendtab[MAX_MACHINE_MODE][MAX_MACHINE_MODE][2];
273
274 /* Tables of patterns for converting between fixed and floating point.  */
275 extern enum insn_code fixtab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
276 extern enum insn_code fixtrunctab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
277 extern enum insn_code floattab[NUM_MACHINE_MODES][NUM_MACHINE_MODES][2];
278
279 /* These arrays record the insn_code of insns that may be needed to
280    perform input and output reloads of special objects.  They provide a
281    place to pass a scratch register.  */
282 extern enum insn_code reload_in_optab[NUM_MACHINE_MODES];
283 extern enum insn_code reload_out_optab[NUM_MACHINE_MODES];
284
285 /* Contains the optab used for each rtx code.  */
286 extern GTY(()) optab code_to_optab[NUM_RTX_CODE + 1];
287
288 \f
289 typedef rtx (*rtxfun) (rtx);
290
291 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
292    gives the gen_function to make a branch to test that condition.  */
293
294 extern rtxfun bcc_gen_fctn[NUM_RTX_CODE];
295
296 /* Indexed by the rtx-code for a conditional (eg. EQ, LT,...)
297    gives the insn code to make a store-condition insn
298    to test that condition.  */
299
300 extern enum insn_code setcc_gen_code[NUM_RTX_CODE];
301
302 #ifdef HAVE_conditional_move
303 /* Indexed by the machine mode, gives the insn code to make a conditional
304    move insn.  */
305
306 extern enum insn_code movcc_gen_code[NUM_MACHINE_MODES];
307 #endif
308
309 /* This array records the insn_code of insns to perform block moves.  */
310 extern enum insn_code movstr_optab[NUM_MACHINE_MODES];
311
312 /* This array records the insn_code of insns to perform block clears.  */
313 extern enum insn_code clrstr_optab[NUM_MACHINE_MODES];
314
315 /* Define functions given in optabs.c.  */
316
317 /* Expand a binary operation given optab and rtx operands.  */
318 extern rtx expand_binop (enum machine_mode, optab, rtx, rtx, rtx, int,
319                          enum optab_methods);
320
321 /* Expand a binary operation with both signed and unsigned forms.  */
322 extern rtx sign_expand_binop (enum machine_mode, optab, optab, rtx, rtx,
323                               rtx, int, enum optab_methods);
324
325 /* Generate code to perform an operation on two operands with two results.  */
326 extern int expand_twoval_binop (optab, rtx, rtx, rtx, rtx, int);
327
328 /* Expand a unary arithmetic operation given optab rtx operand.  */
329 extern rtx expand_unop (enum machine_mode, optab, rtx, rtx, int);
330
331 /* Expand the absolute value operation.  */
332 extern rtx expand_abs_nojump (enum machine_mode, rtx, rtx, int);
333 extern rtx expand_abs (enum machine_mode, rtx, rtx, int, int);
334
335 /* Expand the complex absolute value operation.  */
336 extern rtx expand_complex_abs (enum machine_mode, rtx, rtx, int);
337
338 /* Generate an instruction with a given INSN_CODE with an output and
339    an input.  */
340 extern void emit_unop_insn (int, rtx, rtx, enum rtx_code);
341
342 /* Emit code to perform a series of operations on a multi-word quantity, one
343    word at a time.  */
344 extern rtx emit_no_conflict_block (rtx, rtx, rtx, rtx, rtx);
345
346 /* Emit one rtl instruction to store zero in specified rtx.  */
347 extern void emit_clr_insn (rtx);
348
349 /* Emit one rtl insn to store 1 in specified rtx assuming it contains 0.  */
350 extern void emit_0_to_1_insn (rtx);
351
352 /* Emit one rtl insn to compare two rtx's.  */
353 extern void emit_cmp_insn (rtx, rtx, enum rtx_code, rtx, enum machine_mode,
354                            int);
355
356 /* The various uses that a comparison can have; used by can_compare_p:
357    jumps, conditional moves, store flag operations.  */
358 enum can_compare_purpose
359 {
360   ccp_jump,
361   ccp_cmov,
362   ccp_store_flag
363 };
364
365 /* Nonzero if a compare of mode MODE can be done straightforwardly
366    (without splitting it into pieces).  */
367 extern int can_compare_p (enum rtx_code, enum machine_mode,
368                           enum can_compare_purpose);
369
370 extern rtx prepare_operand (int, rtx, int, enum machine_mode,
371                             enum machine_mode, int);
372
373 /* Return the INSN_CODE to use for an extend operation.  */
374 extern enum insn_code can_extend_p (enum machine_mode, enum machine_mode, int);
375
376 /* Generate the body of an insn to extend Y (with mode MFROM)
377    into X (with mode MTO).  Do zero-extension if UNSIGNEDP is nonzero.  */
378 extern rtx gen_extend_insn (rtx, rtx, enum machine_mode,
379                             enum machine_mode, int);
380
381 /* Initialize the tables that control conversion between fixed and
382    floating values.  */
383 extern void init_fixtab (void);
384 extern void init_floattab (void);
385
386 /* Call this to reset the function entry for one optab.  */
387 extern void set_optab_libfunc (optab, enum machine_mode, const char *);
388
389 /* Generate code for a FLOAT_EXPR.  */
390 extern void expand_float (rtx, rtx, int);
391
392 /* Generate code for a FIX_EXPR.  */
393 extern void expand_fix (rtx, rtx, int);
394
395 #endif /* GCC_OPTABS_H */