1 ;; Machine Description for Renesas RL78 processors
2 ;; Copyright (C) 2011 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/>.
49 (UNS_TRAMPOLINE_INIT 20)
50 (UNS_TRAMPOLINE_UNINIT 21)
51 (UNS_NONLOCAL_GOTO 22)
61 (define_mode_iterator QHI [QI HI])
63 (include "predicates.md")
64 (include "constraints.md")
65 (include "rl78-expand.md")
66 (include "rl78-virt.md")
67 (include "rl78-real.md")
70 ;; Function Prologue/Epilogue Instructions
72 (define_expand "prologue"
75 "rl78_expand_prologue (); DONE;"
78 (define_expand "epilogue"
81 "rl78_expand_epilogue (); DONE;"
84 (define_expand "sibcall_epilogue"
96 (define_insn "interrupt_return"
97 [(unspec_volatile [(return)] UNS_RETI) ]
102 (define_insn "brk_interrupt_return"
103 [(unspec_volatile [(return)] UNS_RETB) ]
108 (define_expand "eh_return"
109 [(match_operand:HI 0 "" "")]
111 "rl78_expand_eh_epilogue (operands[0]);
116 ;; These are used only by prologue/epilogue so it's "safe" to pass
117 ;; virtual registers.
119 [(set (reg:HI SP_REG)
120 (plus:HI (reg:HI SP_REG)
122 (set (mem:HI (reg:HI SP_REG))
123 (match_operand:HI 0 "register_operand" "ABDT,vZint"))]
131 [(set (match_operand:HI 0 "register_operand" "=ABDT,vZint")
132 (mem:HI (reg:HI SP_REG)))
134 (plus:HI (reg:HI SP_REG)
142 (define_insn "sel_rb"
143 [(unspec_volatile [(match_operand 0 "immediate_operand" "")] UNS_SET_RB)]
148 (define_insn "trampoline_init"
149 [(set (match_operand 0 "register_operand" "=Z08W")
150 (unspec_volatile [(match_operand 1 "register_operand" "Z08W")
151 (match_operand 2 "register_operand" "Z10W")
152 ] UNS_TRAMPOLINE_INIT))
155 "call !!___trampoline_init ; %0 <= %1 %2"
158 (define_insn "trampoline_uninit"
159 [(unspec_volatile [(const_int 0)] UNS_TRAMPOLINE_UNINIT)
162 "call !!___trampoline_uninit"
165 ;; GCC restores $fp *before* using it to access values on the *old*
166 ;; frame. So, we do it ourselves, to ensure this is not the case.
167 ;; Note that while %1 is usually a label_ref, we allow for a
168 ;; non-immediate as well.
169 (define_expand "nonlocal_goto"
171 (unspec_volatile [(match_operand 0 "" "") ;; fp (ignore)
172 (match_operand 1 "" "vi") ;; target
173 (match_operand 2 "" "vi") ;; sp
174 (match_operand 3 "" "vi") ;; ?
175 ] UNS_NONLOCAL_GOTO))
178 "emit_jump_insn (gen_nonlocal_goto_insn (operands[0], operands[1], operands[2], operands[3]));
183 (define_insn "nonlocal_goto_insn"
185 (unspec_volatile [(match_operand 0 "" "") ;; fp (ignore)
186 (match_operand 1 "" "vi") ;; target
187 (match_operand 2 "" "vi") ;; sp
188 (match_operand 3 "" "vi") ;; ?
189 ] UNS_NONLOCAL_GOTO))
202 ;;======================================================================
204 ;; "macro" insns - cases where inline chunks of code are more
205 ;; efficient than anything else.
207 (define_expand "addsi3"
208 [(set (match_operand:SI 0 "register_operand" "=&v")
209 (plus:SI (match_operand:SI 1 "nonmemory_operand" "vi")
210 (match_operand 2 "nonmemory_operand" "vi")))
213 "if (!nonmemory_operand (operands[1], SImode))
214 operands[1] = force_reg (SImode, operands[1]);
215 if (!nonmemory_operand (operands[1], SImode))
216 operands[2] = force_reg (SImode, operands[2]);"
219 (define_insn "addsi3_internal"
220 [(set (match_operand:SI 0 "register_operand" "=&v")
221 (plus:SI (match_operand:SI 1 "nonmemory_operand" "vi")
222 (match_operand:SI 2 "nonmemory_operand" "vi")))
225 "; addSI macro %0 = %1 + %2
234 ; end of addSI macro"
235 [(set_attr "valloc" "macax")]
238 (define_expand "mulsi3"
239 [(set (match_operand:SI 0 "register_operand" "=&v")
240 (mult:SI (match_operand:SI 1 "nonmemory_operand" "vi")
241 (match_operand:SI 2 "nonmemory_operand" "vi")))
247 ;; 0xFFFF0 is MACR(L). 0xFFFF2 is MACR(H) but we don't care about it
248 ;; because we're only using the lower 16 bits (which is the upper 16
249 ;; bits of the result).
250 (define_insn "mulsi3_rl78"
251 [(set (match_operand:SI 0 "register_operand" "=&v")
252 (mult:SI (match_operand:SI 1 "nonmemory_operand" "vi")
253 (match_operand:SI 2 "nonmemory_operand" "vi")))
256 "; mulsi macro %0 = %1 * %2
259 MULHU ; bcax = bc * ax
265 MACHU ; MACR += bc * ax
268 MACHU ; MACR += bc * ax
271 ; end of mulsi macro"
272 [(set_attr "valloc" "macax")]
275 ;; 0xFFFF0 is MDAL. 0xFFFF2 is MDAH.
276 ;; 0xFFFF4 is MDBL. 0xFFFF6 is MDBH.
277 ;; 0xF00E0 is MDCL. 0xF00E2 is MDCH.
279 ;; Warning: this matches the documentation, not the silicon.
280 (define_insn "mulsi3_g13"
281 [(set (match_operand:SI 0 "register_operand" "=&v")
282 (mult:SI (match_operand:SI 1 "nonmemory_operand" "vi")
283 (match_operand:SI 2 "nonmemory_operand" "vi")))
286 "; mulsi macro %0 = %1 * %2
288 mov !0xf00e8, a ; MDUC
290 movw 0xffff0, ax ; MDAL
292 movw 0xffff2, ax ; MDAH
293 nop ; mdb = mdal * mdah
294 movw ax, 0xffff4 ; MDBL
298 mov !0xf00e8, a ; MDUC
299 movw ax, 0xffff6 ; MDBH
300 movw !0xf00e0, ax ; MDCL
302 movw !0xf00e2, ax ; MDCL
304 movw 0xffff0, ax ; MDAL
306 movw 0xffff2, ax ; MDAH
307 nop ; mdc += mdal * mdah
310 mov !0xf00e8, a ; MDUC
312 movw 0xffff0, ax ; MDAL
314 movw 0xffff2, ax ; MDAH
315 nop ; mdc += mdal * mdah
316 movw ax, !0xf00e0 ; MDCL
318 ; end of mulsi macro"
319 [(set_attr "valloc" "macax")]