1 ;; Machine Description for Renesas RL78 processors
2 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
3 ;; Contributed by Red Hat.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
21 ;;---------- Moving ------------------------
23 (define_expand "movqi"
24 [(set (match_operand:QI 0 "nonimmediate_operand")
25 (match_operand:QI 1 "general_operand"))]
28 if (MEM_P (operands[0]) && MEM_P (operands[1]))
29 operands[1] = copy_to_mode_reg (QImode, operands[1]);
30 if (rl78_far_p (operands[0]) && rl78_far_p (operands[1]))
31 operands[1] = copy_to_mode_reg (QImode, operands[1]);
33 /* GCC can generate (SUBREG (SYMBOL_REF)) when it has to store a symbol
34 into a bitfield, or a packed ordinary field. We can handle this
35 provided that the destination is a register. If not, then load the
36 source into a register first. */
37 if (GET_CODE (operands[1]) == SUBREG
38 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
39 && ! REG_P (operands[0]))
40 operands[1] = copy_to_mode_reg (QImode, operands[1]);
42 /* Similarly for (SUBREG (CONST (PLUS (SYMBOL_REF)))).
43 cf. g++.dg/abi/packed.C. */
44 if (GET_CODE (operands[1]) == SUBREG
45 && GET_CODE (XEXP (operands[1], 0)) == CONST
46 && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == PLUS
47 && GET_CODE (XEXP (XEXP (XEXP (operands[1], 0), 0), 0)) == SYMBOL_REF
48 && ! REG_P (operands[0]))
49 operands[1] = copy_to_mode_reg (QImode, operands[1]);
51 if (CONST_INT_P (operands[1]) && ! IN_RANGE (INTVAL (operands[1]), (-1 << 8) + 1, (1 << 8) - 1))
56 (define_expand "movhi"
57 [(set (match_operand:HI 0 "nonimmediate_operand")
58 (match_operand:HI 1 "general_operand"))]
61 if (MEM_P (operands[0]) && MEM_P (operands[1]))
62 operands[1] = copy_to_mode_reg (HImode, operands[1]);
63 if (rl78_far_p (operands[0]) && rl78_far_p (operands[1]))
64 operands[1] = copy_to_mode_reg (HImode, operands[1]);
66 /* FIXME: Not sure how GCC can generate (SUBREG (SYMBOL_REF)),
67 but it does. Since this makes no sense, reject it here. */
68 if (GET_CODE (operands[1]) == SUBREG
69 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
71 /* Similarly for (SUBREG (CONST (PLUS (SYMBOL_REF)))). */
72 if (GET_CODE (operands[1]) == SUBREG
73 && GET_CODE (XEXP (operands[1], 0)) == CONST
74 && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == PLUS
75 && GET_CODE (XEXP (XEXP (XEXP (operands[1], 0), 0), 0)) == SYMBOL_REF)
80 (define_insn_and_split "movsi"
81 [(set (match_operand:SI 0 "nonimmediate_operand" "=vYS,v,Wfr")
82 (match_operand:SI 1 "general_operand" "viYS,Wfr,v"))]
86 [(set (match_operand:HI 2 "nonimmediate_operand")
87 (match_operand:HI 4 "general_operand"))
88 (set (match_operand:HI 3 "nonimmediate_operand")
89 (match_operand:HI 5 "general_operand"))]
90 "rl78_split_movsi (operands);"
91 [(set_attr "valloc" "op1")]
94 ;;---------- Conversions ------------------------
96 (define_expand "zero_extendqihi2"
97 [(set (match_operand:HI 0 "nonimmediate_operand")
98 (zero_extend:HI (match_operand:QI 1 "general_operand")))]
100 "if (rl78_force_nonfar_2 (operands, gen_zero_extendqihi2))
104 (define_expand "extendqihi2"
105 [(set (match_operand:HI 0 "nonimmediate_operand")
106 (sign_extend:HI (match_operand:QI 1 "general_operand")))]
108 "if (rl78_force_nonfar_2 (operands, gen_extendqihi2))
112 ;;---------- Arithmetic ------------------------
114 (define_expand "add<mode>3"
115 [(set (match_operand:QHI 0 "nonimmediate_operand")
116 (plus:QHI (match_operand:QHI 1 "general_operand")
117 (match_operand:QHI 2 "general_operand")))
120 "if (rl78_force_nonfar_3 (operands, gen_add<mode>3))
124 (define_expand "sub<mode>3"
125 [(set (match_operand:QHI 0 "nonimmediate_operand")
126 (minus:QHI (match_operand:QHI 1 "general_operand")
127 (match_operand:QHI 2 "general_operand")))
130 "if (rl78_force_nonfar_3 (operands, gen_sub<mode>3))
134 (define_expand "neg<mode>2"
135 [(set (match_operand:QHI 0 "nonimmediate_operand")
136 (minus:QHI (const_int 0)
137 (match_operand:QHI 1 "general_operand")))
140 "if (rl78_force_nonfar_2 (operands, gen_neg<mode>2))
144 (define_expand "umulqihi3"
145 [(set (match_operand:HI 0 "register_operand")
146 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand"))
147 (zero_extend:HI (match_operand:QI 2 "register_operand"))))]
152 (define_expand "andqi3"
153 [(set (match_operand:QI 0 "nonimmediate_operand")
154 (and:QI (match_operand:QI 1 "general_operand")
155 (match_operand:QI 2 "general_operand")))
158 "if (rl78_force_nonfar_3 (operands, gen_andqi3))
162 (define_expand "iorqi3"
163 [(set (match_operand:QI 0 "nonimmediate_operand")
164 (ior:QI (match_operand:QI 1 "general_operand")
165 (match_operand:QI 2 "general_operand")))
168 "if (rl78_force_nonfar_3 (operands, gen_iorqi3))
172 (define_expand "xorqi3"
173 [(set (match_operand:QI 0 "nonimmediate_operand")
174 (xor:QI (match_operand:QI 1 "general_operand")
175 (match_operand:QI 2 "general_operand")))
178 "if (rl78_force_nonfar_3 (operands, gen_xorqi3))
182 (define_expand "one_cmplqi2"
183 [(set (match_operand:QI 0 "nonimmediate_operand")
184 (xor:QI (match_operand:QI 1 "general_operand")
188 "if (rl78_force_nonfar_2 (operands, gen_one_cmplqi2))
192 ;;---------- Shifts ------------------------
194 (define_expand "ashl<mode>3"
195 [(set (match_operand:QHI 0 "nonimmediate_operand")
196 (ashift:QHI (match_operand:QHI 1 "general_operand")
197 (match_operand:QI 2 "general_operand")))
200 "if (rl78_force_nonfar_3 (operands, gen_ashl<mode>3))
204 (define_expand "ashr<mode>3"
205 [(set (match_operand:QHI 0 "nonimmediate_operand")
206 (ashiftrt:QHI (match_operand:QHI 1 "general_operand")
207 (match_operand:QI 2 "general_operand")))
210 "if (rl78_force_nonfar_3 (operands, gen_ashr<mode>3))
214 (define_expand "lshr<mode>3"
215 [(set (match_operand:QHI 0 "nonimmediate_operand")
216 (lshiftrt:QHI (match_operand:QHI 1 "general_operand")
217 (match_operand:QI 2 "general_operand")))
220 "if (rl78_force_nonfar_3 (operands, gen_lshr<mode>3))
224 (define_expand "ashrsi3"
225 [(parallel [(set (match_operand:SI 0 "nonimmediate_operand")
226 (ashiftrt:SI (match_operand:SI 1 "nonimmediate_operand")
227 (match_operand:SI 2 "nonmemory_operand")))
228 (clobber (reg:HI X_REG))])
234 (define_expand "lshrsi3"
235 [(parallel [(set (match_operand:SI 0 "nonimmediate_operand")
236 (lshiftrt:SI (match_operand:SI 1 "nonimmediate_operand")
237 (match_operand:SI 2 "nonmemory_operand")))
238 (clobber (reg:HI X_REG))])
244 (define_expand "ashlsi3"
245 [(parallel [(set (match_operand:SI 0 "nonimmediate_operand")
246 (ashift:SI (match_operand:SI 1 "nonimmediate_operand")
247 (match_operand:SI 2 "nonmemory_operand")))
248 (clobber (reg:HI X_REG))])
254 ;;---------- Branching ------------------------
256 (define_expand "indirect_jump"
258 (match_operand:HI 0 "nonimmediate_operand"))]
263 (define_expand "call"
264 [(call (match_operand:HI 0 "memory_operand")
265 (match_operand 1 ""))]
270 (define_expand "call_value"
271 [(set (match_operand 0 "register_operand")
272 (call (match_operand:HI 1 "memory_operand")
273 (match_operand 2 "")))]
278 (define_expand "cbranchqi4"
279 [(set (pc) (if_then_else
280 (match_operator 0 "rl78_cmp_operator"
281 [(match_operand:QI 1 "general_operand")
282 (match_operand:QI 2 "general_operand")])
283 (label_ref (match_operand 3 "" ""))
286 "rl78_expand_compare (operands);"
289 (define_expand "cbranchhi4"
290 [(set (pc) (if_then_else
291 (match_operator 0 "rl78_cmp_operator"
292 [(match_operand:HI 1 "general_operand")
293 (match_operand:HI 2 "general_operand")])
294 (label_ref (match_operand 3 "" ""))
297 "rl78_expand_compare (operands);"
300 (define_expand "cbranchsi4"
301 [(parallel [(set (pc) (if_then_else
302 (match_operator 0 "rl78_cmp_operator"
303 [(match_operand:SI 1 "general_operand")
304 (match_operand:SI 2 "nonmemory_operand")])
305 (label_ref (match_operand 3 "" ""))
307 (clobber (reg:HI AX_REG))
310 "rl78_expand_compare (operands);"