OSDN Git Service

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