Update FSF address.
[official-gcc.git] / gcc / config / mcore / predicates.md
blob7f1ce397c0d194ac0c438dceacd4d6b328aea125
1 ;; Predicate definitions for Motorola MCore.
2 ;; Copyright (C) 2005 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.
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, 51 Franklin Street, Fifth Floor,
19 ;; Boston, MA 02110-1301, USA.
21 ;; Nonzero if OP is a normal arithmetic register.
23 (define_predicate "mcore_arith_reg_operand"
24   (match_code "reg,subreg")
26   if (! register_operand (op, mode))
27     return 0;
29   if (GET_CODE (op) == SUBREG)
30     op = SUBREG_REG (op);
32   if (GET_CODE (op) == REG)
33     return REGNO (op) != CC_REG;
35   return 1;
38 ;; Nonzero if OP can be source of a simple move operation.
40 (define_predicate "mcore_general_movsrc_operand"
41   (match_code "mem,const_int,reg,subreg,symbol_ref,label_ref")
43   /* Any (MEM LABEL_REF) is OK.  That is a pc-relative load.  */
44   if (GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == LABEL_REF)
45     return 1;
47   return general_operand (op, mode);
50 ;; Nonzero if OP can be destination of a simple move operation.
52 (define_predicate "mcore_general_movdst_operand"
53   (match_code "mem,const_int,reg,subreg")
55   if (GET_CODE (op) == REG && REGNO (op) == CC_REG)
56     return 0;
58   return general_operand (op, mode);
61 ;; Nonzero if OP should be recognized during reload for an ixh/ixw
62 ;; operand.  See the ixh/ixw patterns.
64 (define_predicate "mcore_reload_operand"
65   (match_code "mem,reg,subreg")
67   if (mcore_arith_reg_operand (op, mode))
68     return 1;
70   if (! reload_in_progress)
71     return 0;
73   return GET_CODE (op) == MEM;
76 ;; Nonzero if OP is a valid source operand for an arithmetic insn.
78 (define_predicate "mcore_arith_J_operand"
79   (match_code "const_int,reg,subreg")
81   if (register_operand (op, mode))
82     return 1;
84   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_J (INTVAL (op)))
85     return 1;
87   return 0;
90 ;; Nonzero if OP is a valid source operand for an arithmetic insn.
92 (define_predicate "mcore_arith_K_operand"
93   (match_code "const_int,reg,subreg")
95   if (register_operand (op, mode))
96     return 1;
98   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_K (INTVAL (op)))
99     return 1;
101   return 0;
104 ;; Nonzero if OP is a valid source operand for a shift or rotate insn.
106 (define_predicate "mcore_arith_K_operand_not_0"
107   (match_code "const_int,reg,subreg")
109   if (register_operand (op, mode))
110     return 1;
112   if (   GET_CODE (op) == CONST_INT
113       && CONST_OK_FOR_K (INTVAL (op))
114       && INTVAL (op) != 0)
115     return 1;
117   return 0;
120 ;; TODO: Add a comment here.
122 (define_predicate "mcore_arith_M_operand"
123   (match_code "const_int,reg,subreg")
125   if (register_operand (op, mode))
126     return 1;
128   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_M (INTVAL (op)))
129     return 1;
131   return 0;
134 ;; TODO: Add a comment here.
136 (define_predicate "mcore_arith_K_S_operand"
137   (match_code "const_int,reg,subreg")
139   if (register_operand (op, mode))
140     return 1;
142   if (GET_CODE (op) == CONST_INT)
143     {
144       if (CONST_OK_FOR_K (INTVAL (op)) || CONST_OK_FOR_M (~INTVAL (op)))
145         return 1;
146     }
148   return 0;
151 ;; Nonzero if OP is a valid source operand for a cmov with two consts
152 ;; +/- 1.
154 (define_predicate "mcore_arith_O_operand"
155   (match_code "const_int,reg,subreg")
157   if (register_operand (op, mode))
158     return 1;
160   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_O (INTVAL (op)))
161     return 1;
163   return 0;
166 ;; Nonzero if OP is a valid source operand for loading.
168 (define_predicate "mcore_arith_imm_operand"
169   (match_code "const_int,reg,subreg")
171   if (register_operand (op, mode))
172     return 1;
174   if (GET_CODE (op) == CONST_INT && const_ok_for_mcore (INTVAL (op)))
175     return 1;
177   return 0;
180 ;; TODO: Add a comment here.
182 (define_predicate "mcore_arith_any_imm_operand"
183   (match_code "const_int,reg,subreg")
185   if (register_operand (op, mode))
186     return 1;
188   if (GET_CODE (op) == CONST_INT)
189     return 1;
191   return 0;
194 ;; Nonzero if OP is a valid source operand for a btsti.
196 (define_predicate "mcore_literal_K_operand"
197   (match_code "const_int")
199   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_K (INTVAL (op)))
200     return 1;
202   return 0;
205 ;; Nonzero if OP is a valid source operand for an add/sub insn.
207 (define_predicate "mcore_addsub_operand"
208   (match_code "const_int,reg,subreg")
210   if (register_operand (op, mode))
211     return 1;
213   if (GET_CODE (op) == CONST_INT)
214     {
215       return 1;
217       /* The following is removed because it precludes large constants from being
218          returned as valid source operands for and add/sub insn.  While large
219          constants may not directly be used in an add/sub, they may if first loaded
220          into a register.  Thus, this predicate should indicate that they are valid,
221          and the constraint in mcore.md should control whether an additional load to
222          register is needed. (see mcore.md, addsi). -- DAC 4/2/1998  */
223       /*
224         if (CONST_OK_FOR_J(INTVAL(op)) || CONST_OK_FOR_L(INTVAL(op)))
225           return 1;
226       */
227     }
229   return 0;
232 ;; Nonzero if OP is a valid source operand for a compare operation.
234 (define_predicate "mcore_compare_operand"
235   (match_code "const_int,reg,subreg")
237   if (register_operand (op, mode))
238     return 1;
240   if (GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
241     return 1;
243   return 0;
246 ;; Return 1 if OP is a load multiple operation.  It is known to be a
247 ;; PARALLEL and the first section will be tested.
249 (define_predicate "mcore_load_multiple_operation"
250   (match_code "parallel")
252   int count = XVECLEN (op, 0);
253   int dest_regno;
254   rtx src_addr;
255   int i;
257   /* Perform a quick check so we don't blow up below.  */
258   if (count <= 1
259       || GET_CODE (XVECEXP (op, 0, 0)) != SET
260       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
261       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
262     return 0;
264   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
265   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
267   for (i = 1; i < count; i++)
268     {
269       rtx elt = XVECEXP (op, 0, i);
271       if (GET_CODE (elt) != SET
272           || GET_CODE (SET_DEST (elt)) != REG
273           || GET_MODE (SET_DEST (elt)) != SImode
274           || REGNO (SET_DEST (elt))    != (unsigned) (dest_regno + i)
275           || GET_CODE (SET_SRC (elt))  != MEM
276           || GET_MODE (SET_SRC (elt))  != SImode
277           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
278           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
279           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
280           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
281         return 0;
282     }
284   return 1;
287 ;; Similar, but tests for store multiple.
289 (define_predicate "mcore_store_multiple_operation"
290   (match_code "parallel")
292   int count = XVECLEN (op, 0);
293   int src_regno;
294   rtx dest_addr;
295   int i;
297   /* Perform a quick check so we don't blow up below.  */
298   if (count <= 1
299       || GET_CODE (XVECEXP (op, 0, 0)) != SET
300       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
301       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
302     return 0;
304   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
305   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
307   for (i = 1; i < count; i++)
308     {
309       rtx elt = XVECEXP (op, 0, i);
311       if (GET_CODE (elt) != SET
312           || GET_CODE (SET_SRC (elt)) != REG
313           || GET_MODE (SET_SRC (elt)) != SImode
314           || REGNO (SET_SRC (elt)) != (unsigned) (src_regno + i)
315           || GET_CODE (SET_DEST (elt)) != MEM
316           || GET_MODE (SET_DEST (elt)) != SImode
317           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
318           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
319           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
320           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
321         return 0;
322     }
324   return 1;
327 ;; TODO: Add a comment here.
329 (define_predicate "mcore_call_address_operand"
330   (match_code "reg,subreg,const_int,symbol_ref")
332   return register_operand (op, mode) || CONSTANT_P (op);