h8300.md (*iorsi3_and_ashift): New.
[gcc.git] / gcc / config / h8300 / h8300.md
1 ;; GCC machine description for Hitachi H8/300
2 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 ;; 2001, 2002, 2003 Free Software Foundation, Inc.
4
5 ;; Contributed by Steve Chamberlain (sac@cygnus.com),
6 ;; Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
7
8 ;; This file is part of GCC.
9
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;; Some of the extend instructions accept a general_operand_src, which
26 ;; allows all the normal memory addressing modes. The length computations
27 ;; don't take this into account. The lengths in the MD file should be
28 ;; "worst case" and then be adjusted to their correct values by
29 ;; h8300_adjust_insn_length.
30
31 ;; On the H8/300H and H8S, adds/subs operate on the 32bit "er"
32 ;; registers. Right now GCC doesn't expose the "e" half to the
33 ;; compiler, so using add/subs for addhi and subhi is safe. Long
34 ;; term, we want to expose the "e" half to the compiler (gives us 8
35 ;; more 16bit registers). At that point addhi and subhi can't use
36 ;; adds/subs.
37
38 ;; There's currently no way to have an insv/extzv expander for the H8/300H
39 ;; because word_mode is different for the H8/300 and H8/300H.
40
41 ;; Shifts/rotates by small constants should be handled by special
42 ;; patterns so we get the length and cc status correct.
43
44 ;; Bitfield operations no longer accept memory operands. We need
45 ;; to add variants which operate on memory back to the MD.
46
47 ;; ??? Implement remaining bit ops available on the h8300
48
49 ;; ----------------------------------------------------------------------
50 ;; CONSTANTS
51 ;; ----------------------------------------------------------------------
52
53 (define_constants
54 [(UNSPEC_INCDEC 0)
55 (UNSPEC_MONITOR 1)])
56
57 (define_constants
58 [(SC_REG 3)
59 (FP_REG 6)
60 (SP_REG 7)
61 (MAC_REG 8)
62 (AP_REG 9)
63 (RAP_REG 10)])
64
65 ;; ----------------------------------------------------------------------
66 ;; ATTRIBUTES
67 ;; ----------------------------------------------------------------------
68
69 (define_attr "cpu" "h8300,h8300h"
70 (const (symbol_ref "cpu_type")))
71
72 (define_attr "type" "branch,arith"
73 (const_string "arith"))
74
75 ;; The size of instructions in bytes.
76
77 (define_attr "length" ""
78 (cond [(eq_attr "type" "branch")
79 (if_then_else (and (ge (minus (match_dup 0) (pc))
80 (const_int -126))
81 (le (minus (match_dup 0) (pc))
82 (const_int 126)))
83 (const_int 2)
84 (if_then_else (and (eq_attr "cpu" "h8300h")
85 (and (ge (minus (pc) (match_dup 0))
86 (const_int -32000))
87 (le (minus (pc) (match_dup 0))
88 (const_int 32000))))
89 (const_int 4)
90 (const_int 6)))]
91 (const_int 200)))
92
93 ;; The necessity of instruction length adjustment.
94
95 (define_attr "adjust_length" "yes,no"
96 (cond [(eq_attr "type" "branch") (const_string "no")]
97 (const_string "yes")))
98
99 ;; Condition code settings.
100 ;;
101 ;; none - insn does not affect cc
102 ;; none_0hit - insn does not affect cc but it does modify operand 0
103 ;; This attribute is used to keep track of when operand 0 changes.
104 ;; See the description of NOTICE_UPDATE_CC for more info.
105 ;; set_znv - insn sets z,n,v to usable values (like a tst insn); c is unknown.
106 ;; set_zn - insn sets z,n to usable values; v,c are unknown.
107 ;; compare - compare instruction
108 ;; clobber - value of cc is unknown
109
110 (define_attr "cc" "none,none_0hit,set_znv,set_zn,compare,clobber"
111 (const_string "clobber"))
112 \f
113 ;; ----------------------------------------------------------------------
114 ;; MOVE INSTRUCTIONS
115 ;; ----------------------------------------------------------------------
116
117 ;; movqi
118
119 (define_insn "pushqi1_h8300"
120 [(parallel [(set (reg:HI SP_REG)
121 (plus:HI (reg:HI SP_REG) (const_int -2)))
122 (set (mem:QI (plus:HI (reg:HI SP_REG) (const_int -1)))
123 (match_operand:QI 0 "register_operand" "r"))])]
124 "TARGET_H8300
125 && REGNO (operands[0]) != SP_REG"
126 "mov.w\\t%T0,@-r7"
127 [(set_attr "length" "2")
128 (set_attr "cc" "clobber")])
129
130 (define_insn "pushqi1_h8300hs"
131 [(parallel [(set (reg:SI SP_REG)
132 (plus:SI (reg:SI SP_REG) (const_int -4)))
133 (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
134 (match_operand:QI 0 "register_operand" "r"))])]
135 "(TARGET_H8300H || TARGET_H8300S)
136 && REGNO (operands[0]) != SP_REG"
137 "mov.l\\t%S0,@-er7"
138 [(set_attr "length" "4")
139 (set_attr "cc" "clobber")])
140
141 (define_expand "pushqi1"
142 [(use (match_operand:QI 0 "register_operand" ""))]
143 ""
144 "
145 {
146 if (TARGET_H8300)
147 emit_insn (gen_pushqi1_h8300 (operands[0]));
148 else
149 emit_insn (gen_pushqi1_h8300hs (operands[0]));
150 DONE;
151 }")
152
153 (define_insn ""
154 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
155 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
156 "TARGET_H8300
157 && (register_operand (operands[0], QImode)
158 || register_operand (operands[1], QImode))"
159 "@
160 sub.b %X0,%X0
161 mov.b %R1,%X0
162 mov.b %X1,%R0
163 mov.b %R1,%X0
164 mov.b %R1,%X0
165 mov.b %X1,%R0"
166 [(set_attr "length" "2,2,2,2,4,4")
167 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
168
169 (define_insn ""
170 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
171 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
172 "(TARGET_H8300H || TARGET_H8300S)
173 && (register_operand (operands[0], QImode)
174 || register_operand (operands[1], QImode))"
175 "@
176 sub.b %X0,%X0
177 mov.b %R1,%X0
178 mov.b %X1,%R0
179 mov.b %R1,%X0
180 mov.b %R1,%X0
181 mov.b %X1,%R0"
182 [(set_attr "length" "2,2,2,2,8,8")
183 (set_attr "cc" "set_zn,set_znv,set_znv,clobber,set_znv,set_znv")])
184
185 (define_expand "movqi"
186 [(set (match_operand:QI 0 "general_operand_dst" "")
187 (match_operand:QI 1 "general_operand_src" ""))]
188 ""
189 "
190 {
191 /* One of the ops has to be in a register. */
192 if (!register_operand (operand0, QImode)
193 && !register_operand (operand1, QImode))
194 {
195 operands[1] = copy_to_mode_reg (QImode, operand1);
196 }
197 }")
198
199 (define_insn "movstrictqi"
200 [(set (strict_low_part (match_operand:QI 0 "general_operand_dst" "+r,r,r,r"))
201 (match_operand:QI 1 "general_operand_src" "I,r,n,m"))]
202 ""
203 "@
204 sub.b %X0,%X0
205 mov.b %X1,%X0
206 mov.b %R1,%X0
207 mov.b %R1,%X0"
208 [(set_attr_alternative "length"
209 [(const_int 2) (const_int 2) (const_int 2)
210 (if_then_else (eq_attr "cpu" "h8300") (const_int 4) (const_int 8))])
211 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv")])
212
213 ;; movhi
214
215 (define_expand "pushhi1_h8300"
216 [(set (mem:HI (pre_dec:HI (reg:HI SP_REG)))
217 (match_operand:HI 0 "register_operand" ""))]
218 "TARGET_H8300
219 && REGNO (operands[0]) != SP_REG"
220 "")
221
222 (define_insn "pushhi1_h8300hs"
223 [(parallel [(set (reg:SI SP_REG)
224 (plus:SI (reg:SI SP_REG) (const_int -4)))
225 (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
226 (match_operand:HI 0 "register_operand" "r"))])]
227 "(TARGET_H8300H || TARGET_H8300S)
228 && REGNO (operands[0]) != SP_REG"
229 "mov.l\\t%S0,@-er7"
230 [(set_attr "length" "4")
231 (set_attr "cc" "clobber")])
232
233 (define_expand "pushhi1"
234 [(use (match_operand:HI 0 "register_operand" ""))]
235 ""
236 "
237 {
238 if (TARGET_H8300)
239 emit_insn (gen_pushhi1_h8300 (operands[0]));
240 else
241 emit_insn (gen_pushhi1_h8300hs (operands[0]));
242 DONE;
243 }")
244
245 (define_insn ""
246 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
247 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
248 "TARGET_H8300
249 && (register_operand (operands[0], HImode)
250 || register_operand (operands[1], HImode))
251 && !(GET_CODE (operands[0]) == MEM
252 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
253 && GET_CODE (XEXP (XEXP (operands[0], 0), 0)) == REG
254 && GET_CODE (operands[1]) == REG
255 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == REGNO (operands[1]))"
256 "@
257 sub.w %T0,%T0
258 mov.w %T1,%T0
259 mov.w %T1,%T0
260 mov.w %T1,%T0
261 mov.w %T1,%T0
262 mov.w %T1,%T0"
263 [(set_attr "length" "2,2,2,4,4,4")
264 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
265
266 (define_insn ""
267 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
268 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
269 "(TARGET_H8300H || TARGET_H8300S)
270 && (register_operand (operands[0], HImode)
271 || register_operand (operands[1], HImode))"
272 "@
273 sub.w %T0,%T0
274 mov.w %T1,%T0
275 mov.w %T1,%T0
276 mov.w %T1,%T0
277 mov.w %T1,%T0
278 mov.w %T1,%T0"
279 [(set_attr "length" "2,2,2,4,8,8")
280 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
281
282 (define_expand "movhi"
283 [(set (match_operand:HI 0 "general_operand_dst" "")
284 (match_operand:HI 1 "general_operand_src" ""))]
285 ""
286 "
287 {
288 /* One of the ops has to be in a register. */
289 if (!register_operand (operand1, HImode)
290 && !register_operand (operand0, HImode))
291 {
292 operands[1] = copy_to_mode_reg (HImode, operand1);
293 }
294 }")
295
296 (define_insn "movstricthi"
297 [(set (strict_low_part (match_operand:HI 0 "general_operand_dst" "+r,r,r,r"))
298 (match_operand:HI 1 "general_operand_src" "I,r,i,m"))]
299 ""
300 "@
301 sub.w %T0,%T0
302 mov.w %T1,%T0
303 mov.w %T1,%T0
304 mov.w %T1,%T0"
305 [(set_attr_alternative "length"
306 [(const_int 2) (const_int 2) (const_int 4)
307 (if_then_else (eq_attr "cpu" "h8300") (const_int 4) (const_int 8))])
308 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv")])
309
310 ;; movsi
311
312 (define_expand "movsi"
313 [(set (match_operand:SI 0 "general_operand_dst" "")
314 (match_operand:SI 1 "general_operand_src" ""))]
315 ""
316 "
317 {
318 if (TARGET_H8300)
319 {
320 if (do_movsi (operands))
321 DONE;
322 }
323 else
324 {
325 /* One of the ops has to be in a register. */
326 if (!register_operand (operand1, SImode)
327 && !register_operand (operand0, SImode))
328 {
329 operands[1] = copy_to_mode_reg (SImode, operand1);
330 }
331 }
332 }")
333
334 (define_expand "movsf"
335 [(set (match_operand:SF 0 "general_operand_dst" "")
336 (match_operand:SF 1 "general_operand_src" ""))]
337 ""
338 "
339 {
340 if (TARGET_H8300)
341 {
342 if (do_movsi (operands))
343 DONE;
344 }
345 else
346 {
347 /* One of the ops has to be in a register. */
348 if (!register_operand (operand1, SFmode)
349 && !register_operand (operand0, SFmode))
350 {
351 operands[1] = copy_to_mode_reg (SFmode, operand1);
352 }
353 }
354 }")
355
356 (define_insn "movsi_h8300"
357 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,o,<,r")
358 (match_operand:SI 1 "general_operand_src" "I,r,io,r,r,>"))]
359 "TARGET_H8300
360 && (register_operand (operands[0], SImode)
361 || register_operand (operands[1], SImode))"
362 "*
363 {
364 unsigned int rn = -1;
365 switch (which_alternative)
366 {
367 case 0:
368 return \"sub.w %e0,%e0\;sub.w %f0,%f0\";
369 case 1:
370 if (REGNO (operands[0]) < REGNO (operands[1]))
371 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
372 else
373 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
374 case 2:
375 /* Make sure we don't trample the register we index with. */
376 if (GET_CODE (operands[1]) == MEM)
377 {
378 rtx inside = XEXP (operands[1], 0);
379 if (REG_P (inside))
380 {
381 rn = REGNO (inside);
382 }
383 else if (GET_CODE (inside) == PLUS)
384 {
385 rtx lhs = XEXP (inside, 0);
386 rtx rhs = XEXP (inside, 1);
387 if (REG_P (lhs)) rn = REGNO (lhs);
388 if (REG_P (rhs)) rn = REGNO (rhs);
389 }
390 }
391 if (rn == REGNO (operands[0]))
392 {
393 /* Move the second word first. */
394 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
395 }
396 else
397 {
398 /* See if either half is zero. If so, use sub.w to clear
399 that half. */
400 if (GET_CODE (operands[1]) == CONST_INT)
401 {
402 if ((INTVAL (operands[1]) & 0xffff) == 0)
403 return \"mov.w %e1,%e0\;sub.w %f0,%f0\";
404 if (((INTVAL (operands[1]) >> 16) & 0xffff) == 0)
405 return \"sub.w %e0,%e0\;mov.w %f1,%f0\";
406 }
407 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
408 }
409 case 3:
410 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
411 case 4:
412 return \"mov.w %f1,%T0\;mov.w %e1,%T0\";
413 case 5:
414 return \"mov.w %T1,%e0\;mov.w %T1,%f0\";
415 default:
416 abort ();
417 }
418 }"
419 [(set_attr "length" "4,4,8,8,4,4")
420 (set_attr "cc" "clobber")])
421
422 (define_insn "movsf_h8300"
423 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,o,<,r")
424 (match_operand:SF 1 "general_operand_src" "I,r,io,r,r,>"))]
425 "TARGET_H8300
426 && (register_operand (operands[0], SFmode)
427 || register_operand (operands[1], SFmode))"
428 "*
429 {
430 /* Copy of the movsi stuff. */
431 unsigned int rn = -1;
432 switch (which_alternative)
433 {
434 case 0:
435 return \"sub.w %e0,%e0\;sub.w %f0,%f0\";
436 case 1:
437 if (REGNO (operands[0]) < REGNO (operands[1]))
438 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
439 else
440 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
441 case 2:
442 /* Make sure we don't trample the register we index with. */
443 if (GET_CODE (operands[1]) == MEM)
444 {
445 rtx inside = XEXP (operands[1], 0);
446 if (REG_P (inside))
447 {
448 rn = REGNO (inside);
449 }
450 else if (GET_CODE (inside) == PLUS)
451 {
452 rtx lhs = XEXP (inside, 0);
453 rtx rhs = XEXP (inside, 1);
454 if (REG_P (lhs)) rn = REGNO (lhs);
455 if (REG_P (rhs)) rn = REGNO (rhs);
456 }
457 }
458 if (rn == REGNO (operands[0]))
459 /* Move the second word first. */
460 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
461 else
462 /* Move the first word first. */
463 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
464
465 case 3:
466 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
467 case 4:
468 return \"mov.w %f1,%T0\;mov.w %e1,%T0\";
469 case 5:
470 return \"mov.w %T1,%e0\;mov.w %T1,%f0\";
471 default:
472 abort ();
473 }
474 }"
475 [(set_attr "length" "4,4,8,8,4,4")
476 (set_attr "cc" "clobber")])
477
478 (define_insn "movsi_h8300hs"
479 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,<,r,r,m,*a,*a,r")
480 (match_operand:SI 1 "general_operand_src" "I,r,i,r,>,m,r,I,r,*a"))]
481 "(TARGET_H8300S || TARGET_H8300H)
482 && (register_operand (operands[0], SImode)
483 || register_operand (operands[1], SImode))
484 && !(GET_CODE (operands[0]) == MEM
485 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
486 && GET_CODE (XEXP (XEXP (operands[0], 0), 0)) == REG
487 && GET_CODE (operands[1]) == REG
488 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == REGNO (operands[1]))"
489 "*
490 {
491 switch (which_alternative)
492 {
493 case 0:
494 return \"sub.l %S0,%S0\";
495 case 7:
496 return \"clrmac\";
497 case 8:
498 return \"clrmac\;ldmac %1,macl\";
499 case 9:
500 return \"stmac macl,%0\";
501 default:
502 if (GET_CODE (operands[1]) == CONST_INT)
503 {
504 int val = INTVAL (operands[1]);
505
506 /* Look for constants which can be made by adding an 8-bit
507 number to zero in one of the two low bytes. */
508 if (val == (val & 0xff))
509 {
510 operands[1] = GEN_INT ((char) val & 0xff);
511 return \"sub.l\\t%S0,%S0\;add.b\\t%1,%w0\";
512 }
513
514 if (val == (val & 0xff00))
515 {
516 operands[1] = GEN_INT ((char) (val >> 8) & 0xff);
517 return \"sub.l\\t%S0,%S0\;add.b\\t%1,%x0\";
518 }
519
520 /* Look for constants that can be obtained by subs, inc, and
521 dec to 0. */
522 switch (val & 0xffffffff)
523 {
524 case 0xffffffff:
525 return \"sub.l\\t%S0,%S0\;subs\\t#1,%S0\";
526 case 0xfffffffe:
527 return \"sub.l\\t%S0,%S0\;subs\\t#2,%S0\";
528 case 0xfffffffc:
529 return \"sub.l\\t%S0,%S0\;subs\\t#4,%S0\";
530
531 case 0x0000ffff:
532 return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%f0\";
533 case 0x0000fffe:
534 return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%f0\";
535
536 case 0xffff0000:
537 return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%e0\";
538 case 0xfffe0000:
539 return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%e0\";
540
541 case 0x00010000:
542 return \"sub.l\\t%S0,%S0\;inc.w\\t#1,%e0\";
543 case 0x00020000:
544 return \"sub.l\\t%S0,%S0\;inc.w\\t#2,%e0\";
545 }
546 }
547 }
548 return \"mov.l %S1,%S0\";
549 }"
550 [(set_attr "length" "2,2,6,4,4,10,10,2,6,4")
551 (set_attr "cc" "set_zn,set_znv,clobber,set_znv,set_znv,set_znv,set_znv,none_0hit,none_0hit,set_znv")])
552
553 (define_insn "movsf_h8300h"
554 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,m,<,r")
555 (match_operand:SF 1 "general_operand_src" "I,r,im,r,r,>"))]
556 "(TARGET_H8300H || TARGET_H8300S)
557 && (register_operand (operands[0], SFmode)
558 || register_operand (operands[1], SFmode))"
559 "@
560 sub.l %S0,%S0
561 mov.l %S1,%S0
562 mov.l %S1,%S0
563 mov.l %S1,%S0
564 mov.l %S1,%S0
565 mov.l %S1,%S0"
566 [(set_attr "length" "2,2,10,10,4,4")
567 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
568 \f
569 ;; ----------------------------------------------------------------------
570 ;; TEST INSTRUCTIONS
571 ;; ----------------------------------------------------------------------
572
573 (define_insn ""
574 [(set (cc0) (zero_extract:HI (match_operand:QI 0 "bit_memory_operand" "r,U")
575 (const_int 1)
576 (match_operand 1 "const_int_operand" "n,n")))]
577 "TARGET_H8300"
578 "btst %Z1,%Y0"
579 [(set_attr "length" "2,4")
580 (set_attr "cc" "set_zn,set_zn")])
581
582 (define_insn ""
583 [(set (cc0) (zero_extract:HI (match_operand:HI 0 "register_operand" "r")
584 (const_int 1)
585 (match_operand 1 "const_int_operand" "n")))]
586 "TARGET_H8300"
587 "btst %Z1,%Y0"
588 [(set_attr "length" "2")
589 (set_attr "cc" "set_zn")])
590
591 (define_insn "*tst_extzv_1_n"
592 [(set (cc0)
593 (zero_extract:SI (match_operand:QI 0 "general_operand_src" "r,U,mn>")
594 (const_int 1)
595 (match_operand 1 "const_int_operand" "n,n,n")))
596 (clobber (match_scratch:QI 2 "=X,X,&r"))]
597 "(TARGET_H8300H || TARGET_H8300S)"
598 "@
599 btst\\t%Z1,%Y0
600 btst\\t%Z1,%Y0
601 #"
602 [(set_attr "length" "2,8,10")
603 (set_attr "cc" "set_zn,set_zn,set_zn")])
604
605 (define_split
606 [(set (cc0)
607 (zero_extract:SI (match_operand:QI 0 "general_operand" "")
608 (const_int 1)
609 (match_operand 1 "const_int_operand" "")))
610 (clobber (match_operand:QI 2 "register_operand" ""))]
611 "(TARGET_H8300H || TARGET_H8300S)
612 && reload_completed
613 && !EXTRA_CONSTRAINT (operands[0], 'U')"
614 [(set (match_dup 2)
615 (match_dup 0))
616 (parallel [(set (cc0) (zero_extract:SI (match_dup 2)
617 (const_int 1)
618 (match_dup 1)))
619 (clobber (scratch:QI))])]
620 "")
621
622 (define_insn ""
623 [(set (cc0) (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
624 (const_int 1)
625 (match_operand 1 "const_int_operand" "n")))]
626 "(TARGET_H8300H || TARGET_H8300S)
627 && INTVAL (operands[1]) <= 15"
628 "btst %Z1,%Y0"
629 [(set_attr "length" "2")
630 (set_attr "cc" "set_zn")])
631
632 (define_insn_and_split "*tstsi_upper_bit"
633 [(set (cc0)
634 (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
635 (const_int 1)
636 (match_operand 1 "const_int_operand" "n")))
637 (clobber (match_scratch:SI 2 "=&r"))]
638 "(TARGET_H8300H || TARGET_H8300S)
639 && INTVAL (operands[1]) >= 16"
640 "#"
641 "&& reload_completed"
642 [(set (match_dup 2)
643 (ior:SI (and:SI (match_dup 2)
644 (const_int -65536))
645 (lshiftrt:SI (match_dup 0)
646 (const_int 16))))
647 (set (cc0)
648 (zero_extract:SI (match_dup 2)
649 (const_int 1)
650 (match_dup 3)))]
651 "operands[3] = GEN_INT (INTVAL (operands[1]) - 16);")
652
653 (define_insn ""
654 [(set (cc0)
655 (and:HI (match_operand:HI 0 "register_operand" "r")
656 (match_operand:HI 1 "single_one_operand" "n")))]
657 ""
658 "*
659 {
660 operands[1] = GEN_INT (INTVAL (operands[1]) & 0xffff);
661 if (INTVAL (operands[1]) > 128)
662 {
663 operands[1] = GEN_INT (INTVAL (operands[1]) >> 8);
664 return \"btst\\t%V1,%t0\";
665 }
666 return \"btst\\t%V1,%s0\";
667 }"
668 [(set_attr "length" "2")
669 (set_attr "cc" "set_zn")])
670
671 (define_insn ""
672 [(set (cc0)
673 (and:SI (match_operand:SI 0 "register_operand" "r")
674 (match_operand:SI 1 "single_one_operand" "n")))]
675 "(TARGET_H8300H || TARGET_H8300S)
676 && (INTVAL (operands[1]) & 0xffff) != 0"
677 "*
678 {
679 operands[1] = GEN_INT (INTVAL (operands[1]) & 0xffff);
680 if (INTVAL (operands[1]) > 128)
681 {
682 operands[1] = GEN_INT (INTVAL (operands[1]) >> 8);
683 return \"btst\\t%V1,%x0\";
684 }
685 return \"btst\\t%V1,%w0\";
686 }"
687 [(set_attr "length" "2")
688 (set_attr "cc" "set_zn")])
689
690 (define_insn "tstqi"
691 [(set (cc0) (match_operand:QI 0 "register_operand" "r"))]
692 ""
693 "mov.b %X0,%X0"
694 [(set_attr "length" "2")
695 (set_attr "cc" "set_znv")])
696
697 (define_insn "tsthi"
698 [(set (cc0) (match_operand:HI 0 "register_operand" "r"))]
699 ""
700 "mov.w %T0,%T0"
701 [(set_attr "length" "2")
702 (set_attr "cc" "set_znv")])
703
704 (define_insn ""
705 [(set (cc0)
706 (and:HI (match_operand:HI 0 "register_operand" "r")
707 (const_int -256)))]
708 ""
709 "mov.b %t0,%t0"
710 [(set_attr "length" "2")
711 (set_attr "cc" "set_znv")])
712
713 (define_insn "tstsi"
714 [(set (cc0) (match_operand:SI 0 "register_operand" "r"))]
715 "TARGET_H8300H || TARGET_H8300S"
716 "mov.l %S0,%S0"
717 [(set_attr "length" "2")
718 (set_attr "cc" "set_znv")])
719
720 (define_insn ""
721 [(set (cc0)
722 (and:SI (match_operand:SI 0 "register_operand" "r")
723 (const_int -65536)))]
724 ""
725 "mov.w %e0,%e0"
726 [(set_attr "length" "2")
727 (set_attr "cc" "set_znv")])
728
729 (define_insn "cmpqi"
730 [(set (cc0)
731 (compare (match_operand:QI 0 "register_operand" "r")
732 (match_operand:QI 1 "nonmemory_operand" "rn")))]
733 ""
734 "cmp.b %X1,%X0"
735 [(set_attr "length" "2")
736 (set_attr "cc" "compare")])
737
738 (define_expand "cmphi"
739 [(set (cc0)
740 (compare (match_operand:HI 0 "register_operand" "")
741 (match_operand:HI 1 "nonmemory_operand" "")))]
742 ""
743 "
744 {
745 /* Force operand1 into a register if we're compiling
746 for the H8/300. */
747 if (GET_CODE (operands[1]) != REG && TARGET_H8300)
748 operands[1] = force_reg (HImode, operands[1]);
749 }")
750
751 (define_insn "*cmphi_h8300"
752 [(set (cc0)
753 (compare (match_operand:HI 0 "register_operand" "r")
754 (match_operand:HI 1 "register_operand" "r")))]
755 "TARGET_H8300"
756 "cmp.w %T1,%T0"
757 [(set_attr "length" "2")
758 (set_attr "cc" "compare")])
759
760 (define_insn "*cmphi_h8300hs"
761 [(set (cc0)
762 (compare (match_operand:HI 0 "register_operand" "r,r")
763 (match_operand:HI 1 "nonmemory_operand" "r,n")))]
764 "TARGET_H8300H || TARGET_H8300S"
765 "cmp.w %T1,%T0"
766 [(set_attr "length" "2,4")
767 (set_attr "cc" "compare,compare")])
768
769 (define_insn "cmpsi"
770 [(set (cc0)
771 (compare (match_operand:SI 0 "register_operand" "r,r")
772 (match_operand:SI 1 "nonmemory_operand" "r,i")))]
773 "TARGET_H8300H || TARGET_H8300S"
774 "cmp.l %S1,%S0"
775 [(set_attr "length" "2,6")
776 (set_attr "cc" "compare,compare")])
777 \f
778 ;; ----------------------------------------------------------------------
779 ;; ADD INSTRUCTIONS
780 ;; ----------------------------------------------------------------------
781
782 (define_insn "addqi3"
783 [(set (match_operand:QI 0 "register_operand" "=r")
784 (plus:QI (match_operand:QI 1 "register_operand" "%0")
785 (match_operand:QI 2 "nonmemory_operand" "rn")))]
786 ""
787 "add.b %X2,%X0"
788 [(set_attr "length" "2")
789 (set_attr "cc" "set_zn")])
790
791 (define_expand "addhi3"
792 [(set (match_operand:HI 0 "register_operand" "")
793 (plus:HI (match_operand:HI 1 "register_operand" "")
794 (match_operand:HI 2 "nonmemory_operand" "")))]
795 ""
796 "")
797
798 (define_insn "*addhi3_h8300"
799 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
800 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
801 (match_operand:HI 2 "nonmemory_operand" "L,N,J,n,r")))]
802 "TARGET_H8300"
803 "@
804 adds %2,%T0
805 subs %G2,%T0
806 add.b %t2,%t0
807 add.b %s2,%s0\;addx %t2,%t0
808 add.w %T2,%T0"
809 [(set_attr "length" "2,2,2,4,2")
810 (set_attr "cc" "none_0hit,none_0hit,clobber,clobber,set_zn")])
811
812 ;; This splitter is very important to make the stack adjustment
813 ;; interrupt-safe. The combination of add.b and addx is unsafe!
814 ;;
815 ;; We apply this split after the peephole2 pass so that we won't end
816 ;; up creating too many adds/subs when a scratch register is
817 ;; available, which is actually a common case because stack unrolling
818 ;; tends to happen immediately after a function call.
819
820 (define_split
821 [(set (match_operand:HI 0 "stack_pointer_operand" "")
822 (plus:HI (match_dup 0)
823 (match_operand 1 "const_int_gt_2_operand" "")))]
824 "TARGET_H8300 && flow2_completed"
825 [(const_int 0)]
826 "split_adds_subs (HImode, operands); DONE;")
827
828 (define_peephole2
829 [(match_scratch:HI 2 "r")
830 (set (match_operand:HI 0 "stack_pointer_operand" "")
831 (plus:HI (match_dup 0)
832 (match_operand:HI 1 "const_int_ge_8_operand" "")))]
833 "TARGET_H8300"
834 [(set (match_dup 2)
835 (match_dup 1))
836 (set (match_dup 0)
837 (plus:HI (match_dup 0)
838 (match_dup 2)))]
839 "")
840
841 (define_insn "*addhi3_h8300hs"
842 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
843 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
844 (match_operand:HI 2 "nonmemory_operand" "L,N,J,n,r")))]
845 "TARGET_H8300H || TARGET_H8300S"
846 "@
847 adds %2,%S0
848 subs %G2,%S0
849 add.b %t2,%t0
850 add.w %T2,%T0
851 add.w %T2,%T0"
852 [(set_attr "length" "2,2,2,4,2")
853 (set_attr "cc" "none_0hit,none_0hit,clobber,set_zn,set_zn")])
854
855 (define_insn "*addhi3_incdec"
856 [(set (match_operand:HI 0 "register_operand" "=r,r")
857 (unspec:HI [(match_operand:HI 1 "register_operand" "0,0")
858 (match_operand:HI 2 "incdec_operand" "M,O")]
859 UNSPEC_INCDEC))]
860 "TARGET_H8300H || TARGET_H8300S"
861 "@
862 inc.w %2,%T0
863 dec.w %G2,%T0"
864 [(set_attr "length" "2,2")
865 (set_attr "cc" "set_zn,set_zn")])
866
867 (define_split
868 [(set (match_operand:HI 0 "register_operand" "")
869 (plus:HI (match_dup 0)
870 (match_operand:HI 1 "two_insn_adds_subs_operand" "")))]
871 ""
872 [(const_int 0)]
873 "split_adds_subs (HImode, operands); DONE;")
874
875 (define_expand "addsi3"
876 [(set (match_operand:SI 0 "register_operand" "")
877 (plus:SI (match_operand:SI 1 "register_operand" "")
878 (match_operand:SI 2 "nonmemory_operand" "")))]
879 ""
880 "")
881
882 (define_insn "addsi_h8300"
883 [(set (match_operand:SI 0 "register_operand" "=r,r")
884 (plus:SI (match_operand:SI 1 "register_operand" "%0,0")
885 (match_operand:SI 2 "nonmemory_operand" "n,r")))]
886 "TARGET_H8300"
887 "* return output_plussi (operands);"
888 [(set (attr "length")
889 (symbol_ref "compute_plussi_length (operands)"))
890 (set (attr "cc")
891 (symbol_ref "compute_plussi_cc (operands)"))])
892
893 (define_insn "addsi_h8300h"
894 [(set (match_operand:SI 0 "register_operand" "=r,r")
895 (plus:SI (match_operand:SI 1 "register_operand" "%0,0")
896 (match_operand:SI 2 "nonmemory_operand" "i,r")))]
897 "TARGET_H8300H || TARGET_H8300S"
898 "* return output_plussi (operands);"
899 [(set (attr "length")
900 (symbol_ref "compute_plussi_length (operands)"))
901 (set (attr "cc")
902 (symbol_ref "compute_plussi_cc (operands)"))])
903
904 (define_insn "*addsi3_incdec"
905 [(set (match_operand:SI 0 "register_operand" "=r,r")
906 (unspec:SI [(match_operand:SI 1 "register_operand" "0,0")
907 (match_operand:SI 2 "incdec_operand" "M,O")]
908 UNSPEC_INCDEC))]
909 "TARGET_H8300H || TARGET_H8300S"
910 "@
911 inc.l %2,%S0
912 dec.l %G2,%S0"
913 [(set_attr "length" "2,2")
914 (set_attr "cc" "set_zn,set_zn")])
915
916 (define_split
917 [(set (match_operand:SI 0 "register_operand" "")
918 (plus:SI (match_dup 0)
919 (match_operand:SI 1 "two_insn_adds_subs_operand" "")))]
920 "TARGET_H8300H || TARGET_H8300S"
921 [(const_int 0)]
922 "split_adds_subs (SImode, operands); DONE;")
923
924 ;; ----------------------------------------------------------------------
925 ;; SUBTRACT INSTRUCTIONS
926 ;; ----------------------------------------------------------------------
927
928 (define_insn "subqi3"
929 [(set (match_operand:QI 0 "register_operand" "=r")
930 (minus:QI (match_operand:QI 1 "register_operand" "0")
931 (match_operand:QI 2 "register_operand" "r")))]
932 ""
933 "sub.b %X2,%X0"
934 [(set_attr "length" "2")
935 (set_attr "cc" "set_zn")])
936
937 (define_expand "subhi3"
938 [(set (match_operand:HI 0 "register_operand" "")
939 (minus:HI (match_operand:HI 1 "general_operand" "")
940 (match_operand:HI 2 "nonmemory_operand" "")))]
941 ""
942 "")
943
944 (define_insn ""
945 [(set (match_operand:HI 0 "register_operand" "=r,&r")
946 (minus:HI (match_operand:HI 1 "general_operand" "0,0")
947 (match_operand:HI 2 "nonmemory_operand" "r,n")))]
948 "TARGET_H8300"
949 "@
950 sub.w %T2,%T0
951 add.b %E2,%s0\;addx %F2,%t0"
952 [(set_attr "length" "2,4")
953 (set_attr "cc" "set_zn,clobber")])
954
955 (define_insn ""
956 [(set (match_operand:HI 0 "register_operand" "=r,&r")
957 (minus:HI (match_operand:HI 1 "general_operand" "0,0")
958 (match_operand:HI 2 "nonmemory_operand" "r,n")))]
959 "TARGET_H8300H || TARGET_H8300S"
960 "@
961 sub.w %T2,%T0
962 sub.w %T2,%T0"
963 [(set_attr "length" "2,4")
964 (set_attr "cc" "set_zn,set_zn")])
965
966 (define_expand "subsi3"
967 [(set (match_operand:SI 0 "register_operand" "")
968 (minus:SI (match_operand:SI 1 "register_operand" "")
969 (match_operand:SI 2 "nonmemory_operand" "")))]
970 ""
971 "")
972
973 (define_insn "subsi3_h8300"
974 [(set (match_operand:SI 0 "register_operand" "=r")
975 (minus:SI (match_operand:SI 1 "register_operand" "0")
976 (match_operand:SI 2 "register_operand" "r")))]
977 "TARGET_H8300"
978 "sub.w %f2,%f0\;subx %y2,%y0\;subx %z2,%z0"
979 [(set_attr "length" "6")
980 (set_attr "cc" "clobber")])
981
982 (define_insn "subsi3_h8300h"
983 [(set (match_operand:SI 0 "register_operand" "=r,r")
984 (minus:SI (match_operand:SI 1 "general_operand" "0,0")
985 (match_operand:SI 2 "nonmemory_operand" "r,i")))]
986 "TARGET_H8300H || TARGET_H8300S"
987 "@
988 sub.l %S2,%S0
989 sub.l %S2,%S0"
990 [(set_attr "length" "2,6")
991 (set_attr "cc" "set_zn,set_zn")])
992 \f
993 ;; ----------------------------------------------------------------------
994 ;; MULTIPLY INSTRUCTIONS
995 ;; ----------------------------------------------------------------------
996
997 ;; Note that the H8/300 can only handle umulqihi3.
998
999 (define_insn "mulqihi3"
1000 [(set (match_operand:HI 0 "register_operand" "=r")
1001 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1002 (sign_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1003 "TARGET_H8300H || TARGET_H8300S"
1004 "mulxs.b %X2,%T0"
1005 [(set_attr "length" "4")
1006 (set_attr "cc" "set_zn")])
1007
1008 (define_insn "mulhisi3"
1009 [(set (match_operand:SI 0 "register_operand" "=r")
1010 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1011 (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
1012 "TARGET_H8300H || TARGET_H8300S"
1013 "mulxs.w %T2,%S0"
1014 [(set_attr "length" "4")
1015 (set_attr "cc" "set_zn")])
1016
1017 (define_insn "umulqihi3"
1018 [(set (match_operand:HI 0 "register_operand" "=r")
1019 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1020 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1021 ""
1022 "mulxu %X2,%T0"
1023 [(set_attr "length" "2")
1024 (set_attr "cc" "none_0hit")])
1025
1026 (define_insn "umulhisi3"
1027 [(set (match_operand:SI 0 "register_operand" "=r")
1028 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1029 (zero_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
1030 "TARGET_H8300H || TARGET_H8300S"
1031 "mulxu.w %T2,%S0"
1032 [(set_attr "length" "2")
1033 (set_attr "cc" "none_0hit")])
1034
1035 ;; This is a "bridge" instruction. Combine can't cram enough insns
1036 ;; together to crate a MAC instruction directly, but it can create
1037 ;; this instruction, which then allows combine to create the real
1038 ;; MAC insn.
1039 ;;
1040 ;; Unfortunately, if combine doesn't create a MAC instruction, this
1041 ;; insn must generate reasonably correct code. Egad.
1042 (define_insn ""
1043 [(set (match_operand:SI 0 "register_operand" "=a")
1044 (mult:SI
1045 (sign_extend:SI
1046 (mem:HI (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
1047 (sign_extend:SI
1048 (mem:HI (post_inc:SI (match_operand:SI 2 "register_operand" "r"))))))]
1049 "TARGET_MAC"
1050 "clrmac\;mac @%2+,@%1+"
1051 [(set_attr "length" "6")
1052 (set_attr "cc" "none_0hit")])
1053
1054 (define_insn ""
1055 [(set (match_operand:SI 0 "register_operand" "=a")
1056 (plus:SI (mult:SI
1057 (sign_extend:SI (mem:HI
1058 (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
1059 (sign_extend:SI (mem:HI
1060 (post_inc:SI (match_operand:SI 2 "register_operand" "r")))))
1061 (match_operand:SI 3 "register_operand" "0")))]
1062 "TARGET_MAC"
1063 "mac @%2+,@%1+"
1064 [(set_attr "length" "4")
1065 (set_attr "cc" "none_0hit")])
1066
1067 ;; ----------------------------------------------------------------------
1068 ;; DIVIDE/MOD INSTRUCTIONS
1069 ;; ----------------------------------------------------------------------
1070
1071 (define_insn "udivmodqi4"
1072 [(set (match_operand:QI 0 "register_operand" "=r")
1073 (truncate:QI
1074 (udiv:HI
1075 (match_operand:HI 1 "register_operand" "0")
1076 (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1077 (set (match_operand:QI 3 "register_operand" "=r")
1078 (truncate:QI
1079 (umod:HI
1080 (match_dup 1)
1081 (zero_extend:HI (match_dup 2)))))]
1082 ""
1083 "*
1084 {
1085 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1086 return \"divxu.b\\t%X2,%T0\";
1087 else
1088 return \"divxu.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1089 }"
1090 [(set_attr "length" "4")
1091 (set_attr "cc" "clobber")])
1092
1093 (define_insn "divmodqi4"
1094 [(set (match_operand:QI 0 "register_operand" "=r")
1095 (truncate:QI
1096 (div:HI
1097 (match_operand:HI 1 "register_operand" "0")
1098 (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1099 (set (match_operand:QI 3 "register_operand" "=r")
1100 (truncate:QI
1101 (mod:HI
1102 (match_dup 1)
1103 (sign_extend:HI (match_dup 2)))))]
1104 "TARGET_H8300H || TARGET_H8300S"
1105 "*
1106 {
1107 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1108 return \"divxs.b\\t%X2,%T0\";
1109 else
1110 return \"divxs.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1111 }"
1112 [(set_attr "length" "6")
1113 (set_attr "cc" "clobber")])
1114
1115 (define_insn "udivmodhi4"
1116 [(set (match_operand:HI 0 "register_operand" "=r")
1117 (truncate:HI
1118 (udiv:SI
1119 (match_operand:SI 1 "register_operand" "0")
1120 (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1121 (set (match_operand:HI 3 "register_operand" "=r")
1122 (truncate:HI
1123 (umod:SI
1124 (match_dup 1)
1125 (zero_extend:SI (match_dup 2)))))]
1126 "TARGET_H8300H || TARGET_H8300S"
1127 "*
1128 {
1129 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1130 return \"divxu.w\\t%T2,%S0\";
1131 else
1132 return \"divxu.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1133 }"
1134 [(set_attr "length" "4")
1135 (set_attr "cc" "clobber")])
1136
1137 (define_insn "divmodhi4"
1138 [(set (match_operand:HI 0 "register_operand" "=r")
1139 (truncate:HI
1140 (div:SI
1141 (match_operand:SI 1 "register_operand" "0")
1142 (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1143 (set (match_operand:HI 3 "register_operand" "=r")
1144 (truncate:HI
1145 (mod:SI
1146 (match_dup 1)
1147 (sign_extend:SI (match_dup 2)))))]
1148 "TARGET_H8300H || TARGET_H8300S"
1149 "*
1150 {
1151 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1152 return \"divxs.w\\t%T2,%S0\";
1153 else
1154 return \"divxs.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1155 }"
1156 [(set_attr "length" "6")
1157 (set_attr "cc" "clobber")])
1158 \f
1159 ;; ----------------------------------------------------------------------
1160 ;; AND INSTRUCTIONS
1161 ;; ----------------------------------------------------------------------
1162
1163 (define_insn ""
1164 [(set (match_operand:QI 0 "bit_operand" "=r,U")
1165 (and:QI (match_operand:QI 1 "bit_operand" "%0,0")
1166 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1167 "register_operand (operands[0], QImode)
1168 || single_zero_operand (operands[2], QImode)"
1169 "@
1170 and %X2,%X0
1171 bclr %W2,%R0"
1172 [(set_attr "length" "2,8")
1173 (set_attr "adjust_length" "no")
1174 (set_attr "cc" "set_znv,none_0hit")])
1175
1176 (define_expand "andqi3"
1177 [(set (match_operand:QI 0 "bit_operand" "")
1178 (and:QI (match_operand:QI 1 "bit_operand" "")
1179 (match_operand:QI 2 "nonmemory_operand" "")))]
1180 ""
1181 "
1182 {
1183 if (fix_bit_operand (operands, 0, AND))
1184 DONE;
1185 }")
1186
1187 (define_expand "andhi3"
1188 [(set (match_operand:HI 0 "register_operand" "")
1189 (and:HI (match_operand:HI 1 "register_operand" "")
1190 (match_operand:HI 2 "nonmemory_operand" "")))]
1191 ""
1192 "")
1193
1194 (define_insn "*andorqi3"
1195 [(set (match_operand:QI 0 "register_operand" "=r")
1196 (ior:QI (and:QI (match_operand:QI 2 "register_operand" "r")
1197 (match_operand:QI 3 "single_one_operand" "n"))
1198 (match_operand:QI 1 "register_operand" "0")))]
1199 ""
1200 "bld\\t%V3,%X2\;bor\\t%V3,%X0\;bst\\t%V3,%X0"
1201 [(set_attr "length" "6")
1202 (set_attr "cc" "clobber")])
1203
1204 (define_insn "*andorhi3"
1205 [(set (match_operand:HI 0 "register_operand" "=r")
1206 (ior:HI (and:HI (match_operand:HI 2 "register_operand" "r")
1207 (match_operand:HI 3 "single_one_operand" "n"))
1208 (match_operand:HI 1 "register_operand" "0")))]
1209 ""
1210 "*
1211 {
1212 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1213 if (INTVAL (operands[3]) > 128)
1214 {
1215 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1216 return \"bld\\t%V3,%t2\;bor\\t%V3,%t0\;bst\\t%V3,%t0\";
1217 }
1218 return \"bld\\t%V3,%s2\;bor\\t%V3,%s0\;bst\\t%V3,%s0\";
1219 }"
1220 [(set_attr "length" "6")
1221 (set_attr "cc" "clobber")])
1222
1223 (define_insn "*andorsi3"
1224 [(set (match_operand:SI 0 "register_operand" "=r")
1225 (ior:SI (and:SI (match_operand:SI 2 "register_operand" "r")
1226 (match_operand:SI 3 "single_one_operand" "n"))
1227 (match_operand:SI 1 "register_operand" "0")))]
1228 "(INTVAL (operands[3]) & 0xffff) != 0"
1229 "*
1230 {
1231 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1232 if (INTVAL (operands[3]) > 128)
1233 {
1234 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1235 return \"bld\\t%V3,%x2\;bor\\t%V3,%x0\;bst\\t%V3,%x0\";
1236 }
1237 return \"bld\\t%V3,%w2\;bor\\t%V3,%w0\;bst\\t%V3,%w0\";
1238 }"
1239 [(set_attr "length" "6")
1240 (set_attr "cc" "clobber")])
1241
1242 (define_insn "*andorsi3_shift_8"
1243 [(set (match_operand:SI 0 "register_operand" "=r")
1244 (ior:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1245 (const_int 8))
1246 (const_int 65280))
1247 (match_operand:SI 1 "register_operand" "0")))]
1248 ""
1249 "or.b\\t%w2,%x0"
1250 [(set_attr "length" "2")
1251 (set_attr "cc" "clobber")])
1252
1253 (define_expand "andsi3"
1254 [(set (match_operand:SI 0 "register_operand" "")
1255 (and:SI (match_operand:SI 1 "register_operand" "")
1256 (match_operand:SI 2 "nonmemory_operand" "")))]
1257 ""
1258 "")
1259
1260 ;; ----------------------------------------------------------------------
1261 ;; OR INSTRUCTIONS
1262 ;; ----------------------------------------------------------------------
1263
1264 (define_insn ""
1265 [(set (match_operand:QI 0 "bit_operand" "=r,U")
1266 (ior:QI (match_operand:QI 1 "bit_operand" "%0,0")
1267 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1268 "register_operand (operands[0], QImode)
1269 || single_one_operand (operands[2], QImode)"
1270 "@
1271 or\\t%X2,%X0
1272 bset\\t%V2,%R0"
1273 [(set_attr "length" "2,8")
1274 (set_attr "adjust_length" "no")
1275 (set_attr "cc" "set_znv,none_0hit")])
1276
1277 (define_expand "iorqi3"
1278 [(set (match_operand:QI 0 "bit_operand" "")
1279 (ior:QI (match_operand:QI 1 "bit_operand" "")
1280 (match_operand:QI 2 "nonmemory_operand" "")))]
1281 ""
1282 "
1283 {
1284 if (fix_bit_operand (operands, 1, IOR))
1285 DONE;
1286 }")
1287
1288 (define_expand "iorhi3"
1289 [(set (match_operand:HI 0 "register_operand" "")
1290 (ior:HI (match_operand:HI 1 "register_operand" "")
1291 (match_operand:HI 2 "nonmemory_operand" "")))]
1292 ""
1293 "")
1294
1295 (define_expand "iorsi3"
1296 [(set (match_operand:SI 0 "register_operand" "")
1297 (ior:SI (match_operand:SI 1 "register_operand" "")
1298 (match_operand:SI 2 "nonmemory_operand" "")))]
1299 ""
1300 "")
1301
1302 ;; ----------------------------------------------------------------------
1303 ;; XOR INSTRUCTIONS
1304 ;; ----------------------------------------------------------------------
1305
1306 (define_insn ""
1307 [(set (match_operand:QI 0 "bit_operand" "=r,U")
1308 (xor:QI (match_operand:QI 1 "bit_operand" "%0,0")
1309 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1310 "register_operand (operands[0], QImode)
1311 || single_one_operand (operands[2], QImode)"
1312 "@
1313 xor\\t%X2,%X0
1314 bnot\\t%V2,%R0"
1315 [(set_attr "length" "2,8")
1316 (set_attr "adjust_length" "no")
1317 (set_attr "cc" "set_znv,none_0hit")])
1318
1319 (define_expand "xorqi3"
1320 [(set (match_operand:QI 0 "bit_operand" "")
1321 (xor:QI (match_operand:QI 1 "bit_operand" "")
1322 (match_operand:QI 2 "nonmemory_operand" "")))]
1323 ""
1324 "
1325 {
1326 if (fix_bit_operand (operands, 1, XOR))
1327 DONE;
1328 }")
1329
1330 (define_expand "xorhi3"
1331 [(set (match_operand:HI 0 "register_operand" "")
1332 (xor:HI (match_operand:HI 1 "register_operand" "")
1333 (match_operand:HI 2 "nonmemory_operand" "")))]
1334 ""
1335 "")
1336
1337 (define_expand "xorsi3"
1338 [(set (match_operand:SI 0 "register_operand" "")
1339 (xor:SI (match_operand:SI 1 "register_operand" "")
1340 (match_operand:SI 2 "nonmemory_operand" "")))]
1341 ""
1342 "")
1343
1344 ;; ----------------------------------------------------------------------
1345 ;; {AND,IOR,XOR}{HI3,SI3} PATTERNS
1346 ;; ----------------------------------------------------------------------
1347
1348 (define_insn ""
1349 [(set (match_operand:HI 0 "register_operand" "=r")
1350 (match_operator:HI 3 "bit_operator"
1351 [(match_operand:HI 1 "register_operand" "%0")
1352 (match_operand:HI 2 "nonmemory_operand" "rn")]))]
1353 ""
1354 "* return output_logical_op (HImode, operands);"
1355 [(set (attr "length")
1356 (symbol_ref "compute_logical_op_length (HImode, operands)"))
1357 (set (attr "cc")
1358 (symbol_ref "compute_logical_op_cc (HImode, operands)"))])
1359
1360 (define_insn ""
1361 [(set (match_operand:SI 0 "register_operand" "=r")
1362 (match_operator:SI 3 "bit_operator"
1363 [(match_operand:SI 1 "register_operand" "%0")
1364 (match_operand:SI 2 "nonmemory_operand" "rn")]))]
1365 ""
1366 "* return output_logical_op (SImode, operands);"
1367 [(set (attr "length")
1368 (symbol_ref "compute_logical_op_length (SImode, operands)"))
1369 (set (attr "cc")
1370 (symbol_ref "compute_logical_op_cc (SImode, operands)"))])
1371 \f
1372 ;; ----------------------------------------------------------------------
1373 ;; NEGATION INSTRUCTIONS
1374 ;; ----------------------------------------------------------------------
1375
1376 (define_insn "negqi2"
1377 [(set (match_operand:QI 0 "register_operand" "=r")
1378 (neg:QI (match_operand:QI 1 "register_operand" "0")))]
1379 ""
1380 "neg %X0"
1381 [(set_attr "length" "2")
1382 (set_attr "cc" "set_zn")])
1383
1384 (define_expand "neghi2"
1385 [(set (match_operand:HI 0 "register_operand" "")
1386 (neg:HI (match_operand:HI 1 "register_operand" "")))]
1387 ""
1388 "
1389 {
1390 if (TARGET_H8300)
1391 {
1392 emit_insn (gen_neghi2_h8300 (operands[0], operands[1]));
1393 DONE;
1394 }
1395 }")
1396
1397 (define_expand "neghi2_h8300"
1398 [(set (match_dup 2)
1399 (not:HI (match_operand:HI 1 "register_operand" "")))
1400 (set (match_dup 2) (plus:HI (match_dup 2) (const_int 1)))
1401 (set (match_operand:HI 0 "register_operand" "")
1402 (match_dup 2))]
1403 ""
1404 "operands[2] = gen_reg_rtx (HImode);")
1405
1406 (define_insn "neghi2_h8300h"
1407 [(set (match_operand:HI 0 "register_operand" "=r")
1408 (neg:HI (match_operand:HI 1 "register_operand" "0")))]
1409 "TARGET_H8300H || TARGET_H8300S"
1410 "neg %T0"
1411 [(set_attr "length" "2")
1412 (set_attr "cc" "set_zn")])
1413
1414 (define_expand "negsi2"
1415 [(set (match_operand:SI 0 "register_operand" "")
1416 (neg:SI (match_operand:SI 1 "register_operand" "")))]
1417 ""
1418 "
1419 {
1420 if (TARGET_H8300)
1421 {
1422 emit_insn (gen_negsi2_h8300 (operands[0], operands[1]));
1423 DONE;
1424 }
1425 }")
1426
1427 (define_expand "negsi2_h8300"
1428 [(set (match_dup 2)
1429 (not:SI (match_operand:SI 1 "register_operand" "")))
1430 (set (match_dup 2) (plus:SI (match_dup 2) (const_int 1)))
1431 (set (match_operand:SI 0 "register_operand" "")
1432 (match_dup 2))]
1433 ""
1434 "operands[2] = gen_reg_rtx (SImode);")
1435
1436 (define_insn "negsi2_h8300h"
1437 [(set (match_operand:SI 0 "register_operand" "=r")
1438 (neg:SI (match_operand:SI 1 "register_operand" "0")))]
1439 "TARGET_H8300H || TARGET_H8300S"
1440 "neg %S0"
1441 [(set_attr "length" "2")
1442 (set_attr "cc" "set_zn")])
1443
1444 (define_expand "negsf2"
1445 [(set (match_operand:SF 0 "register_operand" "")
1446 (neg:SF (match_operand:SF 1 "register_operand" "")))]
1447 ""
1448 "")
1449
1450 (define_insn "*negsf2_h8300"
1451 [(set (match_operand:SF 0 "register_operand" "=r")
1452 (neg:SF (match_operand:SF 1 "register_operand" "0")))]
1453 "TARGET_H8300"
1454 "xor.b\\t#128,%z0"
1455 [(set_attr "cc" "clobber")
1456 (set_attr "length" "2")])
1457
1458 (define_insn "*negsf2_h8300hs"
1459 [(set (match_operand:SF 0 "register_operand" "=r")
1460 (neg:SF (match_operand:SF 1 "register_operand" "0")))]
1461 "TARGET_H8300H || TARGET_H8300S"
1462 "xor.w\\t#32768,%e0"
1463 [(set_attr "cc" "clobber")
1464 (set_attr "length" "4")])
1465 \f
1466 ;; ----------------------------------------------------------------------
1467 ;; ABSOLUTE VALUE INSTRUCTIONS
1468 ;; ----------------------------------------------------------------------
1469
1470 (define_expand "abssf2"
1471 [(set (match_operand:SF 0 "register_operand" "")
1472 (abs:SF (match_operand:SF 1 "register_operand" "")))]
1473 ""
1474 "")
1475
1476 (define_insn "*abssf2_h8300"
1477 [(set (match_operand:SF 0 "register_operand" "=r")
1478 (abs:SF (match_operand:SF 1 "register_operand" "0")))]
1479 "TARGET_H8300"
1480 "and.b\\t#127,%z0"
1481 [(set_attr "cc" "clobber")
1482 (set_attr "length" "2")])
1483
1484 (define_insn "*abssf2_h8300hs"
1485 [(set (match_operand:SF 0 "register_operand" "=r")
1486 (abs:SF (match_operand:SF 1 "register_operand" "0")))]
1487 "TARGET_H8300H || TARGET_H8300S"
1488 "and.w\\t#32767,%e0"
1489 [(set_attr "cc" "clobber")
1490 (set_attr "length" "4")])
1491 \f
1492 ;; ----------------------------------------------------------------------
1493 ;; NOT INSTRUCTIONS
1494 ;; ----------------------------------------------------------------------
1495
1496 (define_insn "one_cmplqi2"
1497 [(set (match_operand:QI 0 "register_operand" "=r")
1498 (not:QI (match_operand:QI 1 "register_operand" "0")))]
1499 ""
1500 "not %X0"
1501 [(set_attr "length" "2")
1502 (set_attr "cc" "set_znv")])
1503
1504 (define_expand "one_cmplhi2"
1505 [(set (match_operand:HI 0 "register_operand" "=r")
1506 (not:HI (match_operand:HI 1 "register_operand" "0")))]
1507 ""
1508 "")
1509
1510 (define_insn ""
1511 [(set (match_operand:HI 0 "register_operand" "=r")
1512 (not:HI (match_operand:HI 1 "register_operand" "0")))]
1513 "TARGET_H8300"
1514 "not %s0\;not %t0"
1515 [(set_attr "cc" "clobber")
1516 (set_attr "length" "4")])
1517
1518 (define_insn ""
1519 [(set (match_operand:HI 0 "register_operand" "=r")
1520 (not:HI (match_operand:HI 1 "register_operand" "0")))]
1521 "TARGET_H8300H || TARGET_H8300S"
1522 "not %T0"
1523 [(set_attr "cc" "set_znv")
1524 (set_attr "length" "2")])
1525
1526 (define_expand "one_cmplsi2"
1527 [(set (match_operand:SI 0 "register_operand" "=r")
1528 (not:SI (match_operand:SI 1 "register_operand" "0")))]
1529 ""
1530 "")
1531
1532 (define_insn ""
1533 [(set (match_operand:SI 0 "register_operand" "=r")
1534 (not:SI (match_operand:SI 1 "register_operand" "0")))]
1535 "TARGET_H8300"
1536 "not %w0\;not %x0\;not %y0\;not %z0"
1537 [(set_attr "cc" "clobber")
1538 (set_attr "length" "8")])
1539
1540 (define_insn ""
1541 [(set (match_operand:SI 0 "register_operand" "=r")
1542 (not:SI (match_operand:SI 1 "register_operand" "0")))]
1543 "TARGET_H8300H || TARGET_H8300S"
1544 "not %S0"
1545 [(set_attr "cc" "set_znv")
1546 (set_attr "length" "2")])
1547 \f
1548 ;; ----------------------------------------------------------------------
1549 ;; JUMP INSTRUCTIONS
1550 ;; ----------------------------------------------------------------------
1551
1552 ;; Conditional jump instructions
1553
1554 (define_expand "ble"
1555 [(set (pc)
1556 (if_then_else (le (cc0)
1557 (const_int 0))
1558 (label_ref (match_operand 0 "" ""))
1559 (pc)))]
1560 ""
1561 "")
1562
1563 (define_expand "bleu"
1564 [(set (pc)
1565 (if_then_else (leu (cc0)
1566 (const_int 0))
1567 (label_ref (match_operand 0 "" ""))
1568 (pc)))]
1569 ""
1570 "")
1571
1572 (define_expand "bge"
1573 [(set (pc)
1574 (if_then_else (ge (cc0)
1575 (const_int 0))
1576 (label_ref (match_operand 0 "" ""))
1577 (pc)))]
1578 ""
1579 "")
1580
1581 (define_expand "bgeu"
1582 [(set (pc)
1583 (if_then_else (geu (cc0)
1584 (const_int 0))
1585 (label_ref (match_operand 0 "" ""))
1586 (pc)))]
1587 ""
1588 "")
1589
1590 (define_expand "blt"
1591 [(set (pc)
1592 (if_then_else (lt (cc0)
1593 (const_int 0))
1594 (label_ref (match_operand 0 "" ""))
1595 (pc)))]
1596 ""
1597 "")
1598
1599 (define_expand "bltu"
1600 [(set (pc)
1601 (if_then_else (ltu (cc0)
1602 (const_int 0))
1603 (label_ref (match_operand 0 "" ""))
1604 (pc)))]
1605 ""
1606 "")
1607
1608 (define_expand "bgt"
1609 [(set (pc)
1610 (if_then_else (gt (cc0)
1611 (const_int 0))
1612 (label_ref (match_operand 0 "" ""))
1613 (pc)))]
1614 ""
1615 "")
1616
1617 (define_expand "bgtu"
1618 [(set (pc)
1619 (if_then_else (gtu (cc0)
1620 (const_int 0))
1621 (label_ref (match_operand 0 "" ""))
1622 (pc)))]
1623 ""
1624 "")
1625
1626 (define_expand "beq"
1627 [(set (pc)
1628 (if_then_else (eq (cc0)
1629 (const_int 0))
1630 (label_ref (match_operand 0 "" ""))
1631 (pc)))]
1632 ""
1633 "")
1634
1635 (define_expand "bne"
1636 [(set (pc)
1637 (if_then_else (ne (cc0)
1638 (const_int 0))
1639 (label_ref (match_operand 0 "" ""))
1640 (pc)))]
1641 ""
1642 "")
1643
1644 (define_insn "branch_true"
1645 [(set (pc)
1646 (if_then_else (match_operator 1 "comparison_operator"
1647 [(cc0) (const_int 0)])
1648 (label_ref (match_operand 0 "" ""))
1649 (pc)))]
1650 ""
1651 "*
1652 {
1653 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1654 && (GET_CODE (operands[1]) == GT
1655 || GET_CODE (operands[1]) == GE
1656 || GET_CODE (operands[1]) == LE
1657 || GET_CODE (operands[1]) == LT))
1658 {
1659 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
1660 return 0;
1661 }
1662
1663 if (get_attr_length (insn) == 2)
1664 return \"b%j1 %l0\";
1665 else if (get_attr_length (insn) == 4)
1666 return \"b%j1 %l0:16\";
1667 else
1668 return \"b%k1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
1669 }"
1670 [(set_attr "type" "branch")
1671 (set_attr "cc" "none")])
1672
1673 (define_insn "branch_false"
1674 [(set (pc)
1675 (if_then_else (match_operator 1 "comparison_operator"
1676 [(cc0) (const_int 0)])
1677 (pc)
1678 (label_ref (match_operand 0 "" ""))))]
1679 ""
1680 "*
1681 {
1682 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1683 && (GET_CODE (operands[1]) == GT
1684 || GET_CODE (operands[1]) == GE
1685 || GET_CODE (operands[1]) == LE
1686 || GET_CODE (operands[1]) == LT))
1687 {
1688 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
1689 return 0;
1690 }
1691
1692 if (get_attr_length (insn) == 2)
1693 return \"b%k1 %l0\";
1694 else if (get_attr_length (insn) == 4)
1695 return \"b%k1 %l0:16\";
1696 else
1697 return \"b%j1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
1698 }"
1699 [(set_attr "type" "branch")
1700 (set_attr "cc" "none")])
1701
1702 ;; Unconditional and other jump instructions.
1703
1704 (define_insn "jump"
1705 [(set (pc)
1706 (label_ref (match_operand 0 "" "")))]
1707 ""
1708 "*
1709 {
1710 if (get_attr_length (insn) == 2)
1711 return \"bra %l0\";
1712 else if (get_attr_length (insn) == 4)
1713 return \"bra %l0:16\";
1714 else
1715 return \"jmp @%l0\";
1716 }"
1717 [(set_attr "type" "branch")
1718 (set_attr "cc" "none")])
1719
1720 ;; This is a define expand, because pointers may be either 16 or 32 bits.
1721
1722 (define_expand "tablejump"
1723 [(parallel [(set (pc) (match_operand 0 "register_operand" ""))
1724 (use (label_ref (match_operand 1 "" "")))])]
1725 ""
1726 "")
1727
1728 (define_insn "tablejump_h8300"
1729 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
1730 (use (label_ref (match_operand 1 "" "")))]
1731 "TARGET_H8300"
1732 "jmp @%0"
1733 [(set_attr "cc" "none")
1734 (set_attr "length" "2")])
1735
1736 (define_insn "tablejump_h8300h"
1737 [(set (pc) (match_operand:SI 0 "register_operand" "r"))
1738 (use (label_ref (match_operand 1 "" "")))]
1739 "TARGET_H8300H || TARGET_H8300S"
1740 "jmp @%0"
1741 [(set_attr "cc" "none")
1742 (set_attr "length" "2")])
1743
1744 (define_insn "tablejump_normal_mode"
1745 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
1746 (use (label_ref (match_operand 1 "" "")))]
1747 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
1748 "jmp @%S0"
1749 [(set_attr "cc" "none")
1750 (set_attr "length" "2")])
1751
1752 ;; This is a define expand, because pointers may be either 16 or 32 bits.
1753
1754 (define_expand "indirect_jump"
1755 [(set (pc) (match_operand 0 "jump_address_operand" ""))]
1756 ""
1757 "")
1758
1759 (define_insn "indirect_jump_h8300"
1760 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
1761 "TARGET_H8300"
1762 "jmp @%0"
1763 [(set_attr "cc" "none")
1764 (set_attr "length" "2")])
1765
1766 (define_insn "indirect_jump_h8300h"
1767 [(set (pc) (match_operand:SI 0 "jump_address_operand" "Vr"))]
1768 "TARGET_H8300H || TARGET_H8300S"
1769 "jmp @%0"
1770 [(set_attr "cc" "none")
1771 (set_attr "length" "2")])
1772
1773 (define_insn "indirect_jump_normal_mode"
1774 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
1775 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
1776 "jmp @%S0"
1777 [(set_attr "cc" "none")
1778 (set_attr "length" "2")])
1779
1780 ;; Call subroutine with no return value.
1781
1782 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
1783
1784 (define_insn "call"
1785 [(call (match_operand:QI 0 "call_insn_operand" "or")
1786 (match_operand:HI 1 "general_operand" "g"))]
1787 ""
1788 "*
1789 {
1790 if (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
1791 && SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
1792 return \"jsr\\t@%0:8\";
1793 else
1794 return \"jsr\\t%0\";
1795 }"
1796 [(set_attr "cc" "clobber")
1797 (set (attr "length")
1798 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
1799 (const_int 4)
1800 (const_int 8)))])
1801
1802 ;; Call subroutine, returning value in operand 0
1803 ;; (which must be a hard register).
1804
1805 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
1806
1807 (define_insn "call_value"
1808 [(set (match_operand 0 "" "=r")
1809 (call (match_operand:QI 1 "call_insn_operand" "or")
1810 (match_operand:HI 2 "general_operand" "g")))]
1811 ""
1812 "*
1813 {
1814 if (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
1815 && SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
1816 return \"jsr\\t@%1:8\";
1817 else
1818 return \"jsr\\t%1\";
1819 }"
1820 [(set_attr "cc" "clobber")
1821 (set (attr "length")
1822 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
1823 (const_int 4)
1824 (const_int 8)))])
1825
1826 (define_insn "nop"
1827 [(const_int 0)]
1828 ""
1829 "nop"
1830 [(set_attr "cc" "none")
1831 (set_attr "length" "2")])
1832 \f
1833 ;; ----------------------------------------------------------------------
1834 ;; PROLOGUE/EPILOGUE-RELATED INSTRUCTIONS
1835 ;; ----------------------------------------------------------------------
1836
1837 (define_expand "push_h8300"
1838 [(set (mem:HI (pre_dec:HI (reg:HI SP_REG)))
1839 (match_operand:HI 0 "register_operand" "=r"))]
1840
1841 "TARGET_H8300"
1842 "")
1843
1844 (define_expand "push_h8300hs"
1845 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
1846 (match_operand:SI 0 "register_operand" "=r"))]
1847 "TARGET_H8300H && TARGET_H8300S"
1848 "")
1849
1850 (define_expand "pop_h8300"
1851 [(set (match_operand:HI 0 "register_operand" "=r")
1852 (mem:HI (post_inc:HI (reg:HI SP_REG))))]
1853 "TARGET_H8300"
1854 "")
1855
1856 (define_expand "pop_h8300hs"
1857 [(set (match_operand:SI 0 "register_operand" "=r")
1858 (mem:SI (post_inc:SI (reg:SI SP_REG))))]
1859 "TARGET_H8300H && TARGET_H8300S"
1860 "")
1861
1862 (define_insn "stm_h8300s_2"
1863 [(parallel
1864 [(set (reg:SI SP_REG)
1865 (plus:SI (reg:SI SP_REG) (const_int -8)))
1866 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1867 (match_operand:SI 0 "register_operand" ""))
1868 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1869 (match_operand:SI 1 "register_operand" ""))])]
1870 "TARGET_H8300S
1871 && ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
1872 || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
1873 || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5))"
1874 "stm.l\\t%S0-%S1,@-er7"
1875 [(set_attr "cc" "none")
1876 (set_attr "length" "4")])
1877
1878 (define_insn "stm_h8300s_3"
1879 [(parallel
1880 [(set (reg:SI SP_REG)
1881 (plus:SI (reg:SI SP_REG) (const_int -12)))
1882 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1883 (match_operand:SI 0 "register_operand" ""))
1884 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1885 (match_operand:SI 1 "register_operand" ""))
1886 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
1887 (match_operand:SI 2 "register_operand" ""))])]
1888 "TARGET_H8300S
1889 && ((REGNO (operands[0]) == 0
1890 && REGNO (operands[1]) == 1
1891 && REGNO (operands[2]) == 2)
1892 || (REGNO (operands[0]) == 4
1893 && REGNO (operands[1]) == 5
1894 && REGNO (operands[2]) == 6))"
1895 "stm.l\\t%S0-%S2,@-er7"
1896 [(set_attr "cc" "none")
1897 (set_attr "length" "4")])
1898
1899 (define_insn "stm_h8300s_4"
1900 [(parallel
1901 [(set (reg:SI SP_REG)
1902 (plus:SI (reg:SI SP_REG) (const_int -16)))
1903 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1904 (match_operand:SI 0 "register_operand" ""))
1905 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1906 (match_operand:SI 1 "register_operand" ""))
1907 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
1908 (match_operand:SI 2 "register_operand" ""))
1909 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
1910 (match_operand:SI 3 "register_operand" ""))])]
1911 "TARGET_H8300S
1912 && REGNO (operands[0]) == 0
1913 && REGNO (operands[1]) == 1
1914 && REGNO (operands[2]) == 2
1915 && REGNO (operands[3]) == 3"
1916 "stm.l\\t%S0-%S3,@-er7"
1917 [(set_attr "cc" "none")
1918 (set_attr "length" "4")])
1919
1920 (define_insn "ldm_h8300s_2"
1921 [(parallel
1922 [(set (reg:SI SP_REG)
1923 (plus:SI (reg:SI SP_REG) (const_int 8)))
1924 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int 4)))
1925 (match_operand:SI 0 "register_operand" ""))
1926 (set (mem:SI (reg:SI SP_REG))
1927 (match_operand:SI 1 "register_operand" ""))])]
1928 "TARGET_H8300S
1929 && ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
1930 || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
1931 || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5))"
1932 "ldm.l\\t@er7+,%S0-%S1"
1933 [(set_attr "cc" "none")
1934 (set_attr "length" "4")])
1935
1936 (define_insn "ldm_h8300s_3"
1937 [(parallel
1938 [(set (reg:SI SP_REG)
1939 (plus:SI (reg:SI SP_REG) (const_int 12)))
1940 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int 8)))
1941 (match_operand:SI 0 "register_operand" ""))
1942 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int 4)))
1943 (match_operand:SI 1 "register_operand" ""))
1944 (set (mem:SI (reg:SI SP_REG))
1945 (match_operand:SI 2 "register_operand" ""))])]
1946 "TARGET_H8300S
1947 && ((REGNO (operands[0]) == 0
1948 && REGNO (operands[1]) == 1
1949 && REGNO (operands[2]) == 2)
1950 || (REGNO (operands[0]) == 4
1951 && REGNO (operands[1]) == 5
1952 && REGNO (operands[2]) == 6))"
1953 "ldm.l\\t@er7+,%S0-%S2"
1954 [(set_attr "cc" "none")
1955 (set_attr "length" "4")])
1956
1957 (define_insn "ldm_h8300s_4"
1958 [(parallel
1959 [(set (reg:SI SP_REG)
1960 (plus:SI (reg:SI SP_REG) (const_int 16)))
1961 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int 12)))
1962 (match_operand:SI 0 "register_operand" ""))
1963 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int 8)))
1964 (match_operand:SI 1 "register_operand" ""))
1965 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int 4)))
1966 (match_operand:SI 2 "register_operand" ""))
1967 (set (mem:SI (reg:SI SP_REG))
1968 (match_operand:SI 3 "register_operand" ""))])]
1969 "TARGET_H8300S
1970 && REGNO (operands[0]) == 0
1971 && REGNO (operands[1]) == 1
1972 && REGNO (operands[2]) == 2
1973 && REGNO (operands[3]) == 3"
1974 "ldm.l\\t@er7+,%S0-%S3"
1975 [(set_attr "cc" "none")
1976 (set_attr "length" "4")])
1977
1978 (define_expand "return"
1979 [(return)]
1980 "h8300_can_use_return_insn_p ()"
1981 "")
1982
1983 (define_insn "*return_1"
1984 [(return)]
1985 "reload_completed"
1986 "*
1987 {
1988 if (h8300_current_function_interrupt_function_p ())
1989 return \"rte\";
1990 else
1991 return \"rts\";
1992 }"
1993 [(set_attr "cc" "none")
1994 (set_attr "length" "2")])
1995
1996 (define_expand "prologue"
1997 [(const_int 0)]
1998 ""
1999 "h8300_expand_prologue (); DONE;")
2000
2001 (define_expand "epilogue"
2002 [(return)]
2003 ""
2004 "h8300_expand_epilogue ();")
2005
2006 (define_insn "monitor_prologue"
2007 [(unspec_volatile [(const_int 0)] UNSPEC_MONITOR)]
2008 ""
2009 "*
2010 {
2011 if (TARGET_H8300)
2012 return \"subs\\t#2,r7\;mov.w\\tr0,@-r7\;stc\\tccr,r0l\;mov.b\tr0l,@(2,r7)\;mov.w\\t@r7+,r0\;orc\t#128,ccr\";
2013 else if (TARGET_H8300H)
2014 return \"mov.l\\ter0,@-er7\;stc\\tccr,r0l\;mov.b\\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\\t#128,ccr\";
2015 else if (TARGET_H8300S)
2016 return \"stc\texr,@-er7\;mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(6,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr\";
2017 abort ();
2018 }"
2019 [(set_attr "length" "20")
2020 (set_attr "cc" "clobber")])
2021 \f
2022 ;; ----------------------------------------------------------------------
2023 ;; EXTEND INSTRUCTIONS
2024 ;; ----------------------------------------------------------------------
2025
2026 (define_expand "zero_extendqihi2"
2027 [(set (match_operand:HI 0 "register_operand" "")
2028 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
2029 ""
2030 "")
2031
2032 (define_insn "*zero_extendqihi2_h8300"
2033 [(set (match_operand:HI 0 "register_operand" "=r,r")
2034 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2035 "TARGET_H8300"
2036 "@
2037 mov.b #0,%t0
2038 #"
2039 [(set_attr "length" "2,10")
2040 (set_attr "cc" "clobber,clobber")])
2041
2042 (define_insn "*zero_extendqihi2_h8300hs"
2043 [(set (match_operand:HI 0 "register_operand" "=r,r")
2044 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2045 "TARGET_H8300H || TARGET_H8300S"
2046 "@
2047 extu.w %T0
2048 #"
2049 [(set_attr "length" "2,10")
2050 (set_attr "cc" "set_znv,set_znv")])
2051
2052 ;; Split the zero extension of a general operand (actually a memory
2053 ;; operand) into a load of the operand and the actual zero extension
2054 ;; so that 1) the length will be accurate, and 2) the zero extensions
2055 ;; appearing at the end of basic blocks may be merged.
2056
2057 (define_split
2058 [(set (match_operand:HI 0 "register_operand" "")
2059 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
2060 "reload_completed"
2061 [(set (match_dup 2)
2062 (match_dup 1))
2063 (set (match_dup 0)
2064 (zero_extend:HI (match_dup 2)))]
2065 "operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));")
2066
2067 (define_expand "zero_extendqisi2"
2068 [(set (match_operand:SI 0 "register_operand" "")
2069 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2070 ""
2071 "")
2072
2073 (define_insn "*zero_extendqisi2_h8300"
2074 [(set (match_operand:SI 0 "register_operand" "=r,r")
2075 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2076 "TARGET_H8300"
2077 "@
2078 mov.b #0,%x0\;sub.w %e0,%e0
2079 mov.b %R1,%w0\;mov.b #0,%x0\;sub.w %e0,%e0"
2080 [(set_attr "length" "4,8")
2081 (set_attr "cc" "clobber,clobber")])
2082
2083 (define_insn "*zero_extendqisi2_h8300hs"
2084 [(set (match_operand:SI 0 "register_operand" "=r,r")
2085 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2086 "TARGET_H8300H || TARGET_H8300S"
2087 "@
2088 extu.w %T0\;extu.l %S0
2089 mov.b %R1,%w0\;extu.w %T0\;extu.l %S0"
2090 [(set_attr "length" "4,12")
2091 (set_attr "cc" "set_znv,set_znv")])
2092
2093 (define_split
2094 [(set (match_operand:SI 0 "register_operand" "")
2095 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2096 "(TARGET_H8300H || TARGET_H8300S)
2097 && reg_overlap_mentioned_p (operands[0], operands[1])
2098 && reload_completed"
2099 [(set (match_dup 2)
2100 (match_dup 1))
2101 (set (match_dup 0)
2102 (zero_extend:SI (match_dup 2)))]
2103 "operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));")
2104
2105 (define_split
2106 [(set (match_operand:SI 0 "register_operand" "")
2107 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2108 "(TARGET_H8300H || TARGET_H8300S)
2109 && !reg_overlap_mentioned_p (operands[0], operands[1])
2110 && reload_completed"
2111 [(set (match_dup 0)
2112 (const_int 0))
2113 (set (strict_low_part (match_dup 2))
2114 (match_dup 1))]
2115 "operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));")
2116
2117 (define_expand "zero_extendhisi2"
2118 [(set (match_operand:SI 0 "register_operand" "")
2119 (zero_extend:SI (match_operand:HI 1 "register_operand" "")))]
2120 ""
2121 "")
2122
2123 ;; %e prints the high part of a CONST_INT, not the low part. Arggh.
2124 (define_insn "*zero_extendhisi2_h8300"
2125 [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2126 (zero_extend:SI (match_operand:HI 1 "general_operand_src" "0,i,g>")))]
2127 "TARGET_H8300"
2128 "@
2129 sub.w %e0,%e0
2130 mov.w %f1,%f0\;sub.w %e0,%e0
2131 mov.w %e1,%f0\;sub.w %e0,%e0"
2132 [(set_attr "length" "2,4,6")
2133 (set_attr "cc" "clobber,clobber,clobber")])
2134
2135 (define_insn ""
2136 [(set (match_operand:SI 0 "register_operand" "=r")
2137 (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))]
2138 "TARGET_H8300H || TARGET_H8300S"
2139 "extu.l %S0"
2140 [(set_attr "length" "2")
2141 (set_attr "cc" "set_znv")])
2142
2143 (define_expand "extendqihi2"
2144 [(set (match_operand:HI 0 "register_operand" "")
2145 (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
2146 ""
2147 "")
2148
2149 (define_insn ""
2150 [(set (match_operand:HI 0 "register_operand" "=r,r")
2151 (sign_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2152 "TARGET_H8300"
2153 "@
2154 bld #7,%s0\;subx %t0,%t0
2155 mov.b %R1,%s0\;bld #7,%s0\;subx %t0,%t0"
2156 [(set_attr "length" "4,8")
2157 (set_attr "cc" "clobber,clobber")])
2158
2159 (define_insn ""
2160 [(set (match_operand:HI 0 "register_operand" "=r")
2161 (sign_extend:HI (match_operand:QI 1 "register_operand" "0")))]
2162 "TARGET_H8300H || TARGET_H8300S"
2163 "exts.w %T0"
2164 [(set_attr "length" "2")
2165 (set_attr "cc" "set_znv")])
2166
2167 (define_expand "extendqisi2"
2168 [(set (match_operand:SI 0 "register_operand" "=r,r")
2169 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
2170 ""
2171 "")
2172
2173 (define_insn "*extendqisi2_h8300"
2174 [(set (match_operand:SI 0 "register_operand" "")
2175 (sign_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2176 "TARGET_H8300"
2177 "@
2178 bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0
2179 mov.b %R1,%w0\;bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0"
2180 [(set_attr "length" "8,12")
2181 (set_attr "cc" "clobber,clobber")])
2182
2183 ;; The following pattern is needed because without the pattern, the
2184 ;; combiner would split (sign_extend:SI (reg:QI)) into into two 24-bit
2185 ;; shifts, one ashift and one ashiftrt.
2186
2187 (define_insn_and_split "*extendqisi2_h8300hs"
2188 [(set (match_operand:SI 0 "register_operand" "=r")
2189 (sign_extend:SI (match_operand:QI 1 "register_operand" "0")))]
2190 "(TARGET_H8300H || TARGET_H8300S)"
2191 "#"
2192 "&& reload_completed"
2193 [(set (match_dup 2)
2194 (sign_extend:HI (match_dup 1)))
2195 (set (match_dup 0)
2196 (sign_extend:SI (match_dup 2)))]
2197 "operands[2] = gen_rtx_REG (HImode, REGNO (operands[0]));")
2198
2199 (define_expand "extendhisi2"
2200 [(set (match_operand:SI 0 "register_operand" "")
2201 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
2202 ""
2203 "")
2204
2205 (define_insn "*extendhisi2_h8300"
2206 [(set (match_operand:SI 0 "register_operand" "=r,r")
2207 (sign_extend:SI (match_operand:HI 1 "general_operand_src" "0,g>")))]
2208 "TARGET_H8300"
2209 "@
2210 bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0
2211 mov.w %T1,%f0\;bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0"
2212 [(set_attr "length" "6,10")
2213 (set_attr "cc" "clobber,clobber")])
2214
2215 (define_insn ""
2216 [(set (match_operand:SI 0 "register_operand" "=r")
2217 (sign_extend:SI (match_operand:HI 1 "register_operand" "0")))]
2218 "TARGET_H8300H || TARGET_H8300S"
2219 "exts.l %S0"
2220 [(set_attr "length" "2")
2221 (set_attr "cc" "set_znv")])
2222 \f
2223 ;; ----------------------------------------------------------------------
2224 ;; SHIFTS
2225 ;; ----------------------------------------------------------------------
2226 ;;
2227 ;; We make some attempt to provide real efficient shifting. One example is
2228 ;; doing an 8 bit shift of a 16 bit value by moving a byte reg into the other
2229 ;; reg and moving 0 into the former reg.
2230 ;;
2231 ;; We also try to achieve this in a uniform way. IE: We don't try to achieve
2232 ;; this in both rtl and at insn emit time. Ideally, we'd use rtl as that would
2233 ;; give the optimizer more cracks at the code. However, we wish to do things
2234 ;; like optimizing shifting the sign bit to bit 0 by rotating the other way.
2235 ;; There is rtl to handle this (rotate + and), but the H8/300 doesn't handle
2236 ;; 16 bit rotates. Also, if we emit complicated rtl, combine may not be able
2237 ;; to detect cases it can optimize.
2238 ;;
2239 ;; For these and other fuzzy reasons, I've decided to go the less pretty but
2240 ;; easier "do it at insn emit time" route.
2241
2242 ;; QI BIT SHIFTS
2243
2244 (define_expand "ashlqi3"
2245 [(set (match_operand:QI 0 "register_operand" "")
2246 (ashift:QI (match_operand:QI 1 "register_operand" "")
2247 (match_operand:QI 2 "nonmemory_operand" "")))]
2248 ""
2249 "expand_a_shift (QImode, ASHIFT, operands); DONE;")
2250
2251 (define_expand "ashrqi3"
2252 [(set (match_operand:QI 0 "register_operand" "")
2253 (ashiftrt:QI (match_operand:QI 1 "register_operand" "")
2254 (match_operand:QI 2 "nonmemory_operand" "")))]
2255 ""
2256 "expand_a_shift (QImode, ASHIFTRT, operands); DONE;")
2257
2258 (define_expand "lshrqi3"
2259 [(set (match_operand:QI 0 "register_operand" "")
2260 (lshiftrt:QI (match_operand:QI 1 "register_operand" "")
2261 (match_operand:QI 2 "nonmemory_operand" "")))]
2262 ""
2263 "expand_a_shift (QImode, LSHIFTRT, operands); DONE;")
2264
2265 (define_insn ""
2266 [(set (match_operand:QI 0 "register_operand" "=r,r")
2267 (match_operator:QI 3 "nshift_operator"
2268 [ (match_operand:QI 1 "register_operand" "0,0")
2269 (match_operand:QI 2 "nonmemory_operand" "R,rn")]))
2270 (clobber (match_scratch:QI 4 "=X,&r"))]
2271 ""
2272 "* return output_a_shift (operands);"
2273 [(set (attr "length")
2274 (symbol_ref "compute_a_shift_length (insn, operands)"))
2275 (set_attr "cc" "clobber")])
2276
2277 ;; HI BIT SHIFTS
2278
2279 (define_expand "ashlhi3"
2280 [(set (match_operand:HI 0 "register_operand" "")
2281 (ashift:HI (match_operand:HI 1 "nonmemory_operand" "")
2282 (match_operand:QI 2 "nonmemory_operand" "")))]
2283 ""
2284 "expand_a_shift (HImode, ASHIFT, operands); DONE;")
2285
2286 (define_expand "lshrhi3"
2287 [(set (match_operand:HI 0 "register_operand" "")
2288 (lshiftrt:HI (match_operand:HI 1 "general_operand" "")
2289 (match_operand:QI 2 "nonmemory_operand" "")))]
2290 ""
2291 "expand_a_shift (HImode, LSHIFTRT, operands); DONE;")
2292
2293 (define_expand "ashrhi3"
2294 [(set (match_operand:HI 0 "register_operand" "")
2295 (ashiftrt:HI (match_operand:HI 1 "register_operand" "")
2296 (match_operand:QI 2 "nonmemory_operand" "")))]
2297 ""
2298 "expand_a_shift (HImode, ASHIFTRT, operands); DONE;")
2299
2300 (define_insn ""
2301 [(set (match_operand:HI 0 "register_operand" "=r,r")
2302 (match_operator:HI 3 "nshift_operator"
2303 [ (match_operand:HI 1 "register_operand" "0,0")
2304 (match_operand:QI 2 "nonmemory_operand" "S,rn")]))
2305 (clobber (match_scratch:QI 4 "=X,&r"))]
2306 ""
2307 "* return output_a_shift (operands);"
2308 [(set (attr "length")
2309 (symbol_ref "compute_a_shift_length (insn, operands)"))
2310 (set_attr "cc" "clobber")])
2311
2312 ;; SI BIT SHIFTS
2313
2314 (define_expand "ashlsi3"
2315 [(set (match_operand:SI 0 "register_operand" "")
2316 (ashift:SI (match_operand:SI 1 "general_operand" "")
2317 (match_operand:QI 2 "nonmemory_operand" "")))]
2318 ""
2319 "expand_a_shift (SImode, ASHIFT, operands); DONE;")
2320
2321 (define_expand "lshrsi3"
2322 [(set (match_operand:SI 0 "register_operand" "")
2323 (lshiftrt:SI (match_operand:SI 1 "general_operand" "")
2324 (match_operand:QI 2 "nonmemory_operand" "")))]
2325 ""
2326 "expand_a_shift (SImode, LSHIFTRT, operands); DONE;")
2327
2328 (define_expand "ashrsi3"
2329 [(set (match_operand:SI 0 "register_operand" "")
2330 (ashiftrt:SI (match_operand:SI 1 "general_operand" "")
2331 (match_operand:QI 2 "nonmemory_operand" "")))]
2332 ""
2333 "expand_a_shift (SImode, ASHIFTRT, operands); DONE;")
2334
2335 (define_insn ""
2336 [(set (match_operand:SI 0 "register_operand" "=r,r")
2337 (match_operator:SI 3 "nshift_operator"
2338 [ (match_operand:SI 1 "register_operand" "0,0")
2339 (match_operand:QI 2 "nonmemory_operand" "T,rn")]))
2340 (clobber (match_scratch:QI 4 "=X,&r"))]
2341 ""
2342 "* return output_a_shift (operands);"
2343 [(set (attr "length")
2344 (symbol_ref "compute_a_shift_length (insn, operands)"))
2345 (set_attr "cc" "clobber")])
2346
2347 ;; Split a variable shift into a loop. If the register containing
2348 ;; the shift count dies, then we just use that register.
2349
2350 (define_split
2351 [(parallel
2352 [(set (match_operand 0 "register_operand" "")
2353 (match_operator 2 "nshift_operator"
2354 [(match_dup 0)
2355 (match_operand:QI 1 "register_operand" "")]))
2356 (clobber (match_operand:QI 3 "register_operand" ""))])]
2357 "flow2_completed
2358 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))"
2359 [(set (cc0)
2360 (match_dup 1))
2361 (set (pc)
2362 (if_then_else (le (cc0) (const_int 0))
2363 (label_ref (match_dup 5))
2364 (pc)))
2365 (match_dup 4)
2366 (parallel
2367 [(set (match_dup 0)
2368 (match_op_dup 2 [(match_dup 0) (const_int 1)]))
2369 (clobber (scratch:QI))])
2370 (set (match_dup 1)
2371 (plus:QI (match_dup 1) (const_int -1)))
2372 (set (cc0)
2373 (match_dup 1))
2374 (set (pc)
2375 (if_then_else (ne (cc0) (const_int 0))
2376 (label_ref (match_dup 4))
2377 (pc)))
2378 (match_dup 5)]
2379 "operands[4] = gen_label_rtx ();
2380 operands[5] = gen_label_rtx ();")
2381
2382 (define_split
2383 [(parallel
2384 [(set (match_operand 0 "register_operand" "")
2385 (match_operator 2 "nshift_operator"
2386 [(match_dup 0)
2387 (match_operand:QI 1 "register_operand" "")]))
2388 (clobber (match_operand:QI 3 "register_operand" ""))])]
2389 "flow2_completed
2390 && !find_regno_note (insn, REG_DEAD, REGNO (operands[1]))"
2391 [(set (match_dup 3)
2392 (match_dup 1))
2393 (set (cc0)
2394 (match_dup 3))
2395 (set (pc)
2396 (if_then_else (le (cc0) (const_int 0))
2397 (label_ref (match_dup 5))
2398 (pc)))
2399 (match_dup 4)
2400 (parallel
2401 [(set (match_dup 0)
2402 (match_op_dup 2 [(match_dup 0) (const_int 1)]))
2403 (clobber (scratch:QI))])
2404 (set (match_dup 3)
2405 (plus:QI (match_dup 3) (const_int -1)))
2406 (set (cc0)
2407 (match_dup 3))
2408 (set (pc)
2409 (if_then_else (ne (cc0) (const_int 0))
2410 (label_ref (match_dup 4))
2411 (pc)))
2412 (match_dup 5)]
2413 "operands[4] = gen_label_rtx ();
2414 operands[5] = gen_label_rtx ();")
2415 \f
2416 ;; ----------------------------------------------------------------------
2417 ;; ROTATIONS
2418 ;; ----------------------------------------------------------------------
2419
2420 (define_expand "rotlqi3"
2421 [(set (match_operand:QI 0 "register_operand" "")
2422 (rotate:QI (match_operand:QI 1 "register_operand" "")
2423 (match_operand:QI 2 "nonmemory_operand" "")))]
2424 ""
2425 "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2426
2427 (define_insn "*rotlqi3_1"
2428 [(set (match_operand:QI 0 "register_operand" "=r")
2429 (rotate:QI (match_operand:QI 1 "register_operand" "0")
2430 (match_operand:QI 2 "immediate_operand" "")))]
2431 ""
2432 "* return emit_a_rotate (ROTATE, operands);"
2433 [(set_attr "length" "20")
2434 (set_attr "cc" "clobber")])
2435
2436 (define_expand "rotlhi3"
2437 [(set (match_operand:HI 0 "register_operand" "")
2438 (rotate:HI (match_operand:HI 1 "register_operand" "")
2439 (match_operand:QI 2 "nonmemory_operand" "")))]
2440 ""
2441 "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2442
2443 (define_insn "*rotlhi3_1"
2444 [(set (match_operand:HI 0 "register_operand" "=r")
2445 (rotate:HI (match_operand:HI 1 "register_operand" "0")
2446 (match_operand:QI 2 "immediate_operand" "")))]
2447 ""
2448 "* return emit_a_rotate (ROTATE, operands);"
2449 [(set_attr "length" "20")
2450 (set_attr "cc" "clobber")])
2451
2452 (define_expand "rotlsi3"
2453 [(set (match_operand:SI 0 "register_operand" "")
2454 (rotate:SI (match_operand:SI 1 "register_operand" "")
2455 (match_operand:QI 2 "nonmemory_operand" "")))]
2456 "TARGET_H8300H || TARGET_H8300S"
2457 "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2458
2459 (define_insn "*rotlsi3_1"
2460 [(set (match_operand:SI 0 "register_operand" "=r")
2461 (rotate:SI (match_operand:SI 1 "register_operand" "0")
2462 (match_operand:QI 2 "immediate_operand" "")))]
2463 "TARGET_H8300H || TARGET_H8300S"
2464 "* return emit_a_rotate (ROTATE, operands);"
2465 [(set_attr "length" "20")
2466 (set_attr "cc" "clobber")])
2467 \f
2468 ;; -----------------------------------------------------------------
2469 ;; BIT FIELDS
2470 ;; -----------------------------------------------------------------
2471 ;; The H8/300 has given 1/8th of its opcode space to bitfield
2472 ;; instructions so let's use them as well as we can.
2473
2474 ;; You'll never believe all these patterns perform one basic action --
2475 ;; load a bit from the source, optionally invert the bit, then store it
2476 ;; in the destination (which is known to be zero).
2477 ;;
2478 ;; Combine obviously need some work to better identify this situation and
2479 ;; canonicalize the form better.
2480
2481 ;;
2482 ;; Normal loads with a 16bit destination.
2483 ;;
2484
2485 (define_insn ""
2486 [(set (match_operand:HI 0 "register_operand" "=&r")
2487 (zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2488 (const_int 1)
2489 (match_operand:HI 2 "immediate_operand" "n")))]
2490 "TARGET_H8300"
2491 "sub.w %0,%0\;bld %Z2,%Y1\;bst #0,%X0"
2492 [(set_attr "cc" "clobber")
2493 (set_attr "length" "6")])
2494
2495 ;;
2496 ;; Inverted loads with a 16bit destination.
2497 ;;
2498
2499 (define_insn ""
2500 [(set (match_operand:HI 0 "register_operand" "=&r")
2501 (zero_extract:HI (xor:HI (match_operand:HI 1 "register_operand" "r")
2502 (match_operand:HI 3 "const_int_operand" "n"))
2503 (const_int 1)
2504 (match_operand:HI 2 "const_int_operand" "n")))]
2505 "TARGET_H8300
2506 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2507 "sub.w %0,%0\;bild %Z2,%Y1\;bst #0,%X0"
2508 [(set_attr "cc" "clobber")
2509 (set_attr "length" "8")])
2510
2511 ;;
2512 ;; Normal loads with a 32bit destination.
2513 ;;
2514
2515 (define_insn "*extzv_1_r_h8300"
2516 [(set (match_operand:SI 0 "register_operand" "=&r")
2517 (zero_extract:SI (match_operand:HI 1 "register_operand" "r")
2518 (const_int 1)
2519 (match_operand 2 "const_int_operand" "n")))]
2520 "TARGET_H8300
2521 && INTVAL (operands[2]) < 16"
2522 "* return output_simode_bld (0, operands);"
2523 [(set_attr "cc" "clobber")
2524 (set_attr "length" "8")])
2525
2526 (define_insn "*extzv_1_r_h8300hs"
2527 [(set (match_operand:SI 0 "register_operand" "=r,r")
2528 (zero_extract:SI (match_operand:SI 1 "register_operand" "?0,r")
2529 (const_int 1)
2530 (match_operand 2 "const_int_operand" "n,n")))]
2531 "(TARGET_H8300H || TARGET_H8300S)
2532 && INTVAL (operands[2]) < 16"
2533 "* return output_simode_bld (0, operands);"
2534 [(set_attr "cc" "clobber,clobber")
2535 (set_attr "length" "8,6")])
2536
2537 ;;
2538 ;; Inverted loads with a 32bit destination.
2539 ;;
2540
2541 (define_insn "*extzv_1_r_inv_h8300"
2542 [(set (match_operand:SI 0 "register_operand" "=&r")
2543 (zero_extract:SI (xor:HI (match_operand:HI 1 "register_operand" "r")
2544 (match_operand:HI 3 "const_int_operand" "n"))
2545 (const_int 1)
2546 (match_operand 2 "const_int_operand" "n")))]
2547 "TARGET_H8300
2548 && INTVAL (operands[2]) < 16
2549 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2550 "* return output_simode_bld (1, operands);"
2551 [(set_attr "cc" "clobber")
2552 (set_attr "length" "8")])
2553
2554 (define_insn "*extzv_1_r_inv_h8300hs"
2555 [(set (match_operand:SI 0 "register_operand" "=r,r")
2556 (zero_extract:SI (xor:SI (match_operand:SI 1 "register_operand" "?0,r")
2557 (match_operand 3 "const_int_operand" "n,n"))
2558 (const_int 1)
2559 (match_operand 2 "const_int_operand" "n,n")))]
2560 "(TARGET_H8300H || TARGET_H8300S)
2561 && INTVAL (operands[2]) < 16
2562 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2563 "* return output_simode_bld (1, operands);"
2564 [(set_attr "cc" "clobber,clobber")
2565 (set_attr "length" "8,6")])
2566
2567 (define_expand "insv"
2568 [(set (zero_extract:HI (match_operand:HI 0 "general_operand" "")
2569 (match_operand:HI 1 "general_operand" "")
2570 (match_operand:HI 2 "general_operand" ""))
2571 (match_operand:HI 3 "general_operand" ""))]
2572 "TARGET_H8300"
2573 "
2574 {
2575 /* We only have single bit bit-field instructions. */
2576 if (INTVAL (operands[1]) != 1)
2577 FAIL;
2578
2579 /* For now, we don't allow memory operands. */
2580 if (GET_CODE (operands[0]) == MEM
2581 || GET_CODE (operands[3]) == MEM)
2582 FAIL;
2583 }")
2584
2585 (define_insn ""
2586 [(set (zero_extract:HI (match_operand:HI 0 "register_operand" "+r")
2587 (const_int 1)
2588 (match_operand:HI 1 "immediate_operand" "n"))
2589 (match_operand:HI 2 "register_operand" "r"))]
2590 ""
2591 "bld #0,%R2\;bst %Z1,%Y0 ; i1"
2592 [(set_attr "cc" "clobber")
2593 (set_attr "length" "4")])
2594
2595 (define_expand "extzv"
2596 [(set (match_operand:HI 0 "register_operand" "")
2597 (zero_extract:HI (match_operand:HI 1 "bit_operand" "")
2598 (match_operand:HI 2 "general_operand" "")
2599 (match_operand:HI 3 "general_operand" "")))]
2600 "TARGET_H8300"
2601 "
2602 {
2603 /* We only have single bit bit-field instructions. */
2604 if (INTVAL (operands[2]) != 1)
2605 FAIL;
2606
2607 /* For now, we don't allow memory operands. */
2608 if (GET_CODE (operands[1]) == MEM)
2609 FAIL;
2610 }")
2611
2612 ;; BAND, BOR, and BXOR patterns
2613
2614 (define_insn ""
2615 [(set (match_operand:HI 0 "bit_operand" "=Ur")
2616 (match_operator:HI 4 "bit_operator"
2617 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2618 (const_int 1)
2619 (match_operand:HI 2 "immediate_operand" "n"))
2620 (match_operand:HI 3 "bit_operand" "0")]))]
2621 ""
2622 "bld %Z2,%Y1\;%b4 #0,%R0\;bst #0,%R0; bl1"
2623 [(set_attr "cc" "clobber")
2624 (set_attr "length" "6")
2625 (set_attr "adjust_length" "no")])
2626
2627 (define_insn ""
2628 [(set (match_operand:HI 0 "bit_operand" "=Ur")
2629 (match_operator:HI 5 "bit_operator"
2630 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2631 (const_int 1)
2632 (match_operand:HI 2 "immediate_operand" "n"))
2633 (zero_extract:HI (match_operand:HI 3 "register_operand" "r")
2634 (const_int 1)
2635 (match_operand:HI 4 "immediate_operand" "n"))]))]
2636 ""
2637 "bld %Z2,%Y1\;%b5 %Z4,%Y3\;bst #0,%R0; bl3"
2638 [(set_attr "cc" "clobber")
2639 (set_attr "length" "6")
2640 (set_attr "adjust_length" "no")])
2641 \f
2642 ;; -----------------------------------------------------------------
2643 ;; COMBINE PATTERNS
2644 ;; -----------------------------------------------------------------
2645
2646 ;; insv:SI
2647
2648 (define_insn "*insv_si_1_n"
2649 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
2650 (const_int 1)
2651 (match_operand:SI 1 "const_int_operand" "n"))
2652 (match_operand:SI 2 "register_operand" "r"))]
2653 "(TARGET_H8300H || TARGET_H8300S)
2654 && INTVAL (operands[1]) < 16"
2655 "bld\\t#0,%w2\;bst\\t%Z1,%Y0"
2656 [(set_attr "cc" "clobber")
2657 (set_attr "length" "4")])
2658
2659 (define_insn "*insv_si_1_n_lshiftrt"
2660 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
2661 (const_int 1)
2662 (match_operand:SI 1 "const_int_operand" "n"))
2663 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
2664 (match_operand:SI 3 "const_int_operand" "n")))]
2665 "(TARGET_H8300H || TARGET_H8300S)
2666 && INTVAL (operands[1]) < 16
2667 && INTVAL (operands[3]) < 16"
2668 "bld\\t%Z3,%Y2\;bst\\t%Z1,%Y0"
2669 [(set_attr "cc" "clobber")
2670 (set_attr "length" "4")])
2671
2672 (define_insn "*insv_si_1_n_lshiftrt_16"
2673 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
2674 (const_int 1)
2675 (match_operand:SI 1 "const_int_operand" "n"))
2676 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
2677 (const_int 16)))]
2678 "(TARGET_H8300H || TARGET_H8300S)
2679 && INTVAL (operands[1]) < 16"
2680 "rotr.w\\t%e2\;rotl.w\\t%e2\;bst\\t%Z1,%Y0"
2681 [(set_attr "cc" "clobber")
2682 (set_attr "length" "6")])
2683
2684 (define_insn "*insv_si_8_8"
2685 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
2686 (const_int 8)
2687 (const_int 8))
2688 (match_operand:SI 1 "register_operand" "r"))]
2689 "TARGET_H8300H || TARGET_H8300S"
2690 "mov.b\\t%w1,%x0"
2691 [(set_attr "cc" "clobber")
2692 (set_attr "length" "2")])
2693
2694 (define_insn "*insv_si_8_8_lshiftrt_8"
2695 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
2696 (const_int 8)
2697 (const_int 8))
2698 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2699 (const_int 8)))]
2700 "TARGET_H8300H || TARGET_H8300S"
2701 "mov.b\\t%x1,%x0"
2702 [(set_attr "cc" "clobber")
2703 (set_attr "length" "2")])
2704
2705 ;; extzv:SI
2706
2707 (define_insn "*extzv_8_8"
2708 [(set (match_operand:SI 0 "register_operand" "=r,r")
2709 (zero_extract:SI (match_operand:SI 1 "register_operand" "?0,r")
2710 (const_int 8)
2711 (const_int 8)))]
2712 "TARGET_H8300H || TARGET_H8300S"
2713 "@
2714 mov.b\\t%x1,%w0\;extu.w\\t%f0\;extu.l\\t%S0
2715 sub.l\\t%S0,%S0\;mov.b\\t%x1,%w0"
2716 [(set_attr "cc" "set_znv,clobber")
2717 (set_attr "length" "6,4")])
2718
2719 (define_insn "*extzv_8_16"
2720 [(set (match_operand:SI 0 "register_operand" "=r")
2721 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2722 (const_int 8)
2723 (const_int 16)))]
2724 "TARGET_H8300H || TARGET_H8300S"
2725 "mov.w\\t%e1,%f0\;extu.w\\t%f0\;extu.l\\t%S0"
2726 [(set_attr "cc" "set_znv")
2727 (set_attr "length" "6")])
2728
2729 (define_insn "*extzv_16_8"
2730 [(set (match_operand:SI 0 "register_operand" "=r")
2731 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2732 (const_int 16)
2733 (const_int 8)))
2734 (clobber (match_scratch:SI 2 "=&r"))]
2735 "TARGET_H8300H"
2736 "mov.w\\t%e1,%f2\;mov.b\\t%x1,%w0\;mov.b\\t%w2,%x0\;extu.l\\t%S0"
2737 [(set_attr "length" "8")
2738 (set_attr "cc" "set_znv")])
2739
2740 ;; Extract the exponent of a float.
2741
2742 (define_insn_and_split "*extzv_8_23"
2743 [(set (match_operand:SI 0 "register_operand" "=r")
2744 (zero_extract:SI (match_operand:SI 1 "register_operand" "0")
2745 (const_int 8)
2746 (const_int 23)))]
2747 "(TARGET_H8300H || TARGET_H8300S)"
2748 "#"
2749 "&& reload_completed"
2750 [(parallel [(set (match_dup 0)
2751 (ashift:SI (match_dup 0)
2752 (const_int 1)))
2753 (clobber (scratch:QI))])
2754 (parallel [(set (match_dup 0)
2755 (lshiftrt:SI (match_dup 0)
2756 (const_int 24)))
2757 (clobber (scratch:QI))])]
2758 "")
2759
2760 ;; and:SI
2761
2762 ;; ((SImode) HImode) << 15
2763
2764 (define_insn_and_split "*twoshifts_l16_r1"
2765 [(set (match_operand:SI 0 "register_operand" "=r")
2766 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
2767 (const_int 15))
2768 (const_int 2147450880)))]
2769 "(TARGET_H8300H || TARGET_H8300S)"
2770 "#"
2771 "&& reload_completed"
2772 [(parallel [(set (match_dup 0)
2773 (ashift:SI (match_dup 0)
2774 (const_int 16)))
2775 (clobber (scratch:QI))])
2776 (parallel [(set (match_dup 0)
2777 (lshiftrt:SI (match_dup 0)
2778 (const_int 1)))
2779 (clobber (scratch:QI))])]
2780 "")
2781
2782 ;; Transform (SImode << B) & 0xffff into (SImode) (HImode << B).
2783
2784 (define_insn_and_split "*andsi3_ashift_n_lower"
2785 [(set (match_operand:SI 0 "register_operand" "=r,r")
2786 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0,0")
2787 (match_operand:QI 2 "const_int_operand" "S,n"))
2788 (match_operand:SI 3 "const_int_operand" "n,n")))
2789 (clobber (match_scratch:QI 4 "=X,&r"))]
2790 "(TARGET_H8300H || TARGET_H8300S)
2791 && INTVAL (operands[2]) <= 15
2792 && INTVAL (operands[3]) == ((-1 << INTVAL (operands[2])) & 0xffff)"
2793 "#"
2794 "&& reload_completed"
2795 [(parallel [(set (match_dup 5)
2796 (ashift:HI (match_dup 5)
2797 (match_dup 2)))
2798 (clobber (match_dup 4))])
2799 (set (match_dup 0)
2800 (zero_extend:SI (match_dup 5)))]
2801 "operands[5] = gen_rtx_REG (HImode, REGNO (operands[0]));")
2802
2803 ;; Accept (A >> 30) & 2 and the like.
2804
2805 (define_insn "*andsi3_lshiftrt_n_sb"
2806 [(set (match_operand:SI 0 "register_operand" "=r")
2807 (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
2808 (match_operand:SI 2 "const_int_operand" "n"))
2809 (match_operand:SI 3 "single_one_operand" "n")))]
2810 "(TARGET_H8300H || TARGET_H8300S)
2811 && exact_log2 (INTVAL (operands[3])) < 16
2812 && INTVAL (operands[2]) + exact_log2 (INTVAL (operands[3])) == 31"
2813 "*
2814 {
2815 operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
2816 return \"shll.l\\t%S0\;xor.l\\t%S0,%S0\;bst\\t%Z3,%Y0\";
2817 }"
2818 [(set_attr "length" "8")
2819 (set_attr "cc" "clobber")])
2820
2821 (define_insn_and_split "*andsi3_lshiftrt_9_sb"
2822 [(set (match_operand:SI 0 "register_operand" "=r")
2823 (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
2824 (const_int 9))
2825 (const_int 4194304)))]
2826 "(TARGET_H8300H || TARGET_H8300S)"
2827 "#"
2828 "&& reload_completed"
2829 [(set (match_dup 0)
2830 (and:SI (lshiftrt:SI (match_dup 0)
2831 (const_int 25))
2832 (const_int 64)))
2833 (parallel [(set (match_dup 0)
2834 (ashift:SI (match_dup 0)
2835 (const_int 16)))
2836 (clobber (scratch:QI))])]
2837 "")
2838
2839 ;; plus:SI
2840
2841 (define_insn "*addsi3_upper"
2842 [(set (match_operand:SI 0 "register_operand" "=r")
2843 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
2844 (const_int 65536))
2845 (match_operand:SI 2 "register_operand" "0")))]
2846 "TARGET_H8300H || TARGET_H8300S"
2847 "add.w\\t%f1,%e0"
2848 [(set_attr "length" "2")
2849 (set_attr "cc" "clobber")])
2850
2851 (define_insn "*addsi3_lshiftrt_16_zexthi"
2852 [(set (match_operand:SI 0 "register_operand" "=r")
2853 (plus:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2854 (const_int 16))
2855 (zero_extend:SI (match_operand:HI 2 "register_operand" "0"))))]
2856 "TARGET_H8300H || TARGET_H8300S"
2857 "add.w\\t%e1,%f0\;xor.w\\t%e0,%e0\;rotxl.w\\t%e0,%e0"
2858 [(set_attr "cc" "clobber")
2859 (set_attr "length" "6")])
2860
2861 (define_insn_and_split "*addsi3_and_r_1"
2862 [(set (match_operand:SI 0 "register_operand" "=r")
2863 (plus:SI (and:SI (match_operand:SI 1 "register_operand" "r")
2864 (const_int 1))
2865 (match_operand:SI 2 "register_operand" "0")))]
2866 "(TARGET_H8300H || TARGET_H8300S)"
2867 "#"
2868 "&& reload_completed"
2869 [(set (cc0)
2870 (zero_extract:SI (match_dup 1)
2871 (const_int 1)
2872 (const_int 0)))
2873 (set (pc)
2874 (if_then_else (eq (cc0)
2875 (const_int 0))
2876 (label_ref (match_dup 3))
2877 (pc)))
2878 (set (match_dup 2)
2879 (plus:SI (match_dup 2)
2880 (const_int 1)))
2881 (match_dup 3)]
2882 "operands[3] = gen_label_rtx ();")
2883
2884 (define_insn_and_split "*addsi3_and_not_r_1"
2885 [(set (match_operand:SI 0 "register_operand" "=r")
2886 (plus:SI (and:SI (not:SI (match_operand:SI 1 "register_operand" "r"))
2887 (const_int 1))
2888 (match_operand:SI 2 "register_operand" "0")))]
2889 "(TARGET_H8300H || TARGET_H8300S)"
2890 "#"
2891 "&& reload_completed"
2892 [(set (cc0)
2893 (zero_extract:SI (match_dup 1)
2894 (const_int 1)
2895 (const_int 0)))
2896 (set (pc)
2897 (if_then_else (ne (cc0)
2898 (const_int 0))
2899 (label_ref (match_dup 3))
2900 (pc)))
2901 (set (match_dup 2)
2902 (plus:SI (match_dup 2)
2903 (const_int 1)))
2904 (match_dup 3)]
2905 "operands[3] = gen_label_rtx ();")
2906
2907 ;; [ix]or:HI
2908
2909 (define_insn "*ixorhi3_zext"
2910 [(set (match_operand:HI 0 "register_operand" "=r")
2911 (match_operator:HI 1 "iorxor_operator"
2912 [(zero_extend:HI (match_operand:QI 2 "register_operand" "r"))
2913 (match_operand:HI 3 "register_operand" "0")]))]
2914 ""
2915 "%c1.b\\t%X2,%s0"
2916 [(set_attr "cc" "clobber")
2917 (set_attr "length" "2")])
2918
2919 ;; [ix]or:SI
2920
2921 (define_insn "*ixorsi3_zext_qi"
2922 [(set (match_operand:SI 0 "register_operand" "=r")
2923 (match_operator:SI 1 "iorxor_operator"
2924 [(zero_extend:SI (match_operand:QI 2 "register_operand" "r"))
2925 (match_operand:SI 3 "register_operand" "0")]))]
2926 ""
2927 "%c1.b\\t%X2,%w0"
2928 [(set_attr "cc" "clobber")
2929 (set_attr "length" "2")])
2930
2931 (define_insn "*ixorsi3_zext_hi"
2932 [(set (match_operand:SI 0 "register_operand" "=r")
2933 (match_operator:SI 1 "iorxor_operator"
2934 [(zero_extend:SI (match_operand:HI 2 "register_operand" "r"))
2935 (match_operand:SI 3 "register_operand" "0")]))]
2936 "TARGET_H8300H || TARGET_H8300S"
2937 "%c1.w\\t%T2,%f0"
2938 [(set_attr "cc" "clobber")
2939 (set_attr "length" "2")])
2940
2941 (define_insn "*ixorsi3_ashift_16"
2942 [(set (match_operand:SI 0 "register_operand" "=r")
2943 (match_operator:SI 1 "iorxor_operator"
2944 [(ashift:SI (match_operand:SI 2 "register_operand" "r")
2945 (const_int 16))
2946 (match_operand:SI 3 "register_operand" "0")]))]
2947 "TARGET_H8300H || TARGET_H8300S"
2948 "%c1.w\\t%f2,%e0"
2949 [(set_attr "cc" "clobber")
2950 (set_attr "length" "2")])
2951
2952 (define_insn "*ixorsi3_lshiftrt_16"
2953 [(set (match_operand:SI 0 "register_operand" "=r")
2954 (match_operator:SI 1 "iorxor_operator"
2955 [(lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
2956 (const_int 16))
2957 (match_operand:SI 3 "register_operand" "0")]))]
2958 "TARGET_H8300H || TARGET_H8300S"
2959 "%c1.w\\t%e2,%f0"
2960 [(set_attr "cc" "clobber")
2961 (set_attr "length" "2")])
2962
2963 ;; ior:HI
2964
2965 (define_insn "*iorhi3_ashift_8"
2966 [(set (match_operand:HI 0 "register_operand" "=r")
2967 (ior:HI (ashift:HI (match_operand:HI 1 "register_operand" "r")
2968 (const_int 8))
2969 (match_operand:HI 2 "register_operand" "0")))]
2970 ""
2971 "or.b\\t%s1,%t0"
2972 [(set_attr "cc" "clobber")
2973 (set_attr "length" "2")])
2974
2975 (define_insn "*iorhi3_lshiftrt_8"
2976 [(set (match_operand:HI 0 "register_operand" "=r")
2977 (ior:HI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
2978 (const_int 8))
2979 (match_operand:HI 2 "register_operand" "0")))]
2980 ""
2981 "or.b\\t%t1,%s0"
2982 [(set_attr "cc" "clobber")
2983 (set_attr "length" "2")])
2984
2985 (define_insn "*iorhi3_two_qi"
2986 [(set (match_operand:HI 0 "register_operand" "=r")
2987 (ior:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
2988 (ashift:HI (match_operand:HI 2 "register_operand" "r")
2989 (const_int 8))))]
2990 ""
2991 "mov.b\\t%s2,%t0"
2992 [(set_attr "cc" "clobber")
2993 (set_attr "length" "2")])
2994
2995 (define_insn "*iorhi3_two_qi_mem"
2996 [(set (match_operand:HI 0 "register_operand" "=&r")
2997 (ior:HI (zero_extend:HI (match_operand:QI 1 "memory_operand" "m"))
2998 (ashift:HI (subreg:HI (match_operand:QI 2 "memory_operand" "m") 0)
2999 (const_int 8))))]
3000 ""
3001 "mov.b\\t%X2,%t0\;mov.b\\t%X1,%s0"
3002 [(set_attr "cc" "clobber")
3003 (set_attr "length" "16")])
3004
3005 (define_split
3006 [(set (match_operand:HI 0 "register_operand" "")
3007 (ior:HI (zero_extend:HI (match_operand:QI 1 "memory_operand" ""))
3008 (ashift:HI (subreg:HI (match_operand:QI 2 "memory_operand" "") 0)
3009 (const_int 8))))]
3010 "(TARGET_H8300H || TARGET_H8300S)
3011 && reload_completed
3012 && byte_accesses_mergeable_p (XEXP (operands[2], 0), XEXP (operands[1], 0))"
3013 [(set (match_dup 0)
3014 (match_dup 3))]
3015 "operands[3] = gen_rtx_MEM (HImode, XEXP (operands[2], 0));")
3016
3017 ;; ior:SI
3018
3019 (define_insn "*iorsi3_two_hi"
3020 [(set (match_operand:SI 0 "register_operand" "=r")
3021 (ior:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "0"))
3022 (ashift:SI (match_operand:SI 2 "register_operand" "r")
3023 (const_int 16))))]
3024 "TARGET_H8300H || TARGET_H8300S"
3025 "mov.w\\t%f2,%e0"
3026 [(set_attr "cc" "clobber")
3027 (set_attr "length" "2")])
3028
3029 (define_insn_and_split "*iorsi3_two_qi_zext"
3030 [(set (match_operand:SI 0 "register_operand" "=&r")
3031 (ior:SI (zero_extend:SI (match_operand:QI 1 "memory_operand" "m"))
3032
3033 (and:SI (ashift:SI (subreg:SI (match_operand:QI 2 "memory_operand" "m") 0)
3034 (const_int 8))
3035 (const_int 65280))))]
3036 "(TARGET_H8300H || TARGET_H8300S)"
3037 "#"
3038 "&& reload_completed"
3039 [(set (match_dup 3)
3040 (ior:HI (zero_extend:HI (match_dup 1))
3041 (ashift:HI (subreg:HI (match_dup 2) 0)
3042 (const_int 8))))
3043 (set (match_dup 0)
3044 (zero_extend:SI (match_dup 3)))]
3045 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));")
3046
3047 (define_insn "*iorsi3_e2f"
3048 [(set (match_operand:SI 0 "register_operand" "=r")
3049 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0")
3050 (const_int -65536))
3051 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
3052 (const_int 16))))]
3053 "TARGET_H8300H || TARGET_H8300S"
3054 "mov.w\\t%e2,%f0"
3055 [(set_attr "length" "2")
3056 (set_attr "cc" "clobber")])
3057
3058 (define_insn_and_split "*iorsi3_two_qi_sext"
3059 [(set (match_operand:SI 0 "register_operand" "=r")
3060 (ior:SI (zero_extend:SI (match_operand:QI 1 "register_operand" "0"))
3061 (ashift:SI (sign_extend:SI (match_operand:QI 2 "register_operand" "r"))
3062 (const_int 8))))]
3063 "(TARGET_H8300H || TARGET_H8300S)"
3064 "#"
3065 "&& reload_completed"
3066 [(set (match_dup 3)
3067 (ior:HI (zero_extend:HI (match_dup 1))
3068 (ashift:HI (match_dup 4)
3069 (const_int 8))))
3070 (set (match_dup 0)
3071 (sign_extend:SI (match_dup 3)))]
3072 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
3073 operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));")
3074
3075 (define_insn "*iorsi3_w"
3076 [(set (match_operand:SI 0 "register_operand" "=r,&r")
3077 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0,0")
3078 (const_int -256))
3079 (zero_extend:SI (match_operand:QI 2 "general_operand_src" "r,g>"))))]
3080 "TARGET_H8300H || TARGET_H8300S"
3081 "mov.b\\t%X2,%w0"
3082 [(set_attr "length" "2,8")
3083 (set_attr "cc" "clobber,clobber")])
3084
3085 (define_insn "*iorsi3_ashift_31"
3086 [(set (match_operand:SI 0 "register_operand" "=&r")
3087 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
3088 (const_int 31))
3089 (match_operand:SI 2 "register_operand" "0")))]
3090 "TARGET_H8300H || TARGET_H8300S"
3091 "rotxl.l\\t%S0\;bor\\t#0,%w1\;rotxr.l\\t%S0"
3092 [(set_attr "length" "6")
3093 (set_attr "cc" "set_znv")])
3094
3095 (define_insn "*iorsi3_and_ashift"
3096 [(set (match_operand:SI 0 "register_operand" "=r")
3097 (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
3098 (match_operand:SI 2 "const_int_operand" "n"))
3099 (match_operand:SI 3 "single_one_operand" "n"))
3100 (match_operand:SI 4 "register_operand" "0")))]
3101 "(TARGET_H8300H || TARGET_H8300S)
3102 && (INTVAL (operands[3]) & ~0xffff) == 0"
3103 "*
3104 {
3105 rtx srcpos = GEN_INT (exact_log2 (INTVAL (operands[3]))
3106 - INTVAL (operands[2]));
3107 rtx dstpos = GEN_INT (exact_log2 (INTVAL (operands[3])));
3108 operands[2] = srcpos;
3109 operands[3] = dstpos;
3110 return \"bld\\t%Z2,%Y1\;bor\\t%Z3,%Y0\;bst\\t%Z3,%Y0\";
3111 }"
3112 [(set_attr "length" "6")
3113 (set_attr "cc" "clobber")])
3114
3115 (define_insn "*iorsi3_and_lshiftrt"
3116 [(set (match_operand:SI 0 "register_operand" "=r")
3117 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3118 (match_operand:SI 2 "const_int_operand" "n"))
3119 (match_operand:SI 3 "single_one_operand" "n"))
3120 (match_operand:SI 4 "register_operand" "0")))]
3121 "(TARGET_H8300H || TARGET_H8300S)
3122 && ((INTVAL (operands[3]) << INTVAL (operands[2])) & ~0xffff) == 0"
3123 "*
3124 {
3125 rtx srcpos = GEN_INT (exact_log2 (INTVAL (operands[3]))
3126 + INTVAL (operands[2]));
3127 rtx dstpos = GEN_INT (exact_log2 (INTVAL (operands[3])));
3128 operands[2] = srcpos;
3129 operands[3] = dstpos;
3130 return \"bld\\t%Z2,%Y1\;bor\\t%Z3,%Y0\;bst\\t%Z3,%Y0\";
3131 }"
3132 [(set_attr "length" "6")
3133 (set_attr "cc" "clobber")])
3134
3135 (define_insn "*iorsi3_zero_extract"
3136 [(set (match_operand:SI 0 "register_operand" "=r")
3137 (ior:SI (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
3138 (const_int 1)
3139 (match_operand:SI 2 "const_int_operand" "n"))
3140 (match_operand:SI 3 "register_operand" "0")))]
3141 "(TARGET_H8300H || TARGET_H8300S)
3142 && INTVAL (operands[2]) < 16"
3143 "bld\\t%Z2,%Y1\;bor\\t#0,%w0\;bst\\t#0,%w0"
3144 [(set_attr "length" "6")
3145 (set_attr "cc" "clobber")])
3146
3147 (define_insn "*iorsi3_and_lshiftrt_n_sb"
3148 [(set (match_operand:SI 0 "register_operand" "=r")
3149 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3150 (const_int 30))
3151 (const_int 2))
3152 (match_operand:SI 2 "register_operand" "0")))]
3153 "(TARGET_H8300H || TARGET_H8300S)"
3154 "rotl.l\\t%S1\;rotr.l\\t%S1\;bor\\t#1,%w0\;bst\\t#1,%w0"
3155 [(set_attr "length" "8")
3156 (set_attr "cc" "clobber")])
3157
3158 (define_insn "*iorsi3_and_lshiftrt_9_sb"
3159 [(set (match_operand:SI 0 "register_operand" "=r")
3160 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3161 (const_int 9))
3162 (const_int 4194304))
3163 (match_operand:SI 2 "register_operand" "0")))
3164 (clobber (match_scratch:HI 3 "=&r"))]
3165 "(TARGET_H8300H || TARGET_H8300S)"
3166 "*
3167 {
3168 if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
3169 return \"shll.l\\t%S1\;xor.w\\t%T3,%T3\;bst\\t#6,%s3\;or.w\\t%T3,%e0\";
3170 else
3171 return \"rotl.l\\t%S1\;rotr.l\\t%S1\;xor.w\\t%T3,%T3\;bst\\t#6,%s3\;or.w\\t%T3,%e0\";
3172 }"
3173 [(set_attr "length" "10")
3174 (set_attr "cc" "clobber")])
3175
3176 ;; Used to OR the exponent of a float.
3177
3178 (define_insn "*iorsi3_shift"
3179 [(set (match_operand:SI 0 "register_operand" "=r")
3180 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
3181 (const_int 23))
3182 (match_operand:SI 2 "register_operand" "0")))
3183 (clobber (match_scratch:SI 3 "=&r"))]
3184 "TARGET_H8300H || TARGET_H8300S"
3185 "#")
3186
3187 (define_split
3188 [(parallel
3189 [(set (match_operand:SI 0 "register_operand" "")
3190 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
3191 (const_int 23))
3192 (match_dup 0)))
3193 (clobber (match_operand:SI 2 "register_operand" ""))])]
3194 "(TARGET_H8300H || TARGET_H8300S)
3195 && flow2_completed
3196 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
3197 && REGNO (operands[0]) != REGNO (operands[1])"
3198 [(parallel [(set (match_dup 3)
3199 (ashift:HI (match_dup 3)
3200 (const_int 7)))
3201 (clobber (scratch:QI))])
3202 (set (match_dup 0)
3203 (ior:SI (ashift:SI (match_dup 1)
3204 (const_int 16))
3205 (match_dup 0)))]
3206 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[1]));")
3207
3208 (define_split
3209 [(parallel
3210 [(set (match_operand:SI 0 "register_operand" "")
3211 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
3212 (const_int 23))
3213 (match_dup 0)))
3214 (clobber (match_operand:SI 2 "register_operand" ""))])]
3215 "(TARGET_H8300H || TARGET_H8300S)
3216 && flow2_completed
3217 && !(find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
3218 && REGNO (operands[0]) != REGNO (operands[1]))"
3219 [(set (match_dup 2)
3220 (match_dup 1))
3221 (parallel [(set (match_dup 3)
3222 (ashift:HI (match_dup 3)
3223 (const_int 7)))
3224 (clobber (scratch:QI))])
3225 (set (match_dup 0)
3226 (ior:SI (ashift:SI (match_dup 2)
3227 (const_int 16))
3228 (match_dup 0)))]
3229 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[2]));")
3230
3231 (define_insn "*iorsi2_and_1_lshiftrt_1"
3232 [(set (match_operand:SI 0 "register_operand" "=r")
3233 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0")
3234 (const_int 1))
3235 (lshiftrt:SI (match_dup 1)
3236 (const_int 1))))]
3237 "TARGET_H8300H || TARGET_H8300S"
3238 "shlr.l\\t%S0\;bor\\t#0,%w0\;bst\\t#0,%w0"
3239 [(set_attr "length" "6")
3240 (set_attr "cc" "clobber")])
3241
3242 (define_insn_and_split "*iorsi3_ashift_16_ashift_24"
3243 [(set (match_operand:SI 0 "register_operand" "=r")
3244 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
3245 (const_int 16))
3246 (ashift:SI (match_operand:SI 2 "register_operand" "r")
3247 (const_int 24))))]
3248 "(TARGET_H8300H || TARGET_H8300S)"
3249 "#"
3250 "&& reload_completed"
3251 [(set (match_dup 3)
3252 (ior:HI (ashift:HI (match_dup 4)
3253 (const_int 8))
3254 (match_dup 3)))
3255 (parallel [(set (match_dup 0)
3256 (ashift:SI (match_dup 0)
3257 (const_int 16)))
3258 (clobber (scratch:QI))])]
3259 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
3260 operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));")
3261
3262 (define_insn_and_split "*iorsi3_ashift_16_ashift_24_mem"
3263 [(set (match_operand:SI 0 "register_operand" "=&r")
3264 (ior:SI (and:SI (ashift:SI (subreg:SI (match_operand:QI 1 "memory_operand" "m") 0)
3265 (const_int 16))
3266 (const_int 16711680))
3267 (ashift:SI (subreg:SI (match_operand:QI 2 "memory_operand" "m") 0)
3268 (const_int 24))))]
3269 "(TARGET_H8300H || TARGET_H8300S)"
3270 "#"
3271 "&& reload_completed"
3272 [(set (match_dup 3)
3273 (ior:HI (zero_extend:HI (match_dup 1))
3274 (ashift:HI (subreg:HI (match_dup 2) 0)
3275 (const_int 8))))
3276 (parallel [(set (match_dup 0)
3277 (ashift:SI (match_dup 0)
3278 (const_int 16)))
3279 (clobber (scratch:QI))])]
3280 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));")
3281
3282 ;; Used to add the exponent of a float.
3283
3284 (define_insn "*addsi3_shift"
3285 [(set (match_operand:SI 0 "register_operand" "=r")
3286 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
3287 (const_int 8388608))
3288 (match_operand:SI 2 "register_operand" "0")))
3289 (clobber (match_scratch:SI 3 "=&r"))]
3290 "TARGET_H8300H || TARGET_H8300S"
3291 "#")
3292
3293 (define_split
3294 [(parallel
3295 [(set (match_operand:SI 0 "register_operand" "")
3296 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
3297 (const_int 8388608))
3298 (match_dup 0)))
3299 (clobber (match_operand:SI 2 "register_operand" ""))])]
3300 "(TARGET_H8300H || TARGET_H8300S)
3301 && flow2_completed
3302 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
3303 && REGNO (operands[0]) != REGNO (operands[1])"
3304 [(parallel [(set (match_dup 3)
3305 (ashift:HI (match_dup 3)
3306 (const_int 7)))
3307 (clobber (scratch:QI))])
3308 (set (match_dup 0)
3309 (plus:SI (mult:SI (match_dup 1)
3310 (const_int 65536))
3311 (match_dup 0)))]
3312 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[1]));")
3313
3314 (define_split
3315 [(parallel
3316 [(set (match_operand:SI 0 "register_operand" "")
3317 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
3318 (const_int 8388608))
3319 (match_dup 0)))
3320 (clobber (match_operand:SI 2 "register_operand" ""))])]
3321 "(TARGET_H8300H || TARGET_H8300S)
3322 && flow2_completed
3323 && !(find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
3324 && REGNO (operands[0]) != REGNO (operands[1]))"
3325 [(set (match_dup 2)
3326 (match_dup 1))
3327 (parallel [(set (match_dup 3)
3328 (ashift:HI (match_dup 3)
3329 (const_int 7)))
3330 (clobber (scratch:QI))])
3331 (set (match_dup 0)
3332 (plus:SI (mult:SI (match_dup 2)
3333 (const_int 65536))
3334 (match_dup 0)))]
3335 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[2]));")
3336
3337 ;; ashift:SI
3338
3339 (define_insn_and_split "*ashiftsi_sextqi_7"
3340 [(set (match_operand:SI 0 "register_operand" "=r")
3341 (ashift:SI (sign_extend:SI (match_operand:QI 1 "register_operand" "0"))
3342 (const_int 7)))]
3343 "(TARGET_H8300H || TARGET_H8300S)"
3344 "#"
3345 "&& reload_completed"
3346 [(parallel [(set (match_dup 2)
3347 (ashift:HI (match_dup 2)
3348 (const_int 8)))
3349 (clobber (scratch:QI))])
3350 (set (match_dup 0)
3351 (sign_extend:SI (match_dup 2)))
3352 (parallel [(set (match_dup 0)
3353 (ashiftrt:SI (match_dup 0)
3354 (const_int 1)))
3355 (clobber (scratch:QI))])]
3356 "operands[2] = gen_rtx_REG (HImode, REGNO (operands[0]));")
3357
3358 ;; Storing a part of HImode to QImode.
3359
3360 (define_insn ""
3361 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
3362 (subreg:QI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
3363 (const_int 8)) 1))]
3364 ""
3365 "mov.b\\t%t1,%R0"
3366 [(set_attr "cc" "set_znv")
3367 (set_attr "length" "8")])
3368
3369 ;; Storing a part of SImode to QImode.
3370
3371 (define_insn ""
3372 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
3373 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3374 (const_int 8)) 3))]
3375 ""
3376 "mov.b\\t%x1,%R0"
3377 [(set_attr "cc" "set_znv")
3378 (set_attr "length" "8")])
3379
3380 (define_insn ""
3381 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
3382 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3383 (const_int 16)) 3))
3384 (clobber (match_scratch:SI 2 "=&r"))]
3385 "TARGET_H8300H || TARGET_H8300S"
3386 "mov.w\\t%e1,%f2\;mov.b\\t%w2,%R0"
3387 [(set_attr "cc" "set_znv")
3388 (set_attr "length" "10")])
3389
3390 (define_insn ""
3391 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
3392 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3393 (const_int 24)) 3))
3394 (clobber (match_scratch:SI 2 "=&r"))]
3395 "TARGET_H8300H || TARGET_H8300S"
3396 "mov.w\\t%e1,%f2\;mov.b\\t%x2,%R0"
3397 [(set_attr "cc" "set_znv")
3398 (set_attr "length" "10")])
3399
3400 (define_insn_and_split ""
3401 [(set (pc)
3402 (if_then_else (eq (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
3403 (const_int 1)
3404 (const_int 7))
3405 (const_int 0))
3406 (label_ref (match_operand 1 "" ""))
3407 (pc)))]
3408 ""
3409 "#"
3410 ""
3411 [(set (cc0)
3412 (match_dup 0))
3413 (set (pc)
3414 (if_then_else (ge (cc0)
3415 (const_int 0))
3416 (label_ref (match_dup 1))
3417 (pc)))]
3418 "")
3419
3420 (define_insn_and_split ""
3421 [(set (pc)
3422 (if_then_else (ne (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
3423 (const_int 1)
3424 (const_int 7))
3425 (const_int 0))
3426 (label_ref (match_operand 1 "" ""))
3427 (pc)))]
3428 ""
3429 "#"
3430 ""
3431 [(set (cc0)
3432 (match_dup 0))
3433 (set (pc)
3434 (if_then_else (lt (cc0)
3435 (const_int 0))
3436 (label_ref (match_dup 1))
3437 (pc)))]
3438 "")
3439 \f
3440 ;; -----------------------------------------------------------------
3441 ;; PEEPHOLE PATTERNS
3442 ;; -----------------------------------------------------------------
3443
3444 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
3445
3446 (define_peephole2
3447 [(parallel
3448 [(set (match_operand:HI 0 "register_operand" "")
3449 (lshiftrt:HI (match_dup 0)
3450 (match_operand:HI 1 "const_int_operand" "")))
3451 (clobber (match_operand:HI 2 "" ""))])
3452 (set (match_dup 0)
3453 (and:HI (match_dup 0)
3454 (match_operand:HI 3 "const_int_operand" "")))]
3455 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
3456 [(set (match_dup 0)
3457 (and:HI (match_dup 0)
3458 (const_int 255)))
3459 (parallel
3460 [(set (match_dup 0)
3461 (lshiftrt:HI (match_dup 0)
3462 (match_dup 1)))
3463 (clobber (match_dup 2))])]
3464 "")
3465
3466 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
3467
3468 (define_peephole2
3469 [(parallel
3470 [(set (match_operand:HI 0 "register_operand" "")
3471 (ashift:HI (match_dup 0)
3472 (match_operand:HI 1 "const_int_operand" "")))
3473 (clobber (match_operand:HI 2 "" ""))])
3474 (set (match_dup 0)
3475 (and:HI (match_dup 0)
3476 (match_operand:HI 3 "const_int_operand" "")))]
3477 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
3478 [(set (match_dup 0)
3479 (and:HI (match_dup 0)
3480 (const_int 255)))
3481 (parallel
3482 [(set (match_dup 0)
3483 (ashift:HI (match_dup 0)
3484 (match_dup 1)))
3485 (clobber (match_dup 2))])]
3486 "")
3487
3488 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
3489
3490 (define_peephole2
3491 [(parallel
3492 [(set (match_operand:SI 0 "register_operand" "")
3493 (lshiftrt:SI (match_dup 0)
3494 (match_operand:SI 1 "const_int_operand" "")))
3495 (clobber (match_operand:SI 2 "" ""))])
3496 (set (match_dup 0)
3497 (and:SI (match_dup 0)
3498 (match_operand:SI 3 "const_int_operand" "")))]
3499 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
3500 [(set (match_dup 0)
3501 (and:SI (match_dup 0)
3502 (const_int 255)))
3503 (parallel
3504 [(set (match_dup 0)
3505 (lshiftrt:SI (match_dup 0)
3506 (match_dup 1)))
3507 (clobber (match_dup 2))])]
3508 "")
3509
3510 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
3511
3512 (define_peephole2
3513 [(parallel
3514 [(set (match_operand:SI 0 "register_operand" "")
3515 (ashift:SI (match_dup 0)
3516 (match_operand:SI 1 "const_int_operand" "")))
3517 (clobber (match_operand:SI 2 "" ""))])
3518 (set (match_dup 0)
3519 (and:SI (match_dup 0)
3520 (match_operand:SI 3 "const_int_operand" "")))]
3521 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
3522 [(set (match_dup 0)
3523 (and:SI (match_dup 0)
3524 (const_int 255)))
3525 (parallel
3526 [(set (match_dup 0)
3527 (ashift:SI (match_dup 0)
3528 (match_dup 1)))
3529 (clobber (match_dup 2))])]
3530 "")
3531
3532 ;; Convert (A >> B) & C to (A & 65535) >> B if C == 65535 >> B.
3533
3534 (define_peephole2
3535 [(parallel
3536 [(set (match_operand:SI 0 "register_operand" "")
3537 (lshiftrt:SI (match_dup 0)
3538 (match_operand:SI 1 "const_int_operand" "")))
3539 (clobber (match_operand:SI 2 "" ""))])
3540 (set (match_dup 0)
3541 (and:SI (match_dup 0)
3542 (match_operand:SI 3 "const_int_operand" "")))]
3543 "INTVAL (operands[3]) == (65535 >> INTVAL (operands[1]))"
3544 [(set (match_dup 0)
3545 (and:SI (match_dup 0)
3546 (const_int 65535)))
3547 (parallel
3548 [(set (match_dup 0)
3549 (lshiftrt:SI (match_dup 0)
3550 (match_dup 1)))
3551 (clobber (match_dup 2))])]
3552 "")
3553
3554 ;; Convert (A << B) & C to (A & 65535) << B if C == 65535 << B.
3555
3556 (define_peephole2
3557 [(parallel
3558 [(set (match_operand:SI 0 "register_operand" "")
3559 (ashift:SI (match_dup 0)
3560 (match_operand:SI 1 "const_int_operand" "")))
3561 (clobber (match_operand:SI 2 "" ""))])
3562 (set (match_dup 0)
3563 (and:SI (match_dup 0)
3564 (match_operand:SI 3 "const_int_operand" "")))]
3565 "INTVAL (operands[3]) == (65535 << INTVAL (operands[1]))"
3566 [(set (match_dup 0)
3567 (and:SI (match_dup 0)
3568 (const_int 65535)))
3569 (parallel
3570 [(set (match_dup 0)
3571 (ashift:SI (match_dup 0)
3572 (match_dup 1)))
3573 (clobber (match_dup 2))])]
3574 "")
3575
3576 ;; Convert a QImode push into an SImode push so that the
3577 ;; define_peephole2 below can cram multiple pushes into one stm.l.
3578
3579 (define_peephole2
3580 [(parallel [(set (reg:SI SP_REG)
3581 (plus:SI (reg:SI SP_REG) (const_int -4)))
3582 (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
3583 (match_operand:QI 0 "register_operand" ""))])]
3584 "TARGET_H8300S"
3585 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3586 (match_dup 0))]
3587 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
3588
3589 ;; Convert a HImode push into an SImode push so that the
3590 ;; define_peephole2 below can cram multiple pushes into one stm.l.
3591
3592 (define_peephole2
3593 [(parallel [(set (reg:SI SP_REG)
3594 (plus:SI (reg:SI SP_REG) (const_int -4)))
3595 (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
3596 (match_operand:HI 0 "register_operand" ""))])]
3597 "TARGET_H8300S"
3598 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3599 (match_dup 0))]
3600 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
3601
3602 ;; Cram four pushes into stm.l.
3603
3604 (define_peephole2
3605 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3606 (match_operand:SI 0 "register_operand" ""))
3607 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3608 (match_operand:SI 1 "register_operand" ""))
3609 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3610 (match_operand:SI 2 "register_operand" ""))
3611 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3612 (match_operand:SI 3 "register_operand" ""))]
3613 "TARGET_H8300S
3614 && REGNO (operands[0]) == 0
3615 && REGNO (operands[1]) == 1
3616 && REGNO (operands[2]) == 2
3617 && REGNO (operands[3]) == 3"
3618 [(parallel [(set (reg:SI SP_REG)
3619 (plus:SI (reg:SI SP_REG)
3620 (const_int -16)))
3621 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
3622 (match_dup 0))
3623 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
3624 (match_dup 1))
3625 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
3626 (match_dup 2))
3627 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
3628 (match_dup 3))])]
3629 "")
3630
3631 ;; Cram three pushes into stm.l.
3632
3633 (define_peephole2
3634 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3635 (match_operand:SI 0 "register_operand" ""))
3636 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3637 (match_operand:SI 1 "register_operand" ""))
3638 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3639 (match_operand:SI 2 "register_operand" ""))]
3640 "TARGET_H8300S
3641 && ((REGNO (operands[0]) == 0
3642 && REGNO (operands[1]) == 1
3643 && REGNO (operands[2]) == 2)
3644 || (REGNO (operands[0]) == 4
3645 && REGNO (operands[1]) == 5
3646 && REGNO (operands[2]) == 6))"
3647 [(parallel [(set (reg:SI SP_REG)
3648 (plus:SI (reg:SI SP_REG)
3649 (const_int -12)))
3650 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
3651 (match_dup 0))
3652 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
3653 (match_dup 1))
3654 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
3655 (match_dup 2))])]
3656 "")
3657
3658 ;; Cram two pushes into stm.l.
3659
3660 (define_peephole2
3661 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3662 (match_operand:SI 0 "register_operand" ""))
3663 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
3664 (match_operand:SI 1 "register_operand" ""))]
3665 "TARGET_H8300S
3666 && ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
3667 || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
3668 || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5))"
3669 [(parallel [(set (reg:SI SP_REG)
3670 (plus:SI (reg:SI SP_REG)
3671 (const_int -8)))
3672 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
3673 (match_dup 0))
3674 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
3675 (match_dup 1))])]
3676 "")
3677
3678 ;; Turn
3679 ;;
3680 ;; mov.w #2,r0
3681 ;; add.w r7,r0 (6 bytes)
3682 ;;
3683 ;; into
3684 ;;
3685 ;; mov.w r7,r0
3686 ;; adds #2,r0 (4 bytes)
3687
3688 (define_peephole2
3689 [(set (match_operand:HI 0 "register_operand" "")
3690 (match_operand:HI 1 "const_int_operand" ""))
3691 (set (match_dup 0)
3692 (plus:HI (match_dup 0)
3693 (match_operand:HI 2 "register_operand" "")))]
3694 "REG_P (operands[0]) && REG_P (operands[2])
3695 && REGNO (operands[0]) != REGNO (operands[2])
3696 && (CONST_OK_FOR_J (INTVAL (operands[1]))
3697 || CONST_OK_FOR_L (INTVAL (operands[1]))
3698 || CONST_OK_FOR_N (INTVAL (operands[1])))"
3699 [(set (match_dup 0)
3700 (match_dup 2))
3701 (set (match_dup 0)
3702 (plus:HI (match_dup 0)
3703 (match_dup 1)))]
3704 "")
3705
3706 ;; Turn
3707 ;;
3708 ;; sub.l er0,er0
3709 ;; add.b #4,r0l
3710 ;; add.l er7,er0 (6 bytes)
3711 ;;
3712 ;; into
3713 ;;
3714 ;; mov.l er7,er0
3715 ;; adds #4,er0 (4 bytes)
3716
3717 (define_peephole2
3718 [(set (match_operand:SI 0 "register_operand" "")
3719 (match_operand:SI 1 "const_int_operand" ""))
3720 (set (match_dup 0)
3721 (plus:SI (match_dup 0)
3722 (match_operand:SI 2 "register_operand" "")))]
3723 "(TARGET_H8300H || TARGET_H8300S)
3724 && REG_P (operands[0]) && REG_P (operands[2])
3725 && REGNO (operands[0]) != REGNO (operands[2])
3726 && (CONST_OK_FOR_L (INTVAL (operands[1]))
3727 || CONST_OK_FOR_N (INTVAL (operands[1])))"
3728 [(set (match_dup 0)
3729 (match_dup 2))
3730 (set (match_dup 0)
3731 (plus:SI (match_dup 0)
3732 (match_dup 1)))]
3733 "")
3734
3735 ;; Turn
3736 ;;
3737 ;; mov.l er7,er0
3738 ;; add.l #10,er0 (takes 8 bytes)
3739 ;;
3740 ;; into
3741 ;;
3742 ;; sub.l er0,er0
3743 ;; add.b #10,r0l
3744 ;; add.l er7,er0 (takes 6 bytes)
3745
3746 (define_peephole2
3747 [(set (match_operand:SI 0 "register_operand" "")
3748 (match_operand:SI 1 "register_operand" ""))
3749 (set (match_dup 0)
3750 (plus:SI (match_dup 0)
3751 (match_operand:SI 2 "const_int_operand" "")))]
3752 "(TARGET_H8300H || TARGET_H8300S)
3753 && REG_P (operands[0]) && REG_P (operands[1])
3754 && REGNO (operands[0]) != REGNO (operands[1])
3755 && !CONST_OK_FOR_L (INTVAL (operands[2]))
3756 && !CONST_OK_FOR_N (INTVAL (operands[2]))
3757 && ((INTVAL (operands[2]) & 0xff) == INTVAL (operands[2])
3758 || (INTVAL (operands[2]) & 0xff00) == INTVAL (operands[2])
3759 || INTVAL (operands[2]) == 0xffff
3760 || INTVAL (operands[2]) == 0xfffe)"
3761 [(set (match_dup 0)
3762 (match_dup 2))
3763 (set (match_dup 0)
3764 (plus:SI (match_dup 0)
3765 (match_dup 1)))]
3766 "")
3767
3768 ;; Turn
3769 ;;
3770 ;; subs #1,er4
3771 ;; mov.w r4,r4
3772 ;; bne .L2028
3773 ;;
3774 ;; into
3775 ;;
3776 ;; dec.w #1,r4
3777 ;; bne .L2028
3778
3779 (define_peephole2
3780 [(set (match_operand:HI 0 "register_operand" "")
3781 (plus:HI (match_dup 0)
3782 (match_operand 1 "incdec_operand" "")))
3783 (set (cc0)
3784 (match_dup 0))
3785 (set (pc)
3786 (if_then_else (match_operator 3 "eqne_operator"
3787 [(cc0) (const_int 0)])
3788 (label_ref (match_operand 2 "" ""))
3789 (pc)))]
3790 "TARGET_H8300H || TARGET_H8300S"
3791 [(set (match_operand:HI 0 "register_operand" "")
3792 (unspec:HI [(match_dup 0)
3793 (match_dup 1)]
3794 UNSPEC_INCDEC))
3795 (set (cc0)
3796 (match_dup 0))
3797 (set (pc)
3798 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
3799 (label_ref (match_dup 2))
3800 (pc)))]
3801 "")
3802
3803 ;; The SImode version of the previous pattern.
3804
3805 (define_peephole2
3806 [(set (match_operand:SI 0 "register_operand" "")
3807 (plus:SI (match_dup 0)
3808 (match_operand 1 "incdec_operand" "")))
3809 (set (cc0)
3810 (match_dup 0))
3811 (set (pc)
3812 (if_then_else (match_operator 3 "eqne_operator"
3813 [(cc0) (const_int 0)])
3814 (label_ref (match_operand 2 "" ""))
3815 (pc)))]
3816 "TARGET_H8300H || TARGET_H8300S"
3817 [(set (match_operand:SI 0 "register_operand" "")
3818 (unspec:SI [(match_dup 0)
3819 (match_dup 1)]
3820 UNSPEC_INCDEC))
3821 (set (cc0)
3822 (match_dup 0))
3823 (set (pc)
3824 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
3825 (label_ref (match_dup 2))
3826 (pc)))]
3827 "")
3828
3829 (define_peephole2
3830 [(parallel [(set (cc0)
3831 (zero_extract:SI (match_operand:QI 0 "register_operand" "")
3832 (const_int 1)
3833 (const_int 7)))
3834 (clobber (scratch:QI))])
3835 (set (pc)
3836 (if_then_else (match_operator 1 "eqne_operator"
3837 [(cc0) (const_int 0)])
3838 (label_ref (match_operand 2 "" ""))
3839 (pc)))]
3840 "(TARGET_H8300H || TARGET_H8300S)"
3841 [(set (cc0)
3842 (match_dup 0))
3843 (set (pc)
3844 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
3845 (label_ref (match_dup 2))
3846 (pc)))]
3847 "operands[3] = ((GET_CODE (operands[1]) == EQ)
3848 ? gen_rtx_GE (VOIDmode, cc0_rtx, const0_rtx)
3849 : gen_rtx_LT (VOIDmode, cc0_rtx, const0_rtx));")
3850
3851 ;; The next three peephole2's will try to transform
3852 ;;
3853 ;; mov.b A,r0l (or mov.l A,er0)
3854 ;; and.l #CST,er0
3855 ;;
3856 ;; into
3857 ;;
3858 ;; sub.l er0
3859 ;; mov.b A,r0l
3860 ;; and.b #CST,r0l (if CST is not 255)
3861
3862 (define_peephole2
3863 [(set (match_operand:QI 0 "register_operand" "")
3864 (match_operand:QI 1 "general_operand" ""))
3865 (set (match_operand:SI 2 "register_operand" "")
3866 (and:SI (match_dup 2)
3867 (const_int 255)))]
3868 "(TARGET_H8300H || TARGET_H8300S)
3869 && !reg_overlap_mentioned_p (operands[2], operands[1])
3870 && REGNO (operands[0]) == REGNO (operands[2])"
3871 [(set (match_dup 2)
3872 (const_int 0))
3873 (set (strict_low_part (match_dup 0))
3874 (match_dup 1))]
3875 "")
3876
3877 (define_peephole2
3878 [(set (match_operand:SI 0 "register_operand" "")
3879 (match_operand:SI 1 "general_operand" ""))
3880 (set (match_dup 0)
3881 (and:SI (match_dup 0)
3882 (const_int 255)))]
3883 "(TARGET_H8300H || TARGET_H8300S)
3884 && !reg_overlap_mentioned_p (operands[0], operands[1])
3885 && !(GET_CODE (operands[1]) == MEM && MEM_VOLATILE_P (operands[1]))"
3886 [(set (match_dup 0)
3887 (const_int 0))
3888 (set (strict_low_part (match_dup 2))
3889 (match_dup 3))]
3890 "operands[2] = gen_lowpart (QImode, operands[0]);
3891 operands[3] = gen_lowpart (QImode, operands[1]);")
3892
3893 (define_peephole2
3894 [(set (match_operand 0 "register_operand" "")
3895 (match_operand 1 "general_operand" ""))
3896 (set (match_operand:SI 2 "register_operand" "")
3897 (and:SI (match_dup 2)
3898 (match_operand:SI 3 "const_int_qi_operand" "")))]
3899 "(TARGET_H8300H || TARGET_H8300S)
3900 && (GET_MODE (operands[0]) == QImode
3901 || GET_MODE (operands[0]) == HImode
3902 || GET_MODE (operands[0]) == SImode)
3903 && GET_MODE (operands[0]) == GET_MODE (operands[1])
3904 && REGNO (operands[0]) == REGNO (operands[2])
3905 && !reg_overlap_mentioned_p (operands[2], operands[1])
3906 && !(GET_MODE (operands[1]) != QImode
3907 && GET_CODE (operands[1]) == MEM
3908 && MEM_VOLATILE_P (operands[1]))"
3909 [(set (match_dup 2)
3910 (const_int 0))
3911 (set (strict_low_part (match_dup 4))
3912 (match_dup 5))
3913 (set (match_dup 2)
3914 (and:SI (match_dup 2)
3915 (match_dup 6)))]
3916 "operands[4] = gen_lowpart (QImode, operands[0]);
3917 operands[5] = gen_lowpart (QImode, operands[1]);
3918 operands[6] = GEN_INT (~0xff | INTVAL (operands[3]));")
3919
3920 (define_peephole2
3921 [(set (match_operand:SI 0 "register_operand" "")
3922 (match_operand:SI 1 "register_operand" ""))
3923 (set (match_dup 0)
3924 (and:SI (match_dup 0)
3925 (const_int 65280)))]
3926 "(TARGET_H8300H || TARGET_H8300S)
3927 && !reg_overlap_mentioned_p (operands[0], operands[1])"
3928 [(set (match_dup 0)
3929 (const_int 0))
3930 (set (zero_extract:SI (match_dup 0)
3931 (const_int 8)
3932 (const_int 8))
3933 (lshiftrt:SI (match_dup 1)
3934 (const_int 8)))]
3935 "")
3936
3937 (define_peephole2
3938 [(set (match_operand:SI 0 "register_operand" "")
3939 (match_operand:SI 1 "memory_operand" ""))
3940 (set (match_dup 0)
3941 (and:SI (match_dup 0)
3942 (match_operand:SI 2 "const_int_operand" "")))]
3943 "(TARGET_H8300H || TARGET_H8300S)
3944 && !(GET_CODE (operands[1]) == MEM && MEM_VOLATILE_P (operands[1]))
3945 && (INTVAL (operands[2]) & ~0xffff) == 0
3946 && INTVAL (operands[2]) != 255"
3947 [(set (match_dup 3)
3948 (match_dup 4))
3949 (set (match_dup 0)
3950 (and:SI (match_dup 0)
3951 (match_dup 2)))]
3952 "operands[3] = gen_lowpart (HImode, operands[0]);
3953 operands[4] = gen_lowpart (HImode, operands[1]);")
3954
3955 ;; (compare (reg:SI) (const_int)) takes 6 bytes, so we try to achieve
3956 ;; the equivalent with shorter sequences. Here is the summary. Cases
3957 ;; are grouped for each define_peephole2.
3958 ;;
3959 ;; reg const_int use insn
3960 ;; --------------------------------------------------------
3961 ;; live -2 eq/ne copy and inc.l
3962 ;; live -1 eq/ne copy and inc.l
3963 ;; live 1 eq/ne copy and dec.l
3964 ;; live 2 eq/ne copy and dec.l
3965 ;;
3966 ;; dead -2 eq/ne inc.l
3967 ;; dead -1 eq/ne inc.l
3968 ;; dead 1 eq/ne dec.l
3969 ;; dead 2 eq/ne dec.l
3970 ;;
3971 ;; dead -131072 eq/ne inc.w and test
3972 ;; dead -65536 eq/ne inc.w and test
3973 ;; dead 65536 eq/ne dec.w and test
3974 ;; dead 131072 eq/ne dec.w and test
3975 ;;
3976 ;; dead 0x000000?? except 1 and 2 eq/ne xor.b and test
3977 ;; dead 0x0000??00 eq/ne xor.b and test
3978 ;; dead 0x0000ffff eq/ne not.w and test
3979 ;;
3980 ;; dead 0xffffff?? except -1 and -2 eq/ne xor.b and not.l
3981 ;; dead 0xffff??ff eq/ne xor.b and not.l
3982 ;;
3983 ;; dead 1 geu/ltu and.b and test
3984 ;; dead 3 geu/ltu and.b and test
3985 ;; dead 7 geu/ltu and.b and test
3986 ;; dead 15 geu/ltu and.b and test
3987 ;; dead 31 geu/ltu and.b and test
3988 ;; dead 63 geu/ltu and.b and test
3989 ;; dead 127 geu/ltu and.b and test
3990 ;; dead 255 geu/ltu and.b and test
3991 ;;
3992 ;; dead 65535 geu/ltu mov.w
3993
3994 ;; For a small constant, it is cheaper to actually do the subtraction
3995 ;; and then test the register.
3996
3997 (define_peephole2
3998 [(set (cc0)
3999 (compare (match_operand:HI 0 "register_operand" "")
4000 (match_operand:HI 1 "incdec_operand" "")))
4001 (set (pc)
4002 (if_then_else (match_operator 3 "eqne_operator"
4003 [(cc0) (const_int 0)])
4004 (label_ref (match_operand 2 "" ""))
4005 (pc)))]
4006 "(TARGET_H8300H || TARGET_H8300S)
4007 && peep2_reg_dead_p (1, operands[0])"
4008 [(set (match_dup 0)
4009 (unspec:HI [(match_dup 0)
4010 (match_dup 4)]
4011 UNSPEC_INCDEC))
4012 (set (cc0)
4013 (match_dup 0))
4014 (set (pc)
4015 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4016 (label_ref (match_dup 2))
4017 (pc)))]
4018 "operands[4] = GEN_INT (- INTVAL (operands[1]));")
4019
4020 ;; The SImode version of the previous pattern.
4021
4022 (define_peephole2
4023 [(set (cc0)
4024 (compare (match_operand:SI 0 "register_operand" "")
4025 (match_operand:SI 1 "incdec_operand" "")))
4026 (set (pc)
4027 (if_then_else (match_operator 3 "eqne_operator"
4028 [(cc0) (const_int 0)])
4029 (label_ref (match_operand 2 "" ""))
4030 (pc)))]
4031 "(TARGET_H8300H || TARGET_H8300S)
4032 && peep2_reg_dead_p (1, operands[0])"
4033 [(set (match_dup 0)
4034 (unspec:SI [(match_dup 0)
4035 (match_dup 4)]
4036 UNSPEC_INCDEC))
4037 (set (cc0)
4038 (match_dup 0))
4039 (set (pc)
4040 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4041 (label_ref (match_dup 2))
4042 (pc)))]
4043 "operands[4] = GEN_INT (- INTVAL (operands[1]));")
4044
4045 (define_peephole2
4046 [(set (cc0)
4047 (compare (match_operand:SI 0 "register_operand" "")
4048 (match_operand:SI 1 "const_int_operand" "")))
4049 (set (pc)
4050 (if_then_else (match_operator 3 "eqne_operator"
4051 [(cc0) (const_int 0)])
4052 (label_ref (match_operand 2 "" ""))
4053 (pc)))]
4054 "(TARGET_H8300H || TARGET_H8300S)
4055 && peep2_reg_dead_p (1, operands[0])
4056 && (INTVAL (operands[1]) == -131072
4057 || INTVAL (operands[1]) == -65536
4058 || INTVAL (operands[1]) == 65536
4059 || INTVAL (operands[1]) == 131072)"
4060 [(set (match_dup 0)
4061 (plus:SI (match_dup 0)
4062 (match_dup 4)))
4063 (set (cc0)
4064 (match_dup 0))
4065 (set (pc)
4066 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4067 (label_ref (match_dup 2))
4068 (pc)))]
4069 "operands[4] = GEN_INT (- INTVAL (operands[1]));")
4070
4071 ;; For certain (in)equaltity comparisions against a constant, we can
4072 ;; XOR the register with the constant, and test the register against
4073 ;; 0.
4074
4075 (define_peephole2
4076 [(set (cc0)
4077 (compare (match_operand:SI 0 "register_operand" "")
4078 (match_operand:SI 1 "const_int_operand" "")))
4079 (set (pc)
4080 (if_then_else (match_operator 3 "eqne_operator"
4081 [(cc0) (const_int 0)])
4082 (label_ref (match_operand 2 "" ""))
4083 (pc)))]
4084 "(TARGET_H8300H || TARGET_H8300S)
4085 && peep2_reg_dead_p (1, operands[0])
4086 && ((INTVAL (operands[1]) & 0x00ff) == INTVAL (operands[1])
4087 || (INTVAL (operands[1]) & 0xff00) == INTVAL (operands[1])
4088 || INTVAL (operands[1]) == 0x0000ffff)
4089 && INTVAL (operands[1]) != 1
4090 && INTVAL (operands[1]) != 2"
4091 [(set (match_dup 0)
4092 (xor:SI (match_dup 0)
4093 (match_dup 1)))
4094 (set (cc0)
4095 (match_dup 0))
4096 (set (pc)
4097 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4098 (label_ref (match_dup 2))
4099 (pc)))]
4100 "")
4101
4102 (define_peephole2
4103 [(set (cc0)
4104 (compare (match_operand:SI 0 "register_operand" "")
4105 (match_operand:SI 1 "const_int_operand" "")))
4106 (set (pc)
4107 (if_then_else (match_operator 3 "eqne_operator"
4108 [(cc0) (const_int 0)])
4109 (label_ref (match_operand 2 "" ""))
4110 (pc)))]
4111 "(TARGET_H8300H || TARGET_H8300S)
4112 && peep2_reg_dead_p (1, operands[0])
4113 && ((INTVAL (operands[1]) | 0x00ff) == -1
4114 || (INTVAL (operands[1]) | 0xff00) == -1)
4115 && INTVAL (operands[1]) != -1
4116 && INTVAL (operands[1]) != -2"
4117 [(set (match_dup 0)
4118 (xor:SI (match_dup 0)
4119 (match_dup 4)))
4120 (set (match_dup 0)
4121 (not:SI (match_dup 0)))
4122 (set (cc0)
4123 (match_dup 0))
4124 (set (pc)
4125 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4126 (label_ref (match_dup 2))
4127 (pc)))]
4128 "operands[4] = GEN_INT (INTVAL (operands[1]) ^ -1);")
4129
4130 ;; Transform A <= 1 to (A & 0xfffffffe) == 0.
4131
4132 (define_peephole2
4133 [(set (cc0)
4134 (compare (match_operand:SI 0 "register_operand" "")
4135 (match_operand:SI 1 "const_int_operand" "")))
4136 (set (pc)
4137 (if_then_else (match_operator 2 "gtuleu_operator"
4138 [(cc0) (const_int 0)])
4139 (label_ref (match_operand 3 "" ""))
4140 (pc)))]
4141 "(TARGET_H8300H || TARGET_H8300S)
4142 && peep2_reg_dead_p (1, operands[0])
4143 && (INTVAL (operands[1]) == 1
4144 || INTVAL (operands[1]) == 3
4145 || INTVAL (operands[1]) == 7
4146 || INTVAL (operands[1]) == 15
4147 || INTVAL (operands[1]) == 31
4148 || INTVAL (operands[1]) == 63
4149 || INTVAL (operands[1]) == 127
4150 || INTVAL (operands[1]) == 255)"
4151 [(set (match_dup 0)
4152 (and:SI (match_dup 0)
4153 (match_dup 5)))
4154 (set (cc0)
4155 (match_dup 0))
4156 (set (pc)
4157 (if_then_else (match_dup 4)
4158 (label_ref (match_dup 3))
4159 (pc)))]
4160 "operands[4] = ((GET_CODE (operands[2]) == GTU) ?
4161 gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx) :
4162 gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx));
4163 operands[5] = GEN_INT (~INTVAL (operands[1]));")
4164
4165 ;; Transform A <= 255 to (A & 0xff00) == 0.
4166
4167 (define_peephole2
4168 [(set (cc0)
4169 (compare (match_operand:HI 0 "register_operand" "")
4170 (const_int 255)))
4171 (set (pc)
4172 (if_then_else (match_operator 1 "gtuleu_operator"
4173 [(cc0) (const_int 0)])
4174 (label_ref (match_operand 2 "" ""))
4175 (pc)))]
4176 "TARGET_H8300H || TARGET_H8300S"
4177 [(set (cc0)
4178 (and:HI (match_dup 0)
4179 (const_int -256)))
4180 (set (pc)
4181 (if_then_else (match_dup 4)
4182 (label_ref (match_dup 2))
4183 (pc)))]
4184 "operands[4] = ((GET_CODE (operands[1]) == GTU) ?
4185 gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx) :
4186 gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx));")
4187
4188 ;; Transform A <= 65535 to (A & 0xffff0000) == 0.
4189
4190 (define_peephole2
4191 [(set (cc0)
4192 (compare (match_operand:SI 0 "register_operand" "")
4193 (const_int 65535)))
4194 (set (pc)
4195 (if_then_else (match_operator 1 "gtuleu_operator"
4196 [(cc0) (const_int 0)])
4197 (label_ref (match_operand 2 "" ""))
4198 (pc)))]
4199 "TARGET_H8300H || TARGET_H8300S"
4200 [(set (cc0)
4201 (and:SI (match_dup 0)
4202 (const_int -65536)))
4203 (set (pc)
4204 (if_then_else (match_dup 4)
4205 (label_ref (match_dup 2))
4206 (pc)))]
4207 "operands[4] = ((GET_CODE (operands[1]) == GTU) ?
4208 gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx) :
4209 gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx));")
4210
4211 ;; For constants like -1, -2, 1, 2, it is still cheaper to make a copy
4212 ;; of the register being tested, do the subtraction on the copy, and
4213 ;; then test the copy. We avoid this transformation if we see more
4214 ;; than one copy of the same compare insn.
4215
4216 (define_peephole2
4217 [(match_scratch:SI 4 "r")
4218 (set (cc0)
4219 (compare (match_operand:SI 0 "register_operand" "")
4220 (match_operand:SI 1 "incdec_operand" "")))
4221 (set (pc)
4222 (if_then_else (match_operator 3 "eqne_operator"
4223 [(cc0) (const_int 0)])
4224 (label_ref (match_operand 2 "" ""))
4225 (pc)))]
4226 "(TARGET_H8300H || TARGET_H8300S)
4227 && !peep2_reg_dead_p (1, operands[0])
4228 && !rtx_equal_p (PATTERN (insn),
4229 PATTERN (next_nonnote_insn (next_nonnote_insn (insn))))"
4230 [(set (match_dup 4)
4231 (match_dup 0))
4232 (set (match_dup 4)
4233 (unspec:SI [(match_dup 4)
4234 (match_dup 5)]
4235 UNSPEC_INCDEC))
4236 (set (cc0)
4237 (match_dup 4))
4238 (set (pc)
4239 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4240 (label_ref (match_dup 2))
4241 (pc)))]
4242 "operands[5] = GEN_INT (- INTVAL (operands[1]));")
4243
4244 ;; Narrow the mode of testing if possible.
4245
4246 (define_peephole2
4247 [(set (match_operand:HI 0 "register_operand" "")
4248 (and:HI (match_dup 0)
4249 (match_operand:HI 1 "const_int_qi_operand" "")))
4250 (set (cc0)
4251 (match_dup 0))
4252 (set (pc)
4253 (if_then_else (match_operator 3 "eqne_operator"
4254 [(cc0) (const_int 0)])
4255 (label_ref (match_operand 2 "" ""))
4256 (pc)))]
4257 "peep2_reg_dead_p (2, operands[0])"
4258 [(set (match_dup 4)
4259 (and:QI (match_dup 4)
4260 (match_dup 5)))
4261 (set (cc0)
4262 (match_dup 4))
4263 (set (pc)
4264 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4265 (label_ref (match_dup 2))
4266 (pc)))]
4267 "operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
4268 operands[5] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));")
4269
4270 (define_peephole2
4271 [(set (match_operand:SI 0 "register_operand" "")
4272 (and:SI (match_dup 0)
4273 (match_operand:SI 1 "const_int_qi_operand" "")))
4274 (set (cc0)
4275 (match_dup 0))
4276 (set (pc)
4277 (if_then_else (match_operator 3 "eqne_operator"
4278 [(cc0) (const_int 0)])
4279 (label_ref (match_operand 2 "" ""))
4280 (pc)))]
4281 "peep2_reg_dead_p (2, operands[0])"
4282 [(set (match_dup 4)
4283 (and:QI (match_dup 4)
4284 (match_dup 5)))
4285 (set (cc0)
4286 (match_dup 4))
4287 (set (pc)
4288 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4289 (label_ref (match_dup 2))
4290 (pc)))]
4291 "operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
4292 operands[5] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));")
4293
4294 (define_peephole2
4295 [(set (match_operand:SI 0 "register_operand" "")
4296 (and:SI (match_dup 0)
4297 (match_operand:SI 1 "const_int_hi_operand" "")))
4298 (set (cc0)
4299 (match_dup 0))
4300 (set (pc)
4301 (if_then_else (match_operator 3 "eqne_operator"
4302 [(cc0) (const_int 0)])
4303 (label_ref (match_operand 2 "" ""))
4304 (pc)))]
4305 "peep2_reg_dead_p (2, operands[0])"
4306 [(set (match_dup 4)
4307 (and:HI (match_dup 4)
4308 (match_dup 5)))
4309 (set (cc0)
4310 (match_dup 4))
4311 (set (pc)
4312 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4313 (label_ref (match_dup 2))
4314 (pc)))]
4315 "operands[4] = gen_rtx_REG (HImode, REGNO (operands[0]));
4316 operands[5] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), HImode));")
4317
4318 (define_peephole2
4319 [(set (match_operand:SI 0 "register_operand" "")
4320 (and:SI (match_dup 0)
4321 (match_operand:SI 1 "const_int_qi_operand" "")))
4322 (set (match_dup 0)
4323 (xor:SI (match_dup 0)
4324 (match_operand:SI 2 "const_int_qi_operand" "")))
4325 (set (cc0)
4326 (match_dup 0))
4327 (set (pc)
4328 (if_then_else (match_operator 4 "eqne_operator"
4329 [(cc0) (const_int 0)])
4330 (label_ref (match_operand 3 "" ""))
4331 (pc)))]
4332 "peep2_reg_dead_p (3, operands[0])
4333 && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0"
4334 [(set (match_dup 5)
4335 (and:QI (match_dup 5)
4336 (match_dup 6)))
4337 (set (match_dup 5)
4338 (xor:QI (match_dup 5)
4339 (match_dup 7)))
4340 (set (cc0)
4341 (match_dup 5))
4342 (set (pc)
4343 (if_then_else (match_op_dup 4 [(cc0) (const_int 0)])
4344 (label_ref (match_dup 3))
4345 (pc)))]
4346 "operands[5] = gen_rtx_REG (QImode, REGNO (operands[0]));
4347 operands[6] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));
4348 operands[7] = GEN_INT (trunc_int_for_mode (INTVAL (operands[2]), QImode));")