1 ;; Machine Descriptions for R8C/M16C/M32C
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Red Hat.
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 2, or (at your
11 ;; option) any later version.
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 ;; License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING. If not, write to the Free
20 ;; Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 ;; move, push, extend, etc.
25 ;; Be careful to never create an alternative that has memory as both
26 ;; src and dest, as that makes gcc think that mem-mem moves in general
27 ;; are supported. While the chip does support this, it only has two
28 ;; address registers and sometimes gcc requires more than that. One
29 ;; example is code like this: a = *b where both a and b are spilled to
32 ;; Match push/pop before mov.b for passing char as arg,
33 ;; e.g. stdlib/efgcvt.c.
34 (define_insn "movqi_op"
35 [(set (match_operand:QI 0 "m32c_nonimmediate_operand"
36 "=Rqi*Rmm, <, RqiSd*Rmm, SdSs, Rqi*Rmm, Sd")
37 (match_operand:QI 1 "m32c_any_operand"
38 "iRqi*Rmm, iRqiSd*Rmm, >, Rqi*Rmm, SdSs, i"))]
39 "m32c_mov_ok (operands, QImode)"
47 [(set_attr "flags" "sz,*,*,sz,sz,sz")]
50 (define_expand "movqi"
51 [(set (match_operand:QI 0 "nonimmediate_operand" "=RqiSd*Rmm")
52 (match_operand:QI 1 "general_operand" "iRqiSd*Rmm"))]
54 "if (m32c_prepare_move (operands, QImode)) DONE;"
58 (define_insn "movhi_op"
59 [(set (match_operand:HI 0 "m32c_nonimmediate_operand"
60 "=Rhi*Rmm, Sd, SdSs, *Rcr, RhiSd*Rmm, <, RhiSd*Rmm, <, *Rcr")
61 (match_operand:HI 1 "m32c_any_operand"
62 "iRhi*RmmSdSs, i, Rhi*Rmm, RhiSd*Rmm, *Rcr, iRhiSd*Rmm, >, *Rcr, >"))]
63 "m32c_mov_ok (operands, HImode)"
74 [(set_attr "flags" "sz,sz,sz,n,n,n,n,n,n")]
77 (define_expand "movhi"
78 [(set (match_operand:HI 0 "m32c_nonimmediate_operand" "=RhiSd*Rmm")
79 (match_operand:HI 1 "m32c_any_operand" "iRhiSd*Rmm"))]
81 "if (m32c_prepare_move (operands, HImode)) DONE;"
85 (define_insn "movpsi_op"
86 [(set (match_operand:PSI 0 "m32c_nonimmediate_operand"
87 "=Raa, SdRmmRpi, Rcl, RpiSd*Rmm, <, <, Rcl, RpiRaa*Rmm")
88 (match_operand:PSI 1 "m32c_any_operand"
89 "sIU3, iSdRmmRpi, iRpiSd*Rmm, Rcl, Rpi*Rmm, Rcl, >, >"))]
90 "TARGET_A24 && m32c_mov_ok (operands, PSImode)"
100 [(set_attr "flags" "sz,sz,n,n,n,n,n,*")]
104 ;; The intention here is to combine the add with the move to create an
105 ;; indexed move. GCC doesn't always figure this out itself.
108 [(set (match_operand:HPSI 0 "register_operand" "")
109 (plus:HPSI (match_operand:HPSI 1 "register_operand" "")
110 (match_operand:HPSI 2 "immediate_operand" "")))
111 (set (match_operand:QHSI 3 "nonimmediate_operand" "")
112 (mem:QHSI (match_operand:HPSI 4 "register_operand" "")))]
113 "REGNO (operands[0]) == REGNO (operands[1])
114 && REGNO (operands[0]) == REGNO (operands[4])
115 && (rtx_equal_p (operands[0], operands[3])
116 || (dead_or_set_p (peep2_next_insn (1), operands[4])
117 && ! reg_mentioned_p (operands[0], operands[3])))"
119 (mem:QHSI (plus:HPSI (match_dup 1)
124 [(set (match_operand:HPSI 0 "register_operand" "")
125 (plus:HPSI (match_operand:HPSI 1 "register_operand" "")
126 (match_operand:HPSI 2 "immediate_operand" "")))
127 (set (mem:QHSI (match_operand:HPSI 4 "register_operand" ""))
128 (match_operand:QHSI 3 "m32c_any_operand" ""))]
129 "REGNO (operands[0]) == REGNO (operands[1])
130 && REGNO (operands[0]) == REGNO (operands[4])
131 && dead_or_set_p (peep2_next_insn (1), operands[4])
132 && ! reg_mentioned_p (operands[0], operands[3])"
133 [(set (mem:QHSI (plus:HPSI (match_dup 1)
139 ; Some PSI moves must be split.
141 [(set (match_operand:PSI 0 "m32c_nonimmediate_operand" "")
142 (match_operand:PSI 1 "m32c_any_operand" ""))]
143 "reload_completed && m32c_split_psi_p (operands)"
148 "m32c_split_move (operands, PSImode, 3);"
151 (define_expand "movpsi"
152 [(set (match_operand:PSI 0 "m32c_nonimmediate_operand" "")
153 (match_operand:PSI 1 "m32c_any_operand" ""))]
155 "if (m32c_prepare_move (operands, PSImode)) DONE;"
160 (define_expand "movsi"
161 [(set (match_operand:SI 0 "m32c_nonimmediate_operand" "=RsiSd*Rmm")
162 (match_operand:SI 1 "m32c_any_operand" "iRsiSd*Rmm"))]
164 "if (m32c_split_move (operands, SImode, 0)) DONE;"
167 ; All SI moves are split if TARGET_A16
168 (define_insn_and_split "movsi_splittable"
169 [(set (match_operand:SI 0 "m32c_nonimmediate_operand" "=Rsi<*Rmm,RsiSd*Rmm,Ss")
170 (match_operand:SI 1 "m32c_any_operand" "iRsiSd*Rmm,iRsi>*Rmm,Rsi*Rmm"))]
173 "TARGET_A16 && reload_completed"
175 "m32c_split_move (operands, SImode, 1); DONE;"
178 ; The movsi pattern doesn't always match because sometimes the modes
180 (define_insn "push_a01_l"
181 [(set (mem:SI (pre_dec:PSI (reg:PSI SP_REGNO)))
182 (match_operand 0 "a_operand" "Raa"))]
185 [(set_attr "flags" "n")]
188 (define_insn "movsi_24"
189 [(set (match_operand:SI 0 "m32c_nonimmediate_operand" "=Rsi*Rmm, Sd, RsiSd*Rmm, <")
190 (match_operand:SI 1 "m32c_any_operand" "iRsiSd*Rmm, iRsi*Rmm, >, iRsiRaaSd*Rmm"))]
197 [(set_attr "flags" "sz,sz,*,n")]
200 (define_expand "movdi"
201 [(set (match_operand:DI 0 "m32c_nonimmediate_operand" "=RdiSd*Rmm")
202 (match_operand:DI 1 "m32c_any_operand" "iRdiSd*Rmm"))]
204 "if (m32c_split_move (operands, DImode, 0)) DONE;"
207 (define_insn_and_split "movdi_splittable"
208 [(set (match_operand:DI 0 "m32c_nonimmediate_operand" "=Rdi<*Rmm,RdiSd*Rmm")
209 (match_operand:DI 1 "m32c_any_operand" "iRdiSd*Rmm,iRdi>*Rmm"))]
214 "m32c_split_move (operands, DImode, 1); DONE;"
220 (define_insn "pushqi"
221 [(set (mem:QI (pre_dec:PSI (reg:PSI SP_REGNO)))
222 (match_operand:QI 0 "mrai_operand" "iRqiSd*Rmm"))]
225 [(set_attr "flags" "n")]
228 (define_expand "pushhi"
229 [(set (mem:HI (pre_dec:PSI (reg:PSI SP_REGNO)))
230 (match_operand:HI 0 "" ""))]
233 gen_pushhi_16 (operands[0]);
235 gen_pushhi_24 (operands[0]);
239 (define_insn "pushhi_16"
240 [(set (mem:HI (pre_dec:HI (reg:HI SP_REGNO)))
241 (match_operand:HI 0 "mrai_operand" "iRhiSd*Rmm,Rcr"))]
246 [(set_attr "flags" "n,n")]
249 (define_insn "pushhi_24"
250 [(set (mem:HI (pre_dec:PSI (reg:PSI SP_REGNO)))
251 (match_operand:HI 0 "mrai_operand" "iRhiSd*Rmm"))]
254 [(set_attr "flags" "n")]
257 ;(define_insn "pushpi"
258 ; [(set (mem:PSI (pre_dec:PSI (reg:PSI SP_REGNO)))
259 ; (match_operand:PI 0 "mrai_operand" "iRaa,Rcr"))]
266 (define_insn "pushsi"
267 [(set (mem:SI (pre_dec:PSI (reg:PSI SP_REGNO)))
268 (match_operand:SI 0 "mrai_operand" "iRsiSd*Rmm"))]
271 [(set_attr "flags" "n")]
274 (define_expand "pophi"
275 [(set (match_operand:HI 0 "mra_operand" "=RhiSd*Rmm,Rcr")
276 (mem:HI (post_inc:HI (reg:HI SP_REGNO))))]
279 gen_pophi_16 (operands[0]);
281 gen_pophi_24 (operands[0]);
285 (define_insn "pophi_16"
286 [(set (match_operand:HI 0 "mra_operand" "=RhiSd*Rmm,Rcr")
287 (mem:HI (post_inc:HI (reg:HI SP_REGNO))))]
292 [(set_attr "flags" "n,n")]
295 (define_insn "pophi_24"
296 [(set (match_operand:HI 0 "mra_operand" "=RhiSd*Rmm")
297 (mem:HI (post_inc:PSI (reg:PSI SP_REGNO))))]
300 [(set_attr "flags" "n")]
303 (define_insn "poppsi"
304 [(set (match_operand:PSI 0 "cr_operand" "=Rcl")
305 (mem:PSI (post_inc:PSI (reg:PSI SP_REGNO))))]
308 [(set_attr "flags" "n")]
312 ;; Rhl used here as an HI-mode Rxl
313 (define_insn "extendqihi2"
314 [(set (match_operand:HI 0 "m32c_nonimmediate_operand" "=RhlSd*Rmm")
315 (sign_extend:HI (match_operand:QI 1 "mra_operand" "0")))]
318 [(set_attr "flags" "sz")]
321 (define_insn "extendhisi2"
322 [(set (match_operand:SI 0 "register_operand" "=R03")
323 (sign_extend:SI (match_operand:HI 1 "r0123_operand" "0")))]
326 if (REGNO(operands[0]) == 0) return \"exts.w\t%1\";
327 else return \"mov.w r1,r3 | sha.w #-8,r3 | sha.w #-7,r3\";"
328 [(set_attr "flags" "x")]
331 (define_insn "extendpsisi2"
332 [(set (match_operand:SI 0 "mr_operand" "=R03Sd*Rmm")
333 (sign_extend:SI (match_operand:PSI 1 "mr_operand" "0")))]
335 "; expand psi %1 to si %0"
336 [(set_attr "flags" "n")]
339 (define_insn "zero_extendpsisi2"
340 [(set (match_operand:SI 0 "mr_operand" "=R03Sd*Rmm")
341 (zero_extend:SI (match_operand:PSI 1 "mr_operand" "0")))]
343 "; expand psi %1 to si %0"
344 [(set_attr "flags" "n")]
347 (define_insn "zero_extendhipsi2"
348 [(set (match_operand:PSI 0 "register_operand" "=Raa")
349 (truncate:PSI (zero_extend:SI (match_operand:HI 1 "register_operand" "R03"))))]
352 [(set_attr "flags" "sz")]
355 (define_insn "zero_extendhisi2"
356 [(set (match_operand:SI 0 "m32c_nonimmediate_operand" "=RsiSd")
357 (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "0")))]
360 [(set_attr "flags" "x")]
363 (define_insn "zero_extendqihi2"
364 [(set (match_operand:HI 0 "m32c_nonimmediate_operand" "=Rhl,RhiSd*Rmm")
365 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,0")))]
370 [(set_attr "flags" "x,x")]
373 (define_insn "truncsipsi2_16"
374 [(set (match_operand:PSI 0 "m32c_nonimmediate_operand" "=RsiRadSd*Rmm,Raa,Rcr,RsiSd*Rmm")
375 (truncate:PSI (match_operand:SI 1 "nonimmediate_operand" "0,RsiSd*Rmm,RsiSd*Rmm,Rcr")))]
378 ; no-op trunc si %1 to psi %0
382 [(set_attr "flags" "n,*,n,n")]
385 (define_insn "trunchiqi2"
386 [(set (match_operand:QI 0 "m32c_nonimmediate_operand" "=RqiRmmSd")
387 (truncate:QI (match_operand:HI 1 "mra_qi_operand" "0")))]
389 "; no-op trunc hi %1 to qi %0"
390 [(set_attr "flags" "n")]
393 (define_insn "truncsipsi2_24"
394 [(set (match_operand:PSI 0 "m32c_nonimmediate_operand" "=RsiSd*Rmm,Raa,!Rcl,RsiSd*Rmm")
395 (truncate:PSI (match_operand:SI 1 "m32c_nonimmediate_operand" "0,RsiSd*Rmm,RsiSd*Rmm,!Rcl")))]
398 ; no-op trunc si %1 to psi %0
402 [(set_attr "flags" "n,sz,n,n")]
405 (define_expand "truncsipsi2"
406 [(set (match_operand:PSI 0 "m32c_nonimmediate_operand" "=RsiRadSd*Rmm,Raa,Rcr,RsiSd*Rmm")
407 (truncate:PSI (match_operand:SI 1 "m32c_nonimmediate_operand" "0,RsiSd*Rmm,RsiSd*Rmm,Rcr")))]
412 (define_expand "reload_inqi"
413 [(set (match_operand:QI 2 "" "=&Rqi")
414 (match_operand:QI 1 "" ""))
415 (set (match_operand:QI 0 "" "")
421 (define_expand "reload_outqi"
422 [(set (match_operand:QI 2 "" "=&Rqi")
423 (match_operand:QI 1 "" ""))
424 (set (match_operand:QI 0 "" "")
430 (define_expand "reload_inhi"
431 [(set (match_operand:HI 2 "" "=&Rhi")
432 (match_operand:HI 1 "" ""))
433 (set (match_operand:HI 0 "" "")
439 (define_expand "reload_outhi"
440 [(set (match_operand:HI 2 "" "=&Rhi")
441 (match_operand:HI 1 "" ""))
442 (set (match_operand:HI 0 "" "")