OSDN Git Service

e9922afb42666e71cdb6be8538732ca70280b3ee
[pf3gnuchains/gcc-fork.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 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 GNU CC.
9
10 ;; GNU CC 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 ;; GNU CC 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 GNU CC; 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
56 (define_constants
57   [(SC_REG       3)
58    (FP_REG       6)
59    (SP_REG       7)
60    (MAC_REG      8)
61    (AP_REG       9)
62    (RAP_REG     10)])
63
64 ;; ----------------------------------------------------------------------
65 ;; ATTRIBUTES
66 ;; ----------------------------------------------------------------------
67
68 (define_attr "cpu" "h8300,h8300h"
69   (const (symbol_ref "cpu_type")))
70
71 (define_attr "type" "branch,arith"
72   (const_string "arith"))
73
74 ;; The size of instructions in bytes.
75
76 (define_attr "length" ""
77   (cond [(eq_attr "type" "branch")
78          (if_then_else (and (ge (minus (match_dup 0) (pc))
79                                 (const_int -126))
80                             (le (minus (match_dup 0) (pc))
81                                 (const_int 126)))
82                        (const_int 2)
83                        (if_then_else (and (eq_attr "cpu" "h8300h")
84                                           (and (ge (minus (pc) (match_dup 0))
85                                                    (const_int -32000))
86                                                (le (minus (pc) (match_dup 0))
87                                                    (const_int 32000))))
88                                      (const_int 4)
89                                      (const_int 6)))]
90         (const_int 200)))
91
92 ;; The necessity of instruction length adjustment.
93
94 (define_attr "adjust_length" "yes,no"
95   (cond [(eq_attr "type" "branch") (const_string "no")]
96         (const_string "yes")))
97
98 ;; Condition code settings.
99 ;;
100 ;; none - insn does not affect cc
101 ;; none_0hit - insn does not affect cc but it does modify operand 0
102 ;;      This attribute is used to keep track of when operand 0 changes.
103 ;;      See the description of NOTICE_UPDATE_CC for more info.
104 ;; set_znv - insn sets z,n,v to usable values (like a tst insn); c is unknown.
105 ;; set_zn  - insn sets z,n to usable values; v,c are unknown.
106 ;; compare - compare instruction
107 ;; clobber - value of cc is unknown
108
109 (define_attr "cc" "none,none_0hit,set_znv,set_zn,compare,clobber"
110   (const_string "clobber"))
111 \f
112 ;; ----------------------------------------------------------------------
113 ;; MOVE INSTRUCTIONS
114 ;; ----------------------------------------------------------------------
115
116 ;; movqi
117
118 (define_insn "pushqi1_h8300"
119   [(parallel [(set (reg:HI SP_REG)
120                    (plus:HI (reg:HI SP_REG) (const_int -2)))
121               (set (mem:QI (plus:HI (reg:HI SP_REG) (const_int -1)))
122                    (match_operand:QI 0 "register_operand" "r"))])]
123   "TARGET_H8300
124    && REGNO (operands[0]) != SP_REG"
125   "mov.w\\t%T0,@-r7"
126   [(set_attr "length" "2")
127    (set_attr "cc" "clobber")])
128
129 (define_insn "pushqi1_h8300hs"
130   [(parallel [(set (reg:SI SP_REG)
131                    (plus:SI (reg:SI SP_REG) (const_int -4)))
132               (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
133                    (match_operand:QI 0 "register_operand" "r"))])]
134   "(TARGET_H8300H || TARGET_H8300S)
135    && REGNO (operands[0]) != SP_REG"
136   "mov.l\\t%S0,@-er7"
137   [(set_attr "length" "4")
138    (set_attr "cc" "clobber")])
139
140 (define_expand "pushqi1"
141   [(use (match_operand:QI 0 "register_operand" ""))]
142   ""
143   "
144 {
145   if (TARGET_H8300)
146     emit_insn (gen_pushqi1_h8300 (operands[0]));
147   else
148     emit_insn (gen_pushqi1_h8300hs (operands[0]));
149   DONE;
150 }")
151
152 (define_insn ""
153   [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
154         (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
155   "TARGET_H8300
156    && (register_operand (operands[0], QImode)
157        || register_operand (operands[1], QImode))"
158   "@
159    sub.b        %X0,%X0
160    mov.b        %R1,%X0
161    mov.b        %X1,%R0
162    mov.b        %R1,%X0
163    mov.b        %R1,%X0
164    mov.b        %X1,%R0"
165   [(set_attr "length" "2,2,2,2,4,4")
166    (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
167
168 (define_insn ""
169   [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
170         (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
171   "(TARGET_H8300H || TARGET_H8300S)
172    && (register_operand (operands[0], QImode)
173        || register_operand (operands[1], QImode))"
174   "@
175    sub.b        %X0,%X0
176    mov.b        %R1,%X0
177    mov.b        %X1,%R0
178    mov.b        %R1,%X0
179    mov.b        %R1,%X0
180    mov.b        %X1,%R0"
181   [(set_attr "length" "2,2,2,2,8,8")
182    (set_attr "cc" "set_zn,set_znv,set_znv,clobber,set_znv,set_znv")])
183
184 (define_expand "movqi"
185   [(set (match_operand:QI 0 "general_operand_dst" "")
186         (match_operand:QI 1 "general_operand_src" ""))]
187   ""
188   "
189 {
190   /* One of the ops has to be in a register.  */
191   if (!register_operand (operand0, QImode)
192       && !register_operand (operand1, QImode))
193     {
194       operands[1] = copy_to_mode_reg (QImode, operand1);
195     }
196 }")
197
198 (define_insn "movstrictqi"
199   [(set (strict_low_part (match_operand:QI 0 "general_operand_dst" "+r,r,r,r"))
200                          (match_operand:QI 1 "general_operand_src" "I,r,n,m"))]
201   ""
202   "@
203    sub.b        %X0,%X0
204    mov.b        %X1,%X0
205    mov.b        %R1,%X0
206    mov.b        %R1,%X0"
207   [(set_attr_alternative "length"
208      [(const_int 2) (const_int 2) (const_int 2)
209       (if_then_else (eq_attr "cpu" "h8300") (const_int 4) (const_int 8))])
210    (set_attr "cc" "set_zn,set_znv,set_znv,set_znv")])
211
212 ;; movhi
213
214 (define_expand "pushhi1_h8300"
215   [(set (mem:HI (pre_dec:HI (reg:HI SP_REG)))
216         (match_operand:HI 0 "register_operand" ""))]
217   "TARGET_H8300
218    && REGNO (operands[0]) != SP_REG"
219   "")
220
221 (define_insn "pushhi1_h8300hs"
222   [(parallel [(set (reg:SI SP_REG)
223                    (plus:SI (reg:SI SP_REG) (const_int -4)))
224               (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
225                    (match_operand:HI 0 "register_operand" "r"))])]
226   "(TARGET_H8300H || TARGET_H8300S)
227    && REGNO (operands[0]) != SP_REG"
228   "mov.l\\t%S0,@-er7"
229   [(set_attr "length" "4")
230    (set_attr "cc" "clobber")])
231
232 (define_expand "pushhi1"
233   [(use (match_operand:HI 0 "register_operand" ""))]
234   ""
235   "
236 {
237   if (TARGET_H8300)
238     emit_insn (gen_pushhi1_h8300 (operands[0]));
239   else
240     emit_insn (gen_pushhi1_h8300hs (operands[0]));
241   DONE;
242 }")
243
244 (define_insn ""
245   [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
246         (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
247   "TARGET_H8300
248    && (register_operand (operands[0], HImode)
249        || register_operand (operands[1], HImode))
250    && !(GET_CODE (operands[0]) == MEM
251         && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
252         && GET_CODE (XEXP (XEXP (operands[0], 0), 0)) == REG
253         && GET_CODE (operands[1]) == REG
254         && REGNO (XEXP (XEXP (operands[0], 0), 0)) == REGNO (operands[1]))"
255   "@
256    sub.w        %T0,%T0
257    mov.w        %T1,%T0
258    mov.w        %T1,%T0
259    mov.w        %T1,%T0
260    mov.w        %T1,%T0
261    mov.w        %T1,%T0"
262   [(set_attr "length" "2,2,2,4,4,4")
263    (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
264
265 (define_insn ""
266   [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
267         (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
268   "(TARGET_H8300H || TARGET_H8300S)
269    && (register_operand (operands[0], HImode)
270        || register_operand (operands[1], HImode))"
271   "@
272    sub.w        %T0,%T0
273    mov.w        %T1,%T0
274    mov.w        %T1,%T0
275    mov.w        %T1,%T0
276    mov.w        %T1,%T0
277    mov.w        %T1,%T0"
278   [(set_attr "length" "2,2,2,4,8,8")
279    (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
280
281 (define_expand "movhi"
282   [(set (match_operand:HI 0 "general_operand_dst" "")
283         (match_operand:HI 1 "general_operand_src" ""))]
284   ""
285   "
286 {
287   /* One of the ops has to be in a register.  */
288   if (!register_operand (operand1, HImode)
289       && !register_operand (operand0, HImode))
290     {
291       operands[1] = copy_to_mode_reg (HImode, operand1);
292     }
293 }")
294
295 (define_insn "movstricthi"
296   [(set (strict_low_part (match_operand:HI 0 "general_operand_dst" "+r,r,r,r"))
297                          (match_operand:HI 1 "general_operand_src" "I,r,i,m"))]
298   ""
299   "@
300    sub.w        %T0,%T0
301    mov.w        %T1,%T0
302    mov.w        %T1,%T0
303    mov.w        %T1,%T0"
304   [(set_attr_alternative "length"
305      [(const_int 2) (const_int 2) (const_int 4)
306       (if_then_else (eq_attr "cpu" "h8300") (const_int 4) (const_int 8))])
307    (set_attr "cc" "set_zn,set_znv,set_znv,set_znv")])
308
309 ;; movsi
310
311 (define_expand "movsi"
312   [(set (match_operand:SI 0 "general_operand_dst" "")
313         (match_operand:SI 1 "general_operand_src" ""))]
314   ""
315   "
316 {
317   if (TARGET_H8300)
318     {
319       if (do_movsi (operands))
320         DONE;
321     }
322   else
323     {
324       /* One of the ops has to be in a register.  */
325       if (!register_operand (operand1, SImode)
326           && !register_operand (operand0, SImode))
327         {
328           operands[1] = copy_to_mode_reg (SImode, operand1);
329         }
330     }
331 }")
332
333 (define_expand "movsf"
334   [(set (match_operand:SF 0 "general_operand_dst" "")
335         (match_operand:SF 1 "general_operand_src" ""))]
336   ""
337   "
338 {
339   if (TARGET_H8300)
340     {
341       if (do_movsi (operands))
342         DONE;
343     }
344   else
345     {
346       /* One of the ops has to be in a register.  */
347       if (!register_operand (operand1, SFmode)
348           && !register_operand (operand0, SFmode))
349         {
350           operands[1] = copy_to_mode_reg (SFmode, operand1);
351         }
352     }
353 }")
354
355 (define_insn "movsi_h8300"
356   [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,o,<,r")
357         (match_operand:SI 1 "general_operand_src" "I,r,io,r,r,>"))]
358   "TARGET_H8300
359    && (register_operand (operands[0], SImode)
360        || register_operand (operands[1], SImode))"
361   "*
362 {
363   unsigned int rn = -1;
364   switch (which_alternative)
365     {
366     case 0:
367       return \"sub.w    %e0,%e0\;sub.w  %f0,%f0\";
368     case 1:
369       if (REGNO (operands[0]) < REGNO (operands[1]))
370         return \"mov.w  %e1,%e0\;mov.w  %f1,%f0\";
371       else
372         return \"mov.w  %f1,%f0\;mov.w  %e1,%e0\";
373     case 2:
374       /* Make sure we don't trample the register we index with.  */
375       if (GET_CODE (operands[1]) == MEM)
376         {
377           rtx inside = XEXP (operands[1], 0);
378           if (REG_P (inside))
379             {
380               rn = REGNO (inside);
381             }
382           else if (GET_CODE (inside) == PLUS)
383             {
384               rtx lhs = XEXP (inside, 0);
385               rtx rhs = XEXP (inside, 1);
386               if (REG_P (lhs)) rn = REGNO (lhs);
387               if (REG_P (rhs)) rn = REGNO (rhs);
388             }
389         }
390       if (rn == REGNO (operands[0]))
391         {
392           /* Move the second word first.  */
393           return \"mov.w        %f1,%f0\;mov.w  %e1,%e0\";
394         }
395       else
396         {
397           /* See if either half is zero.  If so, use sub.w to clear
398              that half.  */
399           if (GET_CODE (operands[1]) == CONST_INT)
400             {
401               if ((INTVAL (operands[1]) & 0xffff) == 0)
402                 return \"mov.w  %e1,%e0\;sub.w  %f0,%f0\";
403               if (((INTVAL (operands[1]) >> 16) & 0xffff) == 0)
404                 return \"sub.w  %e0,%e0\;mov.w  %f1,%f0\";
405             }
406           return \"mov.w        %e1,%e0\;mov.w  %f1,%f0\";
407         }
408     case 3:
409       return \"mov.w    %e1,%e0\;mov.w  %f1,%f0\";
410     case 4:
411       return \"mov.w    %f1,%T0\;mov.w  %e1,%T0\";
412     case 5:
413       return \"mov.w    %T1,%e0\;mov.w  %T1,%f0\";
414     default:
415       abort ();
416     }
417 }"
418   [(set_attr "length" "4,4,8,8,4,4")
419    (set_attr "cc" "clobber")])
420
421 (define_insn "movsf_h8300"
422   [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,o,<,r")
423         (match_operand:SF 1 "general_operand_src" "I,r,io,r,r,>"))]
424   "TARGET_H8300
425    && (register_operand (operands[0], SFmode)
426        || register_operand (operands[1], SFmode))"
427   "*
428 {
429   /* Copy of the movsi stuff.  */
430   unsigned int rn = -1;
431   switch (which_alternative)
432     {
433     case 0:
434       return \"sub.w    %e0,%e0\;sub.w  %f0,%f0\";
435     case 1:
436       if (REGNO (operands[0]) < REGNO (operands[1]))
437         return \"mov.w  %e1,%e0\;mov.w  %f1,%f0\";
438       else
439         return \"mov.w  %f1,%f0\;mov.w  %e1,%e0\";
440     case 2:
441       /* Make sure we don't trample the register we index with.  */
442       if (GET_CODE (operands[1]) == MEM)
443         {
444           rtx inside = XEXP (operands[1], 0);
445           if (REG_P (inside))
446             {
447               rn = REGNO (inside);
448             }
449           else if (GET_CODE (inside) == PLUS)
450             {
451               rtx lhs = XEXP (inside, 0);
452               rtx rhs = XEXP (inside, 1);
453               if (REG_P (lhs)) rn = REGNO (lhs);
454               if (REG_P (rhs)) rn = REGNO (rhs);
455             }
456         }
457       if (rn == REGNO (operands[0]))
458         /* Move the second word first.  */
459         return \"mov.w  %f1,%f0\;mov.w  %e1,%e0\";
460       else
461         /* Move the first word first.  */
462         return \"mov.w  %e1,%e0\;mov.w  %f1,%f0\";
463
464     case 3:
465       return \"mov.w    %e1,%e0\;mov.w  %f1,%f0\";
466     case 4:
467       return \"mov.w    %f1,%T0\;mov.w  %e1,%T0\";
468     case 5:
469       return \"mov.w    %T1,%e0\;mov.w  %T1,%f0\";
470     default:
471       abort ();
472     }
473 }"
474   [(set_attr "length" "4,4,8,8,4,4")
475    (set_attr "cc" "clobber")])
476
477 (define_insn "movsi_h8300hs"
478   [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,<,r,r,m,*a,*a,r")
479         (match_operand:SI 1 "general_operand_src" "I,r,i,r,>,m,r,I,r,*a"))]
480   "(TARGET_H8300S || TARGET_H8300H)
481    && (register_operand (operands[0], SImode)
482        || register_operand (operands[1], SImode))
483    && !(GET_CODE (operands[0]) == MEM
484         && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
485         && GET_CODE (XEXP (XEXP (operands[0], 0), 0)) == REG
486         && GET_CODE (operands[1]) == REG
487         && REGNO (XEXP (XEXP (operands[0], 0), 0)) == REGNO (operands[1]))"
488   "*
489 {
490   switch (which_alternative)
491     {
492     case 0:
493       return \"sub.l    %S0,%S0\";
494     case 7:
495       return \"clrmac\";
496     case 8:
497       return \"clrmac\;ldmac %1,macl\";
498     case 9:
499       return \"stmac    macl,%0\";
500     default:
501       if (GET_CODE (operands[1]) == CONST_INT)
502         {
503           int val = INTVAL (operands[1]);
504
505           /* Look for constants which can be made by adding an 8-bit
506              number to zero in one of the two low bytes.  */
507           if (val == (val & 0xff))
508             {
509               operands[1] = GEN_INT ((char) val & 0xff);
510               return \"sub.l\\t%S0,%S0\;add.b\\t%1,%w0\";
511             }
512
513           if (val == (val & 0xff00))
514             {
515               operands[1] = GEN_INT ((char) (val >> 8) & 0xff);
516               return \"sub.l\\t%S0,%S0\;add.b\\t%1,%x0\";
517             }
518
519           /* Look for constants that can be obtained by subs, inc, and
520              dec to 0.  */
521           switch (val & 0xffffffff)
522             {
523             case 0xffffffff:
524               return \"sub.l\\t%S0,%S0\;subs\\t#1,%S0\";
525             case 0xfffffffe:
526               return \"sub.l\\t%S0,%S0\;subs\\t#2,%S0\";
527             case 0xfffffffc:
528               return \"sub.l\\t%S0,%S0\;subs\\t#4,%S0\";
529
530             case 0x0000ffff:
531               return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%f0\";
532             case 0x0000fffe:
533               return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%f0\";
534
535             case 0xffff0000:
536               return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%e0\";
537             case 0xfffe0000:
538               return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%e0\";
539
540             case 0x00010000:
541               return \"sub.l\\t%S0,%S0\;inc.w\\t#1,%e0\";
542             case 0x00020000:
543               return \"sub.l\\t%S0,%S0\;inc.w\\t#2,%e0\";
544             }
545         }
546     }
547    return \"mov.l       %S1,%S0\";
548 }"
549   [(set_attr "length" "2,2,6,4,4,10,10,2,6,4")
550    (set_attr "cc" "set_zn,set_znv,clobber,set_znv,set_znv,set_znv,set_znv,none_0hit,none_0hit,set_znv")])
551
552 (define_insn "movsf_h8300h"
553   [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,m,<,r")
554         (match_operand:SF 1 "general_operand_src" "I,r,im,r,r,>"))]
555   "(TARGET_H8300H || TARGET_H8300S)
556    && (register_operand (operands[0], SFmode)
557        || register_operand (operands[1], SFmode))"
558   "@
559    sub.l        %S0,%S0
560    mov.l        %S1,%S0
561    mov.l        %S1,%S0
562    mov.l        %S1,%S0
563    mov.l        %S1,%S0
564    mov.l        %S1,%S0"
565   [(set_attr "length" "2,2,10,10,4,4")
566    (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
567 \f
568 ;; ----------------------------------------------------------------------
569 ;; TEST INSTRUCTIONS
570 ;; ----------------------------------------------------------------------
571
572 (define_insn ""
573   [(set (cc0) (zero_extract:HI (match_operand:QI 0 "bit_memory_operand" "r,U")
574                                (const_int 1)
575                                (match_operand 1 "const_int_operand" "n,n")))]
576   "TARGET_H8300"
577   "btst %Z1,%Y0"
578   [(set_attr "length" "2,4")
579    (set_attr "cc" "set_zn,set_zn")])
580
581 (define_insn ""
582   [(set (cc0) (zero_extract:HI (match_operand:HI 0 "register_operand" "r")
583                                (const_int 1)
584                                (match_operand 1 "const_int_operand" "n")))]
585   "TARGET_H8300"
586   "btst %Z1,%Y0"
587   [(set_attr "length" "2")
588    (set_attr "cc" "set_zn")])
589
590 (define_insn "*tst_extzv_bitqi_1_n"
591   [(set (cc0) (zero_extract:SI (match_operand:QI 0 "bit_operand" "r,U")
592                                (const_int 1)
593                                (match_operand 1 "const_int_operand" "n,n")))]
594   "(TARGET_H8300H || TARGET_H8300S)
595    && INTVAL (operands[1]) != 7"
596   "btst %Z1,%Y0"
597   [(set_attr "length" "2,8")
598    (set_attr "cc" "set_zn,set_zn")])
599
600 (define_insn_and_split "*tst_extzv_memqi_1_n"
601   [(set (cc0) (zero_extract:SI (match_operand:QI 0 "memory_operand" "m")
602                                (const_int 1)
603                                (match_operand 1 "const_int_operand" "n")))
604    (clobber (match_scratch:QI 2 "=&r"))]
605   "(TARGET_H8300H || TARGET_H8300S)
606    && !EXTRA_CONSTRAINT (operands[0], 'U')
607    && INTVAL (operands[1]) != 7"
608   "#"
609   "&& reload_completed"
610   [(set (match_dup 2)
611         (match_dup 0))
612    (set (cc0) (zero_extract:SI (match_dup 2)
613                                (const_int 1)
614                                (match_dup 1)))]
615   "")
616
617 (define_insn ""
618   [(set (cc0) (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
619                                (const_int 1)
620                                (match_operand 1 "const_int_operand" "n")))]
621   "(TARGET_H8300H || TARGET_H8300S)
622    && INTVAL (operands[1]) <= 15"
623   "btst %Z1,%Y0"
624   [(set_attr "length" "2")
625    (set_attr "cc" "set_zn")])
626
627 (define_insn ""
628   [(set (cc0)
629         (and:HI (match_operand:HI 0 "register_operand" "r")
630                 (match_operand:HI 1 "single_one_operand" "n")))]
631   ""
632   "*
633 {
634   operands[1] = GEN_INT (INTVAL (operands[1]) & 0xffff);
635   if (INTVAL (operands[1]) > 128)
636     {
637       operands[1] = GEN_INT (INTVAL (operands[1]) >> 8);
638       return \"btst\\t%V1,%t0\";
639     }
640   return \"btst\\t%V1,%s0\";
641 }"
642   [(set_attr "length" "2")
643    (set_attr "cc" "set_zn")])
644
645 (define_insn ""
646   [(set (cc0)
647         (and:SI (match_operand:SI 0 "register_operand" "r")
648                 (match_operand:SI 1 "single_one_operand" "n")))]
649   "(TARGET_H8300H || TARGET_H8300S)
650    && (INTVAL (operands[1]) & 0xffff) != 0"
651   "*
652 {
653   operands[1] = GEN_INT (INTVAL (operands[1]) & 0xffff);
654   if (INTVAL (operands[1]) > 128)
655     {
656       operands[1] = GEN_INT (INTVAL (operands[1]) >> 8);
657       return \"btst\\t%V1,%x0\";
658     }
659   return \"btst\\t%V1,%w0\";
660 }"
661   [(set_attr "length" "2")
662    (set_attr "cc" "set_zn")])
663
664 (define_insn "tstqi"
665   [(set (cc0) (match_operand:QI 0 "register_operand" "r"))]
666   ""
667   "mov.b        %X0,%X0"
668   [(set_attr "length" "2")
669    (set_attr "cc" "set_znv")])
670
671 (define_insn "tsthi"
672   [(set (cc0) (match_operand:HI 0 "register_operand" "r"))]
673   ""
674   "mov.w        %T0,%T0"
675   [(set_attr "length" "2")
676    (set_attr "cc" "set_znv")])
677
678 (define_insn ""
679   [(set (cc0)
680         (and:HI (match_operand:HI 0 "register_operand" "r")
681                 (const_int -256)))]
682   ""
683   "mov.b        %t0,%t0"
684   [(set_attr "length" "2")
685    (set_attr "cc" "set_znv")])
686
687 (define_insn "tstsi"
688   [(set (cc0) (match_operand:SI 0 "register_operand" "r"))]
689   "TARGET_H8300H || TARGET_H8300S"
690   "mov.l        %S0,%S0"
691   [(set_attr "length" "2")
692    (set_attr "cc" "set_znv")])
693
694 (define_insn ""
695   [(set (cc0)
696         (and:SI (match_operand:SI 0 "register_operand" "r")
697                 (const_int -65536)))]
698   ""
699   "mov.w        %e0,%e0"
700   [(set_attr "length" "2")
701    (set_attr "cc" "set_znv")])
702
703 (define_insn "cmpqi"
704   [(set (cc0)
705         (compare:QI (match_operand:QI 0 "register_operand" "r")
706                     (match_operand:QI 1 "nonmemory_operand" "rn")))]
707   ""
708   "cmp.b        %X1,%X0"
709   [(set_attr "length" "2")
710    (set_attr "cc" "compare")])
711
712 (define_expand "cmphi"
713   [(set (cc0)
714         (compare:HI (match_operand:HI 0 "register_operand" "")
715                     (match_operand:HI 1 "nonmemory_operand" "")))]
716   ""
717   "
718 {
719   /* Force operand1 into a register if we're compiling
720      for the H8/300.  */
721   if (GET_CODE (operands[1]) != REG && TARGET_H8300)
722     operands[1] = force_reg (HImode, operands[1]);
723 }")
724
725 (define_insn ""
726   [(set (cc0)
727         (compare:HI (match_operand:HI 0 "register_operand" "r")
728                     (match_operand:HI 1 "register_operand" "r")))]
729   "TARGET_H8300"
730   "cmp.w        %T1,%T0"
731   [(set_attr "length" "2")
732    (set_attr "cc" "compare")])
733
734 (define_insn ""
735   [(set (cc0)
736         (compare:HI (match_operand:HI 0 "register_operand" "r,r")
737                     (match_operand:HI 1 "nonmemory_operand" "r,n")))]
738   "TARGET_H8300H || TARGET_H8300S"
739   "cmp.w        %T1,%T0"
740   [(set_attr "length" "2,4")
741    (set_attr "cc" "compare,compare")])
742
743 (define_insn "cmpsi"
744   [(set (cc0)
745         (compare:SI (match_operand:SI 0 "register_operand" "r,r")
746                     (match_operand:SI 1 "nonmemory_operand" "r,i")))]
747   "TARGET_H8300H || TARGET_H8300S"
748   "cmp.l        %S1,%S0"
749   [(set_attr "length" "2,6")
750    (set_attr "cc" "compare,compare")])
751 \f
752 ;; ----------------------------------------------------------------------
753 ;; ADD INSTRUCTIONS
754 ;; ----------------------------------------------------------------------
755
756 (define_insn "addqi3"
757   [(set (match_operand:QI 0 "register_operand" "=r")
758         (plus:QI (match_operand:QI 1 "register_operand" "%0")
759                  (match_operand:QI 2 "nonmemory_operand" "rn")))]
760   ""
761   "add.b        %X2,%X0"
762   [(set_attr "length" "2")
763    (set_attr "cc" "set_zn")])
764
765 (define_expand "addhi3"
766   [(set (match_operand:HI 0 "register_operand" "")
767         (plus:HI (match_operand:HI 1 "register_operand" "")
768                  (match_operand:HI 2 "nonmemory_operand" "")))]
769   ""
770   "")
771
772 (define_insn "*addhi3_h8300"
773   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
774         (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
775                  (match_operand:HI 2 "nonmemory_operand" "L,N,J,n,r")))]
776   "TARGET_H8300"
777   "@
778    adds %2,%T0
779    subs %G2,%T0
780    add.b        %t2,%t0
781    add.b        %s2,%s0\;addx   %t2,%t0
782    add.w        %T2,%T0"
783   [(set_attr "length" "2,2,2,4,2")
784    (set_attr "cc" "none_0hit,none_0hit,clobber,clobber,set_zn")])
785
786 (define_insn "*addhi3_h8300hs"
787   [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
788         (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
789                  (match_operand:HI 2 "nonmemory_operand" "L,N,J,n,r")))]
790   "TARGET_H8300H || TARGET_H8300S"
791   "@
792    adds %2,%S0
793    subs %G2,%S0
794    add.b        %t2,%t0
795    add.w        %T2,%T0
796    add.w        %T2,%T0"
797   [(set_attr "length" "2,2,2,4,2")
798    (set_attr "cc" "none_0hit,none_0hit,clobber,set_zn,set_zn")])
799
800 (define_insn "addhi3_incdec"
801   [(set (match_operand:HI 0 "register_operand" "=r,r")
802         (unspec:HI [(match_operand:HI 1 "register_operand" "0,0")
803                     (match_operand:HI 2 "incdec_operand" "M,O")]
804                    UNSPEC_INCDEC))]
805   "TARGET_H8300H || TARGET_H8300S"
806   "@
807    inc.w        %2,%T0
808    dec.w        %G2,%T0"
809   [(set_attr "length" "2,2")
810    (set_attr "cc" "set_zn,set_zn")])
811
812 (define_split
813   [(set (match_operand:HI 0 "register_operand" "")
814         (plus:HI (match_dup 0)
815                  (match_operand:HI 1 "two_insn_adds_subs_operand" "")))]
816   ""
817   [(const_int 0)]
818   "split_adds_subs (HImode, operands, 0); DONE;")
819
820 (define_expand "addsi3"
821   [(set (match_operand:SI 0 "register_operand" "")
822         (plus:SI (match_operand:SI 1 "register_operand" "")
823                  (match_operand:SI 2 "nonmemory_operand" "")))]
824   ""
825   "")
826
827 (define_insn "addsi_h8300"
828   [(set (match_operand:SI 0 "register_operand" "=r,r,&r")
829         (plus:SI (match_operand:SI 1 "register_operand" "%0,0,r")
830                  (match_operand:SI 2 "nonmemory_operand" "n,r,r")))]
831   "TARGET_H8300"
832   "@
833    add  %w2,%w0\;addx   %x2,%x0\;addx   %y2,%y0\;addx   %z2,%z0
834    add.w        %f2,%f0\;addx   %y2,%y0\;addx   %z2,%z0
835    mov.w        %f1,%f0\;mov.w  %e1,%e0\;add.w  %f2,%f0\;addx   %y2,%y0\;addx   %z2,%z0"
836   [(set_attr "length" "8,6,10")
837    (set_attr "cc" "clobber")])
838
839 (define_insn "addsi_h8300h"
840   [(set (match_operand:SI 0 "register_operand" "=r,r")
841         (plus:SI (match_operand:SI 1 "register_operand" "%0,0")
842                  (match_operand:SI 2 "nonmemory_operand" "i,r")))]
843   "TARGET_H8300H || TARGET_H8300S"
844   "* return output_plussi (operands);"
845   [(set (attr "length")
846         (symbol_ref "compute_plussi_length (operands)"))
847    (set (attr "cc")
848         (symbol_ref "compute_plussi_cc (operands)"))])
849
850 (define_insn "addsi3_incdec"
851   [(set (match_operand:SI 0 "register_operand" "=r,r")
852         (unspec:SI [(match_operand:SI 1 "register_operand" "0,0")
853                     (match_operand:SI 2 "incdec_operand" "M,O")]
854                    UNSPEC_INCDEC))]
855   "TARGET_H8300H || TARGET_H8300S"
856   "@
857    inc.l        %2,%S0
858    dec.l        %G2,%S0"
859   [(set_attr "length" "2,2")
860    (set_attr "cc" "set_zn,set_zn")])
861
862 (define_split
863   [(set (match_operand:SI 0 "register_operand" "")
864         (plus:SI (match_dup 0)
865                  (match_operand:SI 1 "two_insn_adds_subs_operand" "")))]
866   "TARGET_H8300H || TARGET_H8300S"
867   [(const_int 0)]
868   "split_adds_subs (SImode, operands, 0); DONE;")
869
870 ;; ----------------------------------------------------------------------
871 ;; SUBTRACT INSTRUCTIONS
872 ;; ----------------------------------------------------------------------
873
874 (define_insn "subqi3"
875   [(set (match_operand:QI 0 "register_operand" "=r")
876         (minus:QI (match_operand:QI 1 "register_operand" "0")
877                   (match_operand:QI 2 "register_operand" "r")))]
878   ""
879   "sub.b        %X2,%X0"
880   [(set_attr "length" "2")
881    (set_attr "cc" "set_zn")])
882
883 (define_expand "subhi3"
884   [(set (match_operand:HI 0 "register_operand" "")
885         (minus:HI (match_operand:HI 1 "general_operand" "")
886                   (match_operand:HI 2 "nonmemory_operand" "")))]
887   ""
888   "")
889
890 (define_insn ""
891   [(set (match_operand:HI 0 "register_operand" "=r,&r")
892         (minus:HI (match_operand:HI 1 "general_operand" "0,0")
893                   (match_operand:HI 2 "nonmemory_operand" "r,n")))]
894   "TARGET_H8300"
895   "@
896    sub.w        %T2,%T0
897    add.b        %E2,%s0\;addx   %F2,%t0"
898   [(set_attr "length" "2,4")
899    (set_attr "cc" "set_zn,clobber")])
900
901 (define_insn ""
902   [(set (match_operand:HI 0 "register_operand" "=r,&r")
903         (minus:HI (match_operand:HI 1 "general_operand" "0,0")
904                   (match_operand:HI 2 "nonmemory_operand" "r,n")))]
905   "TARGET_H8300H || TARGET_H8300S"
906   "@
907    sub.w        %T2,%T0
908    sub.w        %T2,%T0"
909   [(set_attr "length" "2,4")
910    (set_attr "cc" "set_zn,set_zn")])
911
912 (define_expand "subsi3"
913   [(set (match_operand:SI 0 "register_operand" "")
914         (minus:SI (match_operand:SI 1 "register_operand" "")
915                   (match_operand:SI 2 "nonmemory_operand" "")))]
916   ""
917   "")
918
919 (define_insn "subsi3_h8300"
920   [(set (match_operand:SI 0 "register_operand" "=r")
921         (minus:SI (match_operand:SI 1 "register_operand" "0")
922                   (match_operand:SI 2 "register_operand" "r")))]
923   "TARGET_H8300"
924   "sub.w        %f2,%f0\;subx   %y2,%y0\;subx   %z2,%z0"
925   [(set_attr "length" "6")
926    (set_attr "cc" "clobber")])
927
928 (define_insn "subsi3_h8300h"
929   [(set (match_operand:SI 0 "register_operand" "=r,r")
930         (minus:SI (match_operand:SI 1 "general_operand" "0,0")
931                   (match_operand:SI 2 "nonmemory_operand" "r,i")))]
932   "TARGET_H8300H || TARGET_H8300S"
933   "@
934    sub.l        %S2,%S0
935    sub.l        %S2,%S0"
936   [(set_attr "length" "2,6")
937    (set_attr "cc" "set_zn,set_zn")])
938 \f
939 ;; ----------------------------------------------------------------------
940 ;; MULTIPLY INSTRUCTIONS
941 ;; ----------------------------------------------------------------------
942
943 ;; Note that the H8/300 can only handle umulqihi3.
944
945 (define_insn "mulqihi3"
946   [(set (match_operand:HI 0 "register_operand" "=r")
947         (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
948                  (sign_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
949   "TARGET_H8300H || TARGET_H8300S"
950   "mulxs.b      %X2,%T0"
951   [(set_attr "length" "4")
952    (set_attr "cc" "set_zn")])
953
954 (define_insn "mulhisi3"
955   [(set (match_operand:SI 0 "register_operand" "=r")
956         (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
957                  (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
958   "TARGET_H8300H || TARGET_H8300S"
959   "mulxs.w      %T2,%S0"
960   [(set_attr "length" "4")
961    (set_attr "cc" "set_zn")])
962
963 (define_insn "umulqihi3"
964   [(set (match_operand:HI 0 "register_operand" "=r")
965         (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
966                  (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
967   ""
968   "mulxu        %X2,%T0"
969   [(set_attr "length" "2")
970    (set_attr "cc" "none_0hit")])
971
972 (define_insn "umulhisi3"
973   [(set (match_operand:SI 0 "register_operand" "=r")
974         (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%0"))
975                  (zero_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
976   "TARGET_H8300H || TARGET_H8300S"
977   "mulxu.w      %T2,%S0"
978   [(set_attr "length" "2")
979    (set_attr "cc" "none_0hit")])
980
981 ;; This is a "bridge" instruction.  Combine can't cram enough insns
982 ;; together to crate a MAC instruction directly, but it can create
983 ;; this instruction, which then allows combine to create the real
984 ;; MAC insn.
985 ;;
986 ;; Unfortunately, if combine doesn't create a MAC instruction, this
987 ;; insn must generate reasonably correct code.  Egad.
988 (define_insn ""
989   [(set (match_operand:SI 0 "register_operand" "=a")
990         (mult:SI
991           (sign_extend:SI
992             (mem:HI (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
993           (sign_extend:SI
994             (mem:HI (post_inc:SI (match_operand:SI 2 "register_operand" "r"))))))]
995   "TARGET_MAC"
996   "clrmac\;mac  @%2+,@%1+"
997   [(set_attr "length" "6")
998    (set_attr "cc" "none_0hit")])
999
1000 (define_insn ""
1001   [(set (match_operand:SI 0 "register_operand" "=a")
1002         (plus:SI (mult:SI
1003           (sign_extend:SI (mem:HI
1004             (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
1005           (sign_extend:SI (mem:HI
1006             (post_inc:SI (match_operand:SI 2 "register_operand" "r")))))
1007               (match_operand:SI 3 "register_operand" "0")))]
1008   "TARGET_MAC"
1009   "mac  @%2+,@%1+"
1010   [(set_attr "length" "4")
1011    (set_attr "cc" "none_0hit")])
1012
1013 ;; ----------------------------------------------------------------------
1014 ;; DIVIDE/MOD INSTRUCTIONS
1015 ;; ----------------------------------------------------------------------
1016
1017 (define_insn "udivmodqi4"
1018   [(set (match_operand:QI 0 "register_operand" "=r")
1019         (truncate:QI
1020           (udiv:HI
1021             (match_operand:HI 1 "register_operand" "0")
1022             (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1023    (set (match_operand:QI 3 "register_operand" "=r")
1024         (truncate:QI
1025           (umod:HI
1026             (match_dup 1)
1027             (zero_extend:HI (match_dup 2)))))]
1028   ""
1029   "*
1030 {
1031   if (find_reg_note (insn, REG_UNUSED, operands[3]))
1032     return \"divxu.b\\t%X2,%T0\";
1033   else
1034     return \"divxu.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1035 }"
1036   [(set_attr "length" "4")
1037    (set_attr "cc" "clobber")])
1038
1039 (define_insn "divmodqi4"
1040   [(set (match_operand:QI 0 "register_operand" "=r")
1041         (truncate:QI
1042           (div:HI
1043             (match_operand:HI 1 "register_operand" "0")
1044             (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1045    (set (match_operand:QI 3 "register_operand" "=r")
1046         (truncate:QI
1047           (mod:HI
1048             (match_dup 1)
1049             (sign_extend:HI (match_dup 2)))))]
1050   "TARGET_H8300H || TARGET_H8300S"
1051   "*
1052 {
1053   if (find_reg_note (insn, REG_UNUSED, operands[3]))
1054     return \"divxs.b\\t%X2,%T0\";
1055   else
1056     return \"divxs.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1057 }"
1058   [(set_attr "length" "6")
1059    (set_attr "cc" "clobber")])
1060
1061 (define_insn "udivmodhi4"
1062   [(set (match_operand:HI 0 "register_operand" "=r")
1063         (truncate:HI
1064           (udiv:SI
1065             (match_operand:SI 1 "register_operand" "0")
1066             (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1067    (set (match_operand:HI 3 "register_operand" "=r")
1068         (truncate:HI
1069           (umod:SI
1070             (match_dup 1)
1071             (zero_extend:SI (match_dup 2)))))]
1072   "TARGET_H8300H || TARGET_H8300S"
1073   "*
1074 {
1075   if (find_reg_note (insn, REG_UNUSED, operands[3]))
1076     return \"divxu.w\\t%T2,%S0\";
1077   else
1078     return \"divxu.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1079 }"
1080   [(set_attr "length" "4")
1081    (set_attr "cc" "clobber")])
1082
1083 (define_insn "divmodhi4"
1084   [(set (match_operand:HI 0 "register_operand" "=r")
1085         (truncate:HI
1086           (div:SI
1087             (match_operand:SI 1 "register_operand" "0")
1088             (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1089    (set (match_operand:HI 3 "register_operand" "=r")
1090         (truncate:HI
1091           (mod:SI
1092             (match_dup 1)
1093             (sign_extend:SI (match_dup 2)))))]
1094   "TARGET_H8300H || TARGET_H8300S"
1095   "*
1096 {
1097   if (find_reg_note (insn, REG_UNUSED, operands[3]))
1098     return \"divxs.w\\t%T2,%S0\";
1099   else
1100     return \"divxs.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1101 }"
1102   [(set_attr "length" "6")
1103    (set_attr "cc" "clobber")])
1104 \f
1105 ;; ----------------------------------------------------------------------
1106 ;; AND INSTRUCTIONS
1107 ;; ----------------------------------------------------------------------
1108
1109 (define_insn ""
1110   [(set (match_operand:QI 0 "bit_operand" "=r,U")
1111         (and:QI (match_operand:QI 1 "bit_operand" "%0,0")
1112                 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1113   "register_operand (operands[0], QImode)
1114    || single_zero_operand (operands[2], QImode)"
1115   "@
1116    and  %X2,%X0
1117    bclr %W2,%R0"
1118   [(set_attr "length" "2,8")
1119    (set_attr "adjust_length" "no")
1120    (set_attr "cc" "set_znv,none_0hit")])
1121
1122 (define_expand "andqi3"
1123   [(set (match_operand:QI 0 "bit_operand" "")
1124         (and:QI (match_operand:QI 1 "bit_operand" "")
1125                 (match_operand:QI 2 "nonmemory_operand" "")))]
1126   ""
1127   "
1128 {
1129   if (fix_bit_operand (operands, 0, AND))
1130     DONE;
1131 }")
1132
1133 (define_expand "andhi3"
1134   [(set (match_operand:HI 0 "register_operand" "")
1135         (and:HI (match_operand:HI 1 "register_operand" "")
1136                 (match_operand:HI 2 "nonmemory_operand" "")))]
1137   ""
1138   "")
1139
1140 (define_insn "*andorqi3"
1141   [(set (match_operand:QI 0 "register_operand" "=r")
1142         (ior:QI (and:QI (match_operand:QI 2 "register_operand" "r")
1143                         (match_operand:QI 3 "single_one_operand" "n"))
1144                 (match_operand:QI 1 "register_operand" "0")))]
1145   ""
1146   "bld\\t%V3,%X2\;bor\\t%V3,%X0\;bst\\t%V3,%X0"
1147   [(set_attr "length" "6")
1148    (set_attr "cc" "clobber")])
1149
1150 (define_insn "*andorhi3"
1151   [(set (match_operand:HI 0 "register_operand" "=r")
1152         (ior:HI (and:HI (match_operand:HI 2 "register_operand" "r")
1153                         (match_operand:HI 3 "single_one_operand" "n"))
1154                 (match_operand:HI 1 "register_operand" "0")))]
1155   ""
1156   "*
1157 {
1158   operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1159   if (INTVAL (operands[3]) > 128)
1160     {
1161       operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1162       return \"bld\\t%V3,%t2\;bor\\t%V3,%t0\;bst\\t%V3,%t0\";
1163     }
1164   return \"bld\\t%V3,%s2\;bor\\t%V3,%s0\;bst\\t%V3,%s0\";
1165 }"
1166   [(set_attr "length" "6")
1167    (set_attr "cc" "clobber")])
1168
1169 (define_insn "*andorsi3"
1170   [(set (match_operand:SI 0 "register_operand" "=r")
1171         (ior:SI (and:SI (match_operand:SI 2 "register_operand" "r")
1172                         (match_operand:SI 3 "single_one_operand" "n"))
1173                 (match_operand:SI 1 "register_operand" "0")))]
1174   "(INTVAL (operands[3]) & 0xffff) != 0"
1175   "*
1176 {
1177   operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1178   if (INTVAL (operands[3]) > 128)
1179     {
1180       operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1181       return \"bld\\t%V3,%x2\;bor\\t%V3,%x0\;bst\\t%V3,%x0\";
1182     }
1183   return \"bld\\t%V3,%w2\;bor\\t%V3,%w0\;bst\\t%V3,%w0\";
1184 }"
1185   [(set_attr "length" "6")
1186    (set_attr "cc" "clobber")])
1187
1188 (define_insn "*andorsi3_shift_8"
1189   [(set (match_operand:SI 0 "register_operand" "=r")
1190         (ior:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1191                                    (const_int 8))
1192                         (const_int 65280))
1193                 (match_operand:SI 1 "register_operand" "0")))]
1194   ""
1195   "or.b\\t%w2,%x0"
1196   [(set_attr "length" "2")
1197    (set_attr "cc" "clobber")])
1198
1199 (define_expand "andsi3"
1200   [(set (match_operand:SI 0 "register_operand" "")
1201         (and:SI (match_operand:SI 1 "register_operand" "")
1202                 (match_operand:SI 2 "nonmemory_operand" "")))]
1203   ""
1204   "")
1205
1206 ;; ----------------------------------------------------------------------
1207 ;; OR INSTRUCTIONS
1208 ;; ----------------------------------------------------------------------
1209
1210 (define_insn ""
1211   [(set (match_operand:QI 0 "bit_operand" "=r,U")
1212         (ior:QI (match_operand:QI 1 "bit_operand" "%0,0")
1213                 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1214   "register_operand (operands[0], QImode)
1215    || single_one_operand (operands[2], QImode)"
1216   "@
1217    or\\t%X2,%X0
1218    bset\\t%V2,%R0"
1219   [(set_attr "length" "2,8")
1220    (set_attr "adjust_length" "no")
1221    (set_attr "cc" "set_znv,none_0hit")])
1222
1223 (define_expand "iorqi3"
1224   [(set (match_operand:QI 0 "bit_operand" "")
1225         (ior:QI (match_operand:QI 1 "bit_operand" "")
1226                 (match_operand:QI 2 "nonmemory_operand" "")))]
1227   ""
1228   "
1229 {
1230   if (fix_bit_operand (operands, 1, IOR))
1231     DONE;
1232 }")
1233
1234 (define_expand "iorhi3"
1235   [(set (match_operand:HI 0 "register_operand" "")
1236         (ior:HI (match_operand:HI 1 "register_operand" "")
1237                 (match_operand:HI 2 "nonmemory_operand" "")))]
1238   ""
1239   "")
1240
1241 (define_expand "iorsi3"
1242   [(set (match_operand:SI 0 "register_operand" "")
1243         (ior:SI (match_operand:SI 1 "register_operand" "")
1244                 (match_operand:SI 2 "nonmemory_operand" "")))]
1245   ""
1246   "")
1247
1248 ;; ----------------------------------------------------------------------
1249 ;; XOR INSTRUCTIONS
1250 ;; ----------------------------------------------------------------------
1251
1252 (define_insn ""
1253   [(set (match_operand:QI 0 "bit_operand" "=r,U")
1254         (xor:QI (match_operand:QI 1 "bit_operand" "%0,0")
1255                 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1256   "register_operand (operands[0], QImode)
1257    || single_one_operand (operands[2], QImode)"
1258   "@
1259    xor\\t%X2,%X0
1260    bnot\\t%V2,%R0"
1261   [(set_attr "length" "2,8")
1262    (set_attr "adjust_length" "no")
1263    (set_attr "cc" "set_znv,none_0hit")])
1264
1265 (define_expand "xorqi3"
1266   [(set (match_operand:QI 0 "bit_operand" "")
1267         (xor:QI (match_operand:QI 1 "bit_operand" "")
1268                 (match_operand:QI 2 "nonmemory_operand" "")))]
1269   ""
1270   "
1271 {
1272   if (fix_bit_operand (operands, 1, XOR))
1273     DONE;
1274 }")
1275
1276 (define_expand "xorhi3"
1277   [(set (match_operand:HI 0 "register_operand" "")
1278         (xor:HI (match_operand:HI 1 "register_operand" "")
1279                 (match_operand:HI 2 "nonmemory_operand" "")))]
1280   ""
1281   "")
1282
1283 (define_expand "xorsi3"
1284   [(set (match_operand:SI 0 "register_operand" "")
1285         (xor:SI (match_operand:SI 1 "register_operand" "")
1286                 (match_operand:SI 2 "nonmemory_operand" "")))]
1287   ""
1288   "")
1289
1290 ;; ----------------------------------------------------------------------
1291 ;; {AND,IOR,XOR}{HI3,SI3} PATTERNS
1292 ;; ----------------------------------------------------------------------
1293
1294 (define_insn ""
1295   [(set (match_operand:HI 0 "register_operand" "=r")
1296         (match_operator:HI 3 "bit_operator"
1297           [(match_operand:HI 1 "register_operand" "%0")
1298            (match_operand:HI 2 "nonmemory_operand" "rn")]))]
1299   ""
1300   "* return output_logical_op (HImode, operands);"
1301   [(set (attr "length")
1302         (symbol_ref "compute_logical_op_length (HImode, operands)"))
1303    (set (attr "cc")
1304         (symbol_ref "compute_logical_op_cc (HImode, operands)"))])
1305
1306 (define_insn ""
1307   [(set (match_operand:SI 0 "register_operand" "=r")
1308         (match_operator:SI 3 "bit_operator"
1309           [(match_operand:SI 1 "register_operand" "%0")
1310            (match_operand:SI 2 "nonmemory_operand" "rn")]))]
1311   ""
1312   "* return output_logical_op (SImode, operands);"
1313   [(set (attr "length")
1314         (symbol_ref "compute_logical_op_length (SImode, operands)"))
1315    (set (attr "cc")
1316         (symbol_ref "compute_logical_op_cc (SImode, operands)"))])
1317 \f
1318 ;; ----------------------------------------------------------------------
1319 ;; NEGATION INSTRUCTIONS
1320 ;; ----------------------------------------------------------------------
1321
1322 (define_insn "negqi2"
1323   [(set (match_operand:QI 0 "register_operand" "=r")
1324         (neg:QI (match_operand:QI 1 "register_operand" "0")))]
1325   ""
1326   "neg  %X0"
1327   [(set_attr "length" "2")
1328    (set_attr "cc" "set_zn")])
1329
1330 (define_expand "neghi2"
1331   [(set (match_operand:HI 0 "register_operand" "")
1332         (neg:HI (match_operand:HI 1 "register_operand" "")))]
1333   ""
1334   "
1335 {
1336   if (TARGET_H8300)
1337     {
1338       emit_insn (gen_neghi2_h8300 (operands[0], operands[1]));
1339       DONE;
1340     }
1341 }")
1342
1343 (define_expand "neghi2_h8300"
1344   [(set (match_dup 2)
1345         (not:HI (match_operand:HI 1 "register_operand" "")))
1346    (set (match_dup 2) (plus:HI (match_dup 2) (const_int 1)))
1347    (set (match_operand:HI 0 "register_operand" "")
1348         (match_dup 2))]
1349   ""
1350   "operands[2] = gen_reg_rtx (HImode);")
1351
1352 (define_insn "neghi2_h8300h"
1353   [(set (match_operand:HI 0 "register_operand" "=r")
1354         (neg:HI (match_operand:HI 1 "register_operand" "0")))]
1355   "TARGET_H8300H || TARGET_H8300S"
1356   "neg  %T0"
1357   [(set_attr "length" "2")
1358    (set_attr "cc" "set_zn")])
1359
1360 (define_expand "negsi2"
1361   [(set (match_operand:SI 0 "register_operand" "")
1362         (neg:SI (match_operand:SI 1 "register_operand" "")))]
1363   ""
1364   "
1365 {
1366   if (TARGET_H8300)
1367     {
1368       emit_insn (gen_negsi2_h8300 (operands[0], operands[1]));
1369       DONE;
1370     }
1371 }")
1372
1373 (define_expand "negsi2_h8300"
1374   [(set (match_dup 2)
1375         (not:SI (match_operand:SI 1 "register_operand" "")))
1376    (set (match_dup 2) (plus:SI (match_dup 2) (const_int 1)))
1377    (set (match_operand:SI 0 "register_operand" "")
1378         (match_dup 2))]
1379   ""
1380   "operands[2] = gen_reg_rtx (SImode);")
1381
1382 (define_insn "negsi2_h8300h"
1383   [(set (match_operand:SI 0 "register_operand" "=r")
1384         (neg:SI (match_operand:SI 1 "register_operand" "0")))]
1385   "TARGET_H8300H || TARGET_H8300S"
1386   "neg  %S0"
1387   [(set_attr "length" "2")
1388    (set_attr "cc" "set_zn")])
1389
1390 (define_expand "negsf2"
1391   [(set (match_operand:SF 0 "register_operand" "")
1392         (neg:SF (match_operand:SF 1 "register_operand" "")))]
1393   ""
1394   "")
1395
1396 (define_insn "*negsf2_h8300"
1397   [(set (match_operand:SF 0 "register_operand" "=r")
1398         (neg:SF (match_operand:SF 1 "register_operand" "0")))]
1399   "TARGET_H8300"
1400   "xor.b\t#128,%z0"
1401   [(set_attr "cc" "clobber")
1402    (set_attr "length" "2")])
1403
1404 (define_insn "*negsf2_h8300hs"
1405   [(set (match_operand:SF 0 "register_operand" "=r")
1406         (neg:SF (match_operand:SF 1 "register_operand" "0")))]
1407   "TARGET_H8300H || TARGET_H8300S"
1408   "xor.w\t#32768,%e0"
1409   [(set_attr "cc" "clobber")
1410    (set_attr "length" "4")])
1411
1412 ;; ----------------------------------------------------------------------
1413 ;; NOT INSTRUCTIONS
1414 ;; ----------------------------------------------------------------------
1415
1416 (define_insn "one_cmplqi2"
1417   [(set (match_operand:QI 0 "register_operand" "=r")
1418         (not:QI (match_operand:QI 1 "register_operand" "0")))]
1419   ""
1420   "not  %X0"
1421   [(set_attr "length" "2")
1422    (set_attr "cc" "set_znv")])
1423
1424 (define_expand "one_cmplhi2"
1425   [(set (match_operand:HI 0 "register_operand" "=r")
1426         (not:HI (match_operand:HI 1 "register_operand" "0")))]
1427   ""
1428   "")
1429
1430 (define_insn ""
1431   [(set (match_operand:HI 0 "register_operand" "=r")
1432         (not:HI (match_operand:HI 1 "register_operand" "0")))]
1433   "TARGET_H8300"
1434   "not  %s0\;not        %t0"
1435   [(set_attr "cc" "clobber")
1436    (set_attr "length" "4")])
1437
1438 (define_insn ""
1439   [(set (match_operand:HI 0 "register_operand" "=r")
1440         (not:HI (match_operand:HI 1 "register_operand" "0")))]
1441   "TARGET_H8300H || TARGET_H8300S"
1442   "not  %T0"
1443   [(set_attr "cc" "set_znv")
1444    (set_attr "length" "2")])
1445
1446 (define_expand "one_cmplsi2"
1447   [(set (match_operand:SI 0 "register_operand" "=r")
1448         (not:SI (match_operand:SI 1 "register_operand" "0")))]
1449   ""
1450   "")
1451
1452 (define_insn ""
1453   [(set (match_operand:SI 0 "register_operand" "=r")
1454         (not:SI (match_operand:SI 1 "register_operand" "0")))]
1455   "TARGET_H8300"
1456   "not  %w0\;not        %x0\;not        %y0\;not        %z0"
1457   [(set_attr "cc" "clobber")
1458    (set_attr "length" "8")])
1459
1460 (define_insn ""
1461   [(set (match_operand:SI 0 "register_operand" "=r")
1462         (not:SI (match_operand:SI 1 "register_operand" "0")))]
1463   "TARGET_H8300H || TARGET_H8300S"
1464   "not  %S0"
1465   [(set_attr "cc" "set_znv")
1466    (set_attr "length" "2")])
1467 \f
1468 ;; ----------------------------------------------------------------------
1469 ;; JUMP INSTRUCTIONS
1470 ;; ----------------------------------------------------------------------
1471
1472 ;; Conditional jump instructions
1473
1474 (define_expand "ble"
1475   [(set (pc)
1476         (if_then_else (le (cc0)
1477                           (const_int 0))
1478                       (label_ref (match_operand 0 "" ""))
1479                       (pc)))]
1480   ""
1481   "")
1482
1483 (define_expand "bleu"
1484   [(set (pc)
1485         (if_then_else (leu (cc0)
1486                            (const_int 0))
1487                       (label_ref (match_operand 0 "" ""))
1488                       (pc)))]
1489   ""
1490   "")
1491
1492 (define_expand "bge"
1493   [(set (pc)
1494         (if_then_else (ge (cc0)
1495                           (const_int 0))
1496                       (label_ref (match_operand 0 "" ""))
1497                       (pc)))]
1498   ""
1499   "")
1500
1501 (define_expand "bgeu"
1502   [(set (pc)
1503         (if_then_else (geu (cc0)
1504                            (const_int 0))
1505                       (label_ref (match_operand 0 "" ""))
1506                       (pc)))]
1507   ""
1508   "")
1509
1510 (define_expand "blt"
1511   [(set (pc)
1512         (if_then_else (lt (cc0)
1513                           (const_int 0))
1514                       (label_ref (match_operand 0 "" ""))
1515                       (pc)))]
1516   ""
1517   "")
1518
1519 (define_expand "bltu"
1520   [(set (pc)
1521         (if_then_else (ltu (cc0)
1522                            (const_int 0))
1523                       (label_ref (match_operand 0 "" ""))
1524                       (pc)))]
1525   ""
1526   "")
1527
1528 (define_expand "bgt"
1529   [(set (pc)
1530         (if_then_else (gt (cc0)
1531                           (const_int 0))
1532                       (label_ref (match_operand 0 "" ""))
1533                       (pc)))]
1534   ""
1535   "")
1536
1537 (define_expand "bgtu"
1538   [(set (pc)
1539         (if_then_else (gtu (cc0)
1540                            (const_int 0))
1541                       (label_ref (match_operand 0 "" ""))
1542                       (pc)))]
1543   ""
1544   "")
1545
1546 (define_expand "beq"
1547   [(set (pc)
1548         (if_then_else (eq (cc0)
1549                           (const_int 0))
1550                       (label_ref (match_operand 0 "" ""))
1551                       (pc)))]
1552   ""
1553   "")
1554
1555 (define_expand "bne"
1556   [(set (pc)
1557         (if_then_else (ne (cc0)
1558                           (const_int 0))
1559                       (label_ref (match_operand 0 "" ""))
1560                       (pc)))]
1561   ""
1562   "")
1563
1564 (define_insn "branch_true"
1565   [(set (pc)
1566         (if_then_else (match_operator 1 "comparison_operator"
1567                                       [(cc0) (const_int 0)])
1568                       (label_ref (match_operand 0 "" ""))
1569                       (pc)))]
1570   ""
1571   "*
1572 {
1573   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1574       && (GET_CODE (operands[1]) == GT
1575           || GET_CODE (operands[1]) == GE
1576           || GET_CODE (operands[1]) == LE
1577           || GET_CODE (operands[1]) == LT))
1578     {
1579       cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
1580       return 0;
1581     }
1582
1583   if (get_attr_length (insn) == 2)
1584     return \"b%j1       %l0\";
1585   else if (get_attr_length (insn) == 4)
1586     return \"b%j1       %l0:16\";
1587   else
1588     return \"b%k1       .Lh8BR%=\;jmp   @%l0\\n.Lh8BR%=:\";
1589 }"
1590  [(set_attr "type" "branch")
1591    (set_attr "cc" "none")])
1592
1593 (define_insn "branch_false"
1594   [(set (pc)
1595         (if_then_else (match_operator 1 "comparison_operator"
1596                                       [(cc0) (const_int 0)])
1597                       (pc)
1598                       (label_ref (match_operand 0 "" ""))))]
1599   ""
1600   "*
1601 {
1602   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1603       && (GET_CODE (operands[1]) == GT
1604           || GET_CODE (operands[1]) == GE
1605           || GET_CODE (operands[1]) == LE
1606           || GET_CODE (operands[1]) == LT))
1607     {
1608       cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
1609       return 0;
1610     }
1611
1612   if (get_attr_length (insn) == 2)
1613     return \"b%k1       %l0\";
1614   else if (get_attr_length (insn) == 4)
1615     return \"b%k1       %l0:16\";
1616   else
1617     return \"b%j1       .Lh8BR%=\;jmp   @%l0\\n.Lh8BR%=:\";
1618 }"
1619   [(set_attr "type" "branch")
1620    (set_attr "cc" "none")])
1621
1622 ;; Unconditional and other jump instructions.
1623
1624 (define_insn "jump"
1625   [(set (pc)
1626         (label_ref (match_operand 0 "" "")))]
1627   ""
1628   "*
1629 {
1630   if (get_attr_length (insn) == 2)
1631     return \"bra        %l0\";
1632   else if (get_attr_length (insn) == 4)
1633     return \"bra        %l0:16\";
1634   else
1635     return \"jmp        @%l0\";
1636 }"
1637   [(set_attr "type" "branch")
1638    (set_attr "cc" "none")])
1639
1640 ;; This is a define expand, because pointers may be either 16 or 32 bits.
1641
1642 (define_expand "tablejump"
1643   [(parallel [(set (pc) (match_operand 0 "register_operand" ""))
1644               (use (label_ref (match_operand 1 "" "")))])]
1645   ""
1646   "")
1647
1648 (define_insn "tablejump_h8300"
1649   [(set (pc) (match_operand:HI 0 "register_operand" "r"))
1650    (use (label_ref (match_operand 1 "" "")))]
1651   "TARGET_H8300"
1652   "jmp  @%0"
1653   [(set_attr "cc" "none")
1654    (set_attr "length" "2")])
1655
1656 (define_insn "tablejump_h8300h"
1657   [(set (pc) (match_operand:SI 0 "register_operand" "r"))
1658    (use (label_ref (match_operand 1 "" "")))]
1659   "TARGET_H8300H || TARGET_H8300S"
1660   "jmp  @%0"
1661   [(set_attr "cc" "none")
1662    (set_attr "length" "2")])
1663
1664 (define_insn "tablejump_normal_mode"
1665    [(set (pc) (match_operand:HI 0 "register_operand" "r"))
1666     (use (label_ref (match_operand 1 "" "")))]
1667    "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
1668    "jmp @%S0"
1669    [(set_attr "cc" "none")
1670     (set_attr "length" "2")])
1671
1672 ;; This is a define expand, because pointers may be either 16 or 32 bits.
1673
1674 (define_expand "indirect_jump"
1675   [(set (pc) (match_operand 0 "jump_address_operand" ""))]
1676   ""
1677   "")
1678
1679 (define_insn "indirect_jump_h8300"
1680   [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
1681   "TARGET_H8300"
1682   "jmp  @%0"
1683   [(set_attr "cc" "none")
1684    (set_attr "length" "2")])
1685
1686 (define_insn "indirect_jump_h8300h"
1687   [(set (pc) (match_operand:SI 0 "jump_address_operand" "Vr"))]
1688   "TARGET_H8300H || TARGET_H8300S"
1689   "jmp @%0"
1690   [(set_attr "cc" "none")
1691    (set_attr "length" "2")])
1692
1693 (define_insn "indirect_jump_normal_mode"
1694   [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
1695   "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
1696   "jmp @%S0"
1697   [(set_attr "cc" "none")
1698    (set_attr "length" "2")])
1699
1700 ;; Call subroutine with no return value.
1701
1702 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
1703
1704 (define_insn "call"
1705   [(call (match_operand:QI 0 "call_insn_operand" "or")
1706          (match_operand:HI 1 "general_operand" "g"))]
1707   ""
1708   "*
1709 {
1710   if (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
1711       && SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
1712     return \"jsr\\t@%0:8\";
1713   else
1714     return \"jsr\\t%0\";
1715 }"
1716   [(set_attr "cc" "clobber")
1717    (set (attr "length")
1718         (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
1719                       (const_int 4)
1720                       (const_int 8)))])
1721
1722 ;; Call subroutine, returning value in operand 0
1723 ;; (which must be a hard register).
1724
1725 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
1726
1727 (define_insn "call_value"
1728   [(set (match_operand 0 "" "=r")
1729         (call (match_operand:QI 1 "call_insn_operand" "or")
1730               (match_operand:HI 2 "general_operand" "g")))]
1731   ""
1732   "*
1733 {
1734   if (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
1735       && SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
1736     return \"jsr\\t@%1:8\";
1737   else
1738     return \"jsr\\t%1\";
1739 }"
1740   [(set_attr "cc" "clobber")
1741    (set (attr "length")
1742         (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
1743                       (const_int 4)
1744                       (const_int 8)))])
1745
1746 (define_insn "nop"
1747   [(const_int 0)]
1748   ""
1749   "nop"
1750   [(set_attr "cc" "none")
1751    (set_attr "length" "2")])
1752 \f
1753 ;; ----------------------------------------------------------------------
1754 ;; PROLOGUE/EPILOGUE-RELATED INSTRUCTIONS
1755 ;; ----------------------------------------------------------------------
1756
1757 (define_insn "*stm_h8300s_2"
1758   [(parallel
1759      [(set (reg:SI SP_REG)
1760            (plus:SI (reg:SI SP_REG) (const_int -8)))
1761       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1762            (match_operand:SI 0 "register_operand" ""))
1763       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1764            (match_operand:SI 1 "register_operand" ""))])]
1765   "TARGET_H8300S
1766    && ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
1767        || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
1768        || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5))"
1769   "stm.l\\t%S0-%S1,@-er7"
1770   [(set_attr "cc" "none")
1771    (set_attr "length" "4")])
1772
1773 (define_insn "*stm_h8300s_3"
1774   [(parallel
1775      [(set (reg:SI SP_REG)
1776            (plus:SI (reg:SI SP_REG) (const_int -12)))
1777       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1778            (match_operand:SI 0 "register_operand" ""))
1779       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1780            (match_operand:SI 1 "register_operand" ""))
1781       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
1782            (match_operand:SI 2 "register_operand" ""))])]
1783   "TARGET_H8300S
1784    && ((REGNO (operands[0]) == 0
1785         && REGNO (operands[1]) == 1
1786         && REGNO (operands[2]) == 2)
1787        || (REGNO (operands[0]) == 4
1788            && REGNO (operands[1]) == 5
1789            && REGNO (operands[2]) == 6))"
1790   "stm.l\\t%S0-%S2,@-er7"
1791   [(set_attr "cc" "none")
1792    (set_attr "length" "4")])
1793
1794 (define_insn "*stm_h8300s_4"
1795   [(parallel
1796      [(set (reg:SI SP_REG)
1797            (plus:SI (reg:SI SP_REG) (const_int -16)))
1798       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1799            (match_operand:SI 0 "register_operand" ""))
1800       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1801            (match_operand:SI 1 "register_operand" ""))
1802       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
1803            (match_operand:SI 2 "register_operand" ""))
1804       (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
1805            (match_operand:SI 3 "register_operand" ""))])]
1806   "TARGET_H8300S
1807    && REGNO (operands[0]) == 0
1808    && REGNO (operands[1]) == 1
1809    && REGNO (operands[2]) == 2
1810    && REGNO (operands[3]) == 3"
1811   "stm.l\\t%S0-%S3,@-er7"
1812   [(set_attr "cc" "none")
1813    (set_attr "length" "4")])
1814 \f
1815 ;; ----------------------------------------------------------------------
1816 ;; EXTEND INSTRUCTIONS
1817 ;; ----------------------------------------------------------------------
1818
1819 (define_expand "zero_extendqihi2"
1820   [(set (match_operand:HI 0 "register_operand" "")
1821         (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
1822   ""
1823   "")
1824
1825 (define_insn "*zero_extendqihi2_h8300"
1826   [(set (match_operand:HI 0 "register_operand" "=r,r")
1827         (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1828   "TARGET_H8300"
1829   "@
1830   mov.b #0,%t0
1831   #"
1832   [(set_attr "length" "2,10")
1833    (set_attr "cc" "clobber,clobber")])
1834
1835 (define_insn "*zero_extendqihi2_h8300hs"
1836   [(set (match_operand:HI 0 "register_operand" "=r,r")
1837         (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1838   "TARGET_H8300H || TARGET_H8300S"
1839   "@
1840   extu.w        %T0
1841   #"
1842   [(set_attr "length" "2,10")
1843    (set_attr "cc" "set_znv,set_znv")])
1844
1845 ;; Split the zero extension of a general operand (actually a memory
1846 ;; operand) into a load of the operand and the actual zero extension
1847 ;; so that 1) the length will be accurate, and 2) the zero extensions
1848 ;; appearing at the end of basic blocks may be merged.
1849
1850 (define_split
1851   [(set (match_operand:HI 0 "register_operand" "")
1852         (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
1853   "reload_completed"
1854   [(set (match_dup 2)
1855         (match_dup 1))
1856    (set (match_dup 0)
1857         (zero_extend:HI (match_dup 2)))]
1858   "operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));")
1859
1860 ;; The compiler can synthesize a H8/300H variant of this which is
1861 ;; just as efficient as one that we'd create
1862 (define_insn "zero_extendqisi2"
1863   [(set (match_operand:SI 0 "register_operand" "=r,r")
1864         (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1865   "TARGET_H8300"
1866   "@
1867   mov.b #0,%x0\;sub.w   %e0,%e0
1868   mov.b %R1,%w0\;mov.b  #0,%x0\;sub.w   %e0,%e0"
1869   [(set_attr "length" "4,8")
1870    (set_attr "cc" "clobber,clobber")])
1871
1872 (define_expand "zero_extendhisi2"
1873   [(set (match_operand:SI 0 "register_operand" "")
1874         (zero_extend:SI (match_operand:HI 1 "register_operand" "")))]
1875   ""
1876   "")
1877
1878 ;; %e prints the high part of a CONST_INT, not the low part.  Arggh.
1879 (define_insn ""
1880   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1881         (zero_extend:SI (match_operand:HI 1 "general_operand_src" "0,i,g>")))]
1882   "TARGET_H8300"
1883   "@
1884   sub.w %e0,%e0
1885   mov.w %f1,%f0\;sub.w  %e0,%e0
1886   mov.w %e1,%f0\;sub.w  %e0,%e0"
1887   [(set_attr "length" "2,4,4")
1888    (set_attr "cc" "clobber,clobber,clobber")])
1889
1890 (define_insn ""
1891   [(set (match_operand:SI 0 "register_operand" "=r")
1892         (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))]
1893   "TARGET_H8300H || TARGET_H8300S"
1894   "extu.l       %S0"
1895   [(set_attr "length" "2")
1896    (set_attr "cc" "set_znv")])
1897
1898 (define_expand "extendqihi2"
1899   [(set (match_operand:HI 0 "register_operand" "")
1900         (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
1901   ""
1902   "")
1903
1904 (define_insn ""
1905   [(set (match_operand:HI 0 "register_operand" "=r,r")
1906         (sign_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1907   "TARGET_H8300"
1908   "@
1909   bld   #7,%s0\;subx    %t0,%t0
1910   mov.b %R1,%s0\;bld    #7,%s0\;subx    %t0,%t0"
1911   [(set_attr "length" "4,8")
1912    (set_attr "cc" "clobber,clobber")])
1913
1914 (define_insn ""
1915   [(set (match_operand:HI 0 "register_operand" "=r")
1916         (sign_extend:HI (match_operand:QI 1 "register_operand" "0")))]
1917   "TARGET_H8300H || TARGET_H8300S"
1918   "exts.w       %T0"
1919   [(set_attr "length" "2")
1920    (set_attr "cc" "set_znv")])
1921
1922 ;; The compiler can synthesize a H8/300H variant of this which is
1923 ;; just as efficient as one that we'd create
1924 (define_insn "extendqisi2"
1925   [(set (match_operand:SI 0 "register_operand" "=r,r")
1926         (sign_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1927   "TARGET_H8300"
1928   "@
1929   bld   #7,%w0\;subx    %x0,%x0\;subx   %y0,%y0\;subx   %z0,%z0
1930   mov.b %R1,%w0\;bld    #7,%w0\;subx    %x0,%x0\;subx   %y0,%y0\;subx   %z0,%z0"
1931   [(set_attr "length" "8,10")
1932    (set_attr "cc" "clobber,clobber")])
1933
1934 (define_expand "extendhisi2"
1935   [(set (match_operand:SI 0 "register_operand" "")
1936         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
1937   ""
1938   "")
1939
1940 (define_insn ""
1941   [(set (match_operand:SI 0 "register_operand" "=r,r")
1942         (sign_extend:SI (match_operand:HI 1 "general_operand_src" "0,g>")))]
1943   "TARGET_H8300"
1944   "@
1945   bld   #7,%x0\;subx    %y0,%y0\;subx   %z0,%z0
1946   mov.w %T1,%f0\;bld    #7,%x0\;subx    %y0,%y0\;subx   %z0,%z0"
1947   [(set_attr "length" "6,8")
1948    (set_attr "cc" "clobber,clobber")])
1949
1950 (define_insn ""
1951   [(set (match_operand:SI 0 "register_operand" "=r")
1952         (sign_extend:SI (match_operand:HI 1 "register_operand" "0")))]
1953   "TARGET_H8300H || TARGET_H8300S"
1954   "exts.l       %S0"
1955   [(set_attr "length" "2")
1956    (set_attr "cc" "set_znv")])
1957 \f
1958 ;; ----------------------------------------------------------------------
1959 ;; SHIFTS
1960 ;; ----------------------------------------------------------------------
1961 ;;
1962 ;; We make some attempt to provide real efficient shifting.  One example is
1963 ;; doing an 8 bit shift of a 16 bit value by moving a byte reg into the other
1964 ;; reg and moving 0 into the former reg.
1965 ;;
1966 ;; We also try to achieve this in a uniform way.  IE: We don't try to achieve
1967 ;; this in both rtl and at insn emit time.  Ideally, we'd use rtl as that would
1968 ;; give the optimizer more cracks at the code.  However, we wish to do things
1969 ;; like optimizing shifting the sign bit to bit 0 by rotating the other way.
1970 ;; There is rtl to handle this (rotate + and), but the H8/300 doesn't handle
1971 ;; 16 bit rotates.  Also, if we emit complicated rtl, combine may not be able
1972 ;; to detect cases it can optimize.
1973 ;;
1974 ;; For these and other fuzzy reasons, I've decided to go the less pretty but
1975 ;; easier "do it at insn emit time" route.
1976
1977 ;; QI BIT SHIFTS
1978
1979 (define_expand "ashlqi3"
1980   [(set (match_operand:QI 0 "register_operand" "")
1981         (ashift:QI (match_operand:QI 1 "register_operand" "")
1982                    (match_operand:QI 2 "nonmemory_operand" "")))]
1983   ""
1984   "expand_a_shift (QImode, ASHIFT, operands); DONE;")
1985
1986 (define_expand "ashrqi3"
1987   [(set (match_operand:QI 0 "register_operand" "")
1988         (ashiftrt:QI (match_operand:QI 1 "register_operand" "")
1989                      (match_operand:QI 2 "nonmemory_operand" "")))]
1990   ""
1991   "expand_a_shift (QImode, ASHIFTRT, operands); DONE;")
1992
1993 (define_expand "lshrqi3"
1994   [(set (match_operand:QI 0 "register_operand" "")
1995         (lshiftrt:QI (match_operand:QI 1 "register_operand" "")
1996                      (match_operand:QI 2 "nonmemory_operand" "")))]
1997   ""
1998   "expand_a_shift (QImode, LSHIFTRT, operands); DONE;")
1999
2000 (define_insn ""
2001   [(set (match_operand:QI 0 "register_operand" "=r,r")
2002         (match_operator:QI 3 "nshift_operator"
2003                         [ (match_operand:QI 1 "register_operand" "0,0")
2004                           (match_operand:QI 2 "nonmemory_operand" "R,rn")]))
2005    (clobber (match_scratch:QI 4 "=X,&r"))]
2006   ""
2007   "* return output_a_shift (operands);"
2008   [(set (attr "length")
2009         (symbol_ref "compute_a_shift_length (insn, operands)"))
2010    (set_attr "cc" "clobber")])
2011
2012 ;; HI BIT SHIFTS
2013
2014 (define_expand "ashlhi3"
2015   [(set (match_operand:HI 0 "register_operand" "")
2016         (ashift:HI (match_operand:HI 1 "nonmemory_operand" "")
2017                    (match_operand:QI 2 "nonmemory_operand" "")))]
2018   ""
2019   "expand_a_shift (HImode, ASHIFT, operands); DONE;")
2020
2021 (define_expand "lshrhi3"
2022   [(set (match_operand:HI 0 "register_operand" "")
2023         (lshiftrt:HI (match_operand:HI 1 "general_operand" "")
2024                      (match_operand:QI 2 "nonmemory_operand" "")))]
2025   ""
2026   "expand_a_shift (HImode, LSHIFTRT, operands); DONE;")
2027
2028 (define_expand "ashrhi3"
2029   [(set (match_operand:HI 0 "register_operand" "")
2030         (ashiftrt:HI (match_operand:HI 1 "register_operand" "")
2031                      (match_operand:QI 2 "nonmemory_operand" "")))]
2032   ""
2033   "expand_a_shift (HImode, ASHIFTRT, operands); DONE;")
2034
2035 (define_insn ""
2036   [(set (match_operand:HI 0 "register_operand" "=r,r")
2037         (match_operator:HI 3 "nshift_operator"
2038                         [ (match_operand:HI 1 "register_operand" "0,0")
2039                           (match_operand:QI 2 "nonmemory_operand" "S,rn")]))
2040    (clobber (match_scratch:QI 4 "=X,&r"))]
2041   ""
2042   "* return output_a_shift (operands);"
2043   [(set (attr "length")
2044         (symbol_ref "compute_a_shift_length (insn, operands)"))
2045    (set_attr "cc" "clobber")])
2046
2047 ;;  SI BIT SHIFTS
2048
2049 (define_expand "ashlsi3"
2050   [(set (match_operand:SI 0 "register_operand" "")
2051         (ashift:SI (match_operand:SI 1 "general_operand" "")
2052                    (match_operand:QI 2 "nonmemory_operand" "")))]
2053   ""
2054   "expand_a_shift (SImode, ASHIFT, operands); DONE;")
2055
2056 (define_expand "lshrsi3"
2057   [(set (match_operand:SI 0 "register_operand" "")
2058         (lshiftrt:SI (match_operand:SI 1 "general_operand" "")
2059                      (match_operand:QI 2 "nonmemory_operand" "")))]
2060   ""
2061   "expand_a_shift (SImode, LSHIFTRT, operands); DONE;")
2062
2063 (define_expand "ashrsi3"
2064   [(set (match_operand:SI 0 "register_operand" "")
2065         (ashiftrt:SI (match_operand:SI 1 "general_operand" "")
2066                      (match_operand:QI 2 "nonmemory_operand" "")))]
2067   ""
2068   "expand_a_shift (SImode, ASHIFTRT, operands); DONE;")
2069
2070 (define_insn ""
2071   [(set (match_operand:SI 0 "register_operand" "=r,r")
2072         (match_operator:SI 3 "nshift_operator"
2073                         [ (match_operand:SI 1 "register_operand" "0,0")
2074                           (match_operand:QI 2 "nonmemory_operand" "T,rn")]))
2075    (clobber (match_scratch:QI 4 "=X,&r"))]
2076   ""
2077   "* return output_a_shift (operands);"
2078   [(set (attr "length")
2079         (symbol_ref "compute_a_shift_length (insn, operands)"))
2080    (set_attr "cc" "clobber")])
2081 \f
2082 ;; ----------------------------------------------------------------------
2083 ;; ROTATIONS
2084 ;; ----------------------------------------------------------------------
2085
2086 (define_expand "rotlqi3"
2087   [(set (match_operand:QI 0 "register_operand" "")
2088         (rotate:QI (match_operand:QI 1 "register_operand" "")
2089                    (match_operand:QI 2 "nonmemory_operand" "")))]
2090   ""
2091   "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2092
2093 (define_insn "*rotlqi3_1"
2094   [(set (match_operand:QI 0 "register_operand" "=r")
2095         (rotate:QI (match_operand:QI 1 "register_operand" "0")
2096                    (match_operand:QI 2 "immediate_operand" "")))]
2097   ""
2098   "* return emit_a_rotate (ROTATE, operands);"
2099   [(set_attr "length" "20")
2100    (set_attr "cc" "clobber")])
2101
2102 (define_expand "rotlhi3"
2103   [(set (match_operand:HI 0 "register_operand" "")
2104         (rotate:HI (match_operand:HI 1 "register_operand" "")
2105                    (match_operand:QI 2 "nonmemory_operand" "")))]
2106   ""
2107   "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2108
2109 (define_insn "*rotlhi3_1"
2110   [(set (match_operand:HI 0 "register_operand" "=r")
2111         (rotate:HI (match_operand:HI 1 "register_operand" "0")
2112                    (match_operand:QI 2 "immediate_operand" "")))]
2113   ""
2114   "* return emit_a_rotate (ROTATE, operands);"
2115   [(set_attr "length" "20")
2116    (set_attr "cc" "clobber")])
2117
2118 (define_expand "rotlsi3"
2119   [(set (match_operand:SI 0 "register_operand" "")
2120         (rotate:SI (match_operand:SI 1 "register_operand" "")
2121                    (match_operand:QI 2 "nonmemory_operand" "")))]
2122   "TARGET_H8300H || TARGET_H8300S"
2123   "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2124
2125 (define_insn "*rotlsi3_1"
2126   [(set (match_operand:SI 0 "register_operand" "=r")
2127         (rotate:SI (match_operand:SI 1 "register_operand" "0")
2128                    (match_operand:QI 2 "immediate_operand" "")))]
2129   "TARGET_H8300H || TARGET_H8300S"
2130   "* return emit_a_rotate (ROTATE, operands);"
2131   [(set_attr "length" "20")
2132    (set_attr "cc" "clobber")])
2133 \f
2134 ;; -----------------------------------------------------------------
2135 ;; BIT FIELDS
2136 ;; -----------------------------------------------------------------
2137 ;; The H8/300 has given 1/8th of its opcode space to bitfield
2138 ;; instructions so let's use them as well as we can.
2139
2140 ;; You'll never believe all these patterns perform one basic action --
2141 ;; load a bit from the source, optionally invert the bit, then store it
2142 ;; in the destination (which is known to be zero).
2143 ;;
2144 ;; Combine obviously need some work to better identify this situation and
2145 ;; canonicalize the form better.
2146
2147 ;;
2148 ;; Normal loads with a 16bit destination.
2149 ;;
2150
2151 (define_insn ""
2152   [(set (match_operand:HI 0 "register_operand" "=&r")
2153         (zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2154                          (const_int 1)
2155                          (match_operand:HI 2 "immediate_operand" "n")))]
2156   "TARGET_H8300"
2157   "sub.w        %0,%0\;bld      %Z2,%Y1\;bst    #0,%X0"
2158   [(set_attr "cc" "clobber")
2159    (set_attr "length" "6")])
2160
2161 ;;
2162 ;; Inverted loads with a 16bit destination.
2163 ;;
2164
2165 (define_insn ""
2166   [(set (match_operand:HI 0 "register_operand" "=&r")
2167         (zero_extract:HI (xor:HI (match_operand:HI 1 "register_operand" "r")
2168                                  (match_operand:HI 3 "const_int_operand" "n"))
2169                          (const_int 1)
2170                          (match_operand:HI 2 "const_int_operand" "n")))]
2171   "TARGET_H8300
2172    && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2173   "sub.w        %0,%0\;bild     %Z2,%Y1\;bst    #0,%X0"
2174   [(set_attr "cc" "clobber")
2175    (set_attr "length" "8")])
2176
2177 ;;
2178 ;; Normal loads with a 32bit destination.
2179 ;;
2180
2181 (define_insn ""
2182   [(set (match_operand:SI 0 "register_operand" "=&r")
2183         (zero_extract:SI (match_operand:HI 1 "register_operand" "r")
2184                          (const_int 1)
2185                          (match_operand 2 "const_int_operand" "n")))]
2186   "TARGET_H8300
2187    && INTVAL (operands[2]) < 16"
2188   "* return output_simode_bld (0, operands);"
2189   [(set_attr "cc" "clobber")
2190    (set_attr "length" "6")])
2191
2192 (define_insn ""
2193   [(set (match_operand:SI 0 "register_operand" "=r")
2194         (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2195                          (const_int 1)
2196                          (match_operand 2 "const_int_operand" "n")))]
2197   "(TARGET_H8300H || TARGET_H8300S)
2198    && INTVAL (operands[2]) < 16"
2199   "* return output_simode_bld (0, operands);"
2200   [(set_attr "cc" "clobber")
2201    (set_attr "length" "6")])
2202
2203 ;;
2204 ;; Inverted loads with a 32bit destination.
2205 ;;
2206
2207 (define_insn ""
2208   [(set (match_operand:SI 0 "register_operand" "=&r")
2209         (zero_extract:SI (xor:HI (match_operand:HI 1 "register_operand" "r")
2210                                  (match_operand:HI 3 "const_int_operand" "n"))
2211                          (const_int 1)
2212                          (match_operand 2 "const_int_operand" "n")))]
2213   "TARGET_H8300
2214    && INTVAL (operands[2]) < 16
2215    && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2216   "* return output_simode_bld (1, operands);"
2217   [(set_attr "cc" "clobber")
2218    (set_attr "length" "6")])
2219
2220 (define_insn ""
2221   [(set (match_operand:SI 0 "register_operand" "=r")
2222         (zero_extract:SI (xor:SI (match_operand:SI 1 "register_operand" "r")
2223                                  (match_operand 3 "const_int_operand" "n"))
2224                          (const_int 1)
2225                          (match_operand 2 "const_int_operand" "n")))]
2226   "(TARGET_H8300H || TARGET_H8300S)
2227    && INTVAL (operands[2]) < 16
2228    && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2229   "* return output_simode_bld (1, operands);"
2230   [(set_attr "cc" "clobber")
2231    (set_attr "length" "6")])
2232
2233 (define_expand "insv"
2234   [(set (zero_extract:HI (match_operand:HI 0 "general_operand" "")
2235                          (match_operand:HI 1 "general_operand" "")
2236                          (match_operand:HI 2 "general_operand" ""))
2237         (match_operand:HI 3 "general_operand" ""))]
2238   "TARGET_H8300"
2239   "
2240 {
2241   /* We only have single bit bit-field instructions.  */
2242   if (INTVAL (operands[1]) != 1)
2243     FAIL;
2244
2245   /* For now, we don't allow memory operands.  */
2246   if (GET_CODE (operands[0]) == MEM
2247       || GET_CODE (operands[3]) == MEM)
2248     FAIL;
2249 }")
2250
2251 (define_insn ""
2252   [(set (zero_extract:HI (match_operand:HI 0 "register_operand" "+r")
2253                          (const_int 1)
2254                          (match_operand:HI 1 "immediate_operand" "n"))
2255         (match_operand:HI 2 "register_operand" "r"))]
2256   ""
2257   "bld  #0,%R2\;bst     %Z1,%Y0 ; i1"
2258   [(set_attr "cc" "clobber")
2259    (set_attr "length" "4")])
2260
2261 (define_expand "extzv"
2262   [(set (match_operand:HI 0 "register_operand" "")
2263         (zero_extract:HI (match_operand:HI 1 "bit_operand" "")
2264                          (match_operand:HI 2 "general_operand" "")
2265                          (match_operand:HI 3 "general_operand" "")))]
2266   "TARGET_H8300"
2267   "
2268 {
2269   /* We only have single bit bit-field instructions.  */
2270   if (INTVAL (operands[2]) != 1)
2271     FAIL;
2272
2273   /* For now, we don't allow memory operands.  */
2274   if (GET_CODE (operands[1]) == MEM)
2275     FAIL;
2276 }")
2277
2278 ;; BAND, BOR, and BXOR patterns
2279
2280 (define_insn ""
2281   [(set (match_operand:HI 0 "bit_operand" "=Ur")
2282         (match_operator:HI 4 "bit_operator"
2283            [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2284                              (const_int 1)
2285                              (match_operand:HI 2 "immediate_operand" "n"))
2286             (match_operand:HI 3 "bit_operand" "0")]))]
2287   ""
2288   "bld  %Z2,%Y1\;%b4    #0,%R0\;bst     #0,%R0; bl1"
2289   [(set_attr "cc" "clobber")
2290    (set_attr "length" "6")
2291    (set_attr "adjust_length" "no")])
2292
2293 (define_insn ""
2294   [(set (match_operand:HI 0 "bit_operand" "=Ur")
2295         (match_operator:HI 5 "bit_operator"
2296            [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2297                              (const_int 1)
2298                              (match_operand:HI 2 "immediate_operand" "n"))
2299             (zero_extract:HI (match_operand:HI 3 "register_operand" "r")
2300                              (const_int 1)
2301                              (match_operand:HI 4 "immediate_operand" "n"))]))]
2302   ""
2303   "bld  %Z2,%Y1\;%b5    %Z4,%Y3\;bst    #0,%R0; bl3"
2304   [(set_attr "cc" "clobber")
2305    (set_attr "length" "6")
2306    (set_attr "adjust_length" "no")])
2307 \f
2308 ;; -----------------------------------------------------------------
2309 ;; COMBINE PATTERNS
2310 ;; -----------------------------------------------------------------
2311
2312 (define_insn "*extzv_8_8"
2313   [(set (match_operand:SI 0 "register_operand" "=r")
2314         (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2315                          (const_int 8)
2316                          (const_int 8)))]
2317   "TARGET_H8300H || TARGET_H8300S"
2318   "mov.b\\t%x1,%w0\;extu.w\\t%f0\;extu.l\\t%S0"
2319   [(set_attr "cc" "set_znv")
2320    (set_attr "length" "6")])
2321
2322 (define_insn "*extzv_8_16"
2323   [(set (match_operand:SI 0 "register_operand" "=r")
2324         (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2325                          (const_int 8)
2326                          (const_int 16)))]
2327   "TARGET_H8300H || TARGET_H8300S"
2328   "mov.w\\t%e1,%f0\;extu.w\\t%f0\;extu.l\\t%S0"
2329   [(set_attr "cc" "set_znv")
2330    (set_attr "length" "6")])
2331
2332 ;; plus:SI
2333
2334 (define_insn "*addsi3_lshiftrt_16_zexthi"
2335   [(set (match_operand:SI 0 "register_operand" "=r")
2336         (plus:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2337                               (const_int 16))
2338                  (zero_extend:SI (match_operand:HI 2 "register_operand" "0"))))]
2339   "TARGET_H8300H || TARGET_H8300S"
2340   "add.w\t%e1,%f0\;xor.w\t%e0,%e0\;rotxl.w\t%e0,%e0"
2341   [(set_attr "cc" "clobber")
2342    (set_attr "length" "6")])
2343
2344 ;; ior:HI
2345
2346 (define_insn "*iorhi3_zext"
2347   [(set (match_operand:HI 0 "register_operand" "=r")
2348         (ior:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
2349                 (match_operand:HI 2 "register_operand" "0")))]
2350   "REG_P (operands[0])
2351    && REG_P (operands[1])
2352    && REGNO (operands[0]) != REGNO (operands[1])"
2353   "or\\t%X1,%s0"
2354   [(set_attr "cc" "clobber")
2355    (set_attr "length" "2")])
2356
2357 (define_insn "*iorhi3_ashift_8"
2358   [(set (match_operand:HI 0 "register_operand" "=r")
2359         (ior:HI (ashift:HI (match_operand:HI 1 "register_operand" "r")
2360                            (const_int 8))
2361                 (match_operand:HI 2 "register_operand" "0")))]
2362   ""
2363   "or.b\\t%s1,%t0"
2364   [(set_attr "cc" "clobber")
2365    (set_attr "length" "2")])
2366
2367 (define_insn "*iorhi3_lshiftrt_8"
2368   [(set (match_operand:HI 0 "register_operand" "=r")
2369         (ior:HI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
2370                              (const_int 8))
2371                 (match_operand:HI 2 "register_operand" "0")))]
2372   ""
2373   "or.b\t%t1,%s0"
2374   [(set_attr "cc" "clobber")
2375    (set_attr "length" "2")])
2376
2377 (define_insn "*iorhi3_two_qi"
2378   [(set (match_operand:HI 0 "register_operand" "=r")
2379         (ior:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
2380                 (ashift:HI (match_operand:HI 2 "register_operand" "r")
2381                            (const_int 8))))]
2382   "REG_P (operands[0])
2383    && REG_P (operands[2])
2384    && REGNO (operands[0]) != REGNO (operands[2])"
2385   "mov.b\\t%s2,%t0"
2386   [(set_attr "cc" "clobber")
2387    (set_attr "length" "2")])
2388
2389 ;; ior:SI
2390
2391 (define_insn "*iorsi3_zexthi"
2392   [(set (match_operand:SI 0 "register_operand" "=r")
2393         (ior:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "r"))
2394                 (match_operand:SI 2 "register_operand" "0")))]
2395   "(TARGET_H8300H || TARGET_H8300S)
2396    && REG_P (operands[0])
2397    && REG_P (operands[1])
2398    && (REGNO (operands[0]) != REGNO (operands[1]))"
2399   "or.w\\t%T1,%f0"
2400   [(set_attr "cc" "clobber")
2401    (set_attr "length" "2")])
2402
2403 (define_insn "*iorsi3_zextqi"
2404   [(set (match_operand:SI 0 "register_operand" "=r")
2405         (ior:SI (zero_extend:SI (match_operand:QI 1 "register_operand" "r"))
2406                 (match_operand:SI 2 "register_operand" "0")))]
2407   ""
2408   "or\\t%X1,%w0"
2409   [(set_attr "cc" "clobber")
2410    (set_attr "length" "2")])
2411
2412 ;; xor:HI
2413
2414 (define_insn "*xorhi3_zextqi"
2415   [(set (match_operand:HI 0 "register_operand" "=r")
2416         (xor:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
2417                 (match_operand:HI 2 "register_operand" "0")))]
2418   "REG_P (operands[0])
2419    && REG_P (operands[1])
2420    && REGNO (operands[0]) != REGNO (operands[1])"
2421   "xor\\t%X1,%s0"
2422   [(set_attr "cc" "clobber")
2423    (set_attr "length" "2")])
2424
2425 ;; xor:SI
2426
2427 (define_insn "*xorsi3_zexthi"
2428   [(set (match_operand:SI 0 "register_operand" "=r")
2429         (xor:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "r"))
2430                 (match_operand:SI 2 "register_operand" "0")))]
2431   "(TARGET_H8300H || TARGET_H8300S)
2432    && REG_P (operands[0])
2433    && REG_P (operands[1])
2434    && (REGNO (operands[0]) != REGNO (operands[1]))"
2435   "xor.w\\t%T1,%f0"
2436   [(set_attr "cc" "clobber")
2437    (set_attr "length" "2")])
2438
2439 (define_insn "*xorsi3_zextqi"
2440   [(set (match_operand:SI 0 "register_operand" "=r")
2441         (xor:SI (zero_extend:SI (match_operand:QI 1 "register_operand" "r"))
2442                 (match_operand:SI 2 "register_operand" "0")))]
2443   "REG_P (operands[0])
2444    && REG_P (operands[1])
2445    && REGNO (operands[0]) != REGNO (operands[1])"
2446   "xor\\t%X1,%w0"
2447   [(set_attr "cc" "clobber")
2448    (set_attr "length" "2")])
2449
2450 (define_insn "*iorsi3_two_hi"
2451   [(set (match_operand:SI 0 "register_operand" "=r")
2452         (ior:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "0"))
2453                 (ashift:SI (match_operand:SI 2 "register_operand" "r")
2454                            (const_int 16))))]
2455   "TARGET_H8300H || TARGET_H8300S"
2456   "mov.w\\t%f2,%e0"
2457   [(set_attr "cc" "clobber")
2458    (set_attr "length" "2")])
2459
2460 (define_insn "*iorsi3_ashift_16"
2461   [(set (match_operand:SI 0 "register_operand" "=r")
2462         (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
2463                            (const_int 16))
2464                 (match_operand:SI 2 "register_operand" "0")))]
2465   "TARGET_H8300H || TARGET_H8300S"
2466   "or.w\\t%f1,%e0"
2467   [(set_attr "cc" "clobber")
2468    (set_attr "length" "2")])
2469
2470 ;; Storing a part of HImode to QImode.
2471
2472 (define_insn ""
2473   [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2474         (subreg:QI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
2475                                 (const_int 8)) 1))]
2476   ""
2477   "mov.b\\t%t1,%R0"
2478   [(set_attr "cc" "set_znv")
2479    (set_attr "length" "8")])
2480
2481 ;; Storing a part of SImode to QImode.
2482
2483 (define_insn ""
2484   [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2485         (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2486                                 (const_int 8)) 3))]
2487   ""
2488   "mov.b\\t%x1,%R0"
2489   [(set_attr "cc" "set_znv")
2490    (set_attr "length" "8")])
2491
2492 (define_insn ""
2493   [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2494         (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2495                                 (const_int 16)) 3))
2496    (clobber (match_scratch:SI 2 "=&r"))]
2497   "TARGET_H8300H || TARGET_H8300S"
2498   "mov.w\\t%e1,%f2\;mov.b\\t%w2,%R0"
2499   [(set_attr "cc" "set_znv")
2500    (set_attr "length" "10")])
2501
2502 (define_insn ""
2503   [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2504         (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2505                                 (const_int 24)) 3))
2506    (clobber (match_scratch:SI 2 "=&r"))]
2507   "TARGET_H8300H || TARGET_H8300S"
2508   "mov.w\\t%e1,%f2\;mov.b\\t%x2,%R0"
2509   [(set_attr "cc" "set_znv")
2510    (set_attr "length" "10")])
2511
2512 (define_insn_and_split ""
2513   [(set (pc)
2514         (if_then_else (eq (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
2515                                            (const_int 1)
2516                                            (const_int 7))
2517                           (const_int 0))
2518                       (label_ref (match_operand 1 "" ""))
2519                       (pc)))]
2520   ""
2521   "#"
2522   ""
2523   [(set (cc0)
2524         (match_dup 0))
2525    (set (pc)
2526         (if_then_else (ge (cc0)
2527                           (const_int 0))
2528                       (label_ref (match_dup 1))
2529                       (pc)))]
2530   "")
2531
2532 (define_insn_and_split ""
2533   [(set (pc)
2534         (if_then_else (ne (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
2535                                            (const_int 1)
2536                                            (const_int 7))
2537                           (const_int 0))
2538                       (label_ref (match_operand 1 "" ""))
2539                       (pc)))]
2540   ""
2541   "#"
2542   ""
2543   [(set (cc0)
2544         (match_dup 0))
2545    (set (pc)
2546         (if_then_else (lt (cc0)
2547                           (const_int 0))
2548                       (label_ref (match_dup 1))
2549                       (pc)))]
2550   "")
2551 \f
2552 ;; -----------------------------------------------------------------
2553 ;; PEEPHOLE PATTERNS
2554 ;; -----------------------------------------------------------------
2555
2556 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
2557
2558 (define_peephole2
2559   [(parallel
2560      [(set (match_operand:HI 0 "register_operand" "")
2561            (lshiftrt:HI (match_dup 0)
2562                         (match_operand:HI 1 "const_int_operand" "")))
2563       (clobber (match_operand:HI 2 "" ""))])
2564    (set (match_dup 0)
2565         (and:HI (match_dup 0)
2566                 (match_operand:HI 3 "const_int_operand" "")))]
2567   "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
2568   [(set (match_dup 0)
2569         (and:HI (match_dup 0)
2570                 (const_int 255)))
2571    (parallel
2572      [(set (match_dup 0)
2573            (lshiftrt:HI (match_dup 0)
2574                         (match_dup 1)))
2575       (clobber (match_dup 2))])]
2576   "")
2577
2578 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
2579
2580 (define_peephole2
2581   [(parallel
2582      [(set (match_operand:HI 0 "register_operand" "")
2583            (ashift:HI (match_dup 0)
2584                       (match_operand:HI 1 "const_int_operand" "")))
2585       (clobber (match_operand:HI 2 "" ""))])
2586    (set (match_dup 0)
2587         (and:HI (match_dup 0)
2588                 (match_operand:HI 3 "const_int_operand" "")))]
2589   "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
2590   [(set (match_dup 0)
2591         (and:HI (match_dup 0)
2592                 (const_int 255)))
2593    (parallel
2594      [(set (match_dup 0)
2595            (ashift:HI (match_dup 0)
2596                       (match_dup 1)))
2597       (clobber (match_dup 2))])]
2598   "")
2599
2600 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
2601
2602 (define_peephole2
2603   [(parallel
2604      [(set (match_operand:SI 0 "register_operand" "")
2605            (lshiftrt:SI (match_dup 0)
2606                         (match_operand:SI 1 "const_int_operand" "")))
2607       (clobber (match_operand:SI 2 "" ""))])
2608    (set (match_dup 0)
2609         (and:SI (match_dup 0)
2610                 (match_operand:SI 3 "const_int_operand" "")))]
2611   "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
2612   [(set (match_dup 0)
2613         (and:SI (match_dup 0)
2614                 (const_int 255)))
2615    (parallel
2616      [(set (match_dup 0)
2617            (lshiftrt:SI (match_dup 0)
2618                         (match_dup 1)))
2619       (clobber (match_dup 2))])]
2620   "")
2621
2622 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
2623
2624 (define_peephole2
2625   [(parallel
2626      [(set (match_operand:SI 0 "register_operand" "")
2627            (ashift:SI (match_dup 0)
2628                       (match_operand:SI 1 "const_int_operand" "")))
2629       (clobber (match_operand:SI 2 "" ""))])
2630    (set (match_dup 0)
2631         (and:SI (match_dup 0)
2632                 (match_operand:SI 3 "const_int_operand" "")))]
2633   "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
2634   [(set (match_dup 0)
2635         (and:SI (match_dup 0)
2636                 (const_int 255)))
2637    (parallel
2638      [(set (match_dup 0)
2639            (ashift:SI (match_dup 0)
2640                       (match_dup 1)))
2641       (clobber (match_dup 2))])]
2642   "")
2643
2644 ;; Convert (A >> B) & C to (A & 65535) >> B if C == 65535 >> B.
2645
2646 (define_peephole2
2647   [(parallel
2648      [(set (match_operand:SI 0 "register_operand" "")
2649            (lshiftrt:SI (match_dup 0)
2650                         (match_operand:SI 1 "const_int_operand" "")))
2651       (clobber (match_operand:SI 2 "" ""))])
2652    (set (match_dup 0)
2653         (and:SI (match_dup 0)
2654                 (match_operand:SI 3 "const_int_operand" "")))]
2655   "INTVAL (operands[3]) == (65535 >> INTVAL (operands[1]))"
2656   [(set (match_dup 0)
2657         (and:SI (match_dup 0)
2658                 (const_int 65535)))
2659    (parallel
2660      [(set (match_dup 0)
2661            (lshiftrt:SI (match_dup 0)
2662                         (match_dup 1)))
2663       (clobber (match_dup 2))])]
2664   "")
2665
2666 ;; Convert (A << B) & C to (A & 65535) << B if C == 65535 << B.
2667
2668 (define_peephole2
2669   [(parallel
2670      [(set (match_operand:SI 0 "register_operand" "")
2671            (ashift:SI (match_dup 0)
2672                       (match_operand:SI 1 "const_int_operand" "")))
2673       (clobber (match_operand:SI 2 "" ""))])
2674    (set (match_dup 0)
2675         (and:SI (match_dup 0)
2676                 (match_operand:SI 3 "const_int_operand" "")))]
2677   "INTVAL (operands[3]) == (65535 << INTVAL (operands[1]))"
2678   [(set (match_dup 0)
2679         (and:SI (match_dup 0)
2680                 (const_int 65535)))
2681    (parallel
2682      [(set (match_dup 0)
2683            (ashift:SI (match_dup 0)
2684                       (match_dup 1)))
2685       (clobber (match_dup 2))])]
2686   "")
2687
2688 ;; Convert a QImode push into an SImode push so that the
2689 ;; define_peephole2 below can cram multiple pushes into one stm.l.
2690
2691 (define_peephole2
2692   [(parallel [(set (reg:SI SP_REG)
2693                    (plus:SI (reg:SI SP_REG) (const_int -4)))
2694               (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
2695                    (match_operand:QI 0 "register_operand" ""))])]
2696   "TARGET_H8300S"
2697   [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2698         (match_dup 0))]
2699   "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
2700
2701 ;; Convert a HImode push into an SImode push so that the
2702 ;; define_peephole2 below can cram multiple pushes into one stm.l.
2703
2704 (define_peephole2
2705   [(parallel [(set (reg:SI SP_REG)
2706                    (plus:SI (reg:SI SP_REG) (const_int -4)))
2707               (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
2708                    (match_operand:HI 0 "register_operand" ""))])]
2709   "TARGET_H8300S"
2710   [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2711         (match_dup 0))]
2712   "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
2713
2714 ;; Cram four pushes into stm.l.
2715
2716 (define_peephole2
2717   [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2718         (match_operand:SI 0 "register_operand" ""))
2719    (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2720         (match_operand:SI 1 "register_operand" ""))
2721    (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2722         (match_operand:SI 2 "register_operand" ""))
2723    (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2724         (match_operand:SI 3 "register_operand" ""))]
2725   "TARGET_H8300S
2726    && REGNO (operands[0]) == 0
2727    && REGNO (operands[1]) == 1
2728    && REGNO (operands[2]) == 2
2729    && REGNO (operands[3]) == 3"
2730   [(parallel [(set (reg:SI SP_REG)
2731                    (plus:SI (reg:SI SP_REG)
2732                             (const_int -16)))
2733               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
2734                    (match_dup 0))
2735               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
2736                    (match_dup 1))
2737               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
2738                    (match_dup 2))
2739               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
2740                    (match_dup 3))])]
2741   "")
2742
2743 ;; Cram three pushes into stm.l.
2744
2745 (define_peephole2
2746   [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2747         (match_operand:SI 0 "register_operand" ""))
2748    (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2749         (match_operand:SI 1 "register_operand" ""))
2750    (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2751         (match_operand:SI 2 "register_operand" ""))]
2752   "TARGET_H8300S
2753    && ((REGNO (operands[0]) == 0
2754         && REGNO (operands[1]) == 1
2755         && REGNO (operands[2]) == 2)
2756        || (REGNO (operands[0]) == 4
2757            && REGNO (operands[1]) == 5
2758            && REGNO (operands[2]) == 6))"
2759   [(parallel [(set (reg:SI SP_REG)
2760                    (plus:SI (reg:SI SP_REG)
2761                             (const_int -12)))
2762               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
2763                    (match_dup 0))
2764               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
2765                    (match_dup 1))
2766               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
2767                    (match_dup 2))])]
2768   "")
2769
2770 ;; Cram two pushes into stm.l.
2771
2772 (define_peephole2
2773   [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2774         (match_operand:SI 0 "register_operand" ""))
2775    (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2776         (match_operand:SI 1 "register_operand" ""))]
2777   "TARGET_H8300S
2778    && ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
2779        || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
2780        || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5))"
2781   [(parallel [(set (reg:SI SP_REG)
2782                    (plus:SI (reg:SI SP_REG)
2783                             (const_int -8)))
2784               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
2785                    (match_dup 0))
2786               (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
2787                    (match_dup 1))])]
2788   "")
2789
2790 ;; Turn
2791 ;;
2792 ;;   mov.w #2,r0
2793 ;;   add.w r7,r0  (6 bytes)
2794 ;;
2795 ;; into
2796 ;;
2797 ;;   mov.w r7,r0
2798 ;;   adds  #2,r0  (4 bytes)
2799
2800 (define_peephole2
2801   [(set (match_operand:HI 0 "register_operand" "")
2802         (match_operand:HI 1 "const_int_operand" ""))
2803    (set (match_dup 0)
2804         (plus:HI (match_dup 0)
2805                  (match_operand:HI 2 "register_operand" "")))]
2806   "REG_P (operands[0]) && REG_P (operands[2])
2807    && REGNO (operands[0]) != REGNO (operands[2])
2808    && (CONST_OK_FOR_J (INTVAL (operands[1]))
2809        || CONST_OK_FOR_L (INTVAL (operands[1]))
2810        || CONST_OK_FOR_N (INTVAL (operands[1])))"
2811   [(set (match_dup 0)
2812         (match_dup 2))
2813    (set (match_dup 0)
2814         (plus:HI (match_dup 0)
2815                  (match_dup 1)))]
2816   "")
2817
2818 ;; Turn
2819 ;;
2820 ;;   sub.l  er0,er0
2821 ;;   add.b  #4,r0l
2822 ;;   add.l  er7,er0  (6 bytes)
2823 ;;
2824 ;; into
2825 ;;
2826 ;;   mov.l  er7,er0
2827 ;;   adds   #4,er0   (4 bytes)
2828
2829 (define_peephole2
2830   [(set (match_operand:SI 0 "register_operand" "")
2831         (match_operand:SI 1 "const_int_operand" ""))
2832    (set (match_dup 0)
2833         (plus:SI (match_dup 0)
2834                  (match_operand:SI 2 "register_operand" "")))]
2835   "(TARGET_H8300H || TARGET_H8300S)
2836    && REG_P (operands[0]) && REG_P (operands[2])
2837    && REGNO (operands[0]) != REGNO (operands[2])
2838    && (CONST_OK_FOR_L (INTVAL (operands[1]))
2839        || CONST_OK_FOR_N (INTVAL (operands[1])))"
2840   [(set (match_dup 0)
2841         (match_dup 2))
2842    (set (match_dup 0)
2843         (plus:SI (match_dup 0)
2844                  (match_dup 1)))]
2845   "")
2846
2847 ;; Turn
2848 ;;
2849 ;;   mov.l er7,er0
2850 ;;   add.l #10,er0  (takes 8 bytes)
2851 ;;
2852 ;; into
2853 ;;
2854 ;;   sub.l er0,er0
2855 ;;   add.b #10,r0l
2856 ;;   add.l er7,er0  (takes 6 bytes)
2857
2858 (define_peephole2
2859   [(set (match_operand:SI 0 "register_operand" "")
2860         (match_operand:SI 1 "register_operand" ""))
2861    (set (match_dup 0)
2862         (plus:SI (match_dup 0)
2863                  (match_operand:SI 2 "const_int_operand" "")))]
2864   "(TARGET_H8300H || TARGET_H8300S)
2865    && REG_P (operands[0]) && REG_P (operands[1])
2866    && REGNO (operands[0]) != REGNO (operands[1])
2867    && !CONST_OK_FOR_L (INTVAL (operands[2]))
2868    && !CONST_OK_FOR_N (INTVAL (operands[2]))
2869    && ((INTVAL (operands[2]) & 0xff) == INTVAL (operands[2])
2870        || (INTVAL (operands[2]) & 0xff00) == INTVAL (operands[2])
2871        || INTVAL (operands[2]) == 0xffff
2872        || INTVAL (operands[2]) == 0xfffe)"
2873   [(set (match_dup 0)
2874         (match_dup 2))
2875    (set (match_dup 0)
2876         (plus:SI (match_dup 0)
2877                  (match_dup 1)))]
2878   "")
2879
2880 ;; Turn
2881 ;;
2882 ;;   subs   #1,er4
2883 ;;   mov.w  r4,r4
2884 ;;   bne    .L2028
2885 ;;
2886 ;; into
2887 ;;
2888 ;;   dec.w  #1,r4
2889 ;;   bne    .L2028
2890
2891 (define_peephole2
2892   [(set (match_operand:HI 0 "register_operand" "")
2893         (plus:HI (match_dup 0)
2894                  (match_operand 1 "incdec_operand" "")))
2895    (set (cc0)
2896         (match_dup 0))
2897    (set (pc)
2898         (if_then_else (match_operator 3 "eqne_operator"
2899                         [(cc0) (const_int 0)])
2900                       (label_ref (match_operand 2 "" ""))
2901                       (pc)))]
2902   "TARGET_H8300H || TARGET_H8300S"
2903   [(set (match_operand:HI 0 "register_operand" "")
2904         (unspec:HI [(match_dup 0)
2905                     (match_dup 1)]
2906                    UNSPEC_INCDEC))
2907    (set (cc0)
2908         (match_dup 0))
2909    (set (pc)
2910         (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
2911                       (label_ref (match_dup 2))
2912                       (pc)))]
2913   "")
2914
2915 ;; The SImode version of the previous pattern.
2916
2917 (define_peephole2
2918   [(set (match_operand:SI 0 "register_operand" "")
2919         (plus:SI (match_dup 0)
2920                  (match_operand 1 "incdec_operand" "")))
2921    (set (cc0)
2922         (match_dup 0))
2923    (set (pc)
2924         (if_then_else (match_operator 3 "eqne_operator"
2925                         [(cc0) (const_int 0)])
2926                       (label_ref (match_operand 2 "" ""))
2927                       (pc)))]
2928   "TARGET_H8300H || TARGET_H8300S"
2929   [(set (match_operand:SI 0 "register_operand" "")
2930         (unspec:SI [(match_dup 0)
2931                     (match_dup 1)]
2932                    UNSPEC_INCDEC))
2933    (set (cc0)
2934         (match_dup 0))
2935    (set (pc)
2936         (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
2937                       (label_ref (match_dup 2))
2938                       (pc)))]
2939   "")
2940
2941 ;; For a small constant, it is cheaper to actually do the subtraction
2942 ;; and then test the register.
2943
2944 (define_peephole2
2945   [(set (cc0)
2946         (compare:HI (match_operand:HI 0 "register_operand" "")
2947                     (match_operand:HI 1 "const_int_le_2_operand" "")))
2948    (set (pc)
2949         (if_then_else (match_operator 3 "eqne_operator"
2950                         [(cc0) (const_int 0)])
2951                       (label_ref (match_operand 2 "" ""))
2952                       (pc)))]
2953   "(TARGET_H8300H || TARGET_H8300S)
2954    && find_regno_note (insn, REG_DEAD, REGNO (operands[0]))"
2955   [(set (cc0)
2956         (match_dup 0))
2957    (set (pc)
2958         (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
2959                       (label_ref (match_dup 2))
2960                       (pc)))]
2961   "operands[1] = GEN_INT (- INTVAL (operands[1]));
2962    split_adds_subs (HImode, operands, 1);")
2963
2964 ;; The SImode version of the previous pattern.
2965
2966 (define_peephole2
2967   [(set (cc0)
2968         (compare:SI (match_operand:SI 0 "register_operand" "")
2969                     (match_operand:SI 1 "const_int_le_6_operand" "")))
2970    (set (pc)
2971         (if_then_else (match_operator 3 "eqne_operator"
2972                         [(cc0) (const_int 0)])
2973                       (label_ref (match_operand 2 "" ""))
2974                       (pc)))]
2975   "(TARGET_H8300H || TARGET_H8300S)
2976    && find_regno_note (insn, REG_DEAD, REGNO (operands[0]))"
2977   [(set (cc0)
2978         (match_dup 0))
2979    (set (pc)
2980         (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
2981                       (label_ref (match_dup 2))
2982                       (pc)))]
2983   "operands[1] = GEN_INT (- INTVAL (operands[1]));
2984    split_adds_subs (SImode, operands, 1);")
2985
2986 ;; Narrow the mode of testing if possible.
2987
2988 (define_peephole2
2989   [(set (match_operand:HI 0 "register_operand" "")
2990         (and:HI (match_dup 0)
2991                 (match_operand:HI 1 "const_int_qi_operand" "")))
2992    (set (cc0)
2993         (match_dup 0))
2994    (set (pc)
2995         (if_then_else (match_operator 3 "eqne_operator"
2996                         [(cc0) (const_int 0)])
2997                       (label_ref (match_operand 2 "" ""))
2998                       (pc)))]
2999   "find_regno_note (next_nonnote_insn (insn), REG_DEAD, REGNO (operands[0]))"
3000   [(set (match_dup 4)
3001         (and:QI (match_dup 4)
3002                 (match_dup 5)))
3003    (set (cc0)
3004         (match_dup 4))
3005    (set (pc)
3006         (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
3007                       (label_ref (match_dup 2))
3008                       (pc)))]
3009   "operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
3010    operands[5] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));")
3011
3012 (define_peephole2
3013   [(set (match_operand:SI 0 "register_operand" "")
3014         (and:SI (match_dup 0)
3015                 (match_operand:SI 1 "const_int_qi_operand" "")))
3016    (set (cc0)
3017         (match_dup 0))
3018    (set (pc)
3019         (if_then_else (match_operator 3 "eqne_operator"
3020                         [(cc0) (const_int 0)])
3021                       (label_ref (match_operand 2 "" ""))
3022                       (pc)))]
3023   "find_regno_note (next_nonnote_insn (insn), REG_DEAD, REGNO (operands[0]))"
3024   [(set (match_dup 4)
3025         (and:QI (match_dup 4)
3026                 (match_dup 5)))
3027    (set (cc0)
3028         (match_dup 4))
3029    (set (pc)
3030         (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
3031                       (label_ref (match_dup 2))
3032                       (pc)))]
3033   "operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
3034    operands[5] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), QImode));")
3035
3036 (define_peephole2
3037   [(set (match_operand:SI 0 "register_operand" "")
3038         (and:SI (match_dup 0)
3039                 (match_operand:SI 1 "const_int_hi_operand" "")))
3040    (set (cc0)
3041         (match_dup 0))
3042    (set (pc)
3043         (if_then_else (match_operator 3 "eqne_operator"
3044                         [(cc0) (const_int 0)])
3045                       (label_ref (match_operand 2 "" ""))
3046                       (pc)))]
3047   "find_regno_note (next_nonnote_insn (insn), REG_DEAD, REGNO (operands[0]))"
3048   [(set (match_dup 4)
3049         (and:HI (match_dup 4)
3050                 (match_dup 5)))
3051    (set (cc0)
3052         (match_dup 4))
3053    (set (pc)
3054         (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
3055                       (label_ref (match_dup 2))
3056                       (pc)))]
3057   "operands[4] = gen_rtx_REG (HImode, REGNO (operands[0]));
3058    operands[5] = GEN_INT (trunc_int_for_mode (INTVAL (operands[1]), HImode));")