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 ;; various block move instructions
26 ;; SMOVB - while (r3--) { *a1-- = *r1ha0--; } - memcpy
27 ;; SMOVF - while (r3--) { *a1++ = *r1ha0++; } - memcpy
28 ;; SSTR - while (r3--) { *a1++ = [r0l,r0]; } - memset
31 ;; SCMPU - while (*a0 && *a0 != *a1) { a0++; a1++; } - strcmp
32 ;; SIN - while (r3--) { *a1++ = *a0; }
33 ;; SMOVB - while (r3--) { *a1-- = *a0--; } - memcpy
34 ;; SMOVF - while (r3--) { *a1++ = *a0++; } - memcpy
35 ;; SMOVU - while (*a1++ = *a0++) ; - strcpy
36 ;; SOUT - while (r3--) { *a1 = *a0++; }
37 ;; SSTR - while (r3--) { *a1++ = [r0l,r0]; } - memset
41 ;; 0 = destination (mem:BLK ...)
42 ;; 1 = source (mem:BLK ...)
45 (define_expand "movmemhi"
46 [(match_operand 0 "ap_operand" "")
47 (match_operand 1 "ap_operand" "")
48 (match_operand 2 "m32c_r3_operand" "")
49 (match_operand 3 "" "")
52 "if (m32c_expand_movmemhi(operands)) DONE; FAIL;"
55 ;; We can't use mode macros for these because M16C uses r1h to extend
56 ;; the source address, for copying data from ROM to RAM. We don't yet
57 ;; support that, but we need to zero our r1h, so the patterns differ.
65 (define_insn "movmemhi_bhi_op"
66 [(set (mem:QI (match_operand:HI 3 "ap_operand" "0"))
67 (mem:QI (match_operand:HI 4 "ap_operand" "1")))
68 (set (match_operand:HI 2 "m32c_r3_operand" "=R3w")
70 (set (match_operand:HI 0 "ap_operand" "=Ra1")
71 (plus:HI (match_dup 3)
72 (zero_extend:HI (match_operand:HI 5 "m32c_r3_operand" "2"))))
73 (set (match_operand:HI 1 "ap_operand" "=Ra0")
74 (plus:HI (match_dup 4)
75 (zero_extend:HI (match_dup 5))))
76 (use (reg:HI R1_REGNO))]
78 "mov.b:q\t#0,r1h\n\tsmovf.b\t; %0[0..%2-1]=r1h%1[]"
80 (define_insn "movmemhi_bpsi_op"
81 [(set (mem:QI (match_operand:PSI 3 "ap_operand" "0"))
82 (mem:QI (match_operand:PSI 4 "ap_operand" "1")))
83 (set (match_operand:HI 2 "m32c_r3_operand" "=R3w")
85 (set (match_operand:PSI 0 "ap_operand" "=Ra1")
86 (plus:PSI (match_dup 3)
87 (zero_extend:PSI (match_operand:HI 5 "m32c_r3_operand" "2"))))
88 (set (match_operand:PSI 1 "ap_operand" "=Ra0")
89 (plus:PSI (match_dup 4)
90 (zero_extend:PSI (match_dup 5))))]
92 "smovf.b\t; %0[0..%2-1]=%1[]"
94 (define_insn "movmemhi_whi_op"
95 [(set (mem:HI (match_operand:HI 3 "ap_operand" "0"))
96 (mem:HI (match_operand:HI 4 "ap_operand" "1")))
97 (set (match_operand:HI 2 "m32c_r3_operand" "=R3w")
99 (set (match_operand:HI 0 "ap_operand" "=Ra1")
100 (plus:HI (match_dup 3)
101 (zero_extend:HI (match_operand:HI 5 "m32c_r3_operand" "2"))))
102 (set (match_operand:HI 1 "ap_operand" "=Ra0")
103 (plus:HI (match_dup 4)
104 (zero_extend:HI (match_dup 5))))
105 (use (reg:HI R1_REGNO))]
107 "mov.b:q\t#0,r1h\n\tsmovf.w\t; %0[0..%2-1]=r1h%1[]"
109 (define_insn "movmemhi_wpsi_op"
110 [(set (mem:HI (match_operand:PSI 3 "ap_operand" "0"))
111 (mem:HI (match_operand:PSI 4 "ap_operand" "1")))
112 (set (match_operand:HI 2 "m32c_r3_operand" "=R3w")
114 (set (match_operand:PSI 0 "ap_operand" "=Ra1")
115 (plus:PSI (match_dup 3)
116 (zero_extend:PSI (match_operand:HI 5 "m32c_r3_operand" "2"))))
117 (set (match_operand:PSI 1 "ap_operand" "=Ra0")
118 (plus:PSI (match_dup 4)
119 (zero_extend:PSI (match_dup 5))))]
121 "smovf.w\t; %0[0..%2-1]=%1[]"
126 ;; 0 = destination (mem:BLK ...)
127 ;; 1 = number of bytes
128 ;; 2 = value to store
130 (define_expand "setmemhi"
131 [(match_operand 0 "ap_operand" "")
132 (match_operand 1 "m32c_r3_operand" "")
133 (match_operand 2 "m32c_r0_operand" "")
134 (match_operand 3 "" "")
137 "if (m32c_expand_setmemhi(operands)) DONE; FAIL;"
145 (define_insn "setmemhi_b<mode>_op"
146 [(set (mem:QI (match_operand:HPSI 3 "ap_operand" "0"))
147 (match_operand:QI 2 "m32c_r0_operand" "R0w"))
148 (set (match_operand:HI 1 "m32c_r3_operand" "=R3w")
150 (set (match_operand:HPSI 0 "ap_operand" "=Ra1")
151 (plus:HPSI (match_dup 3)
152 (zero_extend:HPSI (match_operand:HI 4 "m32c_r3_operand" "1"))))]
154 "sstr.b\t; %0[0..%1-1]=%2"
157 (define_insn "setmemhi_w<mode>_op"
158 [(set (mem:HI (match_operand:HPSI 3 "ap_operand" "0"))
159 (match_operand:HI 2 "m32c_r0_operand" "R0w"))
160 (set (match_operand:HI 1 "m32c_r3_operand" "=R3w")
162 (set (match_operand:HPSI 0 "ap_operand" "=Ra1")
163 (plus:HPSI (match_dup 3)
164 (zero_extend:HPSI (match_operand:HI 4 "m32c_r3_operand" "1"))))]
166 "sstr.w\t; %0[0..%1-1]=%2"
170 ;; SCMPU sets the flags according to the result of the string
171 ;; comparison. GCC wants the result to be a signed value reflecting
172 ;; the result, which it then compares to zero. Hopefully we can
173 ;; optimize that later (see peephole in cond.md). Meanwhile, the
174 ;; strcmp builtin is expanded to a SCMPU followed by a flags-to-int
175 ;; pattern in cond.md.
178 ;; 1 = destination (mem:BLK ...)
179 ;; 2 = source (mem:BLK ...)
182 (define_expand "cmpstrsi"
183 [(match_operand:HI 0 "" "")
184 (match_operand 1 "ap_operand" "")
185 (match_operand 2 "ap_operand" "")
186 (match_operand 3 "" "")
189 "if (m32c_expand_cmpstr(operands)) DONE; FAIL;"
195 (define_insn "cmpstrhi_op"
196 [(set (reg:CC FLG_REGNO)
197 (compare:CC (mem:BLK (match_operand:PSI 0 "ap_operand" "Ra0"))
198 (mem:BLK (match_operand:PSI 1 "ap_operand" "Ra1"))))
199 (clobber (match_operand:PSI 2 "ap_operand" "=0"))
200 (clobber (match_operand:PSI 3 "ap_operand" "=1"))]
202 "scmpu.b\t; flags := strcmp(*%0,*%1)"
203 [(set_attr "flags" "oszc")]
208 ;; Note that SMOVU leaves the address registers pointing *after*
209 ;; the NUL at the end of the string. This is not what gcc expects; it
210 ;; expects the address registers to point *at* the NUL. The expander
211 ;; must emit a suitable add insn.
213 ;; 0 = target: set to &NUL in dest
214 ;; 1 = destination (mem:BLK ...)
215 ;; 2 = source (mem:BLK ...)
217 (define_expand "movstr"
218 [(match_operand 0 "" "")
219 (match_operand 1 "ap_operand" "")
220 (match_operand 2 "ap_operand" "")
223 "if (m32c_expand_movstr(operands)) DONE; FAIL;"
227 ;; 1 = src (out) (clobbered)
230 (define_insn "movstr_op"
231 [(set (mem:BLK (match_operand:PSI 2 "ap_operand" "0"))
232 (mem:BLK (match_operand:PSI 3 "ap_operand" "1")))
233 (set (match_operand:PSI 0 "ap_operand" "=Ra1")
234 (plus:PSI (match_dup 2)
235 (unspec:PSI [(const_int 0)] UNS_SMOVU)))
236 (set (match_operand:PSI 1 "ap_operand" "=Ra0")
237 (plus:PSI (match_dup 3)
238 (unspec:PSI [(const_int 0)] UNS_SMOVU)))]
240 "smovu.b\t; while (*%2++ := *%3++) != 0"
241 [(set_attr "flags" "*")]