OSDN Git Service

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