OSDN Git Service

* config/avr/avr.c (avr_rtx_costs): Set cost of CONST, LABEL_REF to 0.
[pf3gnuchains/gcc-fork.git] / gcc / config / avr / predicates.md
1 ;; Predicate definitions for ATMEL AVR micro controllers.
2 ;; Copyright (C) 2006, 2007, 2008 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 3, 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 COPYING3.  If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 ;; Registers from r0 to r15.
21 (define_predicate "l_register_operand"
22   (and (match_code "reg")
23        (match_test "REGNO (op) <= 15")))
24
25 ;; Registers from r16 to r31.
26 (define_predicate "d_register_operand"
27   (and (match_code "reg")
28        (match_test "REGNO (op) >= 16 && REGNO (op) <= 31")))
29
30 (define_predicate "even_register_operand"
31   (and (match_code "reg")
32        (and (match_test "REGNO (op) <= 31")
33             (match_test "(REGNO (op) & 1) == 0"))))
34
35 (define_predicate "odd_register_operand"
36   (and (match_code "reg")
37        (and (match_test "REGNO (op) <= 31")
38             (match_test "(REGNO (op) & 1) != 0"))))
39
40 ;; SP register.
41 (define_predicate "stack_register_operand"
42   (and (match_code "reg")
43        (match_test "REGNO (op) == REG_SP")))
44
45 ;; Return true if OP is a valid address for lower half of I/O space.
46 (define_predicate "low_io_address_operand"
47   (and (match_code "const_int")
48        (match_test "IN_RANGE((INTVAL (op)), 0x20, 0x3F)")))
49
50 ;; Return true if OP is a valid address for high half of I/O space.
51 (define_predicate "high_io_address_operand"
52   (and (match_code "const_int")
53        (match_test "IN_RANGE((INTVAL (op)), 0x40, 0x5F)")))
54
55 ;; Return true if OP is a valid address of I/O space.
56 (define_predicate "io_address_operand"
57   (and (match_code "const_int")
58        (match_test "IN_RANGE((INTVAL (op)), 0x20, (0x60 - GET_MODE_SIZE(mode)))")))
59
60 ;; Return 1 if OP is the zero constant for MODE.
61 (define_predicate "const0_operand"
62   (and (match_code "const_int,const_double")
63        (match_test "op == CONST0_RTX (mode)")))
64
65 ;; Return 1 if OP is the one constant integer for MODE.
66 (define_predicate "const1_operand"
67   (and (match_code "const_int")
68        (match_test "op == CONST1_RTX (mode)")))
69
70
71 ;; Return 1 if OP is constant integer 0..7 for MODE.
72 (define_predicate "const_0_to_7_operand"
73   (and (match_code "const_int")
74        (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
75
76 ;; Return 1 if OP is constant integer 2..7 for MODE.
77 (define_predicate "const_2_to_7_operand"
78   (and (match_code "const_int")
79        (match_test "IN_RANGE (INTVAL (op), 2, 7)")))
80
81 ;; Return 1 if OP is constant integer 2..6 for MODE.
82 (define_predicate "const_2_to_6_operand"
83   (and (match_code "const_int")
84        (match_test "IN_RANGE (INTVAL (op), 2, 6)")))
85
86 ;; Returns true if OP is either the constant zero or a register.
87 (define_predicate "reg_or_0_operand"
88   (ior (match_operand 0 "register_operand")
89        (match_operand 0 "const0_operand")))
90
91 ;; Returns 1 if OP is a SYMBOL_REF.
92 (define_predicate "symbol_ref_operand"
93   (match_code "symbol_ref"))
94
95 ;; Return true if OP is a text segment reference.
96 ;; This is needed for program memory address expressions.
97 (define_predicate "text_segment_operand"
98   (match_code "code_label,label_ref,symbol_ref,plus,const")
99 {
100   switch (GET_CODE (op))
101     {
102     case CODE_LABEL:
103       return true;
104     case LABEL_REF :
105       return true;
106     case SYMBOL_REF :
107       return SYMBOL_REF_FUNCTION_P (op);
108     case PLUS :
109       /* Assume canonical format of symbol + constant.
110          Fall through.  */
111     case CONST :
112       return text_segment_operand (XEXP (op, 0), VOIDmode);
113     default :
114       return false;
115     }
116 })
117
118 ;; Return true if OP is a constant that contains only one 1 in its
119 ;; binary representation.
120 (define_predicate "single_one_operand"
121   (and (match_code "const_int")
122        (match_test "exact_log2(INTVAL (op) & GET_MODE_MASK (mode)) >= 0")))
123
124 ;; Return true if OP is a constant that contains only one 0 in its
125 ;; binary representation.
126 (define_predicate "single_zero_operand"
127   (and (match_code "const_int")
128        (match_test "exact_log2(~INTVAL (op) & GET_MODE_MASK (mode)) >= 0")))
129
130 ;;
131 (define_predicate "avr_sp_immediate_operand"
132   (and (match_code "const_int")
133        (match_test "INTVAL (op) >= -6 && INTVAL (op) <= 5")))
134
135 ;; True for EQ & NE
136 (define_predicate "eqne_operator"
137   (match_code "eq,ne"))
138        
139 ;; True for GE & LT
140 (define_predicate "gelt_operator"
141   (match_code "ge,lt"))
142        
143 ;; True for GT, GTU, LE & LEU
144 (define_predicate "difficult_comparison_operator"
145   (match_code "gt,gtu,le,leu"))
146
147 ;; False for GT, GTU, LE & LEU
148 (define_predicate "simple_comparison_operator"
149   (and (match_operand 0 "comparison_operator")
150        (not (match_code "gt,gtu,le,leu"))))
151
152 ;; Return true if OP is a valid call operand.
153 (define_predicate "call_insn_operand"
154   (and (match_code "mem")
155        (ior (match_test "register_operand (XEXP (op, 0), mode)")
156             (match_test "CONSTANT_ADDRESS_P (XEXP (op, 0))"))))
157
158 ;; True for register that is pseudo register.
159 (define_predicate "pseudo_register_operand"
160   (and (match_code "reg")
161        (match_test "!HARD_REGISTER_P (op)")))
162
163 ;; Return true if OP is a constant integer that is either
164 ;; 8 or 16 or 24.
165 (define_predicate "const_8_16_24_operand"
166   (and (match_code "const_int")
167        (match_test "8 == INTVAL(op) || 16 == INTVAL(op) || 24 == INTVAL(op)")))
168
169 ;; Unsigned CONST_INT that fits in 8 bits, i.e. 0..255.
170 (define_predicate "u8_operand"
171   (and (match_code "const_int")
172        (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
173
174 ;; Signed CONST_INT that fits in 8 bits, i.e. -128..127.
175 (define_predicate "s8_operand"
176   (and (match_code "const_int")
177        (match_test "IN_RANGE (INTVAL (op), -128, 127)")))
178
179 ;; One-extended CONST_INT that fits in 8 bits, i.e. -256..-1.
180 (define_predicate "o8_operand"
181   (and (match_code "const_int")
182        (match_test "IN_RANGE (INTVAL (op), -256, -1)")))
183
184 ;; Signed CONST_INT that fits in 9 bits, i.e. -256..255.
185 (define_predicate "s9_operand"
186   (and (match_code "const_int")
187        (match_test "IN_RANGE (INTVAL (op), -256, 255)")))
188
189 (define_predicate "register_or_s9_operand"
190   (ior (match_operand 0 "register_operand")
191        (match_operand 0 "s9_operand")))