* config/m32c/m32c.h (OVERRIDE_OPTIONS): Omit unneeded semicolon.
[official-gcc.git] / gcc / config / m32c / blkmov.md
blob44083e4793c209f533bc203c24926f94b561296b
1 ;; Machine Descriptions for R8C/M16C/M32C
2 ;; Copyright (C) 2006
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Red Hat.
5 ;;
6 ;; This file is part of GCC.
7 ;;
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
21 ;; 02110-1301, USA.
23 ;; various block move instructions
25 ;; R8C:
26 ;;  SMOVB - while (r3--) { *a1-- = *r1ha0--; } - memcpy
27 ;;  SMOVF - while (r3--) { *a1++ = *r1ha0++; } - memcpy
28 ;;  SSTR  - while (r3--) { *a1++ = [r0l,r0]; } - memset
30 ;; M32CM:
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 ...)
43 ;; 2 = count
44 ;; 3 = alignment
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 "" "")
50    ]
51   ""
52   "if (m32c_expand_movmemhi(operands)) DONE; FAIL;"
53   )
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.
59 ;; 0 = dest (out)
60 ;; 1 = src (out)
61 ;; 2 = count (out)
62 ;; 3 = dest (in)
63 ;; 4 = src (in)
64 ;; 5 = count (in)
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")
69         (const_int 0))
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))]
77   "TARGET_A16"
78   "mov.b:q\t#0,r1h\n\tsmovf.b\t; %0[0..%2-1]=r1h%1[]"
79   )
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")
84         (const_int 0))
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))))]
91   "TARGET_A24"
92   "smovf.b\t; %0[0..%2-1]=%1[]"
93   )
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")
98         (const_int 0))
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))]
106   "TARGET_A16"
107   "mov.b:q\t#0,r1h\n\tsmovf.w\t; %0[0..%2-1]=r1h%1[]"
108   )
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")
113         (const_int 0))
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))))]
120   "TARGET_A24"
121   "smovf.w\t; %0[0..%2-1]=%1[]"
122   )
126 ;; 0 = destination (mem:BLK ...)
127 ;; 1 = number of bytes
128 ;; 2 = value to store
129 ;; 3 = alignment
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 "" "")
135    ]
136   "TARGET_A24"
137   "if (m32c_expand_setmemhi(operands)) DONE; FAIL;"
138   )
140 ;; 0 = address (out)
141 ;; 1 = count (out)
142 ;; 2 = value (in)
143 ;; 3 = address (in)
144 ;; 4 = count (in)
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")
149         (const_int 0))
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"))))]
153   "TARGET_A24"
154   "sstr.b\t; %0[0..%1-1]=%2"
155   )
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")
161         (const_int 0))
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"))))]
165   "TARGET_A24"
166   "sstr.w\t; %0[0..%1-1]=%2"
167   )
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.
177 ;; 0 = result:HI
178 ;; 1 = destination (mem:BLK ...)
179 ;; 2 = source (mem:BLK ...)
180 ;; 3 = alignment
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 "" "")
187    ]
188   "TARGET_A24"
189   "if (m32c_expand_cmpstr(operands)) DONE; FAIL;"
190   )
192 ;; 0 = string1
193 ;; 1 = string2
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"))]
201   "TARGET_A24"
202   "scmpu.b\t; flags := strcmp(*%0,*%1)"
203   [(set_attr "flags" "oszc")]
204   )
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" "")
221    ]
222   "TARGET_A24"
223   "if (m32c_expand_movstr(operands)) DONE; FAIL;"
224   )
226 ;; 0 = dest (out)
227 ;; 1 = src (out) (clobbered)
228 ;; 2 = dest (in)
229 ;; 3 = src (in)
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)))]
239   "TARGET_A24"
240   "smovu.b\t; while (*%2++ := *%3++) != 0"
241   [(set_attr "flags" "*")]
242   )
243