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.
5 ;; Contributed by Steve Chamberlain (sac@cygnus.com),
6 ;; Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
8 ;; This file is part of GNU CC.
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)
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.
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.
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.
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
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.
41 ;; Shifts/rotates by small constants should be handled by special
42 ;; patterns so we get the length and cc status correct.
44 ;; Bitfield operations no longer accept memory operands. We need
45 ;; to add variants which operate on memory back to the MD.
47 ;; ??? Implement remaining bit ops available on the h8300
49 ;; ----------------------------------------------------------------------
51 ;; ----------------------------------------------------------------------
61 ;; ----------------------------------------------------------------------
63 ;; ----------------------------------------------------------------------
65 (define_attr "cpu" "h8300,h8300h"
66 (const (symbol_ref "cpu_type")))
68 (define_attr "type" "branch,arith"
69 (const_string "arith"))
71 ;; The size of instructions in bytes.
73 (define_attr "length" ""
74 (cond [(eq_attr "type" "branch")
75 (if_then_else (and (ge (minus (match_dup 0) (pc))
77 (le (minus (match_dup 0) (pc))
80 (if_then_else (and (eq_attr "cpu" "h8300h")
81 (and (ge (minus (pc) (match_dup 0))
83 (le (minus (pc) (match_dup 0))
89 ;; The necessity of instruction length adjustment.
91 (define_attr "adjust_length" "yes,no"
92 (cond [(eq_attr "type" "branch") (const_string "no")]
93 (const_string "yes")))
95 ;; Condition code settings.
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
106 (define_attr "cc" "none,none_0hit,set_znv,set_zn,compare,clobber"
107 (const_string "clobber"))
109 ;; ----------------------------------------------------------------------
111 ;; ----------------------------------------------------------------------
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"))])]
121 && REGNO (operands[0]) != SP_REG"
123 [(set_attr "length" "2")
124 (set_attr "cc" "clobber")])
126 (define_insn "pushqi1_h8300hs"
127 [(parallel [(set (reg:SI SP_REG)
128 (plus:SI (reg:SI SP_REG) (const_int -4)))
129 (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
130 (match_operand:QI 0 "register_operand" "r"))])]
131 "(TARGET_H8300H || TARGET_H8300S)
132 && REGNO (operands[0]) != SP_REG"
134 [(set_attr "length" "4")
135 (set_attr "cc" "clobber")])
137 (define_expand "pushqi1"
138 [(use (match_operand:QI 0 "register_operand" ""))]
143 emit_insn (gen_pushqi1_h8300 (operands[0]));
145 emit_insn (gen_pushqi1_h8300hs (operands[0]));
150 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
151 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
153 && (register_operand (operands[0], QImode)
154 || register_operand (operands[1], QImode))"
162 [(set_attr "length" "2,2,2,2,4,4")
163 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
166 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
167 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
168 "(TARGET_H8300H || TARGET_H8300S)
169 && (register_operand (operands[0], QImode)
170 || register_operand (operands[1], QImode))"
178 [(set_attr "length" "2,2,2,2,8,8")
179 (set_attr "cc" "set_zn,set_znv,set_znv,clobber,set_znv,set_znv")])
181 (define_expand "movqi"
182 [(set (match_operand:QI 0 "general_operand_dst" "")
183 (match_operand:QI 1 "general_operand_src" ""))]
187 /* One of the ops has to be in a register. */
188 if (!register_operand (operand0, QImode)
189 && !register_operand (operand1, QImode))
191 operands[1] = copy_to_mode_reg (QImode, operand1);
195 (define_insn "movstrictqi"
196 [(set (strict_low_part (match_operand:QI 0 "general_operand_dst" "+r,r,r,r"))
197 (match_operand:QI 1 "general_operand_src" "I,r,n,m"))]
204 [(set_attr_alternative "length"
205 [(const_int 2) (const_int 2) (const_int 2)
206 (if_then_else (eq_attr "cpu" "h8300") (const_int 4) (const_int 8))])
207 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv")])
211 (define_expand "pushhi1_h8300"
212 [(set (mem:HI (pre_dec:HI (reg:HI SP_REG)))
213 (match_operand:HI 0 "register_operand" ""))]
215 && REGNO (operands[0]) != SP_REG"
218 (define_insn "pushhi1_h8300hs"
219 [(parallel [(set (reg:SI SP_REG)
220 (plus:SI (reg:SI SP_REG) (const_int -4)))
221 (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
222 (match_operand:HI 0 "register_operand" "r"))])]
223 "(TARGET_H8300H || TARGET_H8300S)
224 && REGNO (operands[0]) != SP_REG"
226 [(set_attr "length" "4")
227 (set_attr "cc" "clobber")])
229 (define_expand "pushhi1"
230 [(use (match_operand:HI 0 "register_operand" ""))]
235 emit_insn (gen_pushhi1_h8300 (operands[0]));
237 emit_insn (gen_pushhi1_h8300hs (operands[0]));
242 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
243 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
245 && (register_operand (operands[0], HImode)
246 || register_operand (operands[1], HImode))
247 && !(GET_CODE (operands[0]) == MEM
248 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
249 && GET_CODE (XEXP (XEXP (operands[0], 0), 0)) == REG
250 && GET_CODE (operands[1]) == REG
251 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == REGNO (operands[1]))"
259 [(set_attr "length" "2,2,2,4,4,4")
260 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
263 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
264 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
265 "(TARGET_H8300H || TARGET_H8300S)
266 && (register_operand (operands[0], HImode)
267 || register_operand (operands[1], HImode))"
275 [(set_attr "length" "2,2,2,4,8,8")
276 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
278 (define_expand "movhi"
279 [(set (match_operand:HI 0 "general_operand_dst" "")
280 (match_operand:HI 1 "general_operand_src" ""))]
284 /* One of the ops has to be in a register. */
285 if (!register_operand (operand1, HImode)
286 && !register_operand (operand0, HImode))
288 operands[1] = copy_to_mode_reg (HImode, operand1);
292 (define_insn "movstricthi"
293 [(set (strict_low_part (match_operand:HI 0 "general_operand_dst" "+r,r,r,r"))
294 (match_operand:HI 1 "general_operand_src" "I,r,i,m"))]
301 [(set_attr_alternative "length"
302 [(const_int 2) (const_int 2) (const_int 4)
303 (if_then_else (eq_attr "cpu" "h8300") (const_int 4) (const_int 8))])
304 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv")])
308 (define_expand "movsi"
309 [(set (match_operand:SI 0 "general_operand_dst" "")
310 (match_operand:SI 1 "general_operand_src" ""))]
316 if (do_movsi (operands))
321 /* One of the ops has to be in a register. */
322 if (!register_operand (operand1, SImode)
323 && !register_operand (operand0, SImode))
325 operands[1] = copy_to_mode_reg (SImode, operand1);
330 (define_expand "movsf"
331 [(set (match_operand:SF 0 "general_operand_dst" "")
332 (match_operand:SF 1 "general_operand_src" ""))]
338 if (do_movsi (operands))
343 /* One of the ops has to be in a register. */
344 if (!register_operand (operand1, SFmode)
345 && !register_operand (operand0, SFmode))
347 operands[1] = copy_to_mode_reg (SFmode, operand1);
352 (define_insn "movsi_h8300"
353 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,o,<,r")
354 (match_operand:SI 1 "general_operand_src" "I,r,io,r,r,>"))]
356 && (register_operand (operands[0], SImode)
357 || register_operand (operands[1], SImode))"
360 unsigned int rn = -1;
361 switch (which_alternative)
364 return \"sub.w %e0,%e0\;sub.w %f0,%f0\";
366 if (REGNO (operands[0]) < REGNO (operands[1]))
367 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
369 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
371 /* Make sure we don't trample the register we index with. */
372 if (GET_CODE (operands[1]) == MEM)
374 rtx inside = XEXP (operands[1], 0);
379 else if (GET_CODE (inside) == PLUS)
381 rtx lhs = XEXP (inside, 0);
382 rtx rhs = XEXP (inside, 1);
383 if (REG_P (lhs)) rn = REGNO (lhs);
384 if (REG_P (rhs)) rn = REGNO (rhs);
387 if (rn == REGNO (operands[0]))
389 /* Move the second word first. */
390 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
394 /* See if either half is zero. If so, use sub.w to clear
396 if (GET_CODE (operands[1]) == CONST_INT)
398 if ((INTVAL (operands[1]) & 0xffff) == 0)
399 return \"mov.w %e1,%e0\;sub.w %f0,%f0\";
400 if (((INTVAL (operands[1]) >> 16) & 0xffff) == 0)
401 return \"sub.w %e0,%e0\;mov.w %f1,%f0\";
403 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
406 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
408 return \"mov.w %f1,%T0\;mov.w %e1,%T0\";
410 return \"mov.w %T1,%e0\;mov.w %T1,%f0\";
415 [(set_attr "length" "4,4,8,8,4,4")
416 (set_attr "cc" "clobber")])
418 (define_insn "movsf_h8300"
419 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,o,<,r")
420 (match_operand:SF 1 "general_operand_src" "I,r,io,r,r,>"))]
422 && (register_operand (operands[0], SFmode)
423 || register_operand (operands[1], SFmode))"
426 /* Copy of the movsi stuff. */
427 unsigned int rn = -1;
428 switch (which_alternative)
431 return \"sub.w %e0,%e0\;sub.w %f0,%f0\";
433 if (REGNO (operands[0]) < REGNO (operands[1]))
434 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
436 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
438 /* Make sure we don't trample the register we index with. */
439 if (GET_CODE (operands[1]) == MEM)
441 rtx inside = XEXP (operands[1], 0);
446 else if (GET_CODE (inside) == PLUS)
448 rtx lhs = XEXP (inside, 0);
449 rtx rhs = XEXP (inside, 1);
450 if (REG_P (lhs)) rn = REGNO (lhs);
451 if (REG_P (rhs)) rn = REGNO (rhs);
454 if (rn == REGNO (operands[0]))
455 /* Move the second word first. */
456 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
458 /* Move the first word first. */
459 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
462 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
464 return \"mov.w %f1,%T0\;mov.w %e1,%T0\";
466 return \"mov.w %T1,%e0\;mov.w %T1,%f0\";
471 [(set_attr "length" "4,4,8,8,4,4")
472 (set_attr "cc" "clobber")])
474 (define_insn "movsi_h8300hs"
475 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,<,r,r,m,*a,*a,r")
476 (match_operand:SI 1 "general_operand_src" "I,r,i,r,>,m,r,I,r,*a"))]
477 "(TARGET_H8300S || TARGET_H8300H)
478 && (register_operand (operands[0], SImode)
479 || register_operand (operands[1], SImode))
480 && !(GET_CODE (operands[0]) == MEM
481 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
482 && GET_CODE (XEXP (XEXP (operands[0], 0), 0)) == REG
483 && GET_CODE (operands[1]) == REG
484 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == REGNO (operands[1]))"
487 switch (which_alternative)
490 return \"sub.l %S0,%S0\";
494 return \"clrmac\;ldmac %1,macl\";
496 return \"stmac macl,%0\";
498 if (GET_CODE (operands[1]) == CONST_INT)
500 int val = INTVAL (operands[1]);
502 /* Look for constants which can be made by adding an 8-bit
503 number to zero in one of the two low bytes. */
504 if (val == (val & 0xff))
506 operands[1] = GEN_INT ((char) val & 0xff);
507 return \"sub.l\\t%S0,%S0\;add.b\\t%1,%w0\";
510 if (val == (val & 0xff00))
512 operands[1] = GEN_INT ((char) (val >> 8) & 0xff);
513 return \"sub.l\\t%S0,%S0\;add.b\\t%1,%x0\";
516 /* Look for constants that can be obtained by subs, inc, and
518 switch (val & 0xffffffff)
521 return \"sub.l\\t%S0,%S0\;subs\\t#1,%S0\";
523 return \"sub.l\\t%S0,%S0\;subs\\t#2,%S0\";
525 return \"sub.l\\t%S0,%S0\;subs\\t#4,%S0\";
528 return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%f0\";
530 return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%f0\";
533 return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%e0\";
535 return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%e0\";
538 return \"sub.l\\t%S0,%S0\;inc.w\\t#1,%e0\";
540 return \"sub.l\\t%S0,%S0\;inc.w\\t#2,%e0\";
544 return \"mov.l %S1,%S0\";
546 [(set_attr "length" "2,2,6,4,4,10,10,2,6,4")
547 (set_attr "cc" "set_zn,set_znv,clobber,set_znv,set_znv,set_znv,set_znv,none_0hit,none_0hit,set_znv")])
549 (define_insn "movsf_h8300h"
550 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,m,<,r")
551 (match_operand:SF 1 "general_operand_src" "I,r,im,r,r,>"))]
552 "(TARGET_H8300H || TARGET_H8300S)
553 && (register_operand (operands[0], SFmode)
554 || register_operand (operands[1], SFmode))"
562 [(set_attr "length" "2,2,10,10,4,4")
563 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
565 ;; ----------------------------------------------------------------------
567 ;; ----------------------------------------------------------------------
570 [(set (cc0) (zero_extract:HI (match_operand:QI 0 "bit_memory_operand" "r,U")
572 (match_operand 1 "const_int_operand" "n,n")))]
575 [(set_attr "length" "2,4")
576 (set_attr "cc" "set_zn,set_zn")])
579 [(set (cc0) (zero_extract:HI (match_operand:HI 0 "register_operand" "r")
581 (match_operand 1 "const_int_operand" "n")))]
584 [(set_attr "length" "2")
585 (set_attr "cc" "set_zn")])
587 (define_insn "*tst_extzv_bitqi_1_n"
588 [(set (cc0) (zero_extract:SI (match_operand:QI 0 "bit_operand" "r,U")
590 (match_operand 1 "const_int_operand" "n,n")))]
591 "(TARGET_H8300H || TARGET_H8300S)
592 && INTVAL (operands[1]) != 7"
594 [(set_attr "length" "2,8")
595 (set_attr "cc" "set_zn,set_zn")])
597 (define_insn_and_split "*tst_extzv_memqi_1_n"
598 [(set (cc0) (zero_extract:SI (match_operand:QI 0 "memory_operand" "m")
600 (match_operand 1 "const_int_operand" "n")))
601 (clobber (match_scratch:QI 2 "=&r"))]
602 "(TARGET_H8300H || TARGET_H8300S)
603 && !EXTRA_CONSTRAINT (operands[0], 'U')
604 && INTVAL (operands[1]) != 7"
606 "&& reload_completed"
609 (set (cc0) (zero_extract:SI (match_dup 2)
615 [(set (cc0) (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
617 (match_operand 1 "const_int_operand" "n")))]
618 "(TARGET_H8300H || TARGET_H8300S)
619 && INTVAL (operands[1]) <= 15"
621 [(set_attr "length" "2")
622 (set_attr "cc" "set_zn")])
626 (and:HI (match_operand:HI 0 "register_operand" "r")
627 (match_operand:HI 1 "single_one_operand" "n")))]
631 operands[1] = GEN_INT (INTVAL (operands[1]) & 0xffff);
632 if (INTVAL (operands[1]) > 128)
634 operands[1] = GEN_INT (INTVAL (operands[1]) >> 8);
635 return \"btst\\t%V1,%t0\";
637 return \"btst\\t%V1,%s0\";
639 [(set_attr "length" "2")
640 (set_attr "cc" "set_zn")])
644 (and:SI (match_operand:SI 0 "register_operand" "r")
645 (match_operand:SI 1 "single_one_operand" "n")))]
646 "(TARGET_H8300H || TARGET_H8300S)
647 && (INTVAL (operands[1]) & 0xffff) != 0"
650 operands[1] = GEN_INT (INTVAL (operands[1]) & 0xffff);
651 if (INTVAL (operands[1]) > 128)
653 operands[1] = GEN_INT (INTVAL (operands[1]) >> 8);
654 return \"btst\\t%V1,%x0\";
656 return \"btst\\t%V1,%w0\";
658 [(set_attr "length" "2")
659 (set_attr "cc" "set_zn")])
662 [(set (cc0) (match_operand:QI 0 "register_operand" "r"))]
665 [(set_attr "length" "2")
666 (set_attr "cc" "set_znv")])
669 [(set (cc0) (match_operand:HI 0 "register_operand" "r"))]
672 [(set_attr "length" "2")
673 (set_attr "cc" "set_znv")])
677 (and:HI (match_operand:HI 0 "register_operand" "r")
681 [(set_attr "length" "2")
682 (set_attr "cc" "set_znv")])
685 [(set (cc0) (match_operand:SI 0 "register_operand" "r"))]
686 "TARGET_H8300H || TARGET_H8300S"
688 [(set_attr "length" "2")
689 (set_attr "cc" "set_znv")])
693 (and:SI (match_operand:SI 0 "register_operand" "r")
694 (const_int -65536)))]
697 [(set_attr "length" "2")
698 (set_attr "cc" "set_znv")])
702 (compare:QI (match_operand:QI 0 "register_operand" "r")
703 (match_operand:QI 1 "nonmemory_operand" "rn")))]
706 [(set_attr "length" "2")
707 (set_attr "cc" "compare")])
709 (define_expand "cmphi"
711 (compare:HI (match_operand:HI 0 "register_operand" "")
712 (match_operand:HI 1 "nonmemory_operand" "")))]
716 /* Force operand1 into a register if we're compiling
718 if (GET_CODE (operands[1]) != REG && TARGET_H8300)
719 operands[1] = force_reg (HImode, operands[1]);
724 (compare:HI (match_operand:HI 0 "register_operand" "r")
725 (match_operand:HI 1 "register_operand" "r")))]
728 [(set_attr "length" "2")
729 (set_attr "cc" "compare")])
733 (compare:HI (match_operand:HI 0 "register_operand" "r,r")
734 (match_operand:HI 1 "nonmemory_operand" "r,n")))]
735 "TARGET_H8300H || TARGET_H8300S"
737 [(set_attr "length" "2,4")
738 (set_attr "cc" "compare,compare")])
742 (compare:SI (match_operand:SI 0 "register_operand" "r,r")
743 (match_operand:SI 1 "nonmemory_operand" "r,i")))]
744 "TARGET_H8300H || TARGET_H8300S"
746 [(set_attr "length" "2,6")
747 (set_attr "cc" "compare,compare")])
749 ;; ----------------------------------------------------------------------
751 ;; ----------------------------------------------------------------------
753 (define_insn "addqi3"
754 [(set (match_operand:QI 0 "register_operand" "=r")
755 (plus:QI (match_operand:QI 1 "register_operand" "%0")
756 (match_operand:QI 2 "nonmemory_operand" "rn")))]
759 [(set_attr "length" "2")
760 (set_attr "cc" "set_zn")])
762 (define_expand "addhi3"
763 [(set (match_operand:HI 0 "register_operand" "")
764 (plus:HI (match_operand:HI 1 "register_operand" "")
765 (match_operand:HI 2 "nonmemory_operand" "")))]
769 (define_insn "*addhi3_h8300"
770 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
771 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
772 (match_operand:HI 2 "nonmemory_operand" "L,N,J,n,r")))]
778 add.b %s2,%s0\;addx %t2,%t0
780 [(set_attr "length" "2,2,2,4,2")
781 (set_attr "cc" "none_0hit,none_0hit,clobber,clobber,set_zn")])
783 (define_insn "*addhi3_h8300hs"
784 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
785 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
786 (match_operand:HI 2 "nonmemory_operand" "L,N,J,n,r")))]
787 "TARGET_H8300H || TARGET_H8300S"
794 [(set_attr "length" "2,2,2,4,2")
795 (set_attr "cc" "none_0hit,none_0hit,clobber,set_zn,set_zn")])
798 [(set (match_operand:HI 0 "register_operand" "")
799 (plus:HI (match_dup 0)
800 (match_operand:HI 1 "two_insn_adds_subs_operand" "")))]
803 "split_adds_subs (HImode, operands); DONE;")
805 (define_expand "addsi3"
806 [(set (match_operand:SI 0 "register_operand" "")
807 (plus:SI (match_operand:SI 1 "register_operand" "")
808 (match_operand:SI 2 "nonmemory_operand" "")))]
812 (define_insn "addsi_h8300"
813 [(set (match_operand:SI 0 "register_operand" "=r,r,&r")
814 (plus:SI (match_operand:SI 1 "register_operand" "%0,0,r")
815 (match_operand:SI 2 "nonmemory_operand" "n,r,r")))]
818 add %w2,%w0\;addx %x2,%x0\;addx %y2,%y0\;addx %z2,%z0
819 add.w %f2,%f0\;addx %y2,%y0\;addx %z2,%z0
820 mov.w %f1,%f0\;mov.w %e1,%e0\;add.w %f2,%f0\;addx %y2,%y0\;addx %z2,%z0"
821 [(set_attr "length" "8,6,10")
822 (set_attr "cc" "clobber")])
824 (define_insn "addsi_h8300h"
825 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
826 (plus:SI (match_operand:SI 1 "register_operand" "%0,0,0,0")
827 (match_operand:SI 2 "nonmemory_operand" "L,N,i,r")))]
828 "TARGET_H8300H || TARGET_H8300S"
834 [(set_attr "length" "2,2,6,2")
835 (set_attr "cc" "none_0hit,none_0hit,set_zn,set_zn")])
838 [(set (match_operand:SI 0 "register_operand" "")
839 (plus:SI (match_dup 0)
840 (match_operand:SI 1 "two_insn_adds_subs_operand" "")))]
841 "TARGET_H8300H || TARGET_H8300S"
843 "split_adds_subs (SImode, operands); DONE;")
845 ;; ----------------------------------------------------------------------
846 ;; SUBTRACT INSTRUCTIONS
847 ;; ----------------------------------------------------------------------
849 (define_insn "subqi3"
850 [(set (match_operand:QI 0 "register_operand" "=r")
851 (minus:QI (match_operand:QI 1 "register_operand" "0")
852 (match_operand:QI 2 "register_operand" "r")))]
855 [(set_attr "length" "2")
856 (set_attr "cc" "set_zn")])
858 (define_expand "subhi3"
859 [(set (match_operand:HI 0 "register_operand" "")
860 (minus:HI (match_operand:HI 1 "general_operand" "")
861 (match_operand:HI 2 "nonmemory_operand" "")))]
866 [(set (match_operand:HI 0 "register_operand" "=r,&r")
867 (minus:HI (match_operand:HI 1 "general_operand" "0,0")
868 (match_operand:HI 2 "nonmemory_operand" "r,n")))]
872 add.b %E2,%s0\;addx %F2,%t0"
873 [(set_attr "length" "2,4")
874 (set_attr "cc" "set_zn,clobber")])
877 [(set (match_operand:HI 0 "register_operand" "=r,&r")
878 (minus:HI (match_operand:HI 1 "general_operand" "0,0")
879 (match_operand:HI 2 "nonmemory_operand" "r,n")))]
880 "TARGET_H8300H || TARGET_H8300S"
884 [(set_attr "length" "2,4")
885 (set_attr "cc" "set_zn,set_zn")])
887 (define_expand "subsi3"
888 [(set (match_operand:SI 0 "register_operand" "")
889 (minus:SI (match_operand:SI 1 "register_operand" "")
890 (match_operand:SI 2 "nonmemory_operand" "")))]
894 (define_insn "subsi3_h8300"
895 [(set (match_operand:SI 0 "register_operand" "=r")
896 (minus:SI (match_operand:SI 1 "register_operand" "0")
897 (match_operand:SI 2 "register_operand" "r")))]
899 "sub.w %f2,%f0\;subx %y2,%y0\;subx %z2,%z0"
900 [(set_attr "length" "6")
901 (set_attr "cc" "clobber")])
903 (define_insn "subsi3_h8300h"
904 [(set (match_operand:SI 0 "register_operand" "=r,r")
905 (minus:SI (match_operand:SI 1 "general_operand" "0,0")
906 (match_operand:SI 2 "nonmemory_operand" "r,i")))]
907 "TARGET_H8300H || TARGET_H8300S"
911 [(set_attr "length" "2,6")
912 (set_attr "cc" "set_zn,set_zn")])
914 ;; ----------------------------------------------------------------------
915 ;; MULTIPLY INSTRUCTIONS
916 ;; ----------------------------------------------------------------------
918 ;; Note that the H8/300 can only handle umulqihi3.
920 (define_insn "mulqihi3"
921 [(set (match_operand:HI 0 "register_operand" "=r")
922 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
923 (sign_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
924 "TARGET_H8300H || TARGET_H8300S"
926 [(set_attr "length" "4")
927 (set_attr "cc" "set_zn")])
929 (define_insn "mulhisi3"
930 [(set (match_operand:SI 0 "register_operand" "=r")
931 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
932 (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
933 "TARGET_H8300H || TARGET_H8300S"
935 [(set_attr "length" "4")
936 (set_attr "cc" "set_zn")])
938 (define_insn "umulqihi3"
939 [(set (match_operand:HI 0 "register_operand" "=r")
940 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
941 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
944 [(set_attr "length" "2")
945 (set_attr "cc" "none_0hit")])
947 (define_insn "umulhisi3"
948 [(set (match_operand:SI 0 "register_operand" "=r")
949 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%0"))
950 (zero_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
951 "TARGET_H8300H || TARGET_H8300S"
953 [(set_attr "length" "2")
954 (set_attr "cc" "none_0hit")])
956 ;; This is a "bridge" instruction. Combine can't cram enough insns
957 ;; together to crate a MAC instruction directly, but it can create
958 ;; this instruction, which then allows combine to create the real
961 ;; Unfortunately, if combine doesn't create a MAC instruction, this
962 ;; insn must generate reasonably correct code. Egad.
964 [(set (match_operand:SI 0 "register_operand" "=a")
967 (mem:HI (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
969 (mem:HI (post_inc:SI (match_operand:SI 2 "register_operand" "r"))))))]
971 "clrmac\;mac @%2+,@%1+"
972 [(set_attr "length" "6")
973 (set_attr "cc" "none_0hit")])
976 [(set (match_operand:SI 0 "register_operand" "=a")
978 (sign_extend:SI (mem:HI
979 (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
980 (sign_extend:SI (mem:HI
981 (post_inc:SI (match_operand:SI 2 "register_operand" "r")))))
982 (match_operand:SI 3 "register_operand" "0")))]
985 [(set_attr "length" "4")
986 (set_attr "cc" "none_0hit")])
988 ;; ----------------------------------------------------------------------
989 ;; DIVIDE/MOD INSTRUCTIONS
990 ;; ----------------------------------------------------------------------
992 (define_insn "udivmodqi4"
993 [(set (match_operand:QI 0 "register_operand" "=r")
996 (match_operand:HI 1 "register_operand" "0")
997 (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))))
998 (set (match_operand:QI 3 "register_operand" "=r")
1002 (zero_extend:HI (match_dup 2)))))]
1006 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1007 return \"divxu.b\\t%X2,%T0\";
1009 return \"divxu.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1011 [(set_attr "length" "4")
1012 (set_attr "cc" "clobber")])
1014 (define_insn "divmodqi4"
1015 [(set (match_operand:QI 0 "register_operand" "=r")
1018 (match_operand:HI 1 "register_operand" "0")
1019 (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1020 (set (match_operand:QI 3 "register_operand" "=r")
1024 (sign_extend:HI (match_dup 2)))))]
1025 "TARGET_H8300H || TARGET_H8300S"
1028 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1029 return \"divxs.b\\t%X2,%T0\";
1031 return \"divxs.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1033 [(set_attr "length" "6")
1034 (set_attr "cc" "clobber")])
1036 (define_insn "udivmodhi4"
1037 [(set (match_operand:HI 0 "register_operand" "=r")
1040 (match_operand:SI 1 "register_operand" "0")
1041 (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1042 (set (match_operand:HI 3 "register_operand" "=r")
1046 (zero_extend:SI (match_dup 2)))))]
1047 "TARGET_H8300H || TARGET_H8300S"
1050 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1051 return \"divxu.w\\t%T2,%S0\";
1053 return \"divxu.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1055 [(set_attr "length" "4")
1056 (set_attr "cc" "clobber")])
1058 (define_insn "divmodhi4"
1059 [(set (match_operand:HI 0 "register_operand" "=r")
1062 (match_operand:SI 1 "register_operand" "0")
1063 (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1064 (set (match_operand:HI 3 "register_operand" "=r")
1068 (sign_extend:SI (match_dup 2)))))]
1069 "TARGET_H8300H || TARGET_H8300S"
1072 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1073 return \"divxs.w\\t%T2,%S0\";
1075 return \"divxs.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1077 [(set_attr "length" "6")
1078 (set_attr "cc" "clobber")])
1080 ;; ----------------------------------------------------------------------
1082 ;; ----------------------------------------------------------------------
1085 [(set (match_operand:QI 0 "bit_operand" "=r,U")
1086 (and:QI (match_operand:QI 1 "bit_operand" "%0,0")
1087 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1088 "register_operand (operands[0], QImode)
1089 || single_zero_operand (operands[2], QImode)"
1093 [(set_attr "length" "2,8")
1094 (set_attr "adjust_length" "no")
1095 (set_attr "cc" "set_znv,none_0hit")])
1097 (define_expand "andqi3"
1098 [(set (match_operand:QI 0 "bit_operand" "")
1099 (and:QI (match_operand:QI 1 "bit_operand" "")
1100 (match_operand:QI 2 "nonmemory_operand" "")))]
1104 if (fix_bit_operand (operands, 0, AND))
1108 (define_expand "andhi3"
1109 [(set (match_operand:HI 0 "register_operand" "")
1110 (and:HI (match_operand:HI 1 "register_operand" "")
1111 (match_operand:HI 2 "nonmemory_operand" "")))]
1115 (define_insn "*andorqi3"
1116 [(set (match_operand:QI 0 "register_operand" "=r")
1117 (ior:QI (and:QI (match_operand:QI 2 "register_operand" "r")
1118 (match_operand:QI 3 "single_one_operand" "n"))
1119 (match_operand:QI 1 "register_operand" "0")))]
1121 "bld\\t%V3,%X2\;bor\\t%V3,%X0\;bst\\t%V3,%X0"
1122 [(set_attr "length" "6")
1123 (set_attr "cc" "clobber")])
1125 (define_insn "*andorhi3"
1126 [(set (match_operand:HI 0 "register_operand" "=r")
1127 (ior:HI (and:HI (match_operand:HI 2 "register_operand" "r")
1128 (match_operand:HI 3 "single_one_operand" "n"))
1129 (match_operand:HI 1 "register_operand" "0")))]
1133 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1134 if (INTVAL (operands[3]) > 128)
1136 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1137 return \"bld\\t%V3,%t2\;bor\\t%V3,%t0\;bst\\t%V3,%t0\";
1139 return \"bld\\t%V3,%s2\;bor\\t%V3,%s0\;bst\\t%V3,%s0\";
1141 [(set_attr "length" "6")
1142 (set_attr "cc" "clobber")])
1144 (define_insn "*andorsi3"
1145 [(set (match_operand:SI 0 "register_operand" "=r")
1146 (ior:SI (and:SI (match_operand:SI 2 "register_operand" "r")
1147 (match_operand:SI 3 "single_one_operand" "n"))
1148 (match_operand:SI 1 "register_operand" "0")))]
1149 "(INTVAL (operands[3]) & 0xffff) != 0"
1152 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1153 if (INTVAL (operands[3]) > 128)
1155 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1156 return \"bld\\t%V3,%x2\;bor\\t%V3,%x0\;bst\\t%V3,%x0\";
1158 return \"bld\\t%V3,%w2\;bor\\t%V3,%w0\;bst\\t%V3,%w0\";
1160 [(set_attr "length" "6")
1161 (set_attr "cc" "clobber")])
1163 (define_insn "*andorsi3_shift_8"
1164 [(set (match_operand:SI 0 "register_operand" "=r")
1165 (ior:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1168 (match_operand:SI 1 "register_operand" "0")))]
1171 [(set_attr "length" "2")
1172 (set_attr "cc" "clobber")])
1174 (define_expand "andsi3"
1175 [(set (match_operand:SI 0 "register_operand" "")
1176 (and:SI (match_operand:SI 1 "register_operand" "")
1177 (match_operand:SI 2 "nonmemory_operand" "")))]
1181 ;; ----------------------------------------------------------------------
1183 ;; ----------------------------------------------------------------------
1186 [(set (match_operand:QI 0 "bit_operand" "=r,U")
1187 (ior:QI (match_operand:QI 1 "bit_operand" "%0,0")
1188 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1189 "register_operand (operands[0], QImode)
1190 || single_one_operand (operands[2], QImode)"
1194 [(set_attr "length" "2,8")
1195 (set_attr "adjust_length" "no")
1196 (set_attr "cc" "set_znv,none_0hit")])
1198 (define_expand "iorqi3"
1199 [(set (match_operand:QI 0 "bit_operand" "")
1200 (ior:QI (match_operand:QI 1 "bit_operand" "")
1201 (match_operand:QI 2 "nonmemory_operand" "")))]
1205 if (fix_bit_operand (operands, 1, IOR))
1209 (define_expand "iorhi3"
1210 [(set (match_operand:HI 0 "register_operand" "")
1211 (ior:HI (match_operand:HI 1 "register_operand" "")
1212 (match_operand:HI 2 "nonmemory_operand" "")))]
1216 (define_expand "iorsi3"
1217 [(set (match_operand:SI 0 "register_operand" "")
1218 (ior:SI (match_operand:SI 1 "register_operand" "")
1219 (match_operand:SI 2 "nonmemory_operand" "")))]
1223 ;; ----------------------------------------------------------------------
1225 ;; ----------------------------------------------------------------------
1228 [(set (match_operand:QI 0 "bit_operand" "=r,U")
1229 (xor:QI (match_operand:QI 1 "bit_operand" "%0,0")
1230 (match_operand:QI 2 "nonmemory_operand" "rn,n")))]
1231 "register_operand (operands[0], QImode)
1232 || single_one_operand (operands[2], QImode)"
1236 [(set_attr "length" "2,8")
1237 (set_attr "adjust_length" "no")
1238 (set_attr "cc" "set_znv,none_0hit")])
1240 (define_expand "xorqi3"
1241 [(set (match_operand:QI 0 "bit_operand" "")
1242 (xor:QI (match_operand:QI 1 "bit_operand" "")
1243 (match_operand:QI 2 "nonmemory_operand" "")))]
1247 if (fix_bit_operand (operands, 1, XOR))
1251 (define_expand "xorhi3"
1252 [(set (match_operand:HI 0 "register_operand" "")
1253 (xor:HI (match_operand:HI 1 "register_operand" "")
1254 (match_operand:HI 2 "nonmemory_operand" "")))]
1258 (define_expand "xorsi3"
1259 [(set (match_operand:SI 0 "register_operand" "")
1260 (xor:SI (match_operand:SI 1 "register_operand" "")
1261 (match_operand:SI 2 "nonmemory_operand" "")))]
1265 ;; ----------------------------------------------------------------------
1266 ;; {AND,IOR,XOR}{HI3,SI3} PATTERNS
1267 ;; ----------------------------------------------------------------------
1270 [(set (match_operand:HI 0 "register_operand" "=r")
1271 (match_operator:HI 3 "bit_operator"
1272 [(match_operand:HI 1 "register_operand" "%0")
1273 (match_operand:HI 2 "nonmemory_operand" "rn")]))]
1275 "* return output_logical_op (HImode, operands);"
1276 [(set (attr "length")
1277 (symbol_ref "compute_logical_op_length (HImode, operands)"))
1279 (symbol_ref "compute_logical_op_cc (HImode, operands)"))])
1282 [(set (match_operand:SI 0 "register_operand" "=r")
1283 (match_operator:SI 3 "bit_operator"
1284 [(match_operand:SI 1 "register_operand" "%0")
1285 (match_operand:SI 2 "nonmemory_operand" "rn")]))]
1287 "* return output_logical_op (SImode, operands);"
1288 [(set (attr "length")
1289 (symbol_ref "compute_logical_op_length (SImode, operands)"))
1291 (symbol_ref "compute_logical_op_cc (SImode, operands)"))])
1293 ;; ----------------------------------------------------------------------
1294 ;; NEGATION INSTRUCTIONS
1295 ;; ----------------------------------------------------------------------
1297 (define_insn "negqi2"
1298 [(set (match_operand:QI 0 "register_operand" "=r")
1299 (neg:QI (match_operand:QI 1 "register_operand" "0")))]
1302 [(set_attr "length" "2")
1303 (set_attr "cc" "set_zn")])
1305 (define_expand "neghi2"
1306 [(set (match_operand:HI 0 "register_operand" "")
1307 (neg:HI (match_operand:HI 1 "register_operand" "")))]
1313 emit_insn (gen_neghi2_h8300 (operands[0], operands[1]));
1318 (define_expand "neghi2_h8300"
1320 (not:HI (match_operand:HI 1 "register_operand" "")))
1321 (set (match_dup 2) (plus:HI (match_dup 2) (const_int 1)))
1322 (set (match_operand:HI 0 "register_operand" "")
1325 "operands[2] = gen_reg_rtx (HImode);")
1327 (define_insn "neghi2_h8300h"
1328 [(set (match_operand:HI 0 "register_operand" "=r")
1329 (neg:HI (match_operand:HI 1 "register_operand" "0")))]
1330 "TARGET_H8300H || TARGET_H8300S"
1332 [(set_attr "length" "2")
1333 (set_attr "cc" "set_zn")])
1335 (define_expand "negsi2"
1336 [(set (match_operand:SI 0 "register_operand" "")
1337 (neg:SI (match_operand:SI 1 "register_operand" "")))]
1343 emit_insn (gen_negsi2_h8300 (operands[0], operands[1]));
1348 (define_expand "negsi2_h8300"
1350 (not:SI (match_operand:SI 1 "register_operand" "")))
1351 (set (match_dup 2) (plus:SI (match_dup 2) (const_int 1)))
1352 (set (match_operand:SI 0 "register_operand" "")
1355 "operands[2] = gen_reg_rtx (SImode);")
1357 (define_insn "negsi2_h8300h"
1358 [(set (match_operand:SI 0 "register_operand" "=r")
1359 (neg:SI (match_operand:SI 1 "register_operand" "0")))]
1360 "TARGET_H8300H || TARGET_H8300S"
1362 [(set_attr "length" "2")
1363 (set_attr "cc" "set_zn")])
1365 ;; ----------------------------------------------------------------------
1367 ;; ----------------------------------------------------------------------
1369 (define_insn "one_cmplqi2"
1370 [(set (match_operand:QI 0 "register_operand" "=r")
1371 (not:QI (match_operand:QI 1 "register_operand" "0")))]
1374 [(set_attr "length" "2")
1375 (set_attr "cc" "set_znv")])
1377 (define_expand "one_cmplhi2"
1378 [(set (match_operand:HI 0 "register_operand" "=r")
1379 (not:HI (match_operand:HI 1 "register_operand" "0")))]
1384 [(set (match_operand:HI 0 "register_operand" "=r")
1385 (not:HI (match_operand:HI 1 "register_operand" "0")))]
1388 [(set_attr "cc" "clobber")
1389 (set_attr "length" "4")])
1392 [(set (match_operand:HI 0 "register_operand" "=r")
1393 (not:HI (match_operand:HI 1 "register_operand" "0")))]
1394 "TARGET_H8300H || TARGET_H8300S"
1396 [(set_attr "cc" "set_znv")
1397 (set_attr "length" "2")])
1399 (define_expand "one_cmplsi2"
1400 [(set (match_operand:SI 0 "register_operand" "=r")
1401 (not:SI (match_operand:SI 1 "register_operand" "0")))]
1406 [(set (match_operand:SI 0 "register_operand" "=r")
1407 (not:SI (match_operand:SI 1 "register_operand" "0")))]
1409 "not %w0\;not %x0\;not %y0\;not %z0"
1410 [(set_attr "cc" "clobber")
1411 (set_attr "length" "8")])
1414 [(set (match_operand:SI 0 "register_operand" "=r")
1415 (not:SI (match_operand:SI 1 "register_operand" "0")))]
1416 "TARGET_H8300H || TARGET_H8300S"
1418 [(set_attr "cc" "set_znv")
1419 (set_attr "length" "2")])
1421 ;; ----------------------------------------------------------------------
1422 ;; JUMP INSTRUCTIONS
1423 ;; ----------------------------------------------------------------------
1425 ;; Conditional jump instructions
1427 (define_expand "ble"
1429 (if_then_else (le (cc0)
1431 (label_ref (match_operand 0 "" ""))
1436 (define_expand "bleu"
1438 (if_then_else (leu (cc0)
1440 (label_ref (match_operand 0 "" ""))
1445 (define_expand "bge"
1447 (if_then_else (ge (cc0)
1449 (label_ref (match_operand 0 "" ""))
1454 (define_expand "bgeu"
1456 (if_then_else (geu (cc0)
1458 (label_ref (match_operand 0 "" ""))
1463 (define_expand "blt"
1465 (if_then_else (lt (cc0)
1467 (label_ref (match_operand 0 "" ""))
1472 (define_expand "bltu"
1474 (if_then_else (ltu (cc0)
1476 (label_ref (match_operand 0 "" ""))
1481 (define_expand "bgt"
1483 (if_then_else (gt (cc0)
1485 (label_ref (match_operand 0 "" ""))
1490 (define_expand "bgtu"
1492 (if_then_else (gtu (cc0)
1494 (label_ref (match_operand 0 "" ""))
1499 (define_expand "beq"
1501 (if_then_else (eq (cc0)
1503 (label_ref (match_operand 0 "" ""))
1508 (define_expand "bne"
1510 (if_then_else (ne (cc0)
1512 (label_ref (match_operand 0 "" ""))
1517 (define_insn "branch_true"
1519 (if_then_else (match_operator 1 "comparison_operator"
1520 [(cc0) (const_int 0)])
1521 (label_ref (match_operand 0 "" ""))
1526 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1527 && (GET_CODE (operands[1]) == GT
1528 || GET_CODE (operands[1]) == GE
1529 || GET_CODE (operands[1]) == LE
1530 || GET_CODE (operands[1]) == LT))
1532 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
1536 if (get_attr_length (insn) == 2)
1537 return \"b%j1 %l0\";
1538 else if (get_attr_length (insn) == 4)
1539 return \"b%j1 %l0:16\";
1541 return \"b%k1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
1543 [(set_attr "type" "branch")
1544 (set_attr "cc" "none")])
1546 (define_insn "branch_false"
1548 (if_then_else (match_operator 1 "comparison_operator"
1549 [(cc0) (const_int 0)])
1551 (label_ref (match_operand 0 "" ""))))]
1555 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1556 && (GET_CODE (operands[1]) == GT
1557 || GET_CODE (operands[1]) == GE
1558 || GET_CODE (operands[1]) == LE
1559 || GET_CODE (operands[1]) == LT))
1561 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
1565 if (get_attr_length (insn) == 2)
1566 return \"b%k1 %l0\";
1567 else if (get_attr_length (insn) == 4)
1568 return \"b%k1 %l0:16\";
1570 return \"b%j1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
1572 [(set_attr "type" "branch")
1573 (set_attr "cc" "none")])
1575 ;; Unconditional and other jump instructions.
1579 (label_ref (match_operand 0 "" "")))]
1583 if (get_attr_length (insn) == 2)
1585 else if (get_attr_length (insn) == 4)
1586 return \"bra %l0:16\";
1588 return \"jmp @%l0\";
1590 [(set_attr "type" "branch")
1591 (set_attr "cc" "none")])
1593 ;; This is a define expand, because pointers may be either 16 or 32 bits.
1595 (define_expand "tablejump"
1596 [(parallel [(set (pc) (match_operand 0 "register_operand" ""))
1597 (use (label_ref (match_operand 1 "" "")))])]
1601 (define_insn "tablejump_h8300"
1602 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
1603 (use (label_ref (match_operand 1 "" "")))]
1606 [(set_attr "cc" "none")
1607 (set_attr "length" "2")])
1609 (define_insn "tablejump_h8300h"
1610 [(set (pc) (match_operand:SI 0 "register_operand" "r"))
1611 (use (label_ref (match_operand 1 "" "")))]
1612 "TARGET_H8300H || TARGET_H8300S"
1614 [(set_attr "cc" "none")
1615 (set_attr "length" "2")])
1617 (define_insn "tablejump_normal_mode"
1618 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
1619 (use (label_ref (match_operand 1 "" "")))]
1620 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
1622 [(set_attr "cc" "none")
1623 (set_attr "length" "2")])
1625 ;; This is a define expand, because pointers may be either 16 or 32 bits.
1627 (define_expand "indirect_jump"
1628 [(set (pc) (match_operand 0 "jump_address_operand" ""))]
1632 (define_insn "indirect_jump_h8300"
1633 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
1636 [(set_attr "cc" "none")
1637 (set_attr "length" "2")])
1639 (define_insn "indirect_jump_h8300h"
1640 [(set (pc) (match_operand:SI 0 "jump_address_operand" "Vr"))]
1641 "TARGET_H8300H || TARGET_H8300S"
1643 [(set_attr "cc" "none")
1644 (set_attr "length" "2")])
1646 (define_insn "indirect_jump_normal_mode"
1647 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
1648 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
1650 [(set_attr "cc" "none")
1651 (set_attr "length" "2")])
1653 ;; Call subroutine with no return value.
1655 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
1658 [(call (match_operand:QI 0 "call_insn_operand" "or")
1659 (match_operand:HI 1 "general_operand" "g"))]
1663 if (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
1664 && SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
1665 return \"jsr\\t@%0:8\";
1667 return \"jsr\\t%0\";
1669 [(set_attr "cc" "clobber")
1670 (set (attr "length")
1671 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
1675 ;; Call subroutine, returning value in operand 0
1676 ;; (which must be a hard register).
1678 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
1680 (define_insn "call_value"
1681 [(set (match_operand 0 "" "=r")
1682 (call (match_operand:QI 1 "call_insn_operand" "or")
1683 (match_operand:HI 2 "general_operand" "g")))]
1687 if (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
1688 && SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
1689 return \"jsr\\t@%1:8\";
1691 return \"jsr\\t%1\";
1693 [(set_attr "cc" "clobber")
1694 (set (attr "length")
1695 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
1703 [(set_attr "cc" "none")
1704 (set_attr "length" "2")])
1706 ;; ----------------------------------------------------------------------
1707 ;; PROLOGUE/EPILOGUE-RELATED INSTRUCTIONS
1708 ;; ----------------------------------------------------------------------
1710 (define_insn "*stm_h8300s_2"
1712 [(set (reg:SI SP_REG)
1713 (plus:SI (reg:SI SP_REG) (const_int -8)))
1714 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1715 (match_operand:SI 0 "register_operand" ""))
1716 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1717 (match_operand:SI 1 "register_operand" ""))])]
1719 && ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
1720 || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
1721 || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5))"
1722 "stm.l\\t%S0-%S1,@-er7"
1723 [(set_attr "cc" "none")
1724 (set_attr "length" "4")])
1726 (define_insn "*stm_h8300s_3"
1728 [(set (reg:SI SP_REG)
1729 (plus:SI (reg:SI SP_REG) (const_int -12)))
1730 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1731 (match_operand:SI 0 "register_operand" ""))
1732 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1733 (match_operand:SI 1 "register_operand" ""))
1734 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
1735 (match_operand:SI 2 "register_operand" ""))])]
1737 && ((REGNO (operands[0]) == 0
1738 && REGNO (operands[1]) == 1
1739 && REGNO (operands[2]) == 2)
1740 || (REGNO (operands[0]) == 4
1741 && REGNO (operands[1]) == 5
1742 && REGNO (operands[2]) == 6))"
1743 "stm.l\\t%S0-%S2,@-er7"
1744 [(set_attr "cc" "none")
1745 (set_attr "length" "4")])
1747 (define_insn "*stm_h8300s_4"
1749 [(set (reg:SI SP_REG)
1750 (plus:SI (reg:SI SP_REG) (const_int -16)))
1751 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
1752 (match_operand:SI 0 "register_operand" ""))
1753 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
1754 (match_operand:SI 1 "register_operand" ""))
1755 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
1756 (match_operand:SI 2 "register_operand" ""))
1757 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
1758 (match_operand:SI 3 "register_operand" ""))])]
1760 && REGNO (operands[0]) == 0
1761 && REGNO (operands[1]) == 1
1762 && REGNO (operands[2]) == 2
1763 && REGNO (operands[3]) == 3"
1764 "stm.l\\t%S0-%S3,@-er7"
1765 [(set_attr "cc" "none")
1766 (set_attr "length" "4")])
1768 ;; ----------------------------------------------------------------------
1769 ;; EXTEND INSTRUCTIONS
1770 ;; ----------------------------------------------------------------------
1772 (define_expand "zero_extendqihi2"
1773 [(set (match_operand:HI 0 "register_operand" "")
1774 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
1779 [(set (match_operand:HI 0 "register_operand" "=r,r")
1780 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1784 mov.b %R1,%s0\;mov.b #0,%t0"
1785 [(set_attr "length" "2,10")
1786 (set_attr "cc" "clobber,clobber")])
1789 [(set (match_operand:HI 0 "register_operand" "=r,r")
1790 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1791 "TARGET_H8300H || TARGET_H8300S"
1794 mov.b %R1,%s0\;extu.w %T0"
1795 [(set_attr "length" "2,10")
1796 (set_attr "cc" "set_znv,set_znv")])
1798 ;; The compiler can synthesize a H8/300H variant of this which is
1799 ;; just as efficient as one that we'd create
1800 (define_insn "zero_extendqisi2"
1801 [(set (match_operand:SI 0 "register_operand" "=r,r")
1802 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1805 mov.b #0,%x0\;sub.w %e0,%e0
1806 mov.b %R1,%w0\;mov.b #0,%x0\;sub.w %e0,%e0"
1807 [(set_attr "length" "4,6")
1808 (set_attr "cc" "clobber,clobber")])
1810 (define_expand "zero_extendhisi2"
1811 [(set (match_operand:SI 0 "register_operand" "")
1812 (zero_extend:SI (match_operand:HI 1 "register_operand" "")))]
1816 ;; %e prints the high part of a CONST_INT, not the low part. Arggh.
1818 [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1819 (zero_extend:SI (match_operand:HI 1 "general_operand_src" "0,i,g>")))]
1823 mov.w %f1,%f0\;sub.w %e0,%e0
1824 mov.w %e1,%f0\;sub.w %e0,%e0"
1825 [(set_attr "length" "2,4,4")
1826 (set_attr "cc" "clobber,clobber,clobber")])
1829 [(set (match_operand:SI 0 "register_operand" "=r")
1830 (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))]
1831 "TARGET_H8300H || TARGET_H8300S"
1833 [(set_attr "length" "2")
1834 (set_attr "cc" "set_znv")])
1836 (define_expand "extendqihi2"
1837 [(set (match_operand:HI 0 "register_operand" "")
1838 (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
1843 [(set (match_operand:HI 0 "register_operand" "=r,r")
1844 (sign_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1847 bld #7,%s0\;subx %t0,%t0
1848 mov.b %R1,%s0\;bld #7,%s0\;subx %t0,%t0"
1849 [(set_attr "length" "4,8")
1850 (set_attr "cc" "clobber,clobber")])
1853 [(set (match_operand:HI 0 "register_operand" "=r")
1854 (sign_extend:HI (match_operand:QI 1 "register_operand" "0")))]
1855 "TARGET_H8300H || TARGET_H8300S"
1857 [(set_attr "length" "2")
1858 (set_attr "cc" "set_znv")])
1860 ;; The compiler can synthesize a H8/300H variant of this which is
1861 ;; just as efficient as one that we'd create
1862 (define_insn "extendqisi2"
1863 [(set (match_operand:SI 0 "register_operand" "=r,r")
1864 (sign_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
1867 bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0
1868 mov.b %R1,%w0\;bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0"
1869 [(set_attr "length" "8,10")
1870 (set_attr "cc" "clobber,clobber")])
1872 (define_expand "extendhisi2"
1873 [(set (match_operand:SI 0 "register_operand" "")
1874 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
1879 [(set (match_operand:SI 0 "register_operand" "=r,r")
1880 (sign_extend:SI (match_operand:HI 1 "general_operand_src" "0,g>")))]
1883 bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0
1884 mov.w %T1,%f0\;bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0"
1885 [(set_attr "length" "6,8")
1886 (set_attr "cc" "clobber,clobber")])
1889 [(set (match_operand:SI 0 "register_operand" "=r")
1890 (sign_extend:SI (match_operand:HI 1 "register_operand" "0")))]
1891 "TARGET_H8300H || TARGET_H8300S"
1893 [(set_attr "length" "2")
1894 (set_attr "cc" "set_znv")])
1896 ;; ----------------------------------------------------------------------
1898 ;; ----------------------------------------------------------------------
1900 ;; We make some attempt to provide real efficient shifting. One example is
1901 ;; doing an 8 bit shift of a 16 bit value by moving a byte reg into the other
1902 ;; reg and moving 0 into the former reg.
1904 ;; We also try to achieve this in a uniform way. IE: We don't try to achieve
1905 ;; this in both rtl and at insn emit time. Ideally, we'd use rtl as that would
1906 ;; give the optimizer more cracks at the code. However, we wish to do things
1907 ;; like optimizing shifting the sign bit to bit 0 by rotating the other way.
1908 ;; There is rtl to handle this (rotate + and), but the H8/300 doesn't handle
1909 ;; 16 bit rotates. Also, if we emit complicated rtl, combine may not be able
1910 ;; to detect cases it can optimize.
1912 ;; For these and other fuzzy reasons, I've decided to go the less pretty but
1913 ;; easier "do it at insn emit time" route.
1917 (define_expand "ashlqi3"
1918 [(set (match_operand:QI 0 "register_operand" "")
1919 (ashift:QI (match_operand:QI 1 "register_operand" "")
1920 (match_operand:QI 2 "nonmemory_operand" "")))]
1922 "if (expand_a_shift (QImode, ASHIFT, operands)) DONE; else FAIL;")
1924 (define_expand "ashrqi3"
1925 [(set (match_operand:QI 0 "register_operand" "")
1926 (ashiftrt:QI (match_operand:QI 1 "register_operand" "")
1927 (match_operand:QI 2 "nonmemory_operand" "")))]
1929 "if (expand_a_shift (QImode, ASHIFTRT, operands)) DONE; else FAIL;")
1931 (define_expand "lshrqi3"
1932 [(set (match_operand:QI 0 "register_operand" "")
1933 (lshiftrt:QI (match_operand:QI 1 "register_operand" "")
1934 (match_operand:QI 2 "nonmemory_operand" "")))]
1936 "if (expand_a_shift (QImode, LSHIFTRT, operands)) DONE; else FAIL;")
1939 [(set (match_operand:QI 0 "register_operand" "=r,r")
1940 (match_operator:QI 3 "nshift_operator"
1941 [ (match_operand:QI 1 "register_operand" "0,0")
1942 (match_operand:QI 2 "nonmemory_operand" "R,rn")]))
1943 (clobber (match_scratch:QI 4 "=X,&r"))]
1945 "* return output_a_shift (operands);"
1946 [(set (attr "length")
1947 (symbol_ref "compute_a_shift_length (insn, operands)"))
1948 (set_attr "cc" "clobber")])
1952 (define_expand "ashlhi3"
1953 [(set (match_operand:HI 0 "register_operand" "")
1954 (ashift:HI (match_operand:HI 1 "nonmemory_operand" "")
1955 (match_operand:QI 2 "nonmemory_operand" "")))]
1957 "if (expand_a_shift (HImode, ASHIFT, operands)) DONE; else FAIL;")
1959 (define_expand "lshrhi3"
1960 [(set (match_operand:HI 0 "register_operand" "")
1961 (lshiftrt:HI (match_operand:HI 1 "general_operand" "")
1962 (match_operand:QI 2 "nonmemory_operand" "")))]
1964 "if (expand_a_shift (HImode, LSHIFTRT, operands)) DONE; else FAIL;")
1966 (define_expand "ashrhi3"
1967 [(set (match_operand:HI 0 "register_operand" "")
1968 (ashiftrt:HI (match_operand:HI 1 "register_operand" "")
1969 (match_operand:QI 2 "nonmemory_operand" "")))]
1971 "if (expand_a_shift (HImode, ASHIFTRT, operands)) DONE; else FAIL;")
1974 [(set (match_operand:HI 0 "register_operand" "=r,r")
1975 (match_operator:HI 3 "nshift_operator"
1976 [ (match_operand:HI 1 "register_operand" "0,0")
1977 (match_operand:QI 2 "nonmemory_operand" "S,rn")]))
1978 (clobber (match_scratch:QI 4 "=X,&r"))]
1980 "* return output_a_shift (operands);"
1981 [(set (attr "length")
1982 (symbol_ref "compute_a_shift_length (insn, operands)"))
1983 (set_attr "cc" "clobber")])
1987 (define_expand "ashlsi3"
1988 [(set (match_operand:SI 0 "register_operand" "")
1989 (ashift:SI (match_operand:SI 1 "general_operand" "")
1990 (match_operand:QI 2 "nonmemory_operand" "")))]
1992 "if (expand_a_shift (SImode, ASHIFT, operands)) DONE; else FAIL;")
1994 (define_expand "lshrsi3"
1995 [(set (match_operand:SI 0 "register_operand" "")
1996 (lshiftrt:SI (match_operand:SI 1 "general_operand" "")
1997 (match_operand:QI 2 "nonmemory_operand" "")))]
1999 "if (expand_a_shift (SImode, LSHIFTRT, operands)) DONE; else FAIL;")
2001 (define_expand "ashrsi3"
2002 [(set (match_operand:SI 0 "register_operand" "")
2003 (ashiftrt:SI (match_operand:SI 1 "general_operand" "")
2004 (match_operand:QI 2 "nonmemory_operand" "")))]
2006 "if (expand_a_shift (SImode, ASHIFTRT, operands)) DONE; else FAIL;")
2009 [(set (match_operand:SI 0 "register_operand" "=r,r")
2010 (match_operator:SI 3 "nshift_operator"
2011 [ (match_operand:SI 1 "register_operand" "0,0")
2012 (match_operand:QI 2 "nonmemory_operand" "T,rn")]))
2013 (clobber (match_scratch:QI 4 "=X,&r"))]
2015 "* return output_a_shift (operands);"
2016 [(set (attr "length")
2017 (symbol_ref "compute_a_shift_length (insn, operands)"))
2018 (set_attr "cc" "clobber")])
2020 ;; ----------------------------------------------------------------------
2022 ;; ----------------------------------------------------------------------
2024 (define_expand "rotlqi3"
2025 [(set (match_operand:QI 0 "register_operand" "")
2026 (rotate:QI (match_operand:QI 1 "register_operand" "")
2027 (match_operand:QI 2 "nonmemory_operand" "")))]
2029 "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2031 (define_insn "*rotlqi3_1"
2032 [(set (match_operand:QI 0 "register_operand" "=r")
2033 (rotate:QI (match_operand:QI 1 "register_operand" "0")
2034 (match_operand:QI 2 "immediate_operand" "")))]
2036 "* return emit_a_rotate (ROTATE, operands);"
2037 [(set_attr "length" "20")
2038 (set_attr "cc" "clobber")])
2040 (define_expand "rotlhi3"
2041 [(set (match_operand:HI 0 "register_operand" "")
2042 (rotate:HI (match_operand:HI 1 "register_operand" "")
2043 (match_operand:QI 2 "nonmemory_operand" "")))]
2045 "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2047 (define_insn "*rotlhi3_1"
2048 [(set (match_operand:HI 0 "register_operand" "=r")
2049 (rotate:HI (match_operand:HI 1 "register_operand" "0")
2050 (match_operand:QI 2 "immediate_operand" "")))]
2052 "* return emit_a_rotate (ROTATE, operands);"
2053 [(set_attr "length" "20")
2054 (set_attr "cc" "clobber")])
2056 (define_expand "rotlsi3"
2057 [(set (match_operand:SI 0 "register_operand" "")
2058 (rotate:SI (match_operand:SI 1 "register_operand" "")
2059 (match_operand:QI 2 "nonmemory_operand" "")))]
2060 "TARGET_H8300H || TARGET_H8300S"
2061 "if (expand_a_rotate (ROTATE, operands)) DONE; else FAIL;")
2063 (define_insn "*rotlsi3_1"
2064 [(set (match_operand:SI 0 "register_operand" "=r")
2065 (rotate:SI (match_operand:SI 1 "register_operand" "0")
2066 (match_operand:QI 2 "immediate_operand" "")))]
2067 "TARGET_H8300H || TARGET_H8300S"
2068 "* return emit_a_rotate (ROTATE, operands);"
2069 [(set_attr "length" "20")
2070 (set_attr "cc" "clobber")])
2072 ;; -----------------------------------------------------------------
2074 ;; -----------------------------------------------------------------
2075 ;; The H8/300 has given 1/8th of its opcode space to bitfield
2076 ;; instructions so let's use them as well as we can.
2078 ;; You'll never believe all these patterns perform one basic action --
2079 ;; load a bit from the source, optionally invert the bit, then store it
2080 ;; in the destination (which is known to be zero).
2082 ;; Combine obviously need some work to better identify this situation and
2083 ;; canonicalize the form better.
2086 ;; Normal loads with a 16bit destination.
2090 [(set (match_operand:HI 0 "register_operand" "=&r")
2091 (zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2093 (match_operand:HI 2 "immediate_operand" "n")))]
2095 "sub.w %0,%0\;bld %Z2,%Y1\;bst #0,%X0"
2096 [(set_attr "cc" "clobber")
2097 (set_attr "length" "6")])
2100 ;; Inverted loads with a 16bit destination.
2104 [(set (match_operand:HI 0 "register_operand" "=&r")
2105 (zero_extract:HI (xor:HI (match_operand:HI 1 "register_operand" "r")
2106 (match_operand:HI 3 "const_int_operand" "n"))
2108 (match_operand:HI 2 "const_int_operand" "n")))]
2110 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2111 "sub.w %0,%0\;bild %Z2,%Y1\;bst #0,%X0"
2112 [(set_attr "cc" "clobber")
2113 (set_attr "length" "8")])
2116 ;; Normal loads with a 32bit destination.
2120 [(set (match_operand:SI 0 "register_operand" "=&r")
2121 (zero_extract:SI (match_operand:HI 1 "register_operand" "r")
2123 (match_operand 2 "const_int_operand" "n")))]
2125 && INTVAL (operands[2]) < 16"
2126 "* return output_simode_bld (0, operands);"
2127 [(set_attr "cc" "clobber")
2128 (set_attr "length" "6")])
2131 [(set (match_operand:SI 0 "register_operand" "=r")
2132 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2134 (match_operand 2 "const_int_operand" "n")))]
2135 "(TARGET_H8300H || TARGET_H8300S)
2136 && INTVAL (operands[2]) < 16"
2137 "* return output_simode_bld (0, operands);"
2138 [(set_attr "cc" "clobber")
2139 (set_attr "length" "6")])
2142 ;; Inverted loads with a 32bit destination.
2146 [(set (match_operand:SI 0 "register_operand" "=&r")
2147 (zero_extract:SI (xor:HI (match_operand:HI 1 "register_operand" "r")
2148 (match_operand:HI 3 "const_int_operand" "n"))
2150 (match_operand 2 "const_int_operand" "n")))]
2152 && INTVAL (operands[2]) < 16
2153 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2154 "* return output_simode_bld (1, operands);"
2155 [(set_attr "cc" "clobber")
2156 (set_attr "length" "6")])
2159 [(set (match_operand:SI 0 "register_operand" "=r")
2160 (zero_extract:SI (xor:SI (match_operand:SI 1 "register_operand" "r")
2161 (match_operand 3 "const_int_operand" "n"))
2163 (match_operand 2 "const_int_operand" "n")))]
2164 "(TARGET_H8300H || TARGET_H8300S)
2165 && INTVAL (operands[2]) < 16
2166 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
2167 "* return output_simode_bld (1, operands);"
2168 [(set_attr "cc" "clobber")
2169 (set_attr "length" "6")])
2171 (define_expand "insv"
2172 [(set (zero_extract:HI (match_operand:HI 0 "general_operand" "")
2173 (match_operand:HI 1 "general_operand" "")
2174 (match_operand:HI 2 "general_operand" ""))
2175 (match_operand:HI 3 "general_operand" ""))]
2179 /* We only have single bit bit-field instructions. */
2180 if (INTVAL (operands[1]) != 1)
2183 /* For now, we don't allow memory operands. */
2184 if (GET_CODE (operands[0]) == MEM
2185 || GET_CODE (operands[3]) == MEM)
2190 [(set (zero_extract:HI (match_operand:HI 0 "register_operand" "+r")
2192 (match_operand:HI 1 "immediate_operand" "n"))
2193 (match_operand:HI 2 "register_operand" "r"))]
2195 "bld #0,%R2\;bst %Z1,%Y0 ; i1"
2196 [(set_attr "cc" "clobber")
2197 (set_attr "length" "4")])
2199 (define_expand "extzv"
2200 [(set (match_operand:HI 0 "register_operand" "")
2201 (zero_extract:HI (match_operand:HI 1 "bit_operand" "")
2202 (match_operand:HI 2 "general_operand" "")
2203 (match_operand:HI 3 "general_operand" "")))]
2207 /* We only have single bit bit-field instructions. */
2208 if (INTVAL (operands[2]) != 1)
2211 /* For now, we don't allow memory operands. */
2212 if (GET_CODE (operands[1]) == MEM)
2216 ;; BAND, BOR, and BXOR patterns
2219 [(set (match_operand:HI 0 "bit_operand" "=Ur")
2220 (match_operator:HI 4 "bit_operator"
2221 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2223 (match_operand:HI 2 "immediate_operand" "n"))
2224 (match_operand:HI 3 "bit_operand" "0")]))]
2226 "bld %Z2,%Y1\;%b4 #0,%R0\;bst #0,%R0; bl1"
2227 [(set_attr "cc" "clobber")
2228 (set_attr "length" "6")
2229 (set_attr "adjust_length" "no")])
2232 [(set (match_operand:HI 0 "bit_operand" "=Ur")
2233 (match_operator:HI 5 "bit_operator"
2234 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
2236 (match_operand:HI 2 "immediate_operand" "n"))
2237 (zero_extract:HI (match_operand:HI 3 "register_operand" "r")
2239 (match_operand:HI 4 "immediate_operand" "n"))]))]
2241 "bld %Z2,%Y1\;%b5 %Z4,%Y3\;bst #0,%R0; bl3"
2242 [(set_attr "cc" "clobber")
2243 (set_attr "length" "6")
2244 (set_attr "adjust_length" "no")])
2246 ;; -----------------------------------------------------------------
2248 ;; -----------------------------------------------------------------
2250 (define_insn "*extzv_8_8"
2251 [(set (match_operand:SI 0 "register_operand" "=r")
2252 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2255 "TARGET_H8300H || TARGET_H8300S"
2256 "mov.b\\t%x1,%w0\;extu.w\\t%f0\;extu.l\\t%S0"
2257 [(set_attr "cc" "set_znv")
2258 (set_attr "length" "6")])
2260 (define_insn "*extzv_8_16"
2261 [(set (match_operand:SI 0 "register_operand" "=r")
2262 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
2265 "TARGET_H8300H || TARGET_H8300S"
2266 "mov.w\\t%e1,%f0\;extu.w\\t%f0\;extu.l\\t%S0"
2267 [(set_attr "cc" "set_znv")
2268 (set_attr "length" "6")])
2271 [(set (match_operand:HI 0 "register_operand" "=r")
2272 (ior:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
2273 (match_operand:HI 2 "register_operand" "0")))]
2274 "REG_P (operands[0])
2275 && REG_P (operands[1])
2276 && REGNO (operands[0]) != REGNO (operands[1])"
2278 [(set_attr "cc" "clobber")
2279 (set_attr "length" "2")])
2282 [(set (match_operand:SI 0 "register_operand" "=r")
2283 (ior:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "r"))
2284 (match_operand:SI 2 "register_operand" "0")))]
2285 "(TARGET_H8300H || TARGET_H8300S)
2286 && REG_P (operands[0])
2287 && REG_P (operands[1])
2288 && (REGNO (operands[0]) != REGNO (operands[1]))"
2290 [(set_attr "cc" "clobber")
2291 (set_attr "length" "2")])
2294 [(set (match_operand:SI 0 "register_operand" "=r")
2295 (ior:SI (zero_extend:SI (match_operand:QI 1 "register_operand" "r"))
2296 (match_operand:SI 2 "register_operand" "0")))]
2299 [(set_attr "cc" "clobber")
2300 (set_attr "length" "2")])
2303 [(set (match_operand:HI 0 "register_operand" "=r")
2304 (xor:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
2305 (match_operand:HI 2 "register_operand" "0")))]
2306 "REG_P (operands[0])
2307 && REG_P (operands[1])
2308 && REGNO (operands[0]) != REGNO (operands[1])"
2310 [(set_attr "cc" "clobber")
2311 (set_attr "length" "2")])
2314 [(set (match_operand:SI 0 "register_operand" "=r")
2315 (xor:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "r"))
2316 (match_operand:SI 2 "register_operand" "0")))]
2317 "(TARGET_H8300H || TARGET_H8300S)
2318 && REG_P (operands[0])
2319 && REG_P (operands[1])
2320 && (REGNO (operands[0]) != REGNO (operands[1]))"
2322 [(set_attr "cc" "clobber")
2323 (set_attr "length" "2")])
2326 [(set (match_operand:SI 0 "register_operand" "=r")
2327 (xor:SI (zero_extend:SI (match_operand:QI 1 "register_operand" "r"))
2328 (match_operand:SI 2 "register_operand" "0")))]
2329 "REG_P (operands[0])
2330 && REG_P (operands[1])
2331 && REGNO (operands[0]) != REGNO (operands[1])"
2333 [(set_attr "cc" "clobber")
2334 (set_attr "length" "2")])
2337 [(set (match_operand:HI 0 "register_operand" "=r")
2338 (ior:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
2339 (ashift:HI (match_operand:HI 2 "register_operand" "r")
2341 "REG_P (operands[0])
2342 && REG_P (operands[2])
2343 && REGNO (operands[0]) != REGNO (operands[2])"
2345 [(set_attr "cc" "clobber")
2346 (set_attr "length" "2")])
2348 (define_insn "*iorhi_shift_8"
2349 [(set (match_operand:HI 0 "register_operand" "=r")
2350 (ior:HI (ashift:HI (match_operand:HI 1 "register_operand" "r")
2352 (match_operand:HI 2 "register_operand" "0")))]
2355 [(set_attr "cc" "clobber")
2356 (set_attr "length" "2")])
2359 [(set (match_operand:SI 0 "register_operand" "=r")
2360 (ior:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "0"))
2361 (ashift:SI (match_operand:SI 2 "register_operand" "r")
2363 "TARGET_H8300H || TARGET_H8300S"
2365 [(set_attr "cc" "clobber")
2366 (set_attr "length" "2")])
2369 [(set (match_operand:SI 0 "register_operand" "=r")
2370 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
2372 (match_operand:SI 2 "register_operand" "0")))]
2373 "TARGET_H8300H || TARGET_H8300S"
2375 [(set_attr "cc" "clobber")
2376 (set_attr "length" "2")])
2378 ;; Storing a part of HImode to QImode.
2381 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2382 (subreg:QI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
2386 [(set_attr "cc" "set_znv")
2387 (set_attr "length" "8")])
2389 ;; Storing a part of SImode to QImode.
2392 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2393 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2397 [(set_attr "cc" "set_znv")
2398 (set_attr "length" "8")])
2401 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2402 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2404 (clobber (match_scratch:SI 2 "=&r"))]
2405 "TARGET_H8300H || TARGET_H8300S"
2406 "mov.w\\t%e1,%f2\;mov.b\\t%w2,%R0"
2407 [(set_attr "cc" "set_znv")
2408 (set_attr "length" "10")])
2411 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
2412 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
2414 (clobber (match_scratch:SI 2 "=&r"))]
2415 "TARGET_H8300H || TARGET_H8300S"
2416 "mov.w\\t%e1,%f2\;mov.b\\t%x2,%R0"
2417 [(set_attr "cc" "set_znv")
2418 (set_attr "length" "10")])
2420 (define_insn_and_split ""
2422 (if_then_else (eq (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
2426 (label_ref (match_operand 1 "" ""))
2434 (if_then_else (ge (cc0)
2436 (label_ref (match_dup 1))
2440 (define_insn_and_split ""
2442 (if_then_else (ne (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
2446 (label_ref (match_operand 1 "" ""))
2454 (if_then_else (lt (cc0)
2456 (label_ref (match_dup 1))
2460 ;; -----------------------------------------------------------------
2461 ;; PEEPHOLE PATTERNS
2462 ;; -----------------------------------------------------------------
2464 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
2468 [(set (match_operand:HI 0 "register_operand" "")
2469 (lshiftrt:HI (match_dup 0)
2470 (match_operand:HI 1 "const_int_operand" "")))
2471 (clobber (match_operand:HI 2 "" ""))])
2473 (and:HI (match_dup 0)
2474 (match_operand:HI 3 "const_int_operand" "")))]
2475 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
2477 (and:HI (match_dup 0)
2481 (lshiftrt:HI (match_dup 0)
2483 (clobber (match_dup 2))])]
2486 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
2490 [(set (match_operand:HI 0 "register_operand" "")
2491 (ashift:HI (match_dup 0)
2492 (match_operand:HI 1 "const_int_operand" "")))
2493 (clobber (match_operand:HI 2 "" ""))])
2495 (and:HI (match_dup 0)
2496 (match_operand:HI 3 "const_int_operand" "")))]
2497 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
2499 (and:HI (match_dup 0)
2503 (ashift:HI (match_dup 0)
2505 (clobber (match_dup 2))])]
2508 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
2512 [(set (match_operand:SI 0 "register_operand" "")
2513 (lshiftrt:SI (match_dup 0)
2514 (match_operand:SI 1 "const_int_operand" "")))
2515 (clobber (match_operand:SI 2 "" ""))])
2517 (and:SI (match_dup 0)
2518 (match_operand:SI 3 "const_int_operand" "")))]
2519 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
2521 (and:SI (match_dup 0)
2525 (lshiftrt:SI (match_dup 0)
2527 (clobber (match_dup 2))])]
2530 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
2534 [(set (match_operand:SI 0 "register_operand" "")
2535 (ashift:SI (match_dup 0)
2536 (match_operand:SI 1 "const_int_operand" "")))
2537 (clobber (match_operand:SI 2 "" ""))])
2539 (and:SI (match_dup 0)
2540 (match_operand:SI 3 "const_int_operand" "")))]
2541 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
2543 (and:SI (match_dup 0)
2547 (ashift:SI (match_dup 0)
2549 (clobber (match_dup 2))])]
2552 ;; Convert (A >> B) & C to (A & 65535) >> B if C == 65535 >> B.
2556 [(set (match_operand:SI 0 "register_operand" "")
2557 (lshiftrt:SI (match_dup 0)
2558 (match_operand:SI 1 "const_int_operand" "")))
2559 (clobber (match_operand:SI 2 "" ""))])
2561 (and:SI (match_dup 0)
2562 (match_operand:SI 3 "const_int_operand" "")))]
2563 "INTVAL (operands[3]) == (65535 >> INTVAL (operands[1]))"
2565 (and:SI (match_dup 0)
2569 (lshiftrt:SI (match_dup 0)
2571 (clobber (match_dup 2))])]
2574 ;; Convert (A << B) & C to (A & 65535) << B if C == 65535 << B.
2578 [(set (match_operand:SI 0 "register_operand" "")
2579 (ashift:SI (match_dup 0)
2580 (match_operand:SI 1 "const_int_operand" "")))
2581 (clobber (match_operand:SI 2 "" ""))])
2583 (and:SI (match_dup 0)
2584 (match_operand:SI 3 "const_int_operand" "")))]
2585 "INTVAL (operands[3]) == (65535 << INTVAL (operands[1]))"
2587 (and:SI (match_dup 0)
2591 (ashift:SI (match_dup 0)
2593 (clobber (match_dup 2))])]
2596 ;; Convert a QImode push into an SImode push so that the
2597 ;; define_peephole2 below can cram multiple pushes into one stm.l.
2600 [(parallel [(set (reg:SI SP_REG)
2601 (plus:SI (reg:SI SP_REG) (const_int -4)))
2602 (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
2603 (match_operand:QI 0 "register_operand" ""))])]
2605 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2607 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
2609 ;; Convert a HImode push into an SImode push so that the
2610 ;; define_peephole2 below can cram multiple pushes into one stm.l.
2613 [(parallel [(set (reg:SI SP_REG)
2614 (plus:SI (reg:SI SP_REG) (const_int -4)))
2615 (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
2616 (match_operand:HI 0 "register_operand" ""))])]
2618 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2620 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
2622 ;; Cram four pushes into stm.l.
2625 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2626 (match_operand:SI 0 "register_operand" ""))
2627 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2628 (match_operand:SI 1 "register_operand" ""))
2629 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2630 (match_operand:SI 2 "register_operand" ""))
2631 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2632 (match_operand:SI 3 "register_operand" ""))]
2634 && REGNO (operands[0]) == 0
2635 && REGNO (operands[1]) == 1
2636 && REGNO (operands[2]) == 2
2637 && REGNO (operands[3]) == 3"
2638 [(parallel [(set (reg:SI SP_REG)
2639 (plus:SI (reg:SI SP_REG)
2641 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
2643 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
2645 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
2647 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
2651 ;; Cram three pushes into stm.l.
2654 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2655 (match_operand:SI 0 "register_operand" ""))
2656 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2657 (match_operand:SI 1 "register_operand" ""))
2658 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2659 (match_operand:SI 2 "register_operand" ""))]
2661 && ((REGNO (operands[0]) == 0
2662 && REGNO (operands[1]) == 1
2663 && REGNO (operands[2]) == 2)
2664 || (REGNO (operands[0]) == 4
2665 && REGNO (operands[1]) == 5
2666 && REGNO (operands[2]) == 6))"
2667 [(parallel [(set (reg:SI SP_REG)
2668 (plus:SI (reg:SI SP_REG)
2670 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
2672 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
2674 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
2678 ;; Cram two pushes into stm.l.
2681 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2682 (match_operand:SI 0 "register_operand" ""))
2683 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2684 (match_operand:SI 1 "register_operand" ""))]
2686 && ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
2687 || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
2688 || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5))"
2689 [(parallel [(set (reg:SI SP_REG)
2690 (plus:SI (reg:SI SP_REG)
2692 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
2694 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
2701 ;; add.w r7,r0 (6 bytes)
2706 ;; adds #2,r0 (4 bytes)
2709 [(set (match_operand:HI 0 "register_operand" "")
2710 (match_operand:HI 1 "const_int_operand" ""))
2712 (plus:HI (match_dup 0)
2713 (match_operand:HI 2 "register_operand" "")))]
2714 "REG_P (operands[0]) && REG_P (operands[2])
2715 && REGNO (operands[0]) != REGNO (operands[2])
2716 && (CONST_OK_FOR_J (INTVAL (operands[1]))
2717 || CONST_OK_FOR_L (INTVAL (operands[1]))
2718 || CONST_OK_FOR_N (INTVAL (operands[1])))"
2722 (plus:HI (match_dup 0)
2730 ;; add.l er7,er0 (6 bytes)
2735 ;; adds #4,er0 (4 bytes)
2738 [(set (match_operand:SI 0 "register_operand" "")
2739 (match_operand:SI 1 "const_int_operand" ""))
2741 (plus:SI (match_dup 0)
2742 (match_operand:SI 2 "register_operand" "")))]
2743 "(TARGET_H8300H || TARGET_H8300S)
2744 && REG_P (operands[0]) && REG_P (operands[2])
2745 && REGNO (operands[0]) != REGNO (operands[2])
2746 && (CONST_OK_FOR_L (INTVAL (operands[1]))
2747 || CONST_OK_FOR_N (INTVAL (operands[1])))"
2751 (plus:SI (match_dup 0)
2758 ;; add.l #10,er0 (takes 8 bytes)
2764 ;; add.l er7,er0 (takes 6 bytes)
2767 [(set (match_operand:SI 0 "register_operand" "")
2768 (match_operand:SI 1 "register_operand" ""))
2770 (plus:SI (match_dup 0)
2771 (match_operand:SI 2 "const_int_operand" "")))]
2772 "(TARGET_H8300H || TARGET_H8300S)
2773 && REG_P (operands[0]) && REG_P (operands[1])
2774 && REGNO (operands[0]) != REGNO (operands[1])
2775 && !CONST_OK_FOR_L (INTVAL (operands[2]))
2776 && !CONST_OK_FOR_N (INTVAL (operands[2]))
2777 && ((INTVAL (operands[2]) & 0xff) == INTVAL (operands[2])
2778 || (INTVAL (operands[2]) & 0xff00) == INTVAL (operands[2])
2779 || INTVAL (operands[2]) == 0xffff
2780 || INTVAL (operands[2]) == 0xfffe)"
2784 (plus:SI (match_dup 0)