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 "mra_qi_operand"
36 "=Rqi*Rmm, <, RqiSd*Rmm, SdSs, Rqi*Rmm, Sd")
37 (match_operand:QI 1 "mrai_qi_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 "mra_qi_operand" "=RqiSd*Rmm")
52 (match_operand:QI 1 "mrai_qi_operand" "iRqiSd*Rmm"))]
54 "if (m32c_prepare_move (operands, QImode)) DONE;"
58 (define_insn "movhi_op"
59 [(set (match_operand:HI 0 "nonimmediate_operand"
60 "=Rhi*Rmm, Sd, SdSs, *Rcr, RhiSd*Rmm, <, RhiSd*Rmm, <, *Rcr")
61 (match_operand:HI 1 "general_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,*,*,*,*,*,*")]
77 (define_expand "movhi"
78 [(set (match_operand:HI 0 "nonimmediate_operand" "=RhiSd*Rmm")
79 (match_operand:HI 1 "general_operand" "iRhiSd*Rmm"))]
81 "if (m32c_prepare_move (operands, HImode)) DONE;"
85 (define_insn "movpsi_op"
86 [(set (match_operand:PSI 0 "nonimmediate_operand"
87 "=Raa, SdRmmRpi, Rcl, RpiSd*Rmm, <, <, Rcl, Rsi*Rmm")
88 (match_operand:PSI 1 "general_operand"
89 "sIU3, iSdRmmRpi, iRpiSd*Rmm, Rcl, Rsi*Rmm, Rcl, >, >"))]
90 "TARGET_A24 && m32c_mov_ok (operands, PSImode)"
100 [(set_attr "flags" "sz,sz,*,*,*,*,*,*")]
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.
107 (define_mode_macro QHSI [QI HI SI])
108 (define_mode_macro HPSI [(HI "TARGET_A16") (PSI "TARGET_A24")])
111 [(set (match_operand:HPSI 0 "register_operand" "")
112 (plus:HPSI (match_operand:HPSI 1 "register_operand" "")
113 (match_operand:HPSI 2 "immediate_operand" "")))
114 (set (match_operand:QHSI 3 "nonimmediate_operand" "")
115 (mem:QHSI (match_operand:HPSI 4 "register_operand" "")))]
116 "REGNO (operands[0]) == REGNO (operands[1])
117 && REGNO (operands[0]) == REGNO (operands[4])
118 && dead_or_set_p (peep2_next_insn (1), operands[4])
119 && ! reg_mentioned_p (operands[0], operands[3])"
121 (mem:QHSI (plus:HPSI (match_dup 1)
126 [(set (match_operand:HPSI 0 "register_operand" "")
127 (plus:HPSI (match_operand:HPSI 1 "register_operand" "")
128 (match_operand:HPSI 2 "immediate_operand" "")))
129 (set (mem:QHSI (match_operand:HPSI 4 "register_operand" ""))
130 (match_operand:QHSI 3 "general_operand" ""))]
131 "REGNO (operands[0]) == REGNO (operands[1])
132 && REGNO (operands[0]) == REGNO (operands[4])
133 && dead_or_set_p (peep2_next_insn (1), operands[4])
134 && ! reg_mentioned_p (operands[0], operands[3])"
135 [(set (mem:QHSI (plus:HPSI (match_dup 1)
141 ; Some PSI moves must be split.
143 [(set (match_operand:PSI 0 "nonimmediate_operand" "")
144 (match_operand:PSI 1 "general_operand" ""))]
145 "reload_completed && m32c_split_psi_p (operands)"
150 "m32c_split_move (operands, PSImode, 3);"
153 (define_expand "movpsi"
154 [(set (match_operand:PSI 0 "mras_operand" "")
155 (match_operand:PSI 1 "mrasi_operand" ""))]
157 "if (m32c_prepare_move (operands, PSImode)) DONE;"
162 (define_expand "movsi"
163 [(set (match_operand:SI 0 "mras_operand" "=RsiSd*Rmm")
164 (match_operand:SI 1 "mrasi_operand" "iRsiSd*Rmm"))]
166 "if (m32c_split_move (operands, SImode, 0)) DONE;"
169 ; All SI moves are split if TARGET_A16
170 (define_insn_and_split "movsi_splittable"
171 [(set (match_operand:SI 0 "mras_operand" "=Rsi<*Rmm,RsiSd*Rmm,Ss")
172 (match_operand:SI 1 "mrasi_operand" "iRsiSd*Rmm,iRsi>*Rmm,Rsi*Rmm"))]
175 "TARGET_A16 && reload_completed"
177 "m32c_split_move (operands, SImode, 1); DONE;"
180 ; The movsi pattern doesn't always match because sometimes the modes
182 (define_insn "push_a01_l"
183 [(set (mem:SI (pre_dec:PSI (reg:PSI SP_REGNO)))
184 (match_operand 0 "a_operand" ""))]
189 (define_insn "movsi_24"
190 [(set (match_operand:SI 0 "mras_operand" "=Rsi*Rmm, Sd, RsiSd*Rmm, <")
191 (match_operand:SI 1 "mrasi_operand" "iRsiSd*Rmm, iRsi*Rmm, >, iRsiRaaSd*Rmm"))]
200 (define_expand "movdi"
201 [(set (match_operand:DI 0 "mras_operand" "=RdiSd*Rmm")
202 (match_operand:DI 1 "mrasi_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 "mras_operand" "=Rdi<*Rmm,RdiSd*Rmm")
209 (match_operand:DI 1 "mrasi_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"))]
227 (define_expand "pushhi"
228 [(set (mem:HI (pre_dec:PSI (reg:PSI SP_REGNO)))
229 (match_operand:HI 0 "" ""))]
232 gen_pushhi_16 (operands[0]);
234 gen_pushhi_24 (operands[0]);
238 (define_insn "pushhi_16"
239 [(set (mem:HI (pre_dec:HI (reg:HI SP_REGNO)))
240 (match_operand:HI 0 "mrai_operand" "iRhiSd*Rmm,Rcr"))]
247 (define_insn "pushhi_24"
248 [(set (mem:HI (pre_dec:PSI (reg:PSI SP_REGNO)))
249 (match_operand:HI 0 "mrai_operand" "iRhiSd*Rmm"))]
254 ;(define_insn "pushpi"
255 ; [(set (mem:PSI (pre_dec:PSI (reg:PSI SP_REGNO)))
256 ; (match_operand:PI 0 "mrai_operand" "iRaa,Rcr"))]
263 (define_insn "pushsi"
264 [(set (mem:SI (pre_dec:PSI (reg:PSI SP_REGNO)))
265 (match_operand:SI 0 "mrai_operand" "iRsiSd*Rmm"))]
270 (define_expand "pophi"
271 [(set (match_operand:HI 0 "mra_operand" "=RhiSd*Rmm,Rcr")
272 (mem:HI (post_inc:HI (reg:HI SP_REGNO))))]
275 gen_pophi_16 (operands[0]);
277 gen_pophi_24 (operands[0]);
281 (define_insn "pophi_16"
282 [(set (match_operand:HI 0 "mra_operand" "=RhiSd*Rmm,Rcr")
283 (mem:HI (post_inc:HI (reg:HI SP_REGNO))))]
290 (define_insn "pophi_24"
291 [(set (match_operand:HI 0 "mra_operand" "=RhiSd*Rmm")
292 (mem:HI (post_inc:PSI (reg:PSI SP_REGNO))))]
297 (define_insn "poppsi"
298 [(set (match_operand:PSI 0 "cr_operand" "=Rcl")
299 (mem:PSI (post_inc:PSI (reg:PSI SP_REGNO))))]
305 ;; Rhl used here as an HI-mode Rxl
306 (define_insn "extendqihi2"
307 [(set (match_operand:HI 0 "mra_operand" "=RhlSd*Rmm")
308 (sign_extend:HI (match_operand:QI 1 "mra_operand" "0")))]
311 [(set_attr "flags" "sz")]
314 (define_insn "extendhisi2"
315 [(set (match_operand:SI 0 "r0123_operand" "=R03")
316 (sign_extend:SI (match_operand:HI 1 "r0123_operand" "0")))]
319 if (REGNO(operands[0]) == 0) return \"exts.w\t%1\";
320 else return \"mov.w r1,r3 | sha.w #-8,r3 | sha.w #-7,r3\";"
321 [(set_attr "flags" "sz")]
324 (define_insn "extendpsisi2"
325 [(set (match_operand:SI 0 "mr_operand" "=R03Sd*Rmm")
326 (sign_extend:SI (match_operand:PSI 1 "mr_operand" "0")))]
328 "; expand psi %1 to si %0"
331 (define_insn "zero_extendpsisi2"
332 [(set (match_operand:SI 0 "mr_operand" "=R03Sd*Rmm")
333 (zero_extend:SI (match_operand:PSI 1 "mr_operand" "0")))]
335 "; expand psi %1 to si %0"
338 (define_insn "zero_extendhipsi2"
339 [(set (match_operand:PSI 0 "nonimmediate_operand" "=Raa")
340 (truncate:PSI (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "Rhi"))))]
345 (define_insn "zero_extendhisi2"
346 [(set (match_operand:SI 0 "nonimmediate_operand" "=RsiSd")
347 (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "0")))]
352 (define_insn "zero_extendqihi2"
353 [(set (match_operand:HI 0 "nonimmediate_operand" "=RsiRaaSd*Rmm")
354 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0")))]
359 (define_insn "truncsipsi2_16"
360 [(set (match_operand:PSI 0 "nonimmediate_operand" "=RsiRadSd*Rmm,Raa,Rcr,RsiSd*Rmm")
361 (truncate:PSI (match_operand:SI 1 "nonimmediate_operand" "0,RsiSd*Rmm,RsiSd*Rmm,Rcr")))]
364 ; no-op trunc si %1 to psi %0
370 (define_insn "trunchiqi2"
371 [(set (match_operand:QI 0 "mra_qi_operand" "=RqiRmmSd")
372 (truncate:QI (match_operand:HI 1 "mra_qi_operand" "0")))]
374 "; no-op trunc hi %1 to qi %0"
377 (define_insn "truncsipsi2_24"
378 [(set (match_operand:PSI 0 "nonimmediate_operand" "=RsiSd*Rmm,Raa,!Rcl,RsiSd*Rmm")
379 (truncate:PSI (match_operand:SI 1 "nonimmediate_operand" "0,RsiSd*Rmm,RsiSd*Rmm,!Rcl")))]
382 ; no-op trunc si %1 to psi %0
388 (define_expand "truncsipsi2"
389 [(set (match_operand:PSI 0 "nonimmediate_operand" "=RsiRadSd*Rmm,Raa,Rcr,RsiSd*Rmm")
390 (truncate:PSI (match_operand:SI 1 "nonimmediate_operand" "0,RsiSd*Rmm,RsiSd*Rmm,Rcr")))]
395 (define_expand "reload_inqi"
396 [(set (match_operand:QI 2 "" "=&Rqi")
397 (match_operand:QI 1 "" ""))
398 (set (match_operand:QI 0 "" "")
404 (define_expand "reload_outqi"
405 [(set (match_operand:QI 2 "" "=&Rqi")
406 (match_operand:QI 1 "" ""))
407 (set (match_operand:QI 0 "" "")
413 (define_expand "reload_inhi"
414 [(set (match_operand:HI 2 "" "=&Rhi")
415 (match_operand:HI 1 "" ""))
416 (set (match_operand:HI 0 "" "")
422 (define_expand "reload_outhi"
423 [(set (match_operand:HI 2 "" "=&Rhi")
424 (match_operand:HI 1 "" ""))
425 (set (match_operand:HI 0 "" "")