* config/m68k/predicates.md (pcrel_address, extend_operator,
[official-gcc.git] / gcc / config / m68k / predicates.md
blobca97e0b75b007bc5de6053a0ce6223d324228e86
1 ;; Predicate definitions for Motorola 68000.
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 ;; Special case of a general operand that's used as a source
22 ;; operand. Use this to permit reads from PC-relative memory when
23 ;; -mpcrel is specified.
25 (define_predicate "general_src_operand"
26   (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
28   if (TARGET_PCREL
29       && GET_CODE (op) == MEM
30       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
31           || GET_CODE (XEXP (op, 0)) == LABEL_REF
32           || GET_CODE (XEXP (op, 0)) == CONST))
33     return 1;
34   return general_operand (op, mode);
37 ;; Special case of a nonimmediate operand that's used as a source. Use
38 ;; this to permit reads from PC-relative memory when -mpcrel is
39 ;; specified.
41 (define_predicate "nonimmediate_src_operand"
42   (match_code "subreg,reg,mem")
44   if (TARGET_PCREL && GET_CODE (op) == MEM
45       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
46           || GET_CODE (XEXP (op, 0)) == LABEL_REF
47           || GET_CODE (XEXP (op, 0)) == CONST))
48     return 1;
49   return nonimmediate_operand (op, mode);
52 ;; Special case of a memory operand that's used as a source. Use this
53 ;; to permit reads from PC-relative memory when -mpcrel is specified.
55 (define_predicate "memory_src_operand"
56   (match_code "subreg,mem")
58   if (TARGET_PCREL && GET_CODE (op) == MEM
59       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
60           || GET_CODE (XEXP (op, 0)) == LABEL_REF
61           || GET_CODE (XEXP (op, 0)) == CONST))
62     return 1;
63   return memory_operand (op, mode);
66 ;; Similar to general_operand, but exclude stack_pointer_rtx.
68 (define_predicate "not_sp_operand"
69   (match_code "subreg,reg,mem")
71   return op != stack_pointer_rtx && nonimmediate_operand (op, mode);
74 ;; Predicate that accepts only a pc-relative address.  This is needed
75 ;; because pc-relative addresses don't satisfy the predicate
76 ;; "general_src_operand".
78 (define_predicate "pcrel_address"
79   (match_code "symbol_ref,label_ref,const"))
81 ;; Accept integer operands in the range 0..0xffffffff.  We have to
82 ;; check the range carefully since this predicate is used in DImode
83 ;; contexts.  Also, we need some extra crud to make it work when
84 ;; hosted on 64-bit machines.
86 (define_predicate "const_uint32_operand"
87   (match_code "const_int,const_double")
89   /* It doesn't make sense to ask this question with a mode that is
90      not larger than 32 bits.  */
91   gcc_assert (GET_MODE_BITSIZE (mode) > 32);
93 #if HOST_BITS_PER_WIDE_INT > 32
94   /* All allowed constants will fit a CONST_INT.  */
95   return (GET_CODE (op) == CONST_INT
96           && (INTVAL (op) >= 0 && INTVAL (op) <= 0xffffffffL));
97 #else
98   return (GET_CODE (op) == CONST_INT
99           || (GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_HIGH (op) == 0));
100 #endif
103 ;; Accept integer operands in the range -0x80000000..0x7fffffff.  We
104 ;; have to check the range carefully since this predicate is used in
105 ;; DImode contexts.
107 (define_predicate "const_sint32_operand"
108   (match_code "const_int")
110   /* It doesn't make sense to ask this question with a mode that is
111      not larger than 32 bits.  */
112   gcc_assert (GET_MODE_BITSIZE (mode) > 32);
114   /* All allowed constants will fit a CONST_INT.  */
115   return (GET_CODE (op) == CONST_INT
116           && (INTVAL (op) >= (-0x7fffffff - 1) && INTVAL (op) <= 0x7fffffff));
119 ;; Return true if X is a valid comparison operator for the dbcc
120 ;; instruction.  Note it rejects floating point comparison
121 ;; operators. (In the future we could use Fdbcc).  It also rejects
122 ;; some comparisons when CC_NO_OVERFLOW is set.
124 (define_predicate "valid_dbcc_comparison_p"
125   (and (match_code "eq,ne,gtu,ltu,geu,leu,gt,lt,ge,le")
126        (match_test "valid_dbcc_comparison_p_2 (op, mode)")))
128 ;; Check for sign_extend or zero_extend.  Used for bit-count operands.
130 (define_predicate "extend_operator"
131   (match_code "sign_extend,zero_extend"))
133 ;; Returns true if OP is either a symbol reference or a sum of a
134 ;; symbol reference and a constant.
136 (define_predicate "symbolic_operand"
137   (match_code "symbol_ref,label_ref,const")
139   switch (GET_CODE (op))
140     {
141     case SYMBOL_REF:
142     case LABEL_REF:
143       return true;
145     case CONST:
146       op = XEXP (op, 0);
147       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
148                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
149               && GET_CODE (XEXP (op, 1)) == CONST_INT);
151 #if 0 /* Deleted, with corresponding change in m68k.h,
152          so as to fit the specs.  No CONST_DOUBLE is ever symbolic.  */
153     case CONST_DOUBLE:
154       return GET_MODE (op) == mode;
155 #endif
157     default:
158       return false;
159     }
162 ;; TODO: Add a comment here.
164 (define_predicate "post_inc_operand"
165   (and (match_code "mem")
166        (match_test "GET_CODE (XEXP (op, 0)) == POST_INC")))
168 ;; TODO: Add a comment here.
170 (define_predicate "pre_dec_operand"
171   (and (match_code "mem")
172        (match_test "GET_CODE (XEXP (op, 0)) == PRE_DEC")))