1 ;; Predicate definitions for Renesas H8/300.
2 ;; Copyright (C) 2005 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)
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 ;; Return true if OP is a valid source operand for an integer move
24 (define_predicate "general_operand_src"
25 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
27 if (GET_MODE (op) == mode
28 && GET_CODE (op) == MEM
29 && GET_CODE (XEXP (op, 0)) == POST_INC)
31 return general_operand (op, mode);
34 ;; Return true if OP is a valid destination operand for an integer
37 (define_predicate "general_operand_dst"
38 (match_code "subreg,reg,mem")
40 if (GET_MODE (op) == mode
41 && GET_CODE (op) == MEM
42 && GET_CODE (XEXP (op, 0)) == PRE_DEC)
44 return general_operand (op, mode);
47 ;; Likewise the second operand.
49 (define_predicate "h8300_src_operand"
50 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
53 return general_operand (op, mode);
54 return nonmemory_operand (op, mode);
57 ;; Return true if OP is a suitable first operand for a general
58 ;; arithmetic insn such as "add".
60 (define_predicate "h8300_dst_operand"
61 (match_code "subreg,reg,mem")
64 return nonimmediate_operand (op, mode);
65 return register_operand (op, mode);
68 ;; Check that an operand is either a register or an unsigned 4-bit
71 (define_predicate "nibble_operand"
72 (match_code "const_int")
74 return (GET_CODE (op) == CONST_INT && TARGET_H8300SX
75 && INTVAL (op) >= 0 && INTVAL (op) <= 15);
78 ;; Check that an operand is either a register or an unsigned 4-bit
81 (define_predicate "reg_or_nibble_operand"
82 (match_code "const_int,subreg,reg")
84 return (nibble_operand (op, mode) || register_operand (op, mode));
87 ;; Return true if X is a shift operation of type H8SX_SHIFT_UNARY.
89 (define_predicate "h8sx_unary_shift_operator"
90 (match_code "ashiftrt,lshiftrt,ashift,rotate")
92 return (BINARY_P (op) && NON_COMMUTATIVE_P (op)
93 && (h8sx_classify_shift (GET_MODE (op), GET_CODE (op), XEXP (op, 1))
94 == H8SX_SHIFT_UNARY));
97 ;; Likewise H8SX_SHIFT_BINARY.
99 (define_predicate "h8sx_binary_shift_operator"
100 (match_code "ashiftrt,lshiftrt,ashift")
102 return (BINARY_P (op) && NON_COMMUTATIVE_P (op)
103 && (h8sx_classify_shift (GET_MODE (op), GET_CODE (op), XEXP (op, 1))
104 == H8SX_SHIFT_BINARY));
107 ;; Return true if OP is a binary operator in which it would be safe to
108 ;; replace register operands with memory operands.
110 (define_predicate "h8sx_binary_memory_operator"
111 (match_code "plus,minus,and,ior,xor,ashift,ashiftrt,lshiftrt,rotate")
116 if (GET_MODE (op) != QImode
117 && GET_MODE (op) != HImode
118 && GET_MODE (op) != SImode)
121 switch (GET_CODE (op))
131 return h8sx_unary_shift_operator (op, mode);
135 ;; Like h8sx_binary_memory_operator, but applies to unary operators.
137 (define_predicate "h8sx_unary_memory_operator"
138 (match_code "neg,not")
143 if (GET_MODE (op) != QImode
144 && GET_MODE (op) != HImode
145 && GET_MODE (op) != SImode)
148 switch (GET_CODE (op))
159 ;; Return true if X is an ldm.l pattern. X is known to be parallel.
161 (define_predicate "h8300_ldm_parallel"
162 (match_code "parallel")
164 return h8300_ldm_stm_parallel (XVEC (op, 0), 1, 0);
169 (define_predicate "h8300_stm_parallel"
170 (match_code "parallel")
172 return h8300_ldm_stm_parallel (XVEC (op, 0), 0, 0);
175 ;; Likewise rts/l and rte/l. Note that the .md pattern will check for
176 ;; the return so there's no need to do that here.
178 (define_predicate "h8300_return_parallel"
179 (match_code "parallel")
181 return h8300_ldm_stm_parallel (XVEC (op, 0), 1, 1);
184 ;; Return true if OP is a constant that contains only one 1 in its
185 ;; binary representation.
187 (define_predicate "single_one_operand"
188 (match_code "const_int")
190 if (GET_CODE (op) == CONST_INT)
192 /* We really need to do this masking because 0x80 in QImode is
193 represented as -128 for example. */
194 if (exact_log2 (INTVAL (op) & GET_MODE_MASK (mode)) >= 0)
201 ;; Return true if OP is a constant that contains only one 0 in its
202 ;; binary representation.
204 (define_predicate "single_zero_operand"
205 (match_code "const_int")
207 if (GET_CODE (op) == CONST_INT)
209 /* We really need to do this masking because 0x80 in QImode is
210 represented as -128 for example. */
211 if (exact_log2 (~INTVAL (op) & GET_MODE_MASK (mode)) >= 0)
218 ;; Return true if OP is a valid call operand.
220 (define_predicate "call_insn_operand"
223 if (GET_CODE (op) == MEM)
225 rtx inside = XEXP (op, 0);
226 if (register_operand (inside, Pmode))
228 if (CONSTANT_ADDRESS_P (inside))
234 ;; Return true if OP is a valid call operand, and OP represents an
235 ;; operand for a small call (4 bytes instead of 6 bytes).
237 (define_predicate "small_call_insn_operand"
240 if (GET_CODE (op) == MEM)
242 rtx inside = XEXP (op, 0);
244 /* Register indirect is a small call. */
245 if (register_operand (inside, Pmode))
248 /* A call through the function vector is a small call too. */
249 if (GET_CODE (inside) == SYMBOL_REF
250 && (SYMBOL_REF_FLAGS (inside) & SYMBOL_FLAG_FUNCVEC_FUNCTION))
253 /* Otherwise it's a large call. */
257 ;; Return true if OP is a valid jump operand.
259 (define_predicate "jump_address_operand"
260 (match_code "reg,mem")
262 if (GET_CODE (op) == REG)
263 return mode == Pmode;
265 if (GET_CODE (op) == MEM)
267 rtx inside = XEXP (op, 0);
268 if (register_operand (inside, Pmode))
270 if (CONSTANT_ADDRESS_P (inside))
276 ;; Return 1 if an addition/subtraction of a constant integer can be
277 ;; transformed into two consecutive adds/subs that are faster than the
278 ;; straightforward way. Otherwise, return 0.
280 (define_predicate "two_insn_adds_subs_operand"
281 (match_code "const_int")
286 if (GET_CODE (op) == CONST_INT)
288 HOST_WIDE_INT value = INTVAL (op);
290 /* Force VALUE to be positive so that we do not have to consider
291 the negative case. */
294 if (TARGET_H8300H || TARGET_H8300S)
296 /* A constant addition/subtraction takes 2 states in QImode,
297 4 states in HImode, and 6 states in SImode. Thus, the
298 only case we can win is when SImode is used, in which
299 case, two adds/subs are used, taking 4 states. */
309 /* We do not profit directly by splitting addition or
310 subtraction of 3 and 4. However, since these are
311 implemented as a sequence of adds or subs, they do not
312 clobber (cc0) unlike a sequence of add.b and add.x. */
323 ;; Recognize valid operands for bit-field instructions.
325 (define_predicate "bit_operand"
326 (match_code "reg,subreg,mem")
328 /* We can accept any nonimmediate operand, except that MEM operands must
329 be limited to those that use addresses valid for the 'U' constraint. */
330 if (!nonimmediate_operand (op, mode))
333 /* H8SX accepts pretty much anything here. */
337 /* Accept any mem during RTL generation. Otherwise, the code that does
338 insv and extzv will think that we cannot handle memory. However,
339 to avoid reload problems, we only accept 'U' MEM operands after RTL
340 generation. This means that any named pattern which uses this predicate
341 must force its operands to match 'U' before emitting RTL. */
343 if (GET_CODE (op) == REG)
345 if (GET_CODE (op) == SUBREG)
347 return (GET_CODE (op) == MEM
351 ;; Return nonzero if OP is a MEM suitable for bit manipulation insns.
353 (define_predicate "bit_memory_operand"
356 return (GET_CODE (op) == MEM
360 ;; Return nonzero if X is a stack pointer.
362 (define_predicate "stack_pointer_operand"
365 return op == stack_pointer_rtx;
368 ;; Return nonzero if X is a constant whose absolute value is greater
371 (define_predicate "const_int_gt_2_operand"
372 (match_code "const_int")
374 return (GET_CODE (op) == CONST_INT
375 && abs (INTVAL (op)) > 2);
378 ;; Return nonzero if X is a constant whose absolute value is no
381 (define_predicate "const_int_ge_8_operand"
382 (match_code "const_int")
384 return (GET_CODE (op) == CONST_INT
385 && abs (INTVAL (op)) >= 8);
388 ;; Return nonzero if X is a constant expressible in QImode.
390 (define_predicate "const_int_qi_operand"
391 (match_code "const_int")
393 return (GET_CODE (op) == CONST_INT
394 && (INTVAL (op) & 0xff) == INTVAL (op));
397 ;; Return nonzero if X is a constant expressible in HImode.
399 (define_predicate "const_int_hi_operand"
400 (match_code "const_int")
402 return (GET_CODE (op) == CONST_INT
403 && (INTVAL (op) & 0xffff) == INTVAL (op));
406 ;; Return nonzero if X is a constant suitable for inc/dec.
408 (define_predicate "incdec_operand"
409 (match_code "const_int")
411 return (GET_CODE (op) == CONST_INT
412 && (CONST_OK_FOR_M (INTVAL (op))
413 || CONST_OK_FOR_O (INTVAL (op))));
416 ;; Recognize valid operators for bit instructions.
418 (define_predicate "bit_operator"
419 (match_code "xor,and,ior")
421 enum rtx_code code = GET_CODE (op);
428 ;; Return nonzero if OP is a shift operator.
430 (define_predicate "nshift_operator"
431 (match_code "ashiftrt,lshiftrt,ashift")
433 switch (GET_CODE (op))
445 ;; Return nonzero if X is either EQ or NE.
447 (define_predicate "eqne_operator"
450 enum rtx_code code = GET_CODE (op);
452 return (code == EQ || code == NE);
455 ;; Return nonzero if X is either GT or LE.
457 (define_predicate "gtle_operator"
458 (match_code "gt,le,gtu,leu")
460 enum rtx_code code = GET_CODE (op);
462 return (code == GT || code == LE);
465 ;; Return nonzero if X is either GTU or LEU.
467 (define_predicate "gtuleu_operator"
468 (match_code "gtu,leu")
470 enum rtx_code code = GET_CODE (op);
472 return (code == GTU || code == LEU);
475 ;; Return nonzero if X is either IOR or XOR.
477 (define_predicate "iorxor_operator"
478 (match_code "ior,xor")
480 enum rtx_code code = GET_CODE (op);
482 return (code == IOR || code == XOR);