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
25 ; Shifts are unusual for m32c. We only support shifting in one
26 ; "direction" but the shift count is signed. Also, immediate shift
27 ; counts have a limited range, and variable shift counts have to be in
28 ; $r1h which GCC normally doesn't even know about.
30 ; Other than compensating for the above, the patterns below are pretty
33 (define_insn "ashlqi3_i"
34 [(set (match_operand:QI 0 "mra_operand" "=RqiSd*Rmm,RqiSd*Rmm")
35 (ashift:QI (match_operand:QI 1 "mra_operand" "0,0")
36 (match_operand:QI 2 "mrai_operand" "In4,RqiSd")))
37 (clobber (match_scratch:HI 3 "=X,R1w"))]
41 mov.b\t%2,r1h\n\tsha.b\tr1h,%0"
42 [(set_attr "flags" "oszc,oszc")]
45 (define_insn "ashrqi3_i"
46 [(set (match_operand:QI 0 "mra_operand" "=RqiSd*Rmm,RqiSd*Rmm")
47 (ashiftrt:QI (match_operand:QI 1 "mra_operand" "0,0")
48 (neg:QI (match_operand:QI 2 "mrai_operand" "In4,RqiSd"))))
49 (clobber (match_scratch:HI 3 "=X,R1w"))]
53 mov.b\t%2,r1h\n\tsha.b\tr1h,%0"
54 [(set_attr "flags" "oszc,oszc")]
57 (define_insn "lshrqi3_i"
58 [(set (match_operand:QI 0 "mra_operand" "=RqiSd*Rmm,RqiSd*Rmm")
59 (lshiftrt:QI (match_operand:QI 1 "mra_operand" "0,0")
60 (neg:QI (match_operand:QI 2 "mrai_operand" "In4,RqiSd"))))
61 (clobber (match_scratch:HI 3 "=X,R1w"))]
65 mov.b\t%2,r1h\n\tshl.b\tr1h,%0"
66 [(set_attr "flags" "szc,szc")]
70 (define_expand "ashlqi3"
71 [(parallel [(set (match_operand:QI 0 "mra_operand" "")
72 (ashift:QI (match_operand:QI 1 "mra_operand" "")
73 (match_operand:QI 2 "general_operand" "")))
74 (clobber (match_scratch:HI 3 ""))])]
76 "if (m32c_prepare_shift (operands, 1, ASHIFT))
80 (define_expand "ashrqi3"
81 [(parallel [(set (match_operand:QI 0 "mra_operand" "")
82 (ashiftrt:QI (match_operand:QI 1 "mra_operand" "")
83 (neg:QI (match_operand:QI 2 "general_operand" ""))))
84 (clobber (match_scratch:HI 3 ""))])]
86 "if (m32c_prepare_shift (operands, -1, ASHIFTRT))
90 (define_expand "lshrqi3"
91 [(parallel [(set (match_operand:QI 0 "mra_operand" "")
92 (lshiftrt:QI (match_operand:QI 1 "mra_operand" "")
93 (neg:QI (match_operand:QI 2 "general_operand" ""))))
94 (clobber (match_scratch:HI 3 ""))])]
96 "if (m32c_prepare_shift (operands, -1, LSHIFTRT))
100 ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102 (define_insn "ashlhi3_i"
103 [(set (match_operand:HI 0 "mra_operand" "=SdRhi*Rmm,SdRhi*Rmm")
104 (ashift:HI (match_operand:HI 1 "mra_operand" "0,0")
105 (match_operand:QI 2 "mrai_operand" "In4,RqiSd")))
106 (clobber (match_scratch:HI 3 "=X,R1w"))]
110 mov.b\t%2,r1h\n\tsha.w\tr1h,%0"
111 [(set_attr "flags" "oszc,oszc")]
114 (define_insn "ashrhi3_i"
115 [(set (match_operand:HI 0 "mra_operand" "=SdRhi*Rmm,SdRhi*Rmm")
116 (ashiftrt:HI (match_operand:HI 1 "mra_operand" "0,0")
117 (neg:QI (match_operand:QI 2 "mrai_operand" "In4,RqiSd"))))
118 (clobber (match_scratch:HI 3 "=X,R1w"))]
122 mov.b\t%2,r1h\n\tsha.w\tr1h,%0"
123 [(set_attr "flags" "oszc,oszc")]
126 (define_insn "lshrhi3_i"
127 [(set (match_operand:HI 0 "mra_operand" "=RhiSd*Rmm,RhiSd*Rmm")
128 (lshiftrt:HI (match_operand:HI 1 "mra_operand" "0,0")
129 (neg:QI (match_operand:QI 2 "mrai_operand" "In4,RqiSd"))))
130 (clobber (match_scratch:HI 3 "=X,R1w"))]
134 mov.b\t%2,r1h\n\tshl.w\tr1h,%0"
135 [(set_attr "flags" "szc,szc")]
139 (define_expand "ashlhi3"
140 [(parallel [(set (match_operand:HI 0 "mra_operand" "")
141 (ashift:HI (match_operand:HI 1 "mra_operand" "")
142 (match_operand:QI 2 "general_operand" "")))
143 (clobber (match_scratch:HI 3 ""))])]
145 "if (m32c_prepare_shift (operands, 1, ASHIFT))
149 (define_expand "ashrhi3"
150 [(parallel [(set (match_operand:HI 0 "mra_operand" "")
151 (ashiftrt:HI (match_operand:HI 1 "mra_operand" "")
152 (neg:QI (match_operand:QI 2 "general_operand" ""))))
153 (clobber (match_scratch:HI 3 ""))])]
155 "if (m32c_prepare_shift (operands, -1, ASHIFTRT))
159 (define_expand "lshrhi3"
160 [(parallel [(set (match_operand:HI 0 "mra_operand" "")
161 (lshiftrt:HI (match_operand:HI 1 "mra_operand" "")
162 (neg:QI (match_operand:QI 2 "general_operand" ""))))
163 (clobber (match_scratch:HI 3 ""))])]
165 "if (m32c_prepare_shift (operands, -1, LSHIFTRT))
172 ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
175 (define_insn "ashlpsi3_i"
176 [(set (match_operand:PSI 0 "mra_operand" "=R02RaaSd*Rmm,R02RaaSd*Rmm")
177 (ashift:PSI (match_operand:PSI 1 "mra_operand" "0,0")
178 (match_operand:QI 2 "mrai_operand" "In4,RqiSd")))
179 (clobber (match_scratch:HI 3 "=X,R1w"))]
183 mov.b\t%2,r1h\n\tsha.l\tr1h,%0"
184 [(set_attr "flags" "oszc,oszc")]
187 (define_insn "ashrpsi3_i"
188 [(set (match_operand:PSI 0 "mra_operand" "=R02RaaSd*Rmm,R02RaaSd*Rmm")
189 (ashiftrt:PSI (match_operand:PSI 1 "mra_operand" "0,0")
190 (neg:QI (match_operand:QI 2 "mrai_operand" "In4,RqiSd"))))
191 (clobber (match_scratch:HI 3 "=X,R1w"))]
195 mov.b\t%2,r1h\n\tsha.l\tr1h,%0"
196 [(set_attr "flags" "oszc,oszc")]
199 (define_insn "lshrpsi3_i"
200 [(set (match_operand:PSI 0 "mra_operand" "=R02RaaSd,??Rmm")
201 (lshiftrt:PSI (match_operand:PSI 1 "mra_operand" "0,0")
202 (neg:QI (match_operand:QI 2 "shiftcount_operand" "In4,RqiSd"))))
203 (clobber (match_scratch:HI 3 "=X,R1w"))]
207 mov.b\t%2,r1h\n\tshl.l\tr1h,%0"
208 [(set_attr "flags" "szc,szc")]
212 (define_expand "ashlpsi3"
213 [(parallel [(set (match_operand:PSI 0 "mra_operand" "")
214 (ashift:PSI (match_operand:PSI 1 "mra_operand" "")
215 (match_operand:QI 2 "mrai_operand" "")))
216 (clobber (match_scratch:HI 3 ""))])]
218 "if (m32c_prepare_shift (operands, 1, ASHIFT))
222 (define_expand "ashrpsi3"
223 [(parallel [(set (match_operand:PSI 0 "mra_operand" "")
224 (ashiftrt:PSI (match_operand:PSI 1 "mra_operand" "")
225 (neg:QI (match_operand:QI 2 "mrai_operand" ""))))
226 (clobber (match_scratch:HI 3 ""))])]
228 "if (m32c_prepare_shift (operands, -1, ASHIFTRT))
232 (define_expand "lshrpsi3"
233 [(parallel [(set (match_operand:PSI 0 "mra_operand" "")
234 (lshiftrt:PSI (match_operand:PSI 1 "mra_operand" "")
235 (neg:QI (match_operand:QI 2 "mrai_operand" ""))))
236 (clobber (match_scratch:HI 3 ""))])]
238 "if (m32c_prepare_shift (operands, -1, LSHIFTRT))
242 ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
244 ; The m16c has a maximum shift count of -16..16, even when in a
245 ; register. It's optimal to use multiple shifts of -8..8 rather than
246 ; loading larger constants into R1H multiple time. The m32c can shift
247 ; -32..32 either via immediates or in registers. Hence, separate
251 (define_insn "ashlsi3_16"
252 [(set (match_operand:SI 0 "r0123_operand" "=R03,R03")
253 (ashift:SI (match_operand:SI 1 "r0123_operand" "0,0")
254 (match_operand:QI 2 "shiftcount_operand" "In4,RqiSd")))
255 (clobber (match_scratch:HI 3 "=X,R1w"))]
259 mov.b\t%2,r1h\n\tsha.l\tr1h,%0"
260 [(set_attr "flags" "oszc,oszc")]
263 (define_insn "ashrsi3_16"
264 [(set (match_operand:SI 0 "r0123_operand" "=R03,R03")
265 (ashiftrt:SI (match_operand:SI 1 "r0123_operand" "0,0")
266 (neg:QI (match_operand:QI 2 "shiftcount_operand" "In4,RqiSd"))))
267 (clobber (match_scratch:HI 3 "=X,R1w"))]
271 mov.b\t%2,r1h\n\tsha.l\tr1h,%0"
272 [(set_attr "flags" "oszc,oszc")]
275 (define_insn "lshrsi3_16"
276 [(set (match_operand:SI 0 "r0123_operand" "=R03,R03")
277 (lshiftrt:SI (match_operand:SI 1 "r0123_operand" "0,0")
278 (neg:QI (match_operand:QI 2 "shiftcount_operand" "In4,RqiSd"))))
279 (clobber (match_scratch:HI 3 "=X,R1w"))]
283 mov.b\t%2,r1h\n\tshl.l\tr1h,%0"
284 [(set_attr "flags" "szc,szc")]
289 (define_insn "ashlsi3_24"
290 [(set (match_operand:SI 0 "r0123_operand" "=R03,R03")
291 (ashift:SI (match_operand:SI 1 "r0123_operand" "0,0")
292 (match_operand:QI 2 "longshiftcount_operand" "In6,RqiSd")))
293 (clobber (match_scratch:HI 3 "=X,R1w"))]
297 mov.b\t%2,r1h\n\tsha.l\tr1h,%0"
300 (define_insn "ashrsi3_24"
301 [(set (match_operand:SI 0 "r0123_operand" "=R03,R03")
302 (ashiftrt:SI (match_operand:SI 1 "r0123_operand" "0,0")
303 (neg:QI (match_operand:QI 2 "longshiftcount_operand" "In6,RqiSd"))))
304 (clobber (match_scratch:HI 3 "=X,R1w"))]
308 mov.b\t%2,r1h\n\tsha.l\tr1h,%0"
311 (define_insn "lshrsi3_24"
312 [(set (match_operand:SI 0 "r0123_operand" "=R03,R03")
313 (lshiftrt:SI (match_operand:SI 1 "r0123_operand" "0,0")
314 (neg:QI (match_operand:QI 2 "longshiftcount_operand" "In6,RqiSd"))))
315 (clobber (match_scratch:HI 3 "=X,R1w"))]
319 mov.b\t%2,r1h\n\tshl.l\tr1h,%0"
325 (define_expand "ashlsi3"
326 [(parallel [(set (match_operand:SI 0 "r0123_operand" "")
327 (ashift:SI (match_operand:SI 1 "r0123_operand" "")
328 (match_operand:QI 2 "mrai_operand" "")))
329 (clobber (match_scratch:HI 3 ""))])]
331 "if (m32c_prepare_shift (operands, 1, ASHIFT))
335 (define_expand "ashrsi3"
336 [(parallel [(set (match_operand:SI 0 "r0123_operand" "")
337 (ashiftrt:SI (match_operand:SI 1 "r0123_operand" "")
338 (neg:QI (match_operand:QI 2 "mrai_operand" ""))))
339 (clobber (match_scratch:HI 3 ""))])]
341 "if (m32c_prepare_shift (operands, -1, ASHIFTRT))
345 (define_expand "lshrsi3"
346 [(parallel [(set (match_operand:SI 0 "r0123_operand" "")
347 (lshiftrt:SI (match_operand:SI 1 "r0123_operand" "")
348 (neg:QI (match_operand:QI 2 "mrai_operand" ""))))
349 (clobber (match_scratch:HI 3 ""))])]
351 "if (m32c_prepare_shift (operands, -1, LSHIFTRT))