1 ;; GCC machine description for Renesas H8/300
2 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Contributed by Steve Chamberlain (sac@cygnus.com),
7 ;; Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
9 ;; This file is part of GCC.
11 ;; GCC is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; GCC is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GCC; see the file COPYING3. If not see
23 ;; <http://www.gnu.org/licenses/>.
25 ;; We compute exact length on each instruction for most of the time.
26 ;; In some case, most notably bit operations that may involve memory
27 ;; operands, the lengths in this file are "worst case".
29 ;; On the H8/300H and H8S, adds/subs operate on the 32bit "er"
30 ;; registers. Right now GCC doesn't expose the "e" half to the
31 ;; compiler, so using add/subs for addhi and subhi is safe. Long
32 ;; term, we want to expose the "e" half to the compiler (gives us 8
33 ;; more 16bit registers). At that point addhi and subhi can't use
36 ;; There's currently no way to have an insv/extzv expander for the H8/300H
37 ;; because word_mode is different for the H8/300 and H8/300H.
39 ;; Shifts/rotates by small constants should be handled by special
40 ;; patterns so we get the length and cc status correct.
42 ;; Bitfield operations no longer accept memory operands. We need
43 ;; to add variants which operate on memory back to the MD.
45 ;; ??? Implement remaining bit ops available on the h8300
47 ;; ----------------------------------------------------------------------
49 ;; ----------------------------------------------------------------------
72 ;; ----------------------------------------------------------------------
74 ;; ----------------------------------------------------------------------
76 (define_attr "cpu" "h8300,h8300h"
77 (const (symbol_ref "cpu_type")))
79 (define_attr "type" "branch,arith,bitbranch,call"
80 (const_string "arith"))
82 (define_attr "length_table" "none,addb,addw,addl,logicb,movb,movw,movl,mova_zero,mova,unary,mov_imm4,short_immediate,bitfield,bitbranch"
83 (const_string "none"))
85 ;; The size of instructions in bytes.
87 (define_attr "length" ""
88 (cond [(eq_attr "type" "branch")
89 ;; In a forward delayed branch, (pc) represents the end of the
90 ;; delay sequence, not the end of the branch itself.
91 (if_then_else (and (ge (minus (match_dup 0) (pc))
93 (le (plus (minus (match_dup 0) (pc))
94 (symbol_ref "DELAY_SLOT_LENGTH (insn)"))
97 (if_then_else (and (eq_attr "cpu" "h8300h")
98 (and (ge (minus (pc) (match_dup 0))
100 (le (minus (pc) (match_dup 0))
104 (eq_attr "type" "bitbranch")
105 (if_then_else (and (ge (minus (match_dup 0) (pc))
107 (le (minus (match_dup 0) (pc))
109 (plus (symbol_ref "h8300_insn_length_from_table (insn, operands)")
111 (if_then_else (and (eq_attr "cpu" "h8300h")
112 (and (ge (minus (pc) (match_dup 0))
114 (le (minus (pc) (match_dup 0))
116 (plus (symbol_ref "h8300_insn_length_from_table (insn, operands)")
118 (plus (symbol_ref "h8300_insn_length_from_table (insn, operands)")
120 (eq_attr "length_table" "!none")
121 (symbol_ref "h8300_insn_length_from_table (insn, operands)")]
124 ;; Condition code settings.
126 ;; none - insn does not affect cc
127 ;; none_0hit - insn does not affect cc but it does modify operand 0
128 ;; This attribute is used to keep track of when operand 0 changes.
129 ;; See the description of NOTICE_UPDATE_CC for more info.
130 ;; set_znv - insn sets z,n,v to usable values (like a tst insn); c is unknown.
131 ;; set_zn - insn sets z,n to usable values; v,c are unknown.
132 ;; compare - compare instruction
133 ;; clobber - value of cc is unknown
135 (define_attr "cc" "none,none_0hit,set_znv,set_zn,compare,clobber"
136 (const_string "clobber"))
138 ;; Type of delay slot. NONE means the instruction has no delay slot.
139 ;; JUMP means it is an unconditional jump that (if short enough)
140 ;; could be implemented using bra/s.
142 (define_attr "delay_slot" "none,jump"
143 (const_string "none"))
145 ;; "yes" if the instruction can be put into a delay slot. It's not
146 ;; entirely clear that jsr is not valid in delay slots, but it
147 ;; definitely doesn't have the effect of causing the called function
148 ;; to return to the target of the delayed branch.
150 (define_attr "can_delay" "no,yes"
151 (cond [(eq_attr "type" "branch,bitbranch,call")
153 (geu (symbol_ref "get_attr_length (insn)") (const_int 2))
155 (const_string "yes")))
157 ;; Only allow jumps to have a delay slot if we think they might
158 ;; be short enough. This is just an optimization: we don't know
159 ;; for certain whether they will be or not.
161 (define_delay (and (eq_attr "delay_slot" "jump")
162 (eq (symbol_ref "get_attr_length (insn)") (const_int 2)))
163 [(eq_attr "can_delay" "yes")
167 ;; Provide the maximum length of an assembly instruction in an asm
168 ;; statement. The maximum length of 14 bytes is achieved on H8SX.
170 (define_asm_attributes
171 [(set (attr "length")
172 (cond [(match_test "TARGET_H8300") (const_int 4)
173 (match_test "TARGET_H8300H") (const_int 10)
174 (match_test "TARGET_H8300S") (const_int 10)]
177 (include "predicates.md")
178 (include "constraints.md")
180 ;; ----------------------------------------------------------------------
182 ;; ----------------------------------------------------------------------
184 ;; This mode iterator allows :P to be used for patterns that operate on
185 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
187 (define_mode_iterator P [(HI "Pmode == HImode") (SI "Pmode == SImode")])
190 ;; ----------------------------------------------------------------------
192 ;; ----------------------------------------------------------------------
196 (define_insn "*movqi_h8300"
197 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
198 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
200 && h8300_move_ok (operands[0], operands[1])"
208 [(set_attr "length" "2,2,2,2,4,4")
209 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
211 (define_insn "*movqi_h8300hs"
212 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
213 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
214 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
215 && h8300_move_ok (operands[0], operands[1])"
223 [(set (attr "length")
224 (symbol_ref "compute_mov_length (operands)"))
225 (set_attr "cc" "set_zn,set_znv,set_znv,clobber,set_znv,set_znv")])
227 (define_insn "*movqi_h8sx"
228 [(set (match_operand:QI 0 "general_operand_dst" "=Z,rQ")
229 (match_operand:QI 1 "general_operand_src" "P4>X,rQi"))]
234 [(set_attr "length_table" "mov_imm4,movb")
235 (set_attr "cc" "set_znv")])
237 (define_expand "movqi"
238 [(set (match_operand:QI 0 "general_operand_dst" "")
239 (match_operand:QI 1 "general_operand_src" ""))]
242 /* One of the ops has to be in a register. */
243 if (!TARGET_H8300SX && !h8300_move_ok (operands[0], operands[1]))
244 operands[1] = copy_to_mode_reg (QImode, operands[1]);
247 (define_insn "movstrictqi"
248 [(set (strict_low_part (match_operand:QI 0 "general_operand_dst" "+r,r"))
249 (match_operand:QI 1 "general_operand_src" "I,rmi>"))]
254 [(set_attr "length" "2,*")
255 (set_attr "length_table" "*,movb")
256 (set_attr "cc" "set_zn,set_znv")])
260 (define_insn "*movhi_h8300"
261 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
262 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
264 && h8300_move_ok (operands[0], operands[1])"
272 [(set (attr "length")
273 (symbol_ref "compute_mov_length (operands)"))
274 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
276 (define_insn "*movhi_h8300hs"
277 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
278 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
279 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
280 && h8300_move_ok (operands[0], operands[1])"
288 [(set (attr "length")
289 (symbol_ref "compute_mov_length (operands)"))
290 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
292 (define_insn "*movhi_h8sx"
293 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,Z,Q,rQ")
294 (match_operand:HI 1 "general_operand_src" "I,P3>X,P4>X,IP8>X,rQi"))]
302 [(set_attr "length_table" "*,*,mov_imm4,short_immediate,movw")
303 (set_attr "length" "2,2,*,*,*")
304 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv")])
306 (define_expand "movhi"
307 [(set (match_operand:HI 0 "general_operand_dst" "")
308 (match_operand:HI 1 "general_operand_src" ""))]
311 /* One of the ops has to be in a register. */
312 if (!h8300_move_ok (operands[0], operands[1]))
313 operands[1] = copy_to_mode_reg (HImode, operand1);
316 (define_insn "movstricthi"
317 [(set (strict_low_part (match_operand:HI 0 "general_operand_dst" "+r,r,r"))
318 (match_operand:HI 1 "general_operand_src" "I,P3>X,rmi"))]
324 [(set_attr "length" "2,2,*")
325 (set_attr "length_table" "*,*,movw")
326 (set_attr "cc" "set_zn,set_znv,set_znv")])
330 (define_expand "movsi"
331 [(set (match_operand:SI 0 "general_operand_dst" "")
332 (match_operand:SI 1 "general_operand_src" ""))]
337 if (h8300_expand_movsi (operands))
340 else if (!TARGET_H8300SX)
342 /* One of the ops has to be in a register. */
343 if (!h8300_move_ok (operands[0], operands[1]))
344 operands[1] = copy_to_mode_reg (SImode, operand1);
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,>"))]
352 && h8300_move_ok (operands[0], operands[1])"
354 unsigned int rn = -1;
355 switch (which_alternative)
358 return "sub.w %e0,%e0\;sub.w %f0,%f0";
360 if (REGNO (operands[0]) < REGNO (operands[1]))
361 return "mov.w %e1,%e0\;mov.w %f1,%f0";
363 return "mov.w %f1,%f0\;mov.w %e1,%e0";
365 /* Make sure we don't trample the register we index with. */
366 if (GET_CODE (operands[1]) == MEM)
368 rtx inside = XEXP (operands[1], 0);
373 else if (GET_CODE (inside) == PLUS)
375 rtx lhs = XEXP (inside, 0);
376 rtx rhs = XEXP (inside, 1);
377 if (REG_P (lhs)) rn = REGNO (lhs);
378 if (REG_P (rhs)) rn = REGNO (rhs);
381 if (rn == REGNO (operands[0]))
383 /* Move the second word first. */
384 return "mov.w %f1,%f0\;mov.w %e1,%e0";
388 if (GET_CODE (operands[1]) == CONST_INT)
390 /* If either half is zero, use sub.w to clear that
392 if ((INTVAL (operands[1]) & 0xffff) == 0)
393 return "mov.w %e1,%e0\;sub.w %f0,%f0";
394 if (((INTVAL (operands[1]) >> 16) & 0xffff) == 0)
395 return "sub.w %e0,%e0\;mov.w %f1,%f0";
396 /* If the upper half and the lower half are the same,
397 copy one half to the other. */
398 if ((INTVAL (operands[1]) & 0xffff)
399 == ((INTVAL (operands[1]) >> 16) & 0xffff))
400 return "mov.w\\t%e1,%e0\;mov.w\\t%e0,%f0";
402 return "mov.w %e1,%e0\;mov.w %f1,%f0";
405 return "mov.w %e1,%e0\;mov.w %f1,%f0";
407 return "mov.w %f1,%T0\;mov.w %e1,%T0";
409 return "mov.w %T1,%e0\;mov.w %T1,%f0";
414 [(set (attr "length")
415 (symbol_ref "compute_mov_length (operands)"))])
417 (define_insn "*movsi_h8300hs"
418 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,<,r,r,m,*a,*a,r")
419 (match_operand:SI 1 "general_operand_src" "I,r,i,r,>,m,r,I,r,*a"))]
420 "(TARGET_H8300S || TARGET_H8300H) && !TARGET_H8300SX
421 && h8300_move_ok (operands[0], operands[1])"
423 switch (which_alternative)
426 return "sub.l %S0,%S0";
430 return "clrmac\;ldmac %1,macl";
432 return "stmac macl,%0";
434 if (GET_CODE (operands[1]) == CONST_INT)
436 int val = INTVAL (operands[1]);
438 /* Look for constants which can be made by adding an 8-bit
439 number to zero in one of the two low bytes. */
440 if (val == (val & 0xff))
442 operands[1] = GEN_INT ((char) val & 0xff);
443 return "sub.l\\t%S0,%S0\;add.b\\t%1,%w0";
446 if (val == (val & 0xff00))
448 operands[1] = GEN_INT ((char) (val >> 8) & 0xff);
449 return "sub.l\\t%S0,%S0\;add.b\\t%1,%x0";
452 /* Look for constants that can be obtained by subs, inc, and
454 switch (val & 0xffffffff)
457 return "sub.l\\t%S0,%S0\;subs\\t#1,%S0";
459 return "sub.l\\t%S0,%S0\;subs\\t#2,%S0";
461 return "sub.l\\t%S0,%S0\;subs\\t#4,%S0";
464 return "sub.l\\t%S0,%S0\;dec.w\\t#1,%f0";
466 return "sub.l\\t%S0,%S0\;dec.w\\t#2,%f0";
469 return "sub.l\\t%S0,%S0\;dec.w\\t#1,%e0";
471 return "sub.l\\t%S0,%S0\;dec.w\\t#2,%e0";
474 return "sub.l\\t%S0,%S0\;inc.w\\t#1,%e0";
476 return "sub.l\\t%S0,%S0\;inc.w\\t#2,%e0";
480 return "mov.l %S1,%S0";
482 [(set (attr "length")
483 (symbol_ref "compute_mov_length (operands)"))
484 (set_attr "cc" "set_zn,set_znv,clobber,set_znv,set_znv,set_znv,set_znv,none_0hit,none_0hit,set_znv")])
486 (define_insn "*movsi_h8sx"
487 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,Q,rQ,*a,*a,r")
488 (match_operand:SI 1 "general_operand_src" "I,P3>X,IP8>X,rQi,I,r,*a"))]
496 clrmac\;ldmac %1,macl
498 [(set_attr "length_table" "*,*,short_immediate,movl,*,*,*")
499 (set_attr "length" "2,2,*,*,2,6,4")
500 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,none_0hit,none_0hit,set_znv")])
502 (define_insn "*movsf_h8sx"
503 [(set (match_operand:SF 0 "general_operand_dst" "=r,rQ")
504 (match_operand:SF 1 "general_operand_src" "G,rQi"))]
509 [(set_attr "length" "2,*")
510 (set_attr "length_table" "*,movl")
511 (set_attr "cc" "set_zn,set_znv")])
513 ;; Implement block moves using movmd. Defining movmemsi allows the full
514 ;; range of constant lengths (up to 0x40000 bytes when using movmd.l).
515 ;; See h8sx_emit_movmd for details.
517 (define_expand "movmemsi"
518 [(use (match_operand:BLK 0 "memory_operand" ""))
519 (use (match_operand:BLK 1 "memory_operand" ""))
520 (use (match_operand:SI 2 "" ""))
521 (use (match_operand:SI 3 "const_int_operand" ""))]
524 if (h8sx_emit_movmd (operands[0], operands[1], operands[2], INTVAL (operands[3])))
530 ;; Expander for generating movmd insns. Operand 0 is the destination
531 ;; memory region, operand 1 is the source, operand 2 is the counter
532 ;; register and operand 3 is the chunk size (1, 2 or 4).
534 (define_expand "movmd"
536 [(set (match_operand:BLK 0 "memory_operand" "")
537 (match_operand:BLK 1 "memory_operand" ""))
538 (unspec [(match_operand:HI 2 "register_operand" "")
539 (match_operand:HI 3 "const_int_operand" "")] UNSPEC_MOVMD)
540 (clobber (match_dup 4))
541 (clobber (match_dup 5))
546 operands[4] = copy_rtx (XEXP (operands[0], 0));
547 operands[5] = copy_rtx (XEXP (operands[1], 0));
550 ;; This is a difficult instruction to reload since operand 0 must be the
551 ;; frame pointer. See h8300_reg_class_from_letter for an explanation.
553 (define_insn "movmd_internal_normal"
554 [(set (mem:BLK (match_operand:HI 3 "register_operand" "0,r"))
555 (mem:BLK (match_operand:HI 4 "register_operand" "1,1")))
556 (unspec [(match_operand:HI 5 "register_operand" "2,2")
557 (match_operand:HI 6 "const_int_operand" "n,n")] UNSPEC_MOVMD)
558 (clobber (match_operand:HI 0 "register_operand" "=d,??D"))
559 (clobber (match_operand:HI 1 "register_operand" "=f,f"))
560 (set (match_operand:HI 2 "register_operand" "=c,c")
562 "TARGET_H8300SX && TARGET_NORMAL_MODE"
566 [(set_attr "length" "2,14")
567 (set_attr "can_delay" "no")
568 (set_attr "cc" "none,clobber")])
570 (define_insn "movmd_internal"
571 [(set (mem:BLK (match_operand:SI 3 "register_operand" "0,r"))
572 (mem:BLK (match_operand:SI 4 "register_operand" "1,1")))
573 (unspec [(match_operand:HI 5 "register_operand" "2,2")
574 (match_operand:HI 6 "const_int_operand" "n,n")] UNSPEC_MOVMD)
575 (clobber (match_operand:SI 0 "register_operand" "=d,??D"))
576 (clobber (match_operand:SI 1 "register_operand" "=f,f"))
577 (set (match_operand:HI 2 "register_operand" "=c,c")
579 "TARGET_H8300SX && !TARGET_NORMAL_MODE"
583 [(set_attr "length" "2,14")
584 (set_attr "can_delay" "no")
585 (set_attr "cc" "none,clobber")])
587 ;; Split the above instruction if the destination register isn't er6.
588 ;; We need a sequence like:
596 ;; where <dest> is the current destination register (operand 4).
597 ;; The fourth instruction will be deleted if <dest> dies here.
600 [(set (match_operand:BLK 0 "memory_operand" "")
601 (match_operand:BLK 1 "memory_operand" ""))
602 (unspec [(match_operand:HI 2 "register_operand" "")
603 (match_operand:HI 3 "const_int_operand" "")] UNSPEC_MOVMD)
604 (clobber (match_operand:HI 4 "register_operand" ""))
605 (clobber (match_operand:HI 5 "register_operand" ""))
608 "TARGET_H8300SX && TARGET_NORMAL_MODE && reload_completed
609 && REGNO (operands[4]) != DESTINATION_REG"
614 h8300_swap_into_er6 (XEXP (operands[0], 0));
615 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
616 emit_insn (gen_movmd (dest, operands[1], operands[2], operands[3]));
617 h8300_swap_out_of_er6 (operands[4]);
622 [(set (match_operand:BLK 0 "memory_operand" "")
623 (match_operand:BLK 1 "memory_operand" ""))
624 (unspec [(match_operand:HI 2 "register_operand" "")
625 (match_operand:HI 3 "const_int_operand" "")] UNSPEC_MOVMD)
626 (clobber (match_operand:SI 4 "register_operand" ""))
627 (clobber (match_operand:SI 5 "register_operand" ""))
630 "TARGET_H8300SX && !TARGET_NORMAL_MODE && reload_completed
631 && REGNO (operands[4]) != DESTINATION_REG"
636 h8300_swap_into_er6 (XEXP (operands[0], 0));
637 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
638 emit_insn (gen_movmd (dest, operands[1], operands[2], operands[3]));
639 h8300_swap_out_of_er6 (operands[4]);
643 ;; Expand a call to stpcpy() using movsd. Operand 0 should point to
644 ;; the final character, but movsd leaves it pointing to the character
647 (define_expand "movstr"
648 [(use (match_operand 0 "register_operand" ""))
649 (use (match_operand:BLK 1 "memory_operand" ""))
650 (use (match_operand:BLK 2 "memory_operand" ""))]
653 operands[1] = replace_equiv_address
654 (operands[1], copy_to_mode_reg (Pmode, XEXP (operands[1], 0)));
655 operands[2] = replace_equiv_address
656 (operands[2], copy_to_mode_reg (Pmode, XEXP (operands[2], 0)));
657 emit_insn (gen_movsd (operands[1], operands[2], gen_reg_rtx (Pmode)));
658 emit_insn (gen_add3_insn (operands[0], XEXP (operands[1], 0), constm1_rtx));
662 ;; Expander for generating a movsd instruction. Operand 0 is the
663 ;; destination string, operand 1 is the source string and operand 2
664 ;; is a scratch register.
666 (define_expand "movsd"
668 [(set (match_operand:BLK 0 "memory_operand" "")
669 (unspec:BLK [(match_operand:BLK 1 "memory_operand" "")]
671 (clobber (match_dup 3))
672 (clobber (match_dup 4))
673 (clobber (match_operand 2 "register_operand" ""))])]
676 operands[3] = copy_rtx (XEXP (operands[0], 0));
677 operands[4] = copy_rtx (XEXP (operands[1], 0));
680 ;; See comments above memcpy_internal().
682 (define_insn "stpcpy_internal_normal"
683 [(set (mem:BLK (match_operand:HI 3 "register_operand" "0,r"))
684 (unspec:BLK [(mem:BLK (match_operand:HI 4 "register_operand" "1,1"))]
686 (clobber (match_operand:HI 0 "register_operand" "=d,??D"))
687 (clobber (match_operand:HI 1 "register_operand" "=f,f"))
688 (clobber (match_operand:HI 2 "register_operand" "=c,c"))]
689 "TARGET_H8300SX && TARGET_NORMAL_MODE"
691 \n1:\tmovsd\t2f\;bra\t1b\n2:
693 [(set_attr "length" "6,18")
694 (set_attr "cc" "none,clobber")])
696 (define_insn "stpcpy_internal"
697 [(set (mem:BLK (match_operand:SI 3 "register_operand" "0,r"))
698 (unspec:BLK [(mem:BLK (match_operand:SI 4 "register_operand" "1,1"))]
700 (clobber (match_operand:SI 0 "register_operand" "=d,??D"))
701 (clobber (match_operand:SI 1 "register_operand" "=f,f"))
702 (clobber (match_operand:SI 2 "register_operand" "=c,c"))]
703 "TARGET_H8300SX && !TARGET_NORMAL_MODE"
705 \n1:\tmovsd\t2f\;bra\t1b\n2:
707 [(set_attr "length" "6,18")
708 (set_attr "cc" "none,clobber")])
710 ;; Split the above instruction if the destination isn't er6. This works
711 ;; in the same way as the movmd splitter.
714 [(set (match_operand:BLK 0 "memory_operand" "")
715 (unspec:BLK [(match_operand:BLK 1 "memory_operand" "")] UNSPEC_STPCPY))
716 (clobber (match_operand:HI 2 "register_operand" ""))
717 (clobber (match_operand:HI 3 "register_operand" ""))
718 (clobber (match_operand:HI 4 "register_operand" ""))]
719 "TARGET_H8300SX && TARGET_NORMAL_MODE && reload_completed
720 && REGNO (operands[2]) != DESTINATION_REG"
725 h8300_swap_into_er6 (XEXP (operands[0], 0));
726 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
727 emit_insn (gen_movsd (dest, operands[1], operands[4]));
728 h8300_swap_out_of_er6 (operands[2]);
733 [(set (match_operand:BLK 0 "memory_operand" "")
734 (unspec:BLK [(match_operand:BLK 1 "memory_operand" "")] UNSPEC_STPCPY))
735 (clobber (match_operand:SI 2 "register_operand" ""))
736 (clobber (match_operand:SI 3 "register_operand" ""))
737 (clobber (match_operand:SI 4 "register_operand" ""))]
738 "TARGET_H8300SX && !TARGET_NORMAL_MODE && reload_completed
739 && REGNO (operands[2]) != DESTINATION_REG"
744 h8300_swap_into_er6 (XEXP (operands[0], 0));
745 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
746 emit_insn (gen_movsd (dest, operands[1], operands[4]));
747 h8300_swap_out_of_er6 (operands[2]);
753 (define_expand "movsf"
754 [(set (match_operand:SF 0 "general_operand_dst" "")
755 (match_operand:SF 1 "general_operand_src" ""))]
760 if (h8300_expand_movsi (operands))
763 else if (!TARGET_H8300SX)
765 /* One of the ops has to be in a register. */
766 if (!register_operand (operand1, SFmode)
767 && !register_operand (operand0, SFmode))
769 operands[1] = copy_to_mode_reg (SFmode, operand1);
774 (define_insn "*movsf_h8300"
775 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,o,<,r")
776 (match_operand:SF 1 "general_operand_src" "G,r,io,r,r,>"))]
778 && (register_operand (operands[0], SFmode)
779 || register_operand (operands[1], SFmode))"
781 /* Copy of the movsi stuff. */
782 unsigned int rn = -1;
783 switch (which_alternative)
786 return "sub.w %e0,%e0\;sub.w %f0,%f0";
788 if (REGNO (operands[0]) < REGNO (operands[1]))
789 return "mov.w %e1,%e0\;mov.w %f1,%f0";
791 return "mov.w %f1,%f0\;mov.w %e1,%e0";
793 /* Make sure we don't trample the register we index with. */
794 if (GET_CODE (operands[1]) == MEM)
796 rtx inside = XEXP (operands[1], 0);
801 else if (GET_CODE (inside) == PLUS)
803 rtx lhs = XEXP (inside, 0);
804 rtx rhs = XEXP (inside, 1);
805 if (REG_P (lhs)) rn = REGNO (lhs);
806 if (REG_P (rhs)) rn = REGNO (rhs);
809 if (rn == REGNO (operands[0]))
810 /* Move the second word first. */
811 return "mov.w %f1,%f0\;mov.w %e1,%e0";
813 /* Move the first word first. */
814 return "mov.w %e1,%e0\;mov.w %f1,%f0";
817 return "mov.w %e1,%e0\;mov.w %f1,%f0";
819 return "mov.w %f1,%T0\;mov.w %e1,%T0";
821 return "mov.w %T1,%e0\;mov.w %T1,%f0";
826 [(set (attr "length")
827 (symbol_ref "compute_mov_length (operands)"))])
829 (define_insn "*movsf_h8300hs"
830 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,m,<,r")
831 (match_operand:SF 1 "general_operand_src" "G,r,im,r,r,>"))]
832 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
833 && (register_operand (operands[0], SFmode)
834 || register_operand (operands[1], SFmode))"
842 [(set (attr "length")
843 (symbol_ref "compute_mov_length (operands)"))
844 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
846 ;; ----------------------------------------------------------------------
848 ;; ----------------------------------------------------------------------
850 (define_insn "*pushqi1_h8300"
854 (plus:HI (reg:HI SP_REG) (const_int -2))))
855 (match_operand:QI 0 "register_no_sp_elim_operand" "r"))]
858 [(set_attr "length" "2")])
860 (define_insn "*pushqi1_h8300hs_<mode>"
864 (plus:P (reg:P SP_REG) (const_int -4))))
865 (match_operand:QI 0 "register_no_sp_elim_operand" "r"))]
866 "TARGET_H8300H || TARGET_H8300S"
868 [(set_attr "length" "4")])
870 (define_insn "*pushhi1_h8300hs_<mode>"
874 (plus:P (reg:P SP_REG) (const_int -4))))
875 (match_operand:HI 0 "register_no_sp_elim_operand" "r"))]
876 "TARGET_H8300H || TARGET_H8300S"
878 [(set_attr "length" "4")])
880 ;; ----------------------------------------------------------------------
882 ;; ----------------------------------------------------------------------
886 (compare (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "r,U")
888 (match_operand 1 "const_int_operand" "n,n"))
892 [(set_attr "length" "2,4")
893 (set_attr "cc" "set_zn,set_zn")])
897 (compare (zero_extract:HI (match_operand:HI 0 "register_operand" "r")
899 (match_operand 1 "const_int_operand" "n"))
903 [(set_attr "length" "2")
904 (set_attr "cc" "set_zn")])
906 (define_insn_and_split "*tst_extzv_1_n"
908 (compare (zero_extract:SI (match_operand:QI 0 "general_operand_src" "r,U,mn>")
910 (match_operand 1 "const_int_operand" "n,n,n"))
912 (clobber (match_scratch:QI 2 "=X,X,&r"))]
913 "TARGET_H8300H || TARGET_H8300S"
919 && !satisfies_constraint_U (operands[0])"
922 (parallel [(set (cc0) (compare (zero_extract:SI (match_dup 2)
926 (clobber (scratch:QI))])]
928 [(set_attr "length" "2,8,10")
929 (set_attr "cc" "set_zn,set_zn,set_zn")])
933 (compare (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
935 (match_operand 1 "const_int_operand" "n"))
937 "(TARGET_H8300H || TARGET_H8300S)
938 && INTVAL (operands[1]) <= 15"
940 [(set_attr "length" "2")
941 (set_attr "cc" "set_zn")])
943 (define_insn_and_split "*tstsi_upper_bit"
945 (compare (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
947 (match_operand 1 "const_int_operand" "n"))
949 (clobber (match_scratch:SI 2 "=&r"))]
950 "(TARGET_H8300H || TARGET_H8300S)
951 && INTVAL (operands[1]) >= 16"
953 "&& reload_completed"
955 (ior:SI (and:SI (match_dup 2)
957 (lshiftrt:SI (match_dup 0)
960 (compare (zero_extract:SI (match_dup 2)
965 operands[3] = GEN_INT (INTVAL (operands[1]) - 16);
968 (define_insn "*tstsi_variable_bit"
970 (compare (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
972 (and:SI (match_operand:SI 1 "register_operand" "r")
975 "TARGET_H8300H || TARGET_H8300S"
977 [(set_attr "length" "2")
978 (set_attr "cc" "set_zn")])
980 (define_insn_and_split "*tstsi_variable_bit_qi"
982 (compare (zero_extract:SI (zero_extend:SI (match_operand:QI 0 "general_operand_src" "r,U,mn>"))
984 (and:SI (match_operand:SI 1 "register_operand" "r,r,r")
987 (clobber (match_scratch:QI 2 "=X,X,&r"))]
988 "TARGET_H8300H || TARGET_H8300S"
994 && !satisfies_constraint_U (operands[0])"
997 (parallel [(set (cc0)
998 (compare (zero_extract:SI (zero_extend:SI (match_dup 2))
1000 (and:SI (match_dup 1)
1003 (clobber (scratch:QI))])]
1005 [(set_attr "length" "2,8,10")
1006 (set_attr "cc" "set_zn,set_zn,set_zn")])
1008 (define_insn "*tstqi"
1010 (compare (match_operand:QI 0 "register_operand" "r")
1014 [(set_attr "length" "2")
1015 (set_attr "cc" "set_znv")])
1017 (define_insn "*tsthi"
1019 (compare (match_operand:HI 0 "register_operand" "r")
1023 [(set_attr "length" "2")
1024 (set_attr "cc" "set_znv")])
1026 (define_insn "*tsthi_upper"
1028 (compare (and:HI (match_operand:HI 0 "register_operand" "r")
1033 [(set_attr "length" "2")
1034 (set_attr "cc" "set_znv")])
1036 (define_insn "*tstsi"
1038 (compare (match_operand:SI 0 "register_operand" "r")
1040 "TARGET_H8300H || TARGET_H8300S"
1042 [(set_attr "length" "2")
1043 (set_attr "cc" "set_znv")])
1045 (define_insn "*tstsi_upper"
1047 (compare (and:SI (match_operand:SI 0 "register_operand" "r")
1052 [(set_attr "length" "2")
1053 (set_attr "cc" "set_znv")])
1055 (define_insn "*cmpqi"
1057 (compare (match_operand:QI 0 "h8300_dst_operand" "rQ")
1058 (match_operand:QI 1 "h8300_src_operand" "rQi")))]
1061 [(set_attr "length_table" "addb")
1062 (set_attr "cc" "compare")])
1064 (define_insn "*cmphi_h8300_znvc"
1066 (compare (match_operand:HI 0 "register_operand" "r")
1067 (match_operand:HI 1 "register_operand" "r")))]
1070 [(set_attr "length" "2")
1071 (set_attr "cc" "compare")])
1073 (define_insn "*cmphi_h8300hs_znvc"
1075 (compare (match_operand:HI 0 "h8300_dst_operand" "rU,rQ")
1076 (match_operand:HI 1 "h8300_src_operand" "P3>X,rQi")))]
1077 "TARGET_H8300H || TARGET_H8300S"
1079 switch (which_alternative)
1082 if (!TARGET_H8300SX)
1083 return "cmp.w %T1,%T0";
1085 return "cmp.w %T1:3,%T0";
1087 return "cmp.w %T1,%T0";
1092 [(set_attr "length_table" "short_immediate,addw")
1093 (set_attr "cc" "compare,compare")])
1095 (define_insn "cmpsi"
1097 (compare (match_operand:SI 0 "h8300_dst_operand" "r,rQ")
1098 (match_operand:SI 1 "h8300_src_operand" "P3>X,rQi")))]
1099 "TARGET_H8300H || TARGET_H8300S"
1101 switch (which_alternative)
1104 if (!TARGET_H8300SX)
1105 return "cmp.l %S1,%S0";
1107 return "cmp.l %S1:3,%S0";
1109 return "cmp.l %S1,%S0";
1114 [(set_attr "length" "2,*")
1115 (set_attr "length_table" "*,addl")
1116 (set_attr "cc" "compare,compare")])
1118 ;; ----------------------------------------------------------------------
1120 ;; ----------------------------------------------------------------------
1122 (define_expand "addqi3"
1123 [(set (match_operand:QI 0 "register_operand" "")
1124 (plus:QI (match_operand:QI 1 "register_operand" "")
1125 (match_operand:QI 2 "h8300_src_operand" "")))]
1129 (define_insn "*addqi3"
1130 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
1131 (plus:QI (match_operand:QI 1 "h8300_dst_operand" "%0")
1132 (match_operand:QI 2 "h8300_src_operand" "rQi")))]
1133 "h8300_operands_match_p (operands)"
1135 [(set_attr "length_table" "addb")
1136 (set_attr "cc" "set_zn")])
1138 (define_expand "addhi3"
1139 [(set (match_operand:HI 0 "register_operand" "")
1140 (plus:HI (match_operand:HI 1 "register_operand" "")
1141 (match_operand:HI 2 "h8300_src_operand" "")))]
1145 (define_insn "*addhi3_h8300"
1146 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1147 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
1148 (match_operand:HI 2 "h8300_src_operand" "L,N,J,n,r")))]
1154 add.b %s2,%s0\;addx %t2,%t0
1156 [(set_attr "length" "2,2,2,4,2")
1157 (set_attr "cc" "none_0hit,none_0hit,clobber,clobber,set_zn")])
1159 ;; This splitter is very important to make the stack adjustment
1160 ;; interrupt-safe. The combination of add.b and addx is unsafe!
1162 ;; We apply this split after the peephole2 pass so that we won't end
1163 ;; up creating too many adds/subs when a scratch register is
1164 ;; available, which is actually a common case because stack unrolling
1165 ;; tends to happen immediately after a function call.
1168 [(set (match_operand:HI 0 "stack_pointer_operand" "")
1169 (plus:HI (match_dup 0)
1170 (match_operand 1 "const_int_gt_2_operand" "")))]
1171 "TARGET_H8300 && epilogue_completed"
1174 split_adds_subs (HImode, operands);
1179 [(match_scratch:HI 2 "r")
1180 (set (match_operand:HI 0 "stack_pointer_operand" "")
1181 (plus:HI (match_dup 0)
1182 (match_operand:HI 1 "const_int_ge_8_operand" "")))]
1187 (plus:HI (match_dup 0)
1191 (define_insn "*addhi3_h8300hs"
1192 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1193 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
1194 (match_operand:HI 2 "h8300_src_operand" "L,N,J,n,r")))]
1195 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX"
1202 [(set_attr "length" "2,2,2,4,2")
1203 (set_attr "cc" "none_0hit,none_0hit,clobber,set_zn,set_zn")])
1205 (define_insn "*addhi3_incdec"
1206 [(set (match_operand:HI 0 "register_operand" "=r,r")
1207 (unspec:HI [(match_operand:HI 1 "register_operand" "0,0")
1208 (match_operand:HI 2 "incdec_operand" "M,O")]
1210 "TARGET_H8300H || TARGET_H8300S"
1214 [(set_attr "length" "2,2")
1215 (set_attr "cc" "set_zn,set_zn")])
1217 (define_insn "*addhi3_h8sx"
1218 [(set (match_operand:HI 0 "h8300_dst_operand" "=rU,rU,r,rQ")
1219 (plus:HI (match_operand:HI 1 "h8300_dst_operand" "%0,0,0,0")
1220 (match_operand:HI 2 "h8300_src_operand" "P3>X,P3<X,J,rQi")))]
1221 "TARGET_H8300SX && h8300_operands_match_p (operands)"
1227 [(set_attr "length_table" "short_immediate,short_immediate,*,addw")
1228 (set_attr "length" "*,*,2,*")
1229 (set_attr "cc" "set_zn")])
1232 [(set (match_operand:HI 0 "register_operand" "")
1233 (plus:HI (match_dup 0)
1234 (match_operand:HI 1 "two_insn_adds_subs_operand" "")))]
1238 split_adds_subs (HImode, operands);
1242 (define_expand "addsi3"
1243 [(set (match_operand:SI 0 "register_operand" "")
1244 (plus:SI (match_operand:SI 1 "register_operand" "")
1245 (match_operand:SI 2 "h8300_src_operand" "")))]
1249 (define_insn "*addsi_h8300"
1250 [(set (match_operand:SI 0 "register_operand" "=r,r")
1251 (plus:SI (match_operand:SI 1 "register_operand" "%0,0")
1252 (match_operand:SI 2 "h8300_src_operand" "n,r")))]
1255 return output_plussi (operands);
1257 [(set (attr "length")
1258 (symbol_ref "compute_plussi_length (operands)"))
1260 (symbol_ref "compute_plussi_cc (operands)"))])
1262 (define_insn "*addsi_h8300hs"
1263 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ,rQ")
1264 (plus:SI (match_operand:SI 1 "h8300_dst_operand" "%0,0")
1265 (match_operand:SI 2 "h8300_src_operand" "i,rQ")))]
1266 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
1268 return output_plussi (operands);
1270 [(set (attr "length")
1271 (symbol_ref "compute_plussi_length (operands)"))
1273 (symbol_ref "compute_plussi_cc (operands)"))])
1275 (define_insn "*addsi3_incdec"
1276 [(set (match_operand:SI 0 "register_operand" "=r,r")
1277 (unspec:SI [(match_operand:SI 1 "register_operand" "0,0")
1278 (match_operand:SI 2 "incdec_operand" "M,O")]
1280 "TARGET_H8300H || TARGET_H8300S"
1284 [(set_attr "length" "2,2")
1285 (set_attr "cc" "set_zn,set_zn")])
1288 [(set (match_operand:SI 0 "register_operand" "")
1289 (plus:SI (match_dup 0)
1290 (match_operand:SI 1 "two_insn_adds_subs_operand" "")))]
1291 "TARGET_H8300H || TARGET_H8300S"
1294 split_adds_subs (SImode, operands);
1298 ;; ----------------------------------------------------------------------
1299 ;; SUBTRACT INSTRUCTIONS
1300 ;; ----------------------------------------------------------------------
1302 (define_expand "subqi3"
1303 [(set (match_operand:QI 0 "register_operand" "")
1304 (minus:QI (match_operand:QI 1 "register_operand" "")
1305 (match_operand:QI 2 "h8300_src_operand" "")))]
1309 (define_insn "*subqi3"
1310 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
1311 (minus:QI (match_operand:QI 1 "h8300_dst_operand" "0")
1312 (match_operand:QI 2 "h8300_dst_operand" "rQ")))]
1313 "h8300_operands_match_p (operands)"
1315 [(set_attr "length_table" "addb")
1316 (set_attr "cc" "set_zn")])
1318 (define_expand "subhi3"
1319 [(set (match_operand:HI 0 "register_operand" "")
1320 (minus:HI (match_operand:HI 1 "register_operand" "")
1321 (match_operand:HI 2 "h8300_src_operand" "")))]
1325 (define_insn "*subhi3_h8300"
1326 [(set (match_operand:HI 0 "register_operand" "=r,r")
1327 (minus:HI (match_operand:HI 1 "register_operand" "0,0")
1328 (match_operand:HI 2 "h8300_src_operand" "r,n")))]
1332 add.b %E2,%s0\;addx %F2,%t0"
1333 [(set_attr "length" "2,4")
1334 (set_attr "cc" "set_zn,clobber")])
1336 (define_insn "*subhi3_h8300hs"
1337 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ,rQ")
1338 (minus:HI (match_operand:HI 1 "h8300_dst_operand" "0,0")
1339 (match_operand:HI 2 "h8300_src_operand" "rQ,i")))]
1340 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
1344 [(set_attr "length_table" "addw")
1345 (set_attr "cc" "set_zn")])
1347 (define_expand "subsi3"
1348 [(set (match_operand:SI 0 "register_operand" "")
1349 (minus:SI (match_operand:SI 1 "register_operand" "")
1350 (match_operand:SI 2 "h8300_src_operand" "")))]
1354 operands[2] = force_reg (SImode, operands[2]);
1357 (define_insn "*subsi3_h8300"
1358 [(set (match_operand:SI 0 "register_operand" "=r")
1359 (minus:SI (match_operand:SI 1 "register_operand" "0")
1360 (match_operand:SI 2 "register_operand" "r")))]
1362 "sub.w %f2,%f0\;subx %y2,%y0\;subx %z2,%z0"
1363 [(set_attr "length" "6")])
1365 (define_insn "*subsi3_h8300hs"
1366 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ,rQ")
1367 (minus:SI (match_operand:SI 1 "h8300_dst_operand" "0,0")
1368 (match_operand:SI 2 "h8300_src_operand" "rQ,i")))]
1369 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
1373 [(set_attr "length_table" "addl")
1374 (set_attr "cc" "set_zn")])
1376 ;; ----------------------------------------------------------------------
1377 ;; MULTIPLY INSTRUCTIONS
1378 ;; ----------------------------------------------------------------------
1380 ;; Note that the H8/300 can only handle umulqihi3.
1382 (define_expand "mulqihi3"
1383 [(set (match_operand:HI 0 "register_operand" "")
1384 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" ""))
1385 ;; intentionally-mismatched modes
1386 (match_operand:QI 2 "reg_or_nibble_operand" "")))]
1387 "TARGET_H8300H || TARGET_H8300S"
1389 if (GET_MODE (operands[2]) != VOIDmode)
1390 operands[2] = gen_rtx_SIGN_EXTEND (HImode, operands[2]);
1393 (define_insn "*mulqihi3_const"
1394 [(set (match_operand:HI 0 "register_operand" "=r")
1395 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1396 (match_operand:QI 2 "nibble_operand" "IP4>X")))]
1399 [(set_attr "length" "4")
1400 (set_attr "cc" "set_zn")])
1402 (define_insn "*mulqihi3"
1403 [(set (match_operand:HI 0 "register_operand" "=r")
1404 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1405 (sign_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1406 "TARGET_H8300H || TARGET_H8300S"
1408 [(set_attr "length" "4")
1409 (set_attr "cc" "set_zn")])
1411 (define_expand "mulhisi3"
1412 [(set (match_operand:SI 0 "register_operand" "")
1413 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" ""))
1414 ;; intentionally-mismatched modes
1415 (match_operand:HI 2 "reg_or_nibble_operand" "")))]
1416 "TARGET_H8300H || TARGET_H8300S"
1418 if (GET_MODE (operands[2]) != VOIDmode)
1419 operands[2] = gen_rtx_SIGN_EXTEND (SImode, operands[2]);
1422 (define_insn "*mulhisi3_const"
1423 [(set (match_operand:SI 0 "register_operand" "=r")
1424 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1425 (match_operand:SI 2 "nibble_operand" "IP4>X")))]
1428 [(set_attr "length" "4")
1429 (set_attr "cc" "set_zn")])
1431 (define_insn "*mulhisi3"
1432 [(set (match_operand:SI 0 "register_operand" "=r")
1433 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1434 (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
1435 "TARGET_H8300H || TARGET_H8300S"
1437 [(set_attr "length" "4")
1438 (set_attr "cc" "set_zn")])
1440 (define_expand "umulqihi3"
1441 [(set (match_operand:HI 0 "register_operand" "")
1442 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" ""))
1443 ;; intentionally-mismatched modes
1444 (match_operand:QI 2 "reg_or_nibble_operand" "")))]
1445 "TARGET_H8300H || TARGET_H8300S"
1447 if (GET_MODE (operands[2]) != VOIDmode)
1448 operands[2] = gen_rtx_ZERO_EXTEND (HImode, operands[2]);
1451 (define_insn "*umulqihi3_const"
1452 [(set (match_operand:HI 0 "register_operand" "=r")
1453 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1454 (match_operand:QI 2 "nibble_operand" "IP4>X")))]
1457 [(set_attr "length" "4")
1458 (set_attr "cc" "set_zn")])
1460 (define_insn "*umulqihi3"
1461 [(set (match_operand:HI 0 "register_operand" "=r")
1462 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1463 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1466 [(set_attr "length" "2")
1467 (set_attr "cc" "none_0hit")])
1469 (define_expand "umulhisi3"
1470 [(set (match_operand:SI 0 "register_operand" "")
1471 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" ""))
1472 ;; intentionally-mismatched modes
1473 (match_operand:HI 2 "reg_or_nibble_operand" "")))]
1474 "TARGET_H8300H || TARGET_H8300S"
1476 if (GET_MODE (operands[2]) != VOIDmode)
1477 operands[2] = gen_rtx_ZERO_EXTEND (SImode, operands[2]);
1480 (define_insn "*umulhisi3_const"
1481 [(set (match_operand:SI 0 "register_operand" "=r")
1482 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1483 (match_operand:SI 2 "nibble_operand" "IP4>X")))]
1486 [(set_attr "length" "4")
1487 (set_attr "cc" "set_zn")])
1489 (define_insn "*umulhisi3"
1490 [(set (match_operand:SI 0 "register_operand" "=r")
1491 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1492 (zero_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
1493 "TARGET_H8300H || TARGET_H8300S"
1495 [(set_attr "length" "2")
1496 (set_attr "cc" "none_0hit")])
1498 ;; We could have used mulu.[wl] here, but mulu.[lw] is only available
1499 ;; on a H8SX with a multiplier, whereas muls.w seems to be available
1500 ;; on all H8SX variants.
1502 (define_insn "mulhi3"
1503 [(set (match_operand:HI 0 "register_operand" "=r")
1504 (mult:HI (match_operand:HI 1 "register_operand" "%0")
1505 (match_operand:HI 2 "reg_or_nibble_operand" "r IP4>X")))]
1508 [(set_attr "length" "2")
1509 (set_attr "cc" "set_zn")])
1511 (define_insn "mulsi3"
1512 [(set (match_operand:SI 0 "register_operand" "=r")
1513 (mult:SI (match_operand:SI 1 "register_operand" "%0")
1514 (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))]
1517 [(set_attr "length" "2")
1518 (set_attr "cc" "set_zn")])
1520 (define_insn "smulsi3_highpart"
1521 [(set (match_operand:SI 0 "register_operand" "=r")
1525 (sign_extend:DI (match_operand:SI 1 "register_operand" "%0"))
1526 (sign_extend:DI (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))
1529 "muls/u.l\\t%S2,%S0"
1530 [(set_attr "length" "2")
1531 (set_attr "cc" "set_zn")])
1533 (define_insn "umulsi3_highpart"
1534 [(set (match_operand:SI 0 "register_operand" "=r")
1538 (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
1539 (zero_extend:DI (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))
1542 "mulu/u.l\\t%S2,%S0"
1543 [(set_attr "length" "2")
1544 (set_attr "cc" "none_0hit")])
1546 ;; This is a "bridge" instruction. Combine can't cram enough insns
1547 ;; together to crate a MAC instruction directly, but it can create
1548 ;; this instruction, which then allows combine to create the real
1551 ;; Unfortunately, if combine doesn't create a MAC instruction, this
1552 ;; insn must generate reasonably correct code. Egad.
1555 [(set (match_operand:SI 0 "register_operand" "=a")
1558 (mem:HI (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
1560 (mem:HI (post_inc:SI (match_operand:SI 2 "register_operand" "r"))))))]
1562 "clrmac\;mac @%2+,@%1+"
1563 [(set_attr "length" "6")
1564 (set_attr "cc" "none_0hit")])
1567 [(set (match_operand:SI 0 "register_operand" "=a")
1569 (sign_extend:SI (mem:HI
1570 (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
1571 (sign_extend:SI (mem:HI
1572 (post_inc:SI (match_operand:SI 2 "register_operand" "r")))))
1573 (match_operand:SI 3 "register_operand" "0")))]
1576 [(set_attr "length" "4")
1577 (set_attr "cc" "none_0hit")])
1579 ;; ----------------------------------------------------------------------
1580 ;; DIVIDE/MOD INSTRUCTIONS
1581 ;; ----------------------------------------------------------------------
1583 (define_insn "udivhi3"
1584 [(set (match_operand:HI 0 "register_operand" "=r")
1585 (udiv:HI (match_operand:HI 1 "register_operand" "0")
1586 (match_operand:HI 2 "reg_or_nibble_operand" "r IP4>X")))]
1589 [(set_attr "length" "2")])
1591 (define_insn "divhi3"
1592 [(set (match_operand:HI 0 "register_operand" "=r")
1593 (div:HI (match_operand:HI 1 "register_operand" "0")
1594 (match_operand:HI 2 "reg_or_nibble_operand" "r IP4>X")))]
1597 [(set_attr "length" "2")])
1599 (define_insn "udivsi3"
1600 [(set (match_operand:SI 0 "register_operand" "=r")
1601 (udiv:SI (match_operand:SI 1 "register_operand" "0")
1602 (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))]
1605 [(set_attr "length" "2")])
1607 (define_insn "divsi3"
1608 [(set (match_operand:SI 0 "register_operand" "=r")
1609 (div:SI (match_operand:SI 1 "register_operand" "0")
1610 (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))]
1613 [(set_attr "length" "2")])
1615 (define_insn "udivmodqi4"
1616 [(set (match_operand:QI 0 "register_operand" "=r")
1619 (match_operand:HI 1 "register_operand" "0")
1620 (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1621 (set (match_operand:QI 3 "register_operand" "=r")
1625 (zero_extend:HI (match_dup 2)))))]
1628 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1629 return "divxu.b\\t%X2,%T0";
1631 return "divxu.b\\t%X2,%T0\;mov.b\\t%t0,%s3";
1633 [(set_attr "length" "4")])
1635 (define_insn "divmodqi4"
1636 [(set (match_operand:QI 0 "register_operand" "=r")
1639 (match_operand:HI 1 "register_operand" "0")
1640 (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1641 (set (match_operand:QI 3 "register_operand" "=r")
1645 (sign_extend:HI (match_dup 2)))))]
1646 "TARGET_H8300H || TARGET_H8300S"
1648 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1649 return "divxs.b\\t%X2,%T0";
1651 return "divxs.b\\t%X2,%T0\;mov.b\\t%t0,%s3";
1653 [(set_attr "length" "6")])
1655 (define_insn "udivmodhi4"
1656 [(set (match_operand:HI 0 "register_operand" "=r")
1659 (match_operand:SI 1 "register_operand" "0")
1660 (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1661 (set (match_operand:HI 3 "register_operand" "=r")
1665 (zero_extend:SI (match_dup 2)))))]
1666 "TARGET_H8300H || TARGET_H8300S"
1668 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1669 return "divxu.w\\t%T2,%S0";
1671 return "divxu.w\\t%T2,%S0\;mov.w\\t%e0,%f3";
1673 [(set_attr "length" "4")])
1675 (define_insn "divmodhi4"
1676 [(set (match_operand:HI 0 "register_operand" "=r")
1679 (match_operand:SI 1 "register_operand" "0")
1680 (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1681 (set (match_operand:HI 3 "register_operand" "=r")
1685 (sign_extend:SI (match_dup 2)))))]
1686 "TARGET_H8300H || TARGET_H8300S"
1688 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1689 return "divxs.w\\t%T2,%S0";
1691 return "divxs.w\\t%T2,%S0\;mov.w\\t%e0,%f3";
1693 [(set_attr "length" "6")])
1695 ;; ----------------------------------------------------------------------
1697 ;; ----------------------------------------------------------------------
1699 (define_insn "bclrqi_msx"
1700 [(set (match_operand:QI 0 "bit_register_indirect_operand" "=WU")
1701 (and:QI (match_operand:QI 1 "bit_register_indirect_operand" "%0")
1702 (match_operand:QI 2 "single_zero_operand" "Y0")))]
1703 "TARGET_H8300SX && rtx_equal_p (operands[0], operands[1])"
1705 [(set_attr "length" "8")])
1708 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=U")
1709 (and:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1710 (match_operand:HI 2 "single_zero_operand" "Y0")))]
1713 (and:QI (match_dup 1)
1716 if (abs (INTVAL (operands[2])) > 0xFF)
1718 operands[0] = adjust_address (operands[0], QImode, 0);
1719 operands[1] = adjust_address (operands[1], QImode, 0);
1720 operands[2] = GEN_INT ((INTVAL (operands[2])) >> 8);
1724 operands[0] = adjust_address (operands[0], QImode, 1);
1725 operands[1] = adjust_address (operands[1], QImode, 1);
1729 (define_insn "bclrhi_msx"
1730 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=m")
1731 (and:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1732 (match_operand:HI 2 "single_zero_operand" "Y0")))]
1735 [(set_attr "length" "8")])
1737 (define_insn "*andqi3_2"
1738 [(set (match_operand:QI 0 "bit_operand" "=U,rQ,r")
1739 (and:QI (match_operand:QI 1 "bit_operand" "%0,0,WU")
1740 (match_operand:QI 2 "h8300_src_operand" "Y0,rQi,IP1>X")))]
1746 [(set_attr "length" "8,*,8")
1747 (set_attr "length_table" "*,logicb,*")
1748 (set_attr "cc" "none_0hit,set_znv,none_0hit")])
1750 (define_insn "andqi3_1"
1751 [(set (match_operand:QI 0 "bit_operand" "=U,r")
1752 (and:QI (match_operand:QI 1 "bit_operand" "%0,0")
1753 (match_operand:QI 2 "h8300_src_operand" "Y0,rn")))]
1754 "register_operand (operands[0], QImode)
1755 || single_zero_operand (operands[2], QImode)"
1759 [(set_attr "length" "2,8")
1760 (set_attr "cc" "none_0hit,set_znv")])
1762 (define_expand "andqi3"
1763 [(set (match_operand:QI 0 "register_operand" "")
1764 (and:QI (match_operand:QI 1 "register_operand" "")
1765 (match_operand:QI 2 "h8300_src_operand" "")))]
1769 (define_expand "andhi3"
1770 [(set (match_operand:HI 0 "register_operand" "")
1771 (and:HI (match_operand:HI 1 "register_operand" "")
1772 (match_operand:HI 2 "h8300_src_operand" "")))]
1776 (define_insn "*andorqi3"
1777 [(set (match_operand:QI 0 "register_operand" "=r")
1778 (ior:QI (and:QI (match_operand:QI 2 "register_operand" "r")
1779 (match_operand:QI 3 "single_one_operand" "n"))
1780 (match_operand:QI 1 "register_operand" "0")))]
1782 "bld\\t%V3,%X2\;bor\\t%V3,%X0\;bst\\t%V3,%X0"
1783 [(set_attr "length" "6")])
1785 (define_insn "*andorhi3"
1786 [(set (match_operand:HI 0 "register_operand" "=r")
1787 (ior:HI (and:HI (match_operand:HI 2 "register_operand" "r")
1788 (match_operand:HI 3 "single_one_operand" "n"))
1789 (match_operand:HI 1 "register_operand" "0")))]
1792 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1793 if (INTVAL (operands[3]) > 128)
1795 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1796 return "bld\\t%V3,%t2\;bor\\t%V3,%t0\;bst\\t%V3,%t0";
1798 return "bld\\t%V3,%s2\;bor\\t%V3,%s0\;bst\\t%V3,%s0";
1800 [(set_attr "length" "6")])
1802 (define_insn "*andorsi3"
1803 [(set (match_operand:SI 0 "register_operand" "=r")
1804 (ior:SI (and:SI (match_operand:SI 2 "register_operand" "r")
1805 (match_operand:SI 3 "single_one_operand" "n"))
1806 (match_operand:SI 1 "register_operand" "0")))]
1807 "(INTVAL (operands[3]) & 0xffff) != 0"
1809 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1810 if (INTVAL (operands[3]) > 128)
1812 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1813 return "bld\\t%V3,%x2\;bor\\t%V3,%x0\;bst\\t%V3,%x0";
1815 return "bld\\t%V3,%w2\;bor\\t%V3,%w0\;bst\\t%V3,%w0";
1817 [(set_attr "length" "6")])
1819 (define_insn "*andorsi3_shift_8"
1820 [(set (match_operand:SI 0 "register_operand" "=r")
1821 (ior:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1824 (match_operand:SI 1 "register_operand" "0")))]
1827 [(set_attr "length" "2")])
1829 (define_expand "andsi3"
1830 [(set (match_operand:SI 0 "register_operand" "")
1831 (and:SI (match_operand:SI 1 "register_operand" "")
1832 (match_operand:SI 2 "h8300_src_operand" "")))]
1836 ;; ----------------------------------------------------------------------
1838 ;; ----------------------------------------------------------------------
1840 (define_insn "bsetqi_msx"
1841 [(set (match_operand:QI 0 "bit_register_indirect_operand" "=WU")
1842 (ior:QI (match_operand:QI 1 "bit_register_indirect_operand" "%0")
1843 (match_operand:QI 2 "single_one_operand" "Y2")))]
1844 "TARGET_H8300SX && rtx_equal_p (operands[0], operands[1])"
1846 [(set_attr "length" "8")])
1849 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=U")
1850 (ior:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1851 (match_operand:HI 2 "single_one_operand" "Y2")))]
1854 (ior:QI (match_dup 1)
1857 if (abs (INTVAL (operands[2])) > 0xFF)
1859 operands[0] = adjust_address (operands[0], QImode, 0);
1860 operands[1] = adjust_address (operands[1], QImode, 0);
1861 operands[2] = GEN_INT ((INTVAL (operands[2])) >> 8);
1865 operands[0] = adjust_address (operands[0], QImode, 1);
1866 operands[1] = adjust_address (operands[1], QImode, 1);
1870 (define_insn "bsethi_msx"
1871 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=m")
1872 (ior:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1873 (match_operand:HI 2 "single_one_operand" "Y2")))]
1876 [(set_attr "length" "8")])
1878 (define_insn "iorqi3_1"
1879 [(set (match_operand:QI 0 "bit_operand" "=U,rQ")
1880 (ior:QI (match_operand:QI 1 "bit_operand" "%0,0")
1881 (match_operand:QI 2 "h8300_src_operand" "Y2,rQi")))]
1882 "TARGET_H8300SX || register_operand (operands[0], QImode)
1883 || single_one_operand (operands[2], QImode)"
1887 [(set_attr "length" "8,*")
1888 (set_attr "length_table" "*,logicb")
1889 (set_attr "cc" "none_0hit,set_znv")])
1892 (define_expand "iorqi3"
1893 [(set (match_operand:QI 0 "register_operand" "")
1894 (ior:QI (match_operand:QI 1 "register_operand" "")
1895 (match_operand:QI 2 "h8300_src_operand" "")))]
1899 (define_expand "iorhi3"
1900 [(set (match_operand:HI 0 "register_operand" "")
1901 (ior:HI (match_operand:HI 1 "register_operand" "")
1902 (match_operand:HI 2 "h8300_src_operand" "")))]
1906 (define_expand "iorsi3"
1907 [(set (match_operand:SI 0 "register_operand" "")
1908 (ior:SI (match_operand:SI 1 "register_operand" "")
1909 (match_operand:SI 2 "h8300_src_operand" "")))]
1913 ;; ----------------------------------------------------------------------
1915 ;; ----------------------------------------------------------------------
1917 (define_insn "bnotqi_msx"
1918 [(set (match_operand:QI 0 "bit_register_indirect_operand" "=WU")
1919 (xor:QI (match_operand:QI 1 "bit_register_indirect_operand" "%0")
1920 (match_operand:QI 2 "single_one_operand" "Y2")))]
1922 && rtx_equal_p (operands[0], operands[1])"
1924 [(set_attr "length" "8")])
1927 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=U")
1928 (xor:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1929 (match_operand:HI 2 "single_one_operand" "Y2")))]
1932 (xor:QI (match_dup 1)
1935 if (abs (INTVAL (operands[2])) > 0xFF)
1937 operands[0] = adjust_address (operands[0], QImode, 0);
1938 operands[1] = adjust_address (operands[1], QImode, 0);
1939 operands[2] = GEN_INT ((INTVAL (operands[2])) >> 8);
1943 operands[0] = adjust_address (operands[0], QImode, 1);
1944 operands[1] = adjust_address (operands[1], QImode, 1);
1948 (define_insn "bnothi_msx"
1949 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=m")
1950 (xor:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1951 (match_operand:HI 2 "single_one_operand" "Y2")))]
1954 [(set_attr "length" "8")])
1956 (define_insn "xorqi3_1"
1957 [(set (match_operand:QI 0 "bit_operand" "=U,r")
1958 (xor:QI (match_operand:QI 1 "bit_operand" "%0,0")
1959 (match_operand:QI 2 "h8300_src_operand" "Y2,rQi")))]
1960 "TARGET_H8300SX || register_operand (operands[0], QImode)
1961 || single_one_operand (operands[2], QImode)"
1965 [(set_attr "length" "8,*")
1966 (set_attr "length_table" "*,logicb")
1967 (set_attr "cc" "none_0hit,set_znv")])
1969 (define_expand "xorqi3"
1970 [(set (match_operand:QI 0 "register_operand" "")
1971 (xor:QI (match_operand:QI 1 "register_operand" "")
1972 (match_operand:QI 2 "h8300_src_operand" "")))]
1976 (define_expand "xorhi3"
1977 [(set (match_operand:HI 0 "register_operand" "")
1978 (xor:HI (match_operand:HI 1 "register_operand" "")
1979 (match_operand:HI 2 "h8300_src_operand" "")))]
1983 (define_expand "xorsi3"
1984 [(set (match_operand:SI 0 "register_operand" "")
1985 (xor:SI (match_operand:SI 1 "register_operand" "")
1986 (match_operand:SI 2 "h8300_src_operand" "")))]
1990 ;; ----------------------------------------------------------------------
1991 ;; {AND,IOR,XOR}{HI3,SI3} PATTERNS
1992 ;; ----------------------------------------------------------------------
1994 ;; We need a separate pattern here because machines other than the
1995 ;; original H8300 don't have to split the 16-bit operand into a pair
1996 ;; of high/low instructions, so we can accept literal addresses, that
1997 ;; have to be loaded into a register on H8300.
1999 (define_insn "*logicalhi3_sn"
2000 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2001 (match_operator:HI 3 "bit_operator"
2002 [(match_operand:HI 1 "h8300_dst_operand" "%0")
2003 (match_operand:HI 2 "h8300_src_operand" "rQi")]))]
2004 "(TARGET_H8300S || TARGET_H8300H) && h8300_operands_match_p (operands)"
2006 return output_logical_op (HImode, operands);
2008 [(set (attr "length")
2009 (symbol_ref "compute_logical_op_length (HImode, operands)"))
2011 (symbol_ref "compute_logical_op_cc (HImode, operands)"))])
2013 (define_insn "*logicalsi3_sn"
2014 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2015 (match_operator:SI 3 "bit_operator"
2016 [(match_operand:SI 1 "h8300_dst_operand" "%0")
2017 (match_operand:SI 2 "h8300_src_operand" "rQi")]))]
2018 "(TARGET_H8300S || TARGET_H8300H) && h8300_operands_match_p (operands)"
2020 return output_logical_op (SImode, operands);
2022 [(set (attr "length")
2023 (symbol_ref "compute_logical_op_length (SImode, operands)"))
2025 (symbol_ref "compute_logical_op_cc (SImode, operands)"))])
2027 (define_insn "*logicalhi3"
2028 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2029 (match_operator:HI 3 "bit_operator"
2030 [(match_operand:HI 1 "h8300_dst_operand" "%0")
2031 (match_operand:HI 2 "h8300_src_operand" "rQi")]))]
2032 "h8300_operands_match_p (operands)"
2034 return output_logical_op (HImode, operands);
2036 [(set (attr "length")
2037 (symbol_ref "compute_logical_op_length (HImode, operands)"))
2039 (symbol_ref "compute_logical_op_cc (HImode, operands)"))])
2041 (define_insn "*logicalsi3"
2042 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2043 (match_operator:SI 3 "bit_operator"
2044 [(match_operand:SI 1 "h8300_dst_operand" "%0")
2045 (match_operand:SI 2 "h8300_src_operand" "rQi")]))]
2046 "h8300_operands_match_p (operands)"
2048 return output_logical_op (SImode, operands);
2050 [(set (attr "length")
2051 (symbol_ref "compute_logical_op_length (SImode, operands)"))
2053 (symbol_ref "compute_logical_op_cc (SImode, operands)"))])
2055 ;; ----------------------------------------------------------------------
2056 ;; NEGATION INSTRUCTIONS
2057 ;; ----------------------------------------------------------------------
2059 (define_expand "negqi2"
2060 [(set (match_operand:QI 0 "register_operand" "")
2061 (neg:QI (match_operand:QI 1 "register_operand" "")))]
2065 (define_insn "*negqi2"
2066 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
2067 (neg:QI (match_operand:QI 1 "h8300_dst_operand" "0")))]
2070 [(set_attr "length_table" "unary")
2071 (set_attr "cc" "set_zn")])
2073 (define_expand "neghi2"
2074 [(set (match_operand:HI 0 "register_operand" "")
2075 (neg:HI (match_operand:HI 1 "register_operand" "")))]
2080 emit_insn (gen_neghi2_h8300 (operands[0], operands[1]));
2085 (define_expand "neghi2_h8300"
2087 (not:HI (match_operand:HI 1 "register_operand" "")))
2088 (set (match_dup 2) (plus:HI (match_dup 2) (const_int 1)))
2089 (set (match_operand:HI 0 "register_operand" "")
2093 operands[2] = gen_reg_rtx (HImode);
2096 (define_insn "*neghi2_h8300hs"
2097 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2098 (neg:HI (match_operand:HI 1 "h8300_dst_operand" "0")))]
2099 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2101 [(set_attr "length_table" "unary")
2102 (set_attr "cc" "set_zn")])
2104 (define_expand "negsi2"
2105 [(set (match_operand:SI 0 "register_operand" "")
2106 (neg:SI (match_operand:SI 1 "register_operand" "")))]
2111 emit_insn (gen_negsi2_h8300 (operands[0], operands[1]));
2116 (define_expand "negsi2_h8300"
2118 (not:SI (match_operand:SI 1 "register_operand" "")))
2119 (set (match_dup 2) (plus:SI (match_dup 2) (const_int 1)))
2120 (set (match_operand:SI 0 "register_operand" "")
2124 operands[2] = gen_reg_rtx (SImode);
2127 (define_insn "*negsi2_h8300hs"
2128 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2129 (neg:SI (match_operand:SI 1 "h8300_dst_operand" "0")))]
2130 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2132 [(set_attr "length_table" "unary")
2133 (set_attr "cc" "set_zn")])
2135 (define_expand "negsf2"
2136 [(set (match_operand:SF 0 "register_operand" "")
2137 (neg:SF (match_operand:SF 1 "register_operand" "")))]
2141 (define_insn "*negsf2_h8300"
2142 [(set (match_operand:SF 0 "register_operand" "=r")
2143 (neg:SF (match_operand:SF 1 "register_operand" "0")))]
2146 [(set_attr "length" "2")])
2148 (define_insn "*negsf2_h8300hs"
2149 [(set (match_operand:SF 0 "register_operand" "=r")
2150 (neg:SF (match_operand:SF 1 "register_operand" "0")))]
2151 "TARGET_H8300H || TARGET_H8300S"
2152 "xor.w\\t#32768,%e0"
2153 [(set_attr "length" "4")])
2155 ;; ----------------------------------------------------------------------
2156 ;; ABSOLUTE VALUE INSTRUCTIONS
2157 ;; ----------------------------------------------------------------------
2159 (define_expand "abssf2"
2160 [(set (match_operand:SF 0 "register_operand" "")
2161 (abs:SF (match_operand:SF 1 "register_operand" "")))]
2165 (define_insn "*abssf2_h8300"
2166 [(set (match_operand:SF 0 "register_operand" "=r")
2167 (abs:SF (match_operand:SF 1 "register_operand" "0")))]
2170 [(set_attr "length" "2")])
2172 (define_insn "*abssf2_h8300hs"
2173 [(set (match_operand:SF 0 "register_operand" "=r")
2174 (abs:SF (match_operand:SF 1 "register_operand" "0")))]
2175 "TARGET_H8300H || TARGET_H8300S"
2176 "and.w\\t#32767,%e0"
2177 [(set_attr "length" "4")])
2179 ;; ----------------------------------------------------------------------
2181 ;; ----------------------------------------------------------------------
2183 (define_expand "one_cmplqi2"
2184 [(set (match_operand:QI 0 "register_operand" "")
2185 (not:QI (match_operand:QI 1 "register_operand" "")))]
2189 (define_insn "*one_cmplqi2"
2190 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
2191 (not:QI (match_operand:QI 1 "h8300_dst_operand" "0")))]
2194 [(set_attr "length_table" "unary")
2195 (set_attr "cc" "set_znv")])
2197 (define_expand "one_cmplhi2"
2198 [(set (match_operand:HI 0 "register_operand" "")
2199 (not:HI (match_operand:HI 1 "register_operand" "")))]
2203 (define_insn "*one_cmplhi2_h8300"
2204 [(set (match_operand:HI 0 "register_operand" "=r")
2205 (not:HI (match_operand:HI 1 "register_operand" "0")))]
2208 [(set_attr "length" "4")])
2210 (define_insn "*one_cmplhi2_h8300hs"
2211 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2212 (not:HI (match_operand:HI 1 "h8300_dst_operand" "0")))]
2213 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2215 [(set_attr "cc" "set_znv")
2216 (set_attr "length_table" "unary")])
2218 (define_expand "one_cmplsi2"
2219 [(set (match_operand:SI 0 "register_operand" "")
2220 (not:SI (match_operand:SI 1 "register_operand" "")))]
2224 (define_insn "*one_cmplsi2_h8300"
2225 [(set (match_operand:SI 0 "register_operand" "=r")
2226 (not:SI (match_operand:SI 1 "register_operand" "0")))]
2228 "not %w0\;not %x0\;not %y0\;not %z0"
2229 [(set_attr "length" "8")])
2231 (define_insn "*one_cmplsi2_h8300hs"
2232 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2233 (not:SI (match_operand:SI 1 "h8300_dst_operand" "0")))]
2234 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2236 [(set_attr "cc" "set_znv")
2237 (set_attr "length_table" "unary")])
2239 ;; ----------------------------------------------------------------------
2240 ;; JUMP INSTRUCTIONS
2241 ;; ----------------------------------------------------------------------
2243 ;; Conditional jump instructions
2245 (define_expand "cbranchqi4"
2246 [(use (match_operator 0 "ordered_comparison_operator"
2247 [(match_operand:QI 1 "h8300_dst_operand" "")
2248 (match_operand:QI 2 "h8300_src_operand" "")]))
2249 (use (match_operand 3 ""))]
2252 h8300_expand_branch (operands);
2256 (define_expand "cbranchhi4"
2257 [(use (match_operator 0 "ordered_comparison_operator"
2258 [(match_operand:HI 1 "h8300_dst_operand" "")
2259 (match_operand:HI 2 "h8300_src_operand" "")]))
2260 (use (match_operand 3 ""))]
2263 /* Force operand1 into a register if we're compiling
2265 if ((GET_CODE (operands[2]) != REG && operands[2] != const0_rtx)
2267 operands[2] = force_reg (HImode, operands[2]);
2268 h8300_expand_branch (operands);
2272 (define_expand "cbranchsi4"
2273 [(use (match_operator 0 "ordered_comparison_operator"
2274 [(match_operand:SI 1 "h8300_dst_operand" "")
2275 (match_operand:SI 2 "h8300_src_operand" "")]))
2276 (use (match_operand 3 ""))]
2277 "TARGET_H8300H || TARGET_H8300S"
2279 h8300_expand_branch (operands);
2283 (define_insn "branch_true"
2285 (if_then_else (match_operator 1 "comparison_operator"
2286 [(cc0) (const_int 0)])
2287 (label_ref (match_operand 0 "" ""))
2291 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
2292 && (GET_CODE (operands[1]) == GT
2293 || GET_CODE (operands[1]) == GE
2294 || GET_CODE (operands[1]) == LE
2295 || GET_CODE (operands[1]) == LT))
2297 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
2301 if (get_attr_length (insn) == 2)
2303 else if (get_attr_length (insn) == 4)
2304 return "b%j1 %l0:16";
2306 return "b%k1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:";
2308 [(set_attr "type" "branch")
2309 (set_attr "cc" "none")])
2311 (define_insn "branch_false"
2313 (if_then_else (match_operator 1 "comparison_operator"
2314 [(cc0) (const_int 0)])
2316 (label_ref (match_operand 0 "" ""))))]
2319 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
2320 && (GET_CODE (operands[1]) == GT
2321 || GET_CODE (operands[1]) == GE
2322 || GET_CODE (operands[1]) == LE
2323 || GET_CODE (operands[1]) == LT))
2325 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
2329 if (get_attr_length (insn) == 2)
2331 else if (get_attr_length (insn) == 4)
2332 return "b%k1 %l0:16";
2334 return "b%j1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:";
2336 [(set_attr "type" "branch")
2337 (set_attr "cc" "none")])
2339 (define_insn "*brabc"
2341 (if_then_else (eq (zero_extract (match_operand:QI 1 "bit_memory_operand" "WU")
2343 (match_operand:QI 2 "immediate_operand" "n"))
2345 (label_ref (match_operand 0 "" ""))
2349 switch (get_attr_length (insn)
2350 - h8300_insn_length_from_table (insn, operands))
2353 return "bra/bc %2,%R1,%l0";
2355 return "bra/bc %2,%R1,%l0:16";
2357 return "bra/bs %2,%R1,.Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:";
2360 [(set_attr "type" "bitbranch")
2361 (set_attr "length_table" "bitbranch")
2362 (set_attr "cc" "none")])
2364 (define_insn "*brabs"
2366 (if_then_else (ne (zero_extract (match_operand:QI 1 "bit_memory_operand" "WU")
2368 (match_operand:QI 2 "immediate_operand" "n"))
2370 (label_ref (match_operand 0 "" ""))
2374 switch (get_attr_length (insn)
2375 - h8300_insn_length_from_table (insn, operands))
2378 return "bra/bs %2,%R1,%l0";
2380 return "bra/bs %2,%R1,%l0:16";
2382 return "bra/bc %2,%R1,.Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:";
2385 [(set_attr "type" "bitbranch")
2386 (set_attr "length_table" "bitbranch")
2387 (set_attr "cc" "none")])
2389 ;; Unconditional and other jump instructions.
2393 (label_ref (match_operand 0 "" "")))]
2396 if (final_sequence != 0)
2398 if (get_attr_length (insn) == 2)
2402 /* The branch isn't short enough to use bra/s. Output the
2403 branch and delay slot in their normal order.
2405 If this is a backward branch, it will now be branching two
2406 bytes further than previously thought. The length-based
2407 test for bra vs. jump is very conservative though, so the
2408 branch will still be within range. */
2412 vec = XVEC (final_sequence, 0);
2414 final_scan_insn (RTVEC_ELT (vec, 1), asm_out_file, optimize, 1, & seen);
2415 final_scan_insn (RTVEC_ELT (vec, 0), asm_out_file, optimize, 1, & seen);
2416 INSN_DELETED_P (RTVEC_ELT (vec, 1)) = 1;
2420 else if (get_attr_length (insn) == 2)
2422 else if (get_attr_length (insn) == 4)
2423 return "bra %l0:16";
2427 [(set_attr "type" "branch")
2428 (set (attr "delay_slot")
2429 (if_then_else (match_test "TARGET_H8300SX")
2430 (const_string "jump")
2431 (const_string "none")))
2432 (set_attr "cc" "none")])
2434 ;; This is a define expand, because pointers may be either 16 or 32 bits.
2436 (define_expand "tablejump"
2437 [(parallel [(set (pc) (match_operand 0 "register_operand" ""))
2438 (use (label_ref (match_operand 1 "" "")))])]
2442 (define_insn "*tablejump_h8300"
2443 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
2444 (use (label_ref (match_operand 1 "" "")))]
2447 [(set_attr "cc" "none")
2448 (set_attr "length" "2")])
2450 (define_insn "*tablejump_h8300hs_advanced"
2451 [(set (pc) (match_operand:SI 0 "register_operand" "r"))
2452 (use (label_ref (match_operand 1 "" "")))]
2453 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE"
2455 [(set_attr "cc" "none")
2456 (set_attr "length" "2")])
2458 (define_insn "*tablejump_h8300hs_normal"
2459 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
2460 (use (label_ref (match_operand 1 "" "")))]
2461 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
2463 [(set_attr "cc" "none")
2464 (set_attr "length" "2")])
2466 ;; This is a define expand, because pointers may be either 16 or 32 bits.
2468 (define_expand "indirect_jump"
2469 [(set (pc) (match_operand 0 "jump_address_operand" ""))]
2473 (define_insn "*indirect_jump_h8300"
2474 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
2477 [(set_attr "cc" "none")
2478 (set_attr "length" "2")])
2480 (define_insn "*indirect_jump_h8300hs_advanced"
2481 [(set (pc) (match_operand:SI 0 "jump_address_operand" "Vr"))]
2482 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE"
2484 [(set_attr "cc" "none")
2485 (set_attr "length" "2")])
2487 (define_insn "*indirect_jump_h8300hs_normal"
2488 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
2489 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
2491 [(set_attr "cc" "none")
2492 (set_attr "length" "2")])
2494 ;; Call subroutine with no return value.
2496 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
2499 [(call (match_operand:QI 0 "call_insn_operand" "or")
2500 (match_operand:HI 1 "general_operand" "g"))]
2503 if (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
2504 && SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
2505 return "jsr\\t@%0:8";
2509 [(set_attr "type" "call")
2510 (set (attr "length")
2511 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
2515 ;; Call subroutine, returning value in operand 0
2516 ;; (which must be a hard register).
2518 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
2520 (define_insn "call_value"
2521 [(set (match_operand 0 "" "=r")
2522 (call (match_operand:QI 1 "call_insn_operand" "or")
2523 (match_operand:HI 2 "general_operand" "g")))]
2526 if (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
2527 && SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
2528 return "jsr\\t@%1:8";
2532 [(set_attr "type" "call")
2533 (set (attr "length")
2534 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
2542 [(set_attr "cc" "none")
2543 (set_attr "length" "2")])
2545 ;; ----------------------------------------------------------------------
2546 ;; PROLOGUE/EPILOGUE-RELATED INSTRUCTIONS
2547 ;; ----------------------------------------------------------------------
2549 (define_expand "push_h8300"
2550 [(set (mem:HI (pre_dec:HI (reg:HI SP_REG)))
2551 (match_operand:HI 0 "register_operand" ""))]
2555 (define_expand "push_h8300hs_advanced"
2556 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2557 (match_operand:SI 0 "register_operand" ""))]
2558 "TARGET_H8300H && TARGET_H8300S && !TARGET_NORMAL_MODE"
2561 (define_expand "push_h8300hs_normal"
2562 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
2563 (match_operand:SI 0 "register_operand" ""))]
2564 "TARGET_H8300H && TARGET_H8300S && TARGET_NORMAL_MODE"
2567 (define_expand "pop_h8300"
2568 [(set (match_operand:HI 0 "register_operand" "")
2569 (mem:HI (post_inc:HI (reg:HI SP_REG))))]
2573 (define_expand "pop_h8300hs_advanced"
2574 [(set (match_operand:SI 0 "register_operand" "")
2575 (mem:SI (post_inc:SI (reg:SI SP_REG))))]
2576 "TARGET_H8300H && TARGET_H8300S && !TARGET_NORMAL_MODE"
2579 (define_expand "pop_h8300hs_normal"
2580 [(set (match_operand:SI 0 "register_operand" "")
2581 (mem:SI (post_inc:HI (reg:HI SP_REG))))]
2582 "TARGET_H8300H && TARGET_H8300S && TARGET_NORMAL_MODE"
2585 (define_insn "ldm_h8300sx"
2586 [(match_parallel 0 "h8300_ldm_parallel"
2587 [(set (match_operand:SI 1 "register_operand" "")
2588 (match_operand:SI 2 "memory_operand" ""))])]
2591 operands[3] = SET_DEST (XVECEXP (operands[0], 0,
2592 XVECLEN (operands[0], 0) - 2));
2593 return "ldm.l\t@er7+,%S1-%S3";
2595 [(set_attr "cc" "none")
2596 (set_attr "length" "4")])
2598 (define_insn "stm_h8300sx"
2599 [(match_parallel 0 "h8300_stm_parallel"
2600 [(set (match_operand:SI 1 "memory_operand" "")
2601 (match_operand:SI 2 "register_operand" ""))])]
2604 operands[3] = SET_SRC (XVECEXP (operands[0], 0,
2605 XVECLEN (operands[0], 0) - 2));
2606 return "stm.l\t%S2-%S3,@-er7";
2608 [(set_attr "cc" "none")
2609 (set_attr "length" "4")])
2611 (define_insn "return_h8sx"
2612 [(match_parallel 0 "h8300_return_parallel"
2614 (set (match_operand:SI 1 "register_operand" "")
2615 (match_operand:SI 2 "memory_operand" ""))])]
2618 operands[3] = SET_DEST (XVECEXP (operands[0], 0,
2619 XVECLEN (operands[0], 0) - 2));
2620 if (h8300_current_function_interrupt_function_p ()
2621 || h8300_current_function_monitor_function_p ())
2622 return "rte/l\t%S1-%S3";
2624 return "rts/l\t%S1-%S3";
2626 [(set_attr "cc" "none")
2627 (set_attr "can_delay" "no")
2628 (set_attr "length" "2")])
2630 (define_expand "return"
2632 "h8300_can_use_return_insn_p ()"
2635 (define_insn "*return_1"
2639 if (h8300_current_function_interrupt_function_p ()
2640 || h8300_current_function_monitor_function_p ())
2645 [(set_attr "cc" "none")
2646 (set_attr "can_delay" "no")
2647 (set_attr "length" "2")])
2649 (define_expand "prologue"
2653 h8300_expand_prologue ();
2657 (define_expand "epilogue"
2661 h8300_expand_epilogue ();
2665 (define_insn "monitor_prologue"
2666 [(unspec_volatile [(const_int 0)] UNSPEC_MONITOR)]
2670 return "subs\\t#2,r7\;mov.w\\tr0,@-r7\;stc\\tccr,r0l\;mov.b\tr0l,@(2,r7)\;mov.w\\t@r7+,r0\;orc\t#128,ccr";
2671 else if (TARGET_H8300H && TARGET_NORMAL_MODE)
2672 return "subs\\t#2,er7\;mov.l\\ter0,@-er7\;stc\\tccr,r0l\;mov.b\\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\\t#128,ccr";
2673 else if (TARGET_H8300H)
2674 return "mov.l\\ter0,@-er7\;stc\\tccr,r0l\;mov.b\\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\\t#128,ccr";
2675 else if (TARGET_H8300S && TARGET_NEXR )
2676 return "mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr";
2677 else if (TARGET_H8300S && TARGET_NEXR && TARGET_NORMAL_MODE)
2678 return "subs\\t#2,er7\;mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr";
2679 else if (TARGET_H8300S && TARGET_NORMAL_MODE)
2680 return "subs\\t#2,er7\;stc\texr,@-er7\;mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(6,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr";
2681 else if (TARGET_H8300S)
2682 return "stc\texr,@-er7\;mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(6,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr";
2685 [(set_attr "length" "20")])
2687 ;; ----------------------------------------------------------------------
2688 ;; EXTEND INSTRUCTIONS
2689 ;; ----------------------------------------------------------------------
2691 (define_expand "zero_extendqihi2"
2692 [(set (match_operand:HI 0 "register_operand" "")
2693 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
2697 (define_insn "*zero_extendqihi2_h8300"
2698 [(set (match_operand:HI 0 "register_operand" "=r,r")
2699 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2704 [(set_attr "length" "2,10")])
2706 (define_insn "*zero_extendqihi2_h8300hs"
2707 [(set (match_operand:HI 0 "register_operand" "=r,r")
2708 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2709 "TARGET_H8300H || TARGET_H8300S"
2713 [(set_attr "length" "2,10")
2714 (set_attr "cc" "set_znv,set_znv")])
2716 ;; Split the zero extension of a general operand (actually a memory
2717 ;; operand) into a load of the operand and the actual zero extension
2718 ;; so that 1) the length will be accurate, and 2) the zero extensions
2719 ;; appearing at the end of basic blocks may be merged.
2722 [(set (match_operand:HI 0 "register_operand" "")
2723 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
2728 (zero_extend:HI (match_dup 2)))]
2730 operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));
2733 (define_expand "zero_extendqisi2"
2734 [(set (match_operand:SI 0 "register_operand" "")
2735 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2739 operands[1] = force_reg (QImode, operands[1]);
2742 (define_insn "*zero_extendqisi2_h8300"
2743 [(set (match_operand:SI 0 "register_operand" "=r,r")
2744 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2747 mov.b #0,%x0\;sub.w %e0,%e0
2748 mov.b %R1,%w0\;mov.b #0,%x0\;sub.w %e0,%e0"
2749 [(set_attr "length" "4,8")])
2751 (define_insn "*zero_extendqisi2_h8300hs"
2752 [(set (match_operand:SI 0 "register_operand" "=r,r")
2753 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2754 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX"
2758 [(set (match_operand:SI 0 "register_operand" "")
2759 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2760 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
2761 && reg_overlap_mentioned_p (operands[0], operands[1])
2762 && reload_completed"
2766 (zero_extend:HI (match_dup 2)))
2768 (zero_extend:SI (match_dup 3)))]
2770 operands[2] = gen_lowpart (QImode, operands[0]);
2771 operands[3] = gen_lowpart (HImode, operands[0]);
2775 [(set (match_operand:SI 0 "register_operand" "")
2776 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2777 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
2778 && !reg_overlap_mentioned_p (operands[0], operands[1])
2779 && reload_completed"
2782 (set (strict_low_part (match_dup 2))
2785 operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));
2788 (define_insn "*zero_extendqisi2_h8sx"
2789 [(set (match_operand:SI 0 "register_operand" "=r")
2790 (zero_extend:SI (match_operand:QI 1 "register_operand" "0")))]
2793 [(set_attr "length" "2")
2794 (set_attr "cc" "set_znv")])
2796 (define_expand "zero_extendhisi2"
2797 [(set (match_operand:SI 0 "register_operand" "")
2798 (zero_extend:SI (match_operand:HI 1 "register_operand" "")))]
2802 ;; %e prints the high part of a CONST_INT, not the low part. Arggh.
2803 (define_insn "*zero_extendhisi2_h8300"
2804 [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2805 (zero_extend:SI (match_operand:HI 1 "general_operand_src" "0,i,g>")))]
2809 mov.w %f1,%f0\;sub.w %e0,%e0
2810 mov.w %e1,%f0\;sub.w %e0,%e0"
2811 [(set_attr "length" "2,4,6")])
2813 (define_insn "*zero_extendhisi2_h8300hs"
2814 [(set (match_operand:SI 0 "register_operand" "=r")
2815 (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))]
2816 "TARGET_H8300H || TARGET_H8300S"
2818 [(set_attr "length" "2")
2819 (set_attr "cc" "set_znv")])
2821 (define_expand "extendqihi2"
2822 [(set (match_operand:HI 0 "register_operand" "")
2823 (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
2827 (define_insn "*extendqihi2_h8300"
2828 [(set (match_operand:HI 0 "register_operand" "=r,r")
2829 (sign_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2832 bld #7,%s0\;subx %t0,%t0
2833 mov.b %R1,%s0\;bld #7,%s0\;subx %t0,%t0"
2834 [(set_attr "length" "4,8")])
2836 (define_insn "*extendqihi2_h8300hs"
2837 [(set (match_operand:HI 0 "register_operand" "=r")
2838 (sign_extend:HI (match_operand:QI 1 "register_operand" "0")))]
2839 "TARGET_H8300H || TARGET_H8300S"
2841 [(set_attr "length" "2")
2842 (set_attr "cc" "set_znv")])
2844 (define_expand "extendqisi2"
2845 [(set (match_operand:SI 0 "register_operand" "")
2846 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
2850 (define_insn "*extendqisi2_h8300"
2851 [(set (match_operand:SI 0 "register_operand" "=r,r")
2852 (sign_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2855 bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0
2856 mov.b %R1,%w0\;bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0"
2857 [(set_attr "length" "8,12")])
2859 ;; The following pattern is needed because without the pattern, the
2860 ;; combiner would split (sign_extend:SI (reg:QI)) into two 24-bit
2861 ;; shifts, one ashift and one ashiftrt.
2863 (define_insn_and_split "*extendqisi2_h8300hs"
2864 [(set (match_operand:SI 0 "register_operand" "=r")
2865 (sign_extend:SI (match_operand:QI 1 "register_operand" "0")))]
2866 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX"
2868 "&& reload_completed"
2870 (sign_extend:HI (match_dup 1)))
2872 (sign_extend:SI (match_dup 2)))]
2874 operands[2] = gen_rtx_REG (HImode, REGNO (operands[0]));
2877 (define_insn "*extendqisi2_h8sx"
2878 [(set (match_operand:SI 0 "register_operand" "=r")
2879 (sign_extend:SI (match_operand:QI 1 "register_operand" "0")))]
2882 [(set_attr "length" "2")
2883 (set_attr "cc" "set_znv")])
2885 (define_expand "extendhisi2"
2886 [(set (match_operand:SI 0 "register_operand" "")
2887 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
2891 (define_insn "*extendhisi2_h8300"
2892 [(set (match_operand:SI 0 "register_operand" "=r,r")
2893 (sign_extend:SI (match_operand:HI 1 "general_operand_src" "0,g>")))]
2896 bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0
2897 mov.w %T1,%f0\;bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0"
2898 [(set_attr "length" "6,10")])
2900 (define_insn "*extendhisi2_h8300hs"
2901 [(set (match_operand:SI 0 "register_operand" "=r")
2902 (sign_extend:SI (match_operand:HI 1 "register_operand" "0")))]
2903 "TARGET_H8300H || TARGET_H8300S"
2905 [(set_attr "length" "2")
2906 (set_attr "cc" "set_znv")])
2908 ;; ----------------------------------------------------------------------
2910 ;; ----------------------------------------------------------------------
2912 ;; We make some attempt to provide real efficient shifting. One example is
2913 ;; doing an 8-bit shift of a 16-bit value by moving a byte reg into the other
2914 ;; reg and moving 0 into the former reg.
2916 ;; We also try to achieve this in a uniform way. IE: We don't try to achieve
2917 ;; this in both rtl and at insn emit time. Ideally, we'd use rtl as that would
2918 ;; give the optimizer more cracks at the code. However, we wish to do things
2919 ;; like optimizing shifting the sign bit to bit 0 by rotating the other way.
2920 ;; There is rtl to handle this (rotate + and), but the H8/300 doesn't handle
2921 ;; 16-bit rotates. Also, if we emit complicated rtl, combine may not be able
2922 ;; to detect cases it can optimize.
2924 ;; For these and other fuzzy reasons, I've decided to go the less pretty but
2925 ;; easier "do it at insn emit time" route.
2929 (define_expand "ashlqi3"
2930 [(set (match_operand:QI 0 "register_operand" "")
2931 (ashift:QI (match_operand:QI 1 "register_operand" "")
2932 (match_operand:QI 2 "nonmemory_operand" "")))]
2935 if (expand_a_shift (QImode, ASHIFT, operands))
2939 (define_expand "ashrqi3"
2940 [(set (match_operand:QI 0 "register_operand" "")
2941 (ashiftrt:QI (match_operand:QI 1 "register_operand" "")
2942 (match_operand:QI 2 "nonmemory_operand" "")))]
2945 if (expand_a_shift (QImode, ASHIFTRT, operands))
2949 (define_expand "lshrqi3"
2950 [(set (match_operand:QI 0 "register_operand" "")
2951 (lshiftrt:QI (match_operand:QI 1 "register_operand" "")
2952 (match_operand:QI 2 "nonmemory_operand" "")))]
2955 if (expand_a_shift (QImode, LSHIFTRT, operands))
2960 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
2961 (match_operator:QI 3 "h8sx_unary_shift_operator"
2962 [(match_operand:QI 1 "h8300_dst_operand" "0")
2963 (match_operand:QI 2 "const_int_operand" "")]))]
2964 "h8300_operands_match_p (operands)"
2966 return output_h8sx_shift (operands, 'b', 'X');
2968 [(set_attr "length_table" "unary")
2969 (set_attr "cc" "set_znv")])
2972 [(set (match_operand:QI 0 "register_operand" "=r")
2973 (match_operator:QI 3 "h8sx_binary_shift_operator"
2974 [(match_operand:QI 1 "register_operand" "0")
2975 (match_operand:QI 2 "nonmemory_operand" "r P3>X")]))]
2978 return output_h8sx_shift (operands, 'b', 'X');
2980 [(set_attr "length" "4")
2981 (set_attr "cc" "set_znv")])
2983 (define_insn "*shiftqi"
2984 [(set (match_operand:QI 0 "register_operand" "=r,r")
2985 (match_operator:QI 3 "nshift_operator"
2986 [(match_operand:QI 1 "register_operand" "0,0")
2987 (match_operand:QI 2 "nonmemory_operand" "R,rn")]))
2988 (clobber (match_scratch:QI 4 "=X,&r"))]
2991 return output_a_shift (operands);
2993 [(set (attr "length")
2994 (symbol_ref "compute_a_shift_length (insn, operands)"))
2996 (symbol_ref "compute_a_shift_cc (insn, operands)"))])
3000 (define_expand "ashlhi3"
3001 [(set (match_operand:HI 0 "register_operand" "")
3002 (ashift:HI (match_operand:HI 1 "register_operand" "")
3003 (match_operand:QI 2 "nonmemory_operand" "")))]
3006 if (expand_a_shift (HImode, ASHIFT, operands))
3010 (define_expand "lshrhi3"
3011 [(set (match_operand:HI 0 "register_operand" "")
3012 (lshiftrt:HI (match_operand:HI 1 "register_operand" "")
3013 (match_operand:QI 2 "nonmemory_operand" "")))]
3016 if (expand_a_shift (HImode, LSHIFTRT, operands))
3020 (define_expand "ashrhi3"
3021 [(set (match_operand:HI 0 "register_operand" "")
3022 (ashiftrt:HI (match_operand:HI 1 "register_operand" "")
3023 (match_operand:QI 2 "nonmemory_operand" "")))]
3026 if (expand_a_shift (HImode, ASHIFTRT, operands))
3031 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
3032 (match_operator:HI 3 "h8sx_unary_shift_operator"
3033 [(match_operand:HI 1 "h8300_dst_operand" "0")
3034 (match_operand:QI 2 "const_int_operand" "")]))]
3035 "h8300_operands_match_p (operands)"
3037 return output_h8sx_shift (operands, 'w', 'T');
3039 [(set_attr "length_table" "unary")
3040 (set_attr "cc" "set_znv")])
3043 [(set (match_operand:HI 0 "register_operand" "=r")
3044 (match_operator:HI 3 "h8sx_binary_shift_operator"
3045 [(match_operand:HI 1 "register_operand" "0")
3046 (match_operand:QI 2 "nonmemory_operand" "r P4>X")]))]
3049 return output_h8sx_shift (operands, 'w', 'T');
3051 [(set_attr "length" "4")
3052 (set_attr "cc" "set_znv")])
3054 (define_insn "*shifthi"
3055 [(set (match_operand:HI 0 "register_operand" "=r,r")
3056 (match_operator:HI 3 "nshift_operator"
3057 [(match_operand:HI 1 "register_operand" "0,0")
3058 (match_operand:QI 2 "nonmemory_operand" "S,rn")]))
3059 (clobber (match_scratch:QI 4 "=X,&r"))]
3062 return output_a_shift (operands);
3064 [(set (attr "length")
3065 (symbol_ref "compute_a_shift_length (insn, operands)"))
3067 (symbol_ref "compute_a_shift_cc (insn, operands)"))])
3071 (define_expand "ashlsi3"
3072 [(set (match_operand:SI 0 "register_operand" "")
3073 (ashift:SI (match_operand:SI 1 "register_operand" "")
3074 (match_operand:QI 2 "nonmemory_operand" "")))]
3077 if (expand_a_shift (SImode, ASHIFT, operands))
3081 (define_expand "lshrsi3"
3082 [(set (match_operand:SI 0 "register_operand" "")
3083 (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
3084 (match_operand:QI 2 "nonmemory_operand" "")))]
3087 if (expand_a_shift (SImode, LSHIFTRT, operands))
3091 (define_expand "ashrsi3"
3092 [(set (match_operand:SI 0 "register_operand" "")
3093 (ashiftrt:SI (match_operand:SI 1 "register_operand" "")
3094 (match_operand:QI 2 "nonmemory_operand" "")))]
3097 if (expand_a_shift (SImode, ASHIFTRT, operands))
3102 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
3103 (match_operator:SI 3 "h8sx_unary_shift_operator"
3104 [(match_operand:SI 1 "h8300_dst_operand" "0")
3105 (match_operand:QI 2 "const_int_operand" "")]))]
3106 "h8300_operands_match_p (operands)"
3108 return output_h8sx_shift (operands, 'l', 'S');
3110 [(set_attr "length_table" "unary")
3111 (set_attr "cc" "set_znv")])
3114 [(set (match_operand:SI 0 "register_operand" "=r")
3115 (match_operator:SI 3 "h8sx_binary_shift_operator"
3116 [(match_operand:SI 1 "register_operand" "0")
3117 (match_operand:QI 2 "nonmemory_operand" "r P5>X")]))]
3120 return output_h8sx_shift (operands, 'l', 'S');
3122 [(set_attr "length" "4")
3123 (set_attr "cc" "set_znv")])
3125 (define_insn "*shiftsi"
3126 [(set (match_operand:SI 0 "register_operand" "=r,r")
3127 (match_operator:SI 3 "nshift_operator"
3128 [(match_operand:SI 1 "register_operand" "0,0")
3129 (match_operand:QI 2 "nonmemory_operand" "T,rn")]))
3130 (clobber (match_scratch:QI 4 "=X,&r"))]
3133 return output_a_shift (operands);
3135 [(set (attr "length")
3136 (symbol_ref "compute_a_shift_length (insn, operands)"))
3138 (symbol_ref "compute_a_shift_cc (insn, operands)"))])
3140 ;; Split a variable shift into a loop. If the register containing
3141 ;; the shift count dies, then we just use that register.
3144 [(set (match_operand 0 "register_operand" "")
3145 (match_operator 2 "nshift_operator"
3147 (match_operand:QI 1 "register_operand" "")]))
3148 (clobber (match_operand:QI 3 "register_operand" ""))]
3150 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))"
3151 [(set (cc0) (compare (match_dup 1) (const_int 0)))
3153 (if_then_else (le (cc0) (const_int 0))
3154 (label_ref (match_dup 5))
3159 (match_op_dup 2 [(match_dup 0) (const_int 1)]))
3160 (clobber (scratch:QI))])
3161 (set (match_dup 1) (plus:QI (match_dup 1) (const_int -1)))
3162 (set (cc0) (compare (match_dup 1) (const_int 0)))
3164 (if_then_else (ne (cc0) (const_int 0))
3165 (label_ref (match_dup 4))
3169 operands[4] = gen_label_rtx ();
3170 operands[5] = gen_label_rtx ();
3174 [(set (match_operand 0 "register_operand" "")
3175 (match_operator 2 "nshift_operator"
3177 (match_operand:QI 1 "register_operand" "")]))
3178 (clobber (match_operand:QI 3 "register_operand" ""))]
3180 && !find_regno_note (insn, REG_DEAD, REGNO (operands[1]))"
3183 (set (cc0) (compare (match_dup 3) (const_int 0)))
3185 (if_then_else (le (cc0) (const_int 0))
3186 (label_ref (match_dup 5))
3191 (match_op_dup 2 [(match_dup 0) (const_int 1)]))
3192 (clobber (scratch:QI))])
3193 (set (match_dup 3) (plus:QI (match_dup 3) (const_int -1)))
3194 (set (cc0) (compare (match_dup 3) (const_int 0)))
3196 (if_then_else (ne (cc0) (const_int 0))
3197 (label_ref (match_dup 4))
3201 operands[4] = gen_label_rtx ();
3202 operands[5] = gen_label_rtx ();
3205 ;; ----------------------------------------------------------------------
3207 ;; ----------------------------------------------------------------------
3209 (define_expand "rotlqi3"
3210 [(set (match_operand:QI 0 "register_operand" "")
3211 (rotate:QI (match_operand:QI 1 "register_operand" "")
3212 (match_operand:QI 2 "nonmemory_operand" "")))]
3215 if (expand_a_rotate (operands))
3219 (define_insn "rotlqi3_1"
3220 [(set (match_operand:QI 0 "register_operand" "=r")
3221 (rotate:QI (match_operand:QI 1 "register_operand" "0")
3222 (match_operand:QI 2 "immediate_operand" "")))]
3225 return output_a_rotate (ROTATE, operands);
3227 [(set (attr "length")
3228 (symbol_ref "compute_a_rotate_length (operands)"))])
3230 (define_expand "rotlhi3"
3231 [(set (match_operand:HI 0 "register_operand" "")
3232 (rotate:HI (match_operand:HI 1 "register_operand" "")
3233 (match_operand:QI 2 "nonmemory_operand" "")))]
3236 if (expand_a_rotate (operands))
3240 (define_insn "rotlhi3_1"
3241 [(set (match_operand:HI 0 "register_operand" "=r")
3242 (rotate:HI (match_operand:HI 1 "register_operand" "0")
3243 (match_operand:QI 2 "immediate_operand" "")))]
3246 return output_a_rotate (ROTATE, operands);
3248 [(set (attr "length")
3249 (symbol_ref "compute_a_rotate_length (operands)"))])
3251 (define_expand "rotlsi3"
3252 [(set (match_operand:SI 0 "register_operand" "")
3253 (rotate:SI (match_operand:SI 1 "register_operand" "")
3254 (match_operand:QI 2 "nonmemory_operand" "")))]
3255 "TARGET_H8300H || TARGET_H8300S"
3257 if (expand_a_rotate (operands))
3261 (define_insn "rotlsi3_1"
3262 [(set (match_operand:SI 0 "register_operand" "=r")
3263 (rotate:SI (match_operand:SI 1 "register_operand" "0")
3264 (match_operand:QI 2 "immediate_operand" "")))]
3265 "TARGET_H8300H || TARGET_H8300S"
3267 return output_a_rotate (ROTATE, operands);
3269 [(set (attr "length")
3270 (symbol_ref "compute_a_rotate_length (operands)"))])
3272 ;; -----------------------------------------------------------------
3274 ;; -----------------------------------------------------------------
3275 ;; The H8/300 has given 1/8th of its opcode space to bitfield
3276 ;; instructions so let's use them as well as we can.
3278 ;; You'll never believe all these patterns perform one basic action --
3279 ;; load a bit from the source, optionally invert the bit, then store it
3280 ;; in the destination (which is known to be zero).
3282 ;; Combine obviously need some work to better identify this situation and
3283 ;; canonicalize the form better.
3286 ;; Normal loads with a 16bit destination.
3290 [(set (match_operand:HI 0 "register_operand" "=&r")
3291 (zero_extract:HI (match_operand:HI 1 "register_operand" "r")
3293 (match_operand:HI 2 "immediate_operand" "n")))]
3295 "sub.w %0,%0\;bld %Z2,%Y1\;bst #0,%X0"
3296 [(set_attr "length" "6")])
3299 ;; Inverted loads with a 16bit destination.
3303 [(set (match_operand:HI 0 "register_operand" "=&r")
3304 (zero_extract:HI (xor:HI (match_operand:HI 1 "register_operand" "r")
3305 (match_operand:HI 3 "const_int_operand" "n"))
3307 (match_operand:HI 2 "const_int_operand" "n")))]
3308 "(TARGET_H8300 || TARGET_H8300SX)
3309 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
3310 "sub.w %0,%0\;bild %Z2,%Y1\;bst #0,%X0"
3311 [(set_attr "length" "8")])
3314 ;; Normal loads with a 32bit destination.
3317 (define_insn "*extzv_1_r_h8300"
3318 [(set (match_operand:SI 0 "register_operand" "=&r")
3319 (zero_extract:SI (match_operand:HI 1 "register_operand" "r")
3321 (match_operand 2 "const_int_operand" "n")))]
3322 "TARGET_H8300 && INTVAL (operands[2]) < 16"
3324 return output_simode_bld (0, operands);
3326 [(set_attr "length" "8")])
3328 (define_insn "*extzv_1_r_h8300hs"
3329 [(set (match_operand:SI 0 "register_operand" "=r,r")
3330 (zero_extract:SI (match_operand:SI 1 "register_operand" "?0,r")
3332 (match_operand 2 "const_int_operand" "n,n")))]
3333 "(TARGET_H8300H || TARGET_H8300S) && INTVAL (operands[2]) < 16"
3335 return output_simode_bld (0, operands);
3337 [(set_attr "cc" "set_znv,set_znv")
3338 (set_attr "length" "8,6")])
3341 ;; Inverted loads with a 32bit destination.
3344 (define_insn "*extzv_1_r_inv_h8300"
3345 [(set (match_operand:SI 0 "register_operand" "=&r")
3346 (zero_extract:SI (xor:HI (match_operand:HI 1 "register_operand" "r")
3347 (match_operand:HI 3 "const_int_operand" "n"))
3349 (match_operand 2 "const_int_operand" "n")))]
3350 "TARGET_H8300 && INTVAL (operands[2]) < 16
3351 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
3353 return output_simode_bld (1, operands);
3355 [(set_attr "length" "8")])
3357 (define_insn "*extzv_1_r_inv_h8300hs"
3358 [(set (match_operand:SI 0 "register_operand" "=r,r")
3359 (zero_extract:SI (xor:SI (match_operand:SI 1 "register_operand" "?0,r")
3360 (match_operand 3 "const_int_operand" "n,n"))
3362 (match_operand 2 "const_int_operand" "n,n")))]
3363 "(TARGET_H8300H || TARGET_H8300S) && INTVAL (operands[2]) < 16
3364 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
3366 return output_simode_bld (1, operands);
3368 [(set_attr "cc" "set_znv,set_znv")
3369 (set_attr "length" "8,6")])
3371 (define_expand "insv"
3372 [(set (zero_extract:HI (match_operand:HI 0 "general_operand" "")
3373 (match_operand:HI 1 "general_operand" "")
3374 (match_operand:HI 2 "general_operand" ""))
3375 (match_operand:HI 3 "general_operand" ""))]
3376 "TARGET_H8300 || TARGET_H8300SX"
3380 if (GET_CODE (operands[1]) == CONST_INT
3381 && GET_CODE (operands[2]) == CONST_INT
3382 && INTVAL (operands[1]) <= 8
3383 && INTVAL (operands[2]) >= 0
3384 && INTVAL (operands[1]) + INTVAL (operands[2]) <= 8
3385 && memory_operand (operands[0], GET_MODE (operands[0])))
3387 /* If the source operand is zero, it's better to use AND rather
3388 than BFST. Likewise OR if the operand is all ones. */
3389 if (GET_CODE (operands[3]) == CONST_INT)
3391 HOST_WIDE_INT mask = (1 << INTVAL (operands[1])) - 1;
3392 if ((INTVAL (operands[3]) & mask) == 0)
3394 if ((INTVAL (operands[3]) & mask) == mask)
3397 if (! bit_memory_operand (operands[0], GET_MODE (operands[0])))
3399 if (!can_create_pseudo_p ())
3401 operands[0] = replace_equiv_address (operands[0], force_reg (Pmode,
3402 XEXP (operands[0], 0)));
3404 operands[3] = gen_lowpart (QImode, operands[3]);
3407 if (! register_operand (operands[3], QImode))
3409 if (!can_create_pseudo_p ())
3411 operands[3] = force_reg (QImode, operands[3]);
3413 emit_insn (gen_bfst (adjust_address (operands[0], QImode, 0),
3414 operands[3], operands[1], operands[2]));
3420 /* We only have single bit bit-field instructions. */
3421 if (INTVAL (operands[1]) != 1)
3424 /* For now, we don't allow memory operands. */
3425 if (GET_CODE (operands[0]) == MEM
3426 || GET_CODE (operands[3]) == MEM)
3429 if (GET_CODE (operands[3]) != REG)
3430 operands[3] = force_reg (HImode, operands[3]);
3434 [(set (zero_extract:HI (match_operand:HI 0 "register_operand" "+r")
3436 (match_operand:HI 1 "immediate_operand" "n"))
3437 (match_operand:HI 2 "register_operand" "r"))]
3439 "bld #0,%R2\;bst %Z1,%Y0 ; i1"
3440 [(set_attr "length" "4")])
3442 (define_expand "extzv"
3443 [(set (match_operand:HI 0 "register_operand" "")
3444 (zero_extract:HI (match_operand:HI 1 "bit_operand" "")
3445 (match_operand:HI 2 "general_operand" "")
3446 (match_operand:HI 3 "general_operand" "")))]
3447 "TARGET_H8300 || TARGET_H8300SX"
3451 if (GET_CODE (operands[2]) == CONST_INT
3452 && GET_CODE (operands[3]) == CONST_INT
3453 && INTVAL (operands[2]) <= 8
3454 && INTVAL (operands[3]) >= 0
3455 && INTVAL (operands[2]) + INTVAL (operands[3]) <= 8
3456 && memory_operand (operands[1], QImode))
3460 /* Optimize the case where we're extracting into a paradoxical
3461 subreg. It's only necessary to extend to the inner reg. */
3462 if (GET_CODE (operands[0]) == SUBREG
3463 && subreg_lowpart_p (operands[0])
3464 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0])))
3465 < GET_MODE_SIZE (GET_MODE (operands[0])))
3466 && (GET_MODE_CLASS (GET_MODE (SUBREG_REG (operands[0])))
3468 operands[0] = SUBREG_REG (operands[0]);
3470 if (!can_create_pseudo_p ())
3471 temp = gen_lowpart (QImode, operands[0]);
3473 temp = gen_reg_rtx (QImode);
3476 if (! bit_memory_operand (operands[1], QImode))
3478 if (!can_create_pseudo_p ())
3480 operands[1] = replace_equiv_address (operands[1],
3481 force_reg (Pmode, XEXP (operands[1], 0)));
3483 emit_insn (gen_bfld (temp, operands[1], operands[2], operands[3]));
3484 convert_move (operands[0], temp, 1);
3490 /* We only have single bit bit-field instructions. */
3491 if (INTVAL (operands[2]) != 1)
3494 /* For now, we don't allow memory operands. */
3495 if (GET_CODE (operands[1]) == MEM)
3499 ;; BAND, BOR, and BXOR patterns
3502 [(set (match_operand:HI 0 "bit_operand" "=Ur")
3503 (match_operator:HI 4 "bit_operator"
3504 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
3506 (match_operand:HI 2 "immediate_operand" "n"))
3507 (match_operand:HI 3 "bit_operand" "0")]))]
3509 "bld %Z2,%Y1\;b%c4 #0,%R0\;bst #0,%R0; bl1"
3510 [(set_attr "length" "6")])
3513 [(set (match_operand:HI 0 "bit_operand" "=Ur")
3514 (match_operator:HI 5 "bit_operator"
3515 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
3517 (match_operand:HI 2 "immediate_operand" "n"))
3518 (zero_extract:HI (match_operand:HI 3 "register_operand" "r")
3520 (match_operand:HI 4 "immediate_operand" "n"))]))]
3522 "bld %Z2,%Y1\;b%c5 %Z4,%Y3\;bst #0,%R0; bl3"
3523 [(set_attr "length" "6")])
3526 [(set (match_operand:QI 0 "register_operand" "=r")
3527 (zero_extract:QI (match_operand:QI 1 "bit_memory_operand" "WU")
3528 (match_operand:QI 2 "immediate_operand" "n")
3529 (match_operand:QI 3 "immediate_operand" "n")))]
3530 "TARGET_H8300SX && INTVAL (operands[2]) + INTVAL (operands[3]) <= 8"
3532 operands[2] = GEN_INT ((1 << (INTVAL (operands[2]) + INTVAL (operands[3])))
3533 - (1 << INTVAL (operands[3])));
3534 return "bfld %2,%1,%R0";
3536 [(set_attr "cc" "none_0hit")
3537 (set_attr "length_table" "bitfield")])
3540 [(set (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "+WU")
3541 (match_operand:QI 2 "immediate_operand" "n")
3542 (match_operand:QI 3 "immediate_operand" "n"))
3543 (match_operand:QI 1 "register_operand" "r"))]
3544 "TARGET_H8300SX && INTVAL (operands[2]) + INTVAL (operands[3]) <= 8"
3546 operands[2] = GEN_INT ((1 << (INTVAL (operands[2]) + INTVAL (operands[3])))
3547 - (1 << INTVAL (operands[3])));
3548 return "bfst %R1,%2,%0";
3550 [(set_attr "cc" "none_0hit")
3551 (set_attr "length_table" "bitfield")])
3553 (define_expand "cstoreqi4"
3554 [(use (match_operator 1 "eqne_operator"
3555 [(match_operand:QI 2 "h8300_dst_operand" "")
3556 (match_operand:QI 3 "h8300_src_operand" "")]))
3557 (clobber (match_operand:HI 0 "register_operand"))]
3560 h8300_expand_store (operands);
3564 (define_expand "cstorehi4"
3565 [(use (match_operator 1 "eqne_operator"
3566 [(match_operand:HI 2 "h8300_dst_operand" "")
3567 (match_operand:HI 3 "h8300_src_operand" "")]))
3568 (clobber (match_operand:HI 0 "register_operand"))]
3571 h8300_expand_store (operands);
3575 (define_expand "cstoresi4"
3576 [(use (match_operator 1 "eqne_operator"
3577 [(match_operand:SI 2 "h8300_dst_operand" "")
3578 (match_operand:SI 3 "h8300_src_operand" "")]))
3579 (clobber (match_operand:HI 0 "register_operand"))]
3582 h8300_expand_store (operands);
3586 (define_insn "*bstzhireg"
3587 [(set (match_operand:HI 0 "register_operand" "=r")
3588 (match_operator:HI 1 "eqne_operator" [(cc0) (const_int 0)]))]
3590 "mulu.w #0,%T0\;b%k1 .Lh8BR%=\;inc.w #1,%T0\\n.Lh8BR%=:"
3591 [(set_attr "cc" "clobber")])
3593 (define_insn_and_split "*cmpstz"
3594 [(set (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "+WU,+WU")
3596 (match_operand:QI 1 "immediate_operand" "n,n"))
3597 (match_operator:QI 2 "eqne_operator"
3598 [(match_operand 3 "h8300_dst_operand" "r,rQ")
3599 (match_operand 4 "h8300_src_operand" "I,rQi")]))]
3601 && (GET_MODE (operands[3]) == GET_MODE (operands[4])
3602 || GET_CODE (operands[4]) == CONST_INT)
3603 && GET_MODE_CLASS (GET_MODE (operands[3])) == MODE_INT
3604 && GET_MODE_SIZE (GET_MODE (operands[3])) <= 4"
3607 [(set (cc0) (match_dup 5))
3608 (set (zero_extract:QI (match_dup 0) (const_int 1) (match_dup 1))
3609 (match_op_dup:QI 2 [(cc0) (const_int 0)]))]
3611 operands[5] = gen_rtx_COMPARE (VOIDmode, operands[3], operands[4]);
3613 [(set_attr "cc" "set_znv,compare")])
3615 (define_insn "*bstz"
3616 [(set (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "+WU")
3618 (match_operand:QI 1 "immediate_operand" "n"))
3619 (eq:QI (cc0) (const_int 0)))]
3620 "TARGET_H8300SX && reload_completed"
3622 [(set_attr "cc" "none_0hit")
3623 (set_attr "length_table" "unary")])
3625 (define_insn "*bistz"
3626 [(set (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "+WU")
3628 (match_operand:QI 1 "immediate_operand" "n"))
3629 (ne:QI (cc0) (const_int 0)))]
3630 "TARGET_H8300SX && reload_completed"
3632 [(set_attr "cc" "none_0hit")
3633 (set_attr "length_table" "unary")])
3635 (define_insn_and_split "*cmpcondbset"
3636 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3637 (if_then_else:QI (match_operator 1 "eqne_operator"
3638 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3639 (match_operand 3 "h8300_src_operand" "I,rQi")])
3640 (ior:QI (match_operand:QI 4 "bit_memory_operand" "0,0")
3641 (match_operand:QI 5 "single_one_operand" "n,n"))
3646 [(set (cc0) (match_dup 6))
3648 (if_then_else:QI (match_op_dup 1 [(cc0) (const_int 0)])
3649 (ior:QI (match_dup 4) (match_dup 5))
3652 operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);
3654 [(set_attr "cc" "set_znv,compare")])
3656 (define_insn "*condbset"
3657 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3658 (if_then_else:QI (match_operator:QI 2 "eqne_operator"
3659 [(cc0) (const_int 0)])
3660 (ior:QI (match_operand:QI 3 "bit_memory_operand" "0")
3661 (match_operand:QI 1 "single_one_operand" "n"))
3663 "TARGET_H8300SX && reload_completed"
3665 [(set_attr "cc" "none_0hit")
3666 (set_attr "length_table" "logicb")])
3668 (define_insn_and_split "*cmpcondbclr"
3669 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3670 (if_then_else:QI (match_operator 1 "eqne_operator"
3671 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3672 (match_operand 3 "h8300_src_operand" "I,rQi")])
3673 (and:QI (match_operand:QI 4 "bit_memory_operand" "0,0")
3674 (match_operand:QI 5 "single_zero_operand" "n,n"))
3679 [(set (cc0) (match_dup 6))
3681 (if_then_else:QI (match_op_dup 1 [(cc0) (const_int 0)])
3682 (and:QI (match_dup 4) (match_dup 5))
3685 operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);
3687 [(set_attr "cc" "set_znv,compare")])
3689 (define_insn "*condbclr"
3690 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3691 (if_then_else:QI (match_operator:QI 2 "eqne_operator"
3692 [(cc0) (const_int 0)])
3693 (and:QI (match_operand:QI 3 "bit_memory_operand" "0")
3694 (match_operand:QI 1 "single_zero_operand" "n"))
3696 "TARGET_H8300SX && reload_completed"
3698 [(set_attr "cc" "none_0hit")
3699 (set_attr "length_table" "logicb")])
3701 (define_insn_and_split "*cmpcondbsetreg"
3702 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3703 (if_then_else:QI (match_operator 1 "eqne_operator"
3704 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3705 (match_operand 3 "h8300_src_operand" "I,rQi")])
3706 (ior:QI (match_operand:QI 4 "bit_memory_operand" "0,0")
3707 (ashift:QI (const_int 1)
3708 (match_operand:QI 5 "register_operand" "r,r")))
3713 [(set (cc0) (match_dup 6))
3715 (if_then_else:QI (match_op_dup 1 [(cc0) (const_int 0)])
3716 (ior:QI (match_dup 4)
3717 (ashift:QI (const_int 1)
3718 (match_operand:QI 5 "register_operand" "r,r")))
3721 operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);
3723 [(set_attr "cc" "set_znv,compare")])
3725 (define_insn "*condbsetreg"
3726 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3727 (if_then_else:QI (match_operator:QI 2 "eqne_operator"
3728 [(cc0) (const_int 0)])
3729 (ior:QI (match_operand:QI 3 "bit_memory_operand" "0")
3730 (ashift:QI (const_int 1)
3731 (match_operand:QI 1 "register_operand" "r")))
3733 "TARGET_H8300SX && reload_completed"
3735 [(set_attr "cc" "none_0hit")
3736 (set_attr "length_table" "logicb")])
3738 (define_insn_and_split "*cmpcondbclrreg"
3739 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3740 (if_then_else:QI (match_operator 1 "eqne_operator"
3741 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3742 (match_operand 3 "h8300_src_operand" "I,rQi")])
3743 (and:QI (match_operand:QI 4 "bit_memory_operand" "0,0")
3744 (ashift:QI (const_int 1)
3745 (match_operand:QI 5 "register_operand" "r,r")))
3750 [(set (cc0) (match_dup 6))
3752 (if_then_else:QI (match_op_dup 1 [(cc0) (const_int 0)])
3753 (and:QI (match_dup 4)
3754 (ashift:QI (const_int 1)
3755 (match_operand:QI 5 "register_operand" "r,r")))
3758 operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);
3760 [(set_attr "cc" "set_znv,compare")])
3762 (define_insn "*condbclrreg"
3763 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3764 (if_then_else:QI (match_operator:QI 2 "eqne_operator"
3765 [(cc0) (const_int 0)])
3766 (and:QI (match_operand:QI 3 "bit_memory_operand" "0")
3767 (ashift:QI (const_int 1)
3768 (match_operand:QI 1 "register_operand" "r")))
3770 "TARGET_H8300SX && reload_completed"
3772 [(set_attr "cc" "none_0hit")
3773 (set_attr "length_table" "logicb")])
3776 ;; -----------------------------------------------------------------
3778 ;; -----------------------------------------------------------------
3782 (define_insn "*insv_si_1_n"
3783 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3785 (match_operand:SI 1 "const_int_operand" "n"))
3786 (match_operand:SI 2 "register_operand" "r"))]
3787 "(TARGET_H8300H || TARGET_H8300S) && INTVAL (operands[1]) < 16"
3788 "bld\\t#0,%w2\;bst\\t%Z1,%Y0"
3789 [(set_attr "length" "4")])
3791 (define_insn "*insv_si_1_n_lshiftrt"
3792 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3794 (match_operand:SI 1 "const_int_operand" "n"))
3795 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
3796 (match_operand:SI 3 "const_int_operand" "n")))]
3797 "(TARGET_H8300H || TARGET_H8300S)
3798 && INTVAL (operands[1]) < 16
3799 && INTVAL (operands[3]) < 16"
3800 "bld\\t%Z3,%Y2\;bst\\t%Z1,%Y0"
3801 [(set_attr "length" "4")])
3803 (define_insn "*insv_si_1_n_lshiftrt_16"
3804 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3806 (match_operand:SI 1 "const_int_operand" "n"))
3807 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
3809 "(TARGET_H8300H || TARGET_H8300S) && INTVAL (operands[1]) < 16"
3810 "rotr.w\\t%e2\;rotl.w\\t%e2\;bst\\t%Z1,%Y0"
3811 [(set_attr "length" "6")])
3813 (define_insn "*insv_si_8_8"
3814 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3817 (match_operand:SI 1 "register_operand" "r"))]
3818 "TARGET_H8300H || TARGET_H8300S"
3820 [(set_attr "length" "2")])
3822 (define_insn "*insv_si_8_8_lshiftrt_8"
3823 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3826 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3828 "TARGET_H8300H || TARGET_H8300S"
3830 [(set_attr "length" "2")])
3834 (define_insn "*extzv_8_8"
3835 [(set (match_operand:SI 0 "register_operand" "=r,r")
3836 (zero_extract:SI (match_operand:SI 1 "register_operand" "?0,r")
3839 "TARGET_H8300H || TARGET_H8300S"
3841 mov.b\\t%x1,%w0\;extu.w\\t%f0\;extu.l\\t%S0
3842 sub.l\\t%S0,%S0\;mov.b\\t%x1,%w0"
3843 [(set_attr "cc" "set_znv,clobber")
3844 (set_attr "length" "6,4")])
3846 (define_insn "*extzv_8_16"
3847 [(set (match_operand:SI 0 "register_operand" "=r")
3848 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
3851 "TARGET_H8300H || TARGET_H8300S"
3852 "mov.w\\t%e1,%f0\;extu.w\\t%f0\;extu.l\\t%S0"
3853 [(set_attr "cc" "set_znv")
3854 (set_attr "length" "6")])
3856 (define_insn "*extzv_16_8"
3857 [(set (match_operand:SI 0 "register_operand" "=r")
3858 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
3861 (clobber (match_scratch:SI 2 "=&r"))]
3863 "mov.w\\t%e1,%f2\;mov.b\\t%x1,%w0\;mov.b\\t%w2,%x0\;extu.l\\t%S0"
3864 [(set_attr "length" "8")
3865 (set_attr "cc" "set_znv")])
3867 ;; Extract the exponent of a float.
3869 (define_insn_and_split "*extzv_8_23"
3870 [(set (match_operand:SI 0 "register_operand" "=r")
3871 (zero_extract:SI (match_operand:SI 1 "register_operand" "0")
3874 "(TARGET_H8300H || TARGET_H8300S)"
3876 "&& reload_completed"
3877 [(parallel [(set (match_dup 0)
3878 (ashift:SI (match_dup 0)
3880 (clobber (scratch:QI))])
3881 (parallel [(set (match_dup 0)
3882 (lshiftrt:SI (match_dup 0)
3884 (clobber (scratch:QI))])]
3889 ;; ((SImode) HImode) << 15
3891 (define_insn_and_split "*twoshifts_l16_r1"
3892 [(set (match_operand:SI 0 "register_operand" "=r")
3893 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
3895 (const_int 2147450880)))]
3896 "(TARGET_H8300H || TARGET_H8300S)"
3898 "&& reload_completed"
3899 [(parallel [(set (match_dup 0)
3900 (ashift:SI (match_dup 0)
3902 (clobber (scratch:QI))])
3903 (parallel [(set (match_dup 0)
3904 (lshiftrt:SI (match_dup 0)
3906 (clobber (scratch:QI))])]
3909 ;; Transform (SImode << B) & 0xffff into (SImode) (HImode << B).
3911 (define_insn_and_split "*andsi3_ashift_n_lower"
3912 [(set (match_operand:SI 0 "register_operand" "=r,r")
3913 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0,0")
3914 (match_operand:QI 2 "const_int_operand" "S,n"))
3915 (match_operand:SI 3 "const_int_operand" "n,n")))
3916 (clobber (match_scratch:QI 4 "=X,&r"))]
3917 "(TARGET_H8300H || TARGET_H8300S)
3918 && INTVAL (operands[2]) <= 15
3919 && INTVAL (operands[3]) == ((-1 << INTVAL (operands[2])) & 0xffff)"
3921 "&& reload_completed"
3922 [(parallel [(set (match_dup 5)
3923 (ashift:HI (match_dup 5)
3925 (clobber (match_dup 4))])
3927 (zero_extend:SI (match_dup 5)))]
3929 operands[5] = gen_rtx_REG (HImode, REGNO (operands[0]));
3932 ;; Accept (A >> 30) & 2 and the like.
3934 (define_insn "*andsi3_lshiftrt_n_sb"
3935 [(set (match_operand:SI 0 "register_operand" "=r")
3936 (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
3937 (match_operand:SI 2 "const_int_operand" "n"))
3938 (match_operand:SI 3 "single_one_operand" "n")))]
3939 "(TARGET_H8300H || TARGET_H8300S)
3940 && exact_log2 (INTVAL (operands[3])) < 16
3941 && INTVAL (operands[2]) + exact_log2 (INTVAL (operands[3])) == 31"
3943 operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
3944 return "shll.l\\t%S0\;xor.l\\t%S0,%S0\;bst\\t%Z3,%Y0";
3946 [(set_attr "length" "8")])
3948 (define_insn_and_split "*andsi3_lshiftrt_9_sb"
3949 [(set (match_operand:SI 0 "register_operand" "=r")
3950 (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
3952 (const_int 4194304)))]
3953 "TARGET_H8300H || TARGET_H8300S"
3955 "&& reload_completed"
3957 (and:SI (lshiftrt:SI (match_dup 0)
3960 (parallel [(set (match_dup 0)
3961 (ashift:SI (match_dup 0)
3963 (clobber (scratch:QI))])]
3968 (define_insn "*addsi3_upper"
3969 [(set (match_operand:SI 0 "register_operand" "=r")
3970 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
3972 (match_operand:SI 2 "register_operand" "0")))]
3973 "TARGET_H8300H || TARGET_H8300S"
3975 [(set_attr "length" "2")])
3977 (define_insn "*addsi3_lshiftrt_16_zexthi"
3978 [(set (match_operand:SI 0 "register_operand" "=r")
3979 (plus:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3981 (zero_extend:SI (match_operand:HI 2 "register_operand" "0"))))]
3982 "TARGET_H8300H || TARGET_H8300S"
3983 "add.w\\t%e1,%f0\;xor.w\\t%e0,%e0\;rotxl.w\\t%e0"
3984 [(set_attr "length" "6")])
3986 (define_insn_and_split "*addsi3_and_r_1"
3987 [(set (match_operand:SI 0 "register_operand" "=r")
3988 (plus:SI (and:SI (match_operand:SI 1 "register_operand" "r")
3990 (match_operand:SI 2 "register_operand" "0")))]
3991 "TARGET_H8300H || TARGET_H8300S"
3993 "&& reload_completed"
3994 [(set (cc0) (compare (zero_extract:SI (match_dup 1)
3999 (if_then_else (eq (cc0)
4001 (label_ref (match_dup 3))
4004 (plus:SI (match_dup 2)
4008 operands[3] = gen_label_rtx ();
4011 (define_insn_and_split "*addsi3_and_not_r_1"
4012 [(set (match_operand:SI 0 "register_operand" "=r")
4013 (plus:SI (and:SI (not:SI (match_operand:SI 1 "register_operand" "r"))
4015 (match_operand:SI 2 "register_operand" "0")))]
4016 "TARGET_H8300H || TARGET_H8300S"
4018 "&& reload_completed"
4019 [(set (cc0) (compare (zero_extract:SI (match_dup 1)
4024 (if_then_else (ne (cc0)
4026 (label_ref (match_dup 3))
4029 (plus:SI (match_dup 2)
4033 operands[3] = gen_label_rtx ();
4038 (define_insn "*ixorhi3_zext"
4039 [(set (match_operand:HI 0 "register_operand" "=r")
4040 (match_operator:HI 1 "iorxor_operator"
4041 [(zero_extend:HI (match_operand:QI 2 "register_operand" "r"))
4042 (match_operand:HI 3 "register_operand" "0")]))]
4045 [(set_attr "length" "2")])
4049 (define_insn "*ixorsi3_zext_qi"
4050 [(set (match_operand:SI 0 "register_operand" "=r")
4051 (match_operator:SI 1 "iorxor_operator"
4052 [(zero_extend:SI (match_operand:QI 2 "register_operand" "r"))
4053 (match_operand:SI 3 "register_operand" "0")]))]
4056 [(set_attr "length" "2")])
4058 (define_insn "*ixorsi3_zext_hi"
4059 [(set (match_operand:SI 0 "register_operand" "=r")
4060 (match_operator:SI 1 "iorxor_operator"
4061 [(zero_extend:SI (match_operand:HI 2 "register_operand" "r"))
4062 (match_operand:SI 3 "register_operand" "0")]))]
4063 "TARGET_H8300H || TARGET_H8300S"
4065 [(set_attr "length" "2")])
4067 (define_insn "*ixorsi3_ashift_16"
4068 [(set (match_operand:SI 0 "register_operand" "=r")
4069 (match_operator:SI 1 "iorxor_operator"
4070 [(ashift:SI (match_operand:SI 2 "register_operand" "r")
4072 (match_operand:SI 3 "register_operand" "0")]))]
4073 "TARGET_H8300H || TARGET_H8300S"
4075 [(set_attr "length" "2")])
4077 (define_insn "*ixorsi3_lshiftrt_16"
4078 [(set (match_operand:SI 0 "register_operand" "=r")
4079 (match_operator:SI 1 "iorxor_operator"
4080 [(lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
4082 (match_operand:SI 3 "register_operand" "0")]))]
4083 "TARGET_H8300H || TARGET_H8300S"
4085 [(set_attr "length" "2")])
4089 (define_insn "*iorhi3_ashift_8"
4090 [(set (match_operand:HI 0 "register_operand" "=r")
4091 (ior:HI (ashift:HI (match_operand:HI 1 "register_operand" "r")
4093 (match_operand:HI 2 "register_operand" "0")))]
4096 [(set_attr "length" "2")])
4098 (define_insn "*iorhi3_lshiftrt_8"
4099 [(set (match_operand:HI 0 "register_operand" "=r")
4100 (ior:HI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
4102 (match_operand:HI 2 "register_operand" "0")))]
4105 [(set_attr "length" "2")])
4107 (define_insn "*iorhi3_two_qi"
4108 [(set (match_operand:HI 0 "register_operand" "=r")
4109 (ior:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
4110 (ashift:HI (match_operand:HI 2 "register_operand" "r")
4114 [(set_attr "length" "2")])
4116 (define_insn "*iorhi3_two_qi_mem"
4117 [(set (match_operand:HI 0 "register_operand" "=&r")
4118 (ior:HI (zero_extend:HI (match_operand:QI 1 "memory_operand" "m"))
4119 (ashift:HI (subreg:HI (match_operand:QI 2 "memory_operand" "m") 0)
4122 "mov.b\\t%X2,%t0\;mov.b\\t%X1,%s0"
4123 [(set_attr "length" "16")])
4126 [(set (match_operand:HI 0 "register_operand" "")
4127 (ior:HI (zero_extend:HI (match_operand:QI 1 "memory_operand" ""))
4128 (ashift:HI (subreg:HI (match_operand:QI 2 "memory_operand" "") 0)
4130 "(TARGET_H8300H || TARGET_H8300S)
4132 && byte_accesses_mergeable_p (XEXP (operands[2], 0), XEXP (operands[1], 0))"
4136 operands[3] = gen_rtx_MEM (HImode, XEXP (operands[2], 0));
4141 (define_insn "*iorsi3_two_hi"
4142 [(set (match_operand:SI 0 "register_operand" "=r")
4143 (ior:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "0"))
4144 (ashift:SI (match_operand:SI 2 "register_operand" "r")
4146 "TARGET_H8300H || TARGET_H8300S"
4148 [(set_attr "length" "2")])
4150 (define_insn_and_split "*iorsi3_two_qi_zext"
4151 [(set (match_operand:SI 0 "register_operand" "=&r")
4152 (ior:SI (zero_extend:SI (match_operand:QI 1 "memory_operand" "m"))
4153 (and:SI (ashift:SI (subreg:SI (match_operand:QI 2 "memory_operand" "m") 0)
4155 (const_int 65280))))]
4156 "TARGET_H8300H || TARGET_H8300S"
4158 "&& reload_completed"
4160 (ior:HI (zero_extend:HI (match_dup 1))
4161 (ashift:HI (subreg:HI (match_dup 2) 0)
4164 (zero_extend:SI (match_dup 3)))]
4166 operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4169 (define_insn "*iorsi3_e2f"
4170 [(set (match_operand:SI 0 "register_operand" "=r")
4171 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0")
4173 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
4175 "TARGET_H8300H || TARGET_H8300S"
4177 [(set_attr "length" "2")])
4179 (define_insn_and_split "*iorsi3_two_qi_sext"
4180 [(set (match_operand:SI 0 "register_operand" "=r")
4181 (ior:SI (zero_extend:SI (match_operand:QI 1 "register_operand" "0"))
4182 (ashift:SI (sign_extend:SI (match_operand:QI 2 "register_operand" "r"))
4184 "TARGET_H8300H || TARGET_H8300S"
4186 "&& reload_completed"
4188 (ior:HI (zero_extend:HI (match_dup 1))
4189 (ashift:HI (match_dup 4)
4192 (sign_extend:SI (match_dup 3)))]
4194 operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4195 operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));
4198 (define_insn "*iorsi3_w"
4199 [(set (match_operand:SI 0 "register_operand" "=r,&r")
4200 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0,0")
4202 (zero_extend:SI (match_operand:QI 2 "general_operand_src" "r,g>"))))]
4203 "TARGET_H8300H || TARGET_H8300S"
4205 [(set_attr "length" "2,8")])
4207 (define_insn "*iorsi3_ashift_31"
4208 [(set (match_operand:SI 0 "register_operand" "=&r")
4209 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
4211 (match_operand:SI 2 "register_operand" "0")))]
4212 "TARGET_H8300H || TARGET_H8300S"
4213 "rotxl.l\\t%S0\;bor\\t#0,%w1\;rotxr.l\\t%S0"
4214 [(set_attr "length" "6")
4215 (set_attr "cc" "set_znv")])
4217 (define_insn "*iorsi3_and_ashift"
4218 [(set (match_operand:SI 0 "register_operand" "=r")
4219 (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
4220 (match_operand:SI 2 "const_int_operand" "n"))
4221 (match_operand:SI 3 "single_one_operand" "n"))
4222 (match_operand:SI 4 "register_operand" "0")))]
4223 "(TARGET_H8300H || TARGET_H8300S)
4224 && (INTVAL (operands[3]) & ~0xffff) == 0"
4226 rtx srcpos = GEN_INT (exact_log2 (INTVAL (operands[3]))
4227 - INTVAL (operands[2]));
4228 rtx dstpos = GEN_INT (exact_log2 (INTVAL (operands[3])));
4229 operands[2] = srcpos;
4230 operands[3] = dstpos;
4231 return "bld\\t%Z2,%Y1\;bor\\t%Z3,%Y0\;bst\\t%Z3,%Y0";
4233 [(set_attr "length" "6")])
4235 (define_insn "*iorsi3_and_lshiftrt"
4236 [(set (match_operand:SI 0 "register_operand" "=r")
4237 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4238 (match_operand:SI 2 "const_int_operand" "n"))
4239 (match_operand:SI 3 "single_one_operand" "n"))
4240 (match_operand:SI 4 "register_operand" "0")))]
4241 "(TARGET_H8300H || TARGET_H8300S)
4242 && ((INTVAL (operands[3]) << INTVAL (operands[2])) & ~0xffff) == 0"
4244 rtx srcpos = GEN_INT (exact_log2 (INTVAL (operands[3]))
4245 + INTVAL (operands[2]));
4246 rtx dstpos = GEN_INT (exact_log2 (INTVAL (operands[3])));
4247 operands[2] = srcpos;
4248 operands[3] = dstpos;
4249 return "bld\\t%Z2,%Y1\;bor\\t%Z3,%Y0\;bst\\t%Z3,%Y0";
4251 [(set_attr "length" "6")])
4253 (define_insn "*iorsi3_zero_extract"
4254 [(set (match_operand:SI 0 "register_operand" "=r")
4255 (ior:SI (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
4257 (match_operand:SI 2 "const_int_operand" "n"))
4258 (match_operand:SI 3 "register_operand" "0")))]
4259 "(TARGET_H8300H || TARGET_H8300S) && INTVAL (operands[2]) < 16"
4260 "bld\\t%Z2,%Y1\;bor\\t#0,%w0\;bst\\t#0,%w0"
4261 [(set_attr "length" "6")])
4263 (define_insn "*iorsi3_and_lshiftrt_n_sb"
4264 [(set (match_operand:SI 0 "register_operand" "=r")
4265 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4268 (match_operand:SI 2 "register_operand" "0")))]
4269 "TARGET_H8300H || TARGET_H8300S"
4270 "rotl.l\\t%S1\;rotr.l\\t%S1\;bor\\t#1,%w0\;bst\\t#1,%w0"
4271 [(set_attr "length" "8")])
4273 (define_insn "*iorsi3_and_lshiftrt_9_sb"
4274 [(set (match_operand:SI 0 "register_operand" "=r")
4275 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4277 (const_int 4194304))
4278 (match_operand:SI 2 "register_operand" "0")))
4279 (clobber (match_scratch:HI 3 "=&r"))]
4280 "TARGET_H8300H || TARGET_H8300S"
4282 if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4283 return "shll.l\\t%S1\;xor.w\\t%T3,%T3\;bst\\t#6,%s3\;or.w\\t%T3,%e0";
4285 return "rotl.l\\t%S1\;rotr.l\\t%S1\;xor.w\\t%T3,%T3\;bst\\t#6,%s3\;or.w\\t%T3,%e0";
4287 [(set_attr "length" "10")])
4289 ;; Used to OR the exponent of a float.
4291 (define_insn "*iorsi3_shift"
4292 [(set (match_operand:SI 0 "register_operand" "=r")
4293 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
4295 (match_operand:SI 2 "register_operand" "0")))
4296 (clobber (match_scratch:SI 3 "=&r"))]
4297 "TARGET_H8300H || TARGET_H8300S"
4301 [(set (match_operand:SI 0 "register_operand" "")
4302 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4305 (clobber (match_operand:SI 2 "register_operand" ""))]
4306 "(TARGET_H8300H || TARGET_H8300S)
4307 && epilogue_completed
4308 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4309 && REGNO (operands[0]) != REGNO (operands[1])"
4310 [(parallel [(set (match_dup 3)
4311 (ashift:HI (match_dup 3)
4313 (clobber (scratch:QI))])
4315 (ior:SI (ashift:SI (match_dup 1)
4319 operands[3] = gen_rtx_REG (HImode, REGNO (operands[1]));
4323 [(set (match_operand:SI 0 "register_operand" "")
4324 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4327 (clobber (match_operand:SI 2 "register_operand" ""))]
4328 "(TARGET_H8300H || TARGET_H8300S)
4329 && epilogue_completed
4330 && !(find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4331 && REGNO (operands[0]) != REGNO (operands[1]))"
4334 (parallel [(set (match_dup 3)
4335 (ashift:HI (match_dup 3)
4337 (clobber (scratch:QI))])
4339 (ior:SI (ashift:SI (match_dup 2)
4343 operands[3] = gen_rtx_REG (HImode, REGNO (operands[2]));
4346 (define_insn "*iorsi2_and_1_lshiftrt_1"
4347 [(set (match_operand:SI 0 "register_operand" "=r")
4348 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0")
4350 (lshiftrt:SI (match_dup 1)
4352 "TARGET_H8300H || TARGET_H8300S"
4353 "shlr.l\\t%S0\;bor\\t#0,%w0\;bst\\t#0,%w0"
4354 [(set_attr "length" "6")])
4356 (define_insn_and_split "*iorsi3_ashift_16_ashift_24"
4357 [(set (match_operand:SI 0 "register_operand" "=r")
4358 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
4360 (ashift:SI (match_operand:SI 2 "register_operand" "r")
4362 "TARGET_H8300H || TARGET_H8300S"
4364 "&& reload_completed"
4366 (ior:HI (ashift:HI (match_dup 4)
4369 (parallel [(set (match_dup 0)
4370 (ashift:SI (match_dup 0)
4372 (clobber (scratch:QI))])]
4374 operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4375 operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));
4378 (define_insn_and_split "*iorsi3_ashift_16_ashift_24_mem"
4379 [(set (match_operand:SI 0 "register_operand" "=&r")
4380 (ior:SI (and:SI (ashift:SI (subreg:SI (match_operand:QI 1 "memory_operand" "m") 0)
4382 (const_int 16711680))
4383 (ashift:SI (subreg:SI (match_operand:QI 2 "memory_operand" "m") 0)
4385 "TARGET_H8300H || TARGET_H8300S"
4387 "&& reload_completed"
4389 (ior:HI (zero_extend:HI (match_dup 1))
4390 (ashift:HI (subreg:HI (match_dup 2) 0)
4392 (parallel [(set (match_dup 0)
4393 (ashift:SI (match_dup 0)
4395 (clobber (scratch:QI))])]
4397 operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4400 ;; Used to add the exponent of a float.
4402 (define_insn "*addsi3_shift"
4403 [(set (match_operand:SI 0 "register_operand" "=r")
4404 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
4405 (const_int 8388608))
4406 (match_operand:SI 2 "register_operand" "0")))
4407 (clobber (match_scratch:SI 3 "=&r"))]
4408 "TARGET_H8300H || TARGET_H8300S"
4412 [(set (match_operand:SI 0 "register_operand" "")
4413 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
4414 (const_int 8388608))
4416 (clobber (match_operand:SI 2 "register_operand" ""))]
4417 "(TARGET_H8300H || TARGET_H8300S)
4418 && epilogue_completed
4419 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4420 && REGNO (operands[0]) != REGNO (operands[1])"
4421 [(parallel [(set (match_dup 3)
4422 (ashift:HI (match_dup 3)
4424 (clobber (scratch:QI))])
4426 (plus:SI (mult:SI (match_dup 1)
4430 operands[3] = gen_rtx_REG (HImode, REGNO (operands[1]));
4434 [(set (match_operand:SI 0 "register_operand" "")
4435 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
4436 (const_int 8388608))
4438 (clobber (match_operand:SI 2 "register_operand" ""))]
4439 "(TARGET_H8300H || TARGET_H8300S)
4440 && epilogue_completed
4441 && !(find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4442 && REGNO (operands[0]) != REGNO (operands[1]))"
4445 (parallel [(set (match_dup 3)
4446 (ashift:HI (match_dup 3)
4448 (clobber (scratch:QI))])
4450 (plus:SI (mult:SI (match_dup 2)
4454 operands[3] = gen_rtx_REG (HImode, REGNO (operands[2]));
4459 (define_insn_and_split "*ashiftsi_sextqi_7"
4460 [(set (match_operand:SI 0 "register_operand" "=r")
4461 (ashift:SI (sign_extend:SI (match_operand:QI 1 "register_operand" "0"))
4463 "TARGET_H8300H || TARGET_H8300S"
4465 "&& reload_completed"
4466 [(parallel [(set (match_dup 2)
4467 (ashift:HI (match_dup 2)
4469 (clobber (scratch:QI))])
4471 (sign_extend:SI (match_dup 2)))
4472 (parallel [(set (match_dup 0)
4473 (ashiftrt:SI (match_dup 0)
4475 (clobber (scratch:QI))])]
4477 operands[2] = gen_rtx_REG (HImode, REGNO (operands[0]));
4480 ;; Storing a part of HImode to QImode.
4483 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4484 (subreg:QI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
4488 [(set_attr "cc" "set_znv")
4489 (set_attr "length" "8")])
4491 ;; Storing a part of SImode to QImode.
4494 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4495 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4499 [(set_attr "cc" "set_znv")
4500 (set_attr "length" "8")])
4503 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4504 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4506 (clobber (match_scratch:SI 2 "=&r"))]
4507 "TARGET_H8300H || TARGET_H8300S"
4508 "mov.w\\t%e1,%f2\;mov.b\\t%w2,%R0"
4509 [(set_attr "cc" "set_znv")
4510 (set_attr "length" "10")])
4513 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4514 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4516 (clobber (match_scratch:SI 2 "=&r"))]
4517 "TARGET_H8300H || TARGET_H8300S"
4518 "mov.w\\t%e1,%f2\;mov.b\\t%x2,%R0"
4519 [(set_attr "cc" "set_znv")
4520 (set_attr "length" "10")])
4522 (define_insn_and_split ""
4524 (if_then_else (eq (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
4528 (label_ref (match_operand 1 "" ""))
4533 [(set (cc0) (compare (match_dup 0)
4536 (if_then_else (ge (cc0)
4538 (label_ref (match_dup 1))
4542 (define_insn_and_split ""
4544 (if_then_else (ne (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
4548 (label_ref (match_operand 1 "" ""))
4553 [(set (cc0) (compare (match_dup 0)
4556 (if_then_else (lt (cc0)
4558 (label_ref (match_dup 1))
4562 ;; -----------------------------------------------------------------
4563 ;; PEEPHOLE PATTERNS
4564 ;; -----------------------------------------------------------------
4566 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
4569 [(parallel [(set (match_operand:HI 0 "register_operand" "")
4570 (lshiftrt:HI (match_dup 0)
4571 (match_operand:HI 1 "const_int_operand" "")))
4572 (clobber (match_operand:HI 2 "" ""))])
4574 (and:HI (match_dup 0)
4575 (match_operand:HI 3 "const_int_operand" "")))]
4576 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
4578 (and:HI (match_dup 0)
4580 (parallel [(set (match_dup 0)
4581 (lshiftrt:HI (match_dup 0) (match_dup 1)))
4582 (clobber (match_dup 2))])]
4585 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
4588 [(parallel [(set (match_operand:HI 0 "register_operand" "")
4589 (ashift:HI (match_dup 0)
4590 (match_operand:HI 1 "const_int_operand" "")))
4591 (clobber (match_operand:HI 2 "" ""))])
4593 (and:HI (match_dup 0)
4594 (match_operand:HI 3 "const_int_operand" "")))]
4595 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
4597 (and:HI (match_dup 0)
4599 (parallel [(set (match_dup 0)
4600 (ashift:HI (match_dup 0) (match_dup 1)))
4601 (clobber (match_dup 2))])]
4604 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
4607 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4608 (lshiftrt:SI (match_dup 0)
4609 (match_operand:SI 1 "const_int_operand" "")))
4610 (clobber (match_operand:SI 2 "" ""))])
4612 (and:SI (match_dup 0)
4613 (match_operand:SI 3 "const_int_operand" "")))]
4614 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
4616 (and:SI (match_dup 0)
4618 (parallel [(set (match_dup 0)
4619 (lshiftrt:SI (match_dup 0) (match_dup 1)))
4620 (clobber (match_dup 2))])]
4623 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
4626 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4627 (ashift:SI (match_dup 0)
4628 (match_operand:SI 1 "const_int_operand" "")))
4629 (clobber (match_operand:SI 2 "" ""))])
4631 (and:SI (match_dup 0)
4632 (match_operand:SI 3 "const_int_operand" "")))]
4633 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
4635 (and:SI (match_dup 0)
4637 (parallel [(set (match_dup 0)
4638 (ashift:SI (match_dup 0) (match_dup 1)))
4639 (clobber (match_dup 2))])]
4642 ;; Convert (A >> B) & C to (A & 65535) >> B if C == 65535 >> B.
4645 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4646 (lshiftrt:SI (match_dup 0)
4647 (match_operand:SI 1 "const_int_operand" "")))
4648 (clobber (match_operand:SI 2 "" ""))])
4650 (and:SI (match_dup 0)
4651 (match_operand:SI 3 "const_int_operand" "")))]
4652 "INTVAL (operands[3]) == (65535 >> INTVAL (operands[1]))"
4654 (and:SI (match_dup 0)
4656 (parallel [(set (match_dup 0)
4657 (lshiftrt:SI (match_dup 0) (match_dup 1)))
4658 (clobber (match_dup 2))])]
4661 ;; Convert (A << B) & C to (A & 65535) << B if C == 65535 << B.
4664 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4665 (ashift:SI (match_dup 0)
4666 (match_operand:SI 1 "const_int_operand" "")))
4667 (clobber (match_operand:SI 2 "" ""))])
4669 (and:SI (match_dup 0)
4670 (match_operand:SI 3 "const_int_operand" "")))]
4671 "INTVAL (operands[3]) == (65535 << INTVAL (operands[1]))"
4673 (and:SI (match_dup 0)
4675 (parallel [(set (match_dup 0)
4676 (ashift:SI (match_dup 0) (match_dup 1)))
4677 (clobber (match_dup 2))])]
4680 ;; Convert a QImode push into an SImode push so that the
4681 ;; define_peephole2 below can cram multiple pushes into one stm.l.
4684 [(parallel [(set (reg:SI SP_REG)
4685 (plus:SI (reg:SI SP_REG) (const_int -4)))
4686 (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
4687 (match_operand:QI 0 "register_operand" ""))])]
4688 "TARGET_H8300S && !TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4689 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4692 operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));
4696 [(parallel [(set (reg:HI SP_REG)
4697 (plus:HI (reg:HI SP_REG) (const_int -4)))
4698 (set (mem:QI (plus:HI (reg:HI SP_REG) (const_int -3)))
4699 (match_operand:QI 0 "register_operand" ""))])]
4700 "TARGET_H8300S && TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4701 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4704 operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));
4707 ;; Convert a HImode push into an SImode push so that the
4708 ;; define_peephole2 below can cram multiple pushes into one stm.l.
4711 [(parallel [(set (reg:SI SP_REG)
4712 (plus:SI (reg:SI SP_REG) (const_int -4)))
4713 (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
4714 (match_operand:HI 0 "register_operand" ""))])]
4715 "TARGET_H8300S && !TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4716 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4719 operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));
4723 [(parallel [(set (reg:HI SP_REG)
4724 (plus:HI (reg:HI SP_REG) (const_int -4)))
4725 (set (mem:HI (plus:HI (reg:HI SP_REG) (const_int -2)))
4726 (match_operand:HI 0 "register_operand" ""))])]
4727 "TARGET_H8300S && TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4728 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4731 operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));
4734 ;; Cram four pushes into stm.l.
4737 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4738 (match_operand:SI 0 "register_operand" ""))
4739 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4740 (match_operand:SI 1 "register_operand" ""))
4741 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4742 (match_operand:SI 2 "register_operand" ""))
4743 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4744 (match_operand:SI 3 "register_operand" ""))]
4745 "TARGET_H8300S && !TARGET_NORMAL_MODE
4746 && (REGNO_REG_CLASS (REGNO (operands[3])) == GENERAL_REGS
4747 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4748 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4749 && REGNO (operands[3]) == REGNO (operands[0]) + 3
4750 && (TARGET_H8300SX || REGNO (operands[0]) == 0))"
4751 [(parallel [(set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
4753 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
4755 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
4757 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
4759 (set (reg:SI SP_REG)
4760 (plus:SI (reg:SI SP_REG)
4761 (const_int -16)))])]
4765 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4766 (match_operand:SI 0 "register_operand" ""))
4767 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4768 (match_operand:SI 1 "register_operand" ""))
4769 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4770 (match_operand:SI 2 "register_operand" ""))
4771 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4772 (match_operand:SI 3 "register_operand" ""))]
4773 "TARGET_H8300S && TARGET_NORMAL_MODE
4774 && (REGNO_REG_CLASS (REGNO (operands[3])) == GENERAL_REGS
4775 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4776 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4777 && REGNO (operands[3]) == REGNO (operands[0]) + 3
4778 && (TARGET_H8300SX || REGNO (operands[0]) == 0))"
4779 [(parallel [(set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -4)))
4781 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -8)))
4783 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -12)))
4785 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -16)))
4787 (set (reg:HI SP_REG)
4788 (plus:HI (reg:HI SP_REG)
4789 (const_int -16)))])]
4792 ;; Cram three pushes into stm.l.
4795 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4796 (match_operand:SI 0 "register_operand" ""))
4797 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4798 (match_operand:SI 1 "register_operand" ""))
4799 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4800 (match_operand:SI 2 "register_operand" ""))]
4801 "TARGET_H8300S && !TARGET_NORMAL_MODE
4802 && (REGNO_REG_CLASS (REGNO (operands[2])) == GENERAL_REGS
4803 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4804 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4805 && (TARGET_H8300SX || (REGNO (operands[0]) & 3) == 0))"
4806 [(parallel [(set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
4808 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
4810 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
4812 (set (reg:SI SP_REG)
4813 (plus:SI (reg:SI SP_REG)
4814 (const_int -12)))])]
4818 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4819 (match_operand:SI 0 "register_operand" ""))
4820 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4821 (match_operand:SI 1 "register_operand" ""))
4822 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4823 (match_operand:SI 2 "register_operand" ""))]
4824 "TARGET_H8300S && TARGET_NORMAL_MODE
4825 && (REGNO_REG_CLASS (REGNO (operands[2])) == GENERAL_REGS
4826 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4827 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4828 && (TARGET_H8300SX || (REGNO (operands[0]) & 3) == 0))"
4829 [(parallel [(set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -4)))
4831 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -8)))
4833 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -12)))
4835 (set (reg:HI SP_REG)
4836 (plus:HI (reg:HI SP_REG)
4837 (const_int -12)))])]
4840 ;; Cram two pushes into stm.l.
4843 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4844 (match_operand:SI 0 "register_operand" ""))
4845 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4846 (match_operand:SI 1 "register_operand" ""))]
4847 "TARGET_H8300S && !TARGET_NORMAL_MODE
4848 && (REGNO_REG_CLASS (REGNO (operands[1])) == GENERAL_REGS
4849 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4850 && (TARGET_H8300SX || (REGNO (operands[0]) & 1) == 0))"
4851 [(parallel [(set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
4853 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
4855 (set (reg:SI SP_REG)
4856 (plus:SI (reg:SI SP_REG)
4861 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4862 (match_operand:SI 0 "register_operand" ""))
4863 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4864 (match_operand:SI 1 "register_operand" ""))]
4865 "TARGET_H8300S && TARGET_NORMAL_MODE
4866 && (REGNO_REG_CLASS (REGNO (operands[1])) == GENERAL_REGS
4867 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4868 && (TARGET_H8300SX || (REGNO (operands[0]) & 1) == 0))"
4869 [(parallel [(set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -4)))
4871 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -8)))
4873 (set (reg:HI SP_REG)
4874 (plus:HI (reg:HI SP_REG)
4881 ;; add.w r7,r0 (6 bytes)
4886 ;; adds #2,r0 (4 bytes)
4889 [(set (match_operand:HI 0 "register_operand" "")
4890 (match_operand:HI 1 "const_int_operand" ""))
4892 (plus:HI (match_dup 0)
4893 (match_operand:HI 2 "register_operand" "")))]
4894 "REG_P (operands[0]) && REG_P (operands[2])
4895 && REGNO (operands[0]) != REGNO (operands[2])
4896 && (satisfies_constraint_J (operands[1])
4897 || satisfies_constraint_L (operands[1])
4898 || satisfies_constraint_N (operands[1]))"
4902 (plus:HI (match_dup 0)
4910 ;; add.l er7,er0 (6 bytes)
4915 ;; adds #4,er0 (4 bytes)
4918 [(set (match_operand:SI 0 "register_operand" "")
4919 (match_operand:SI 1 "const_int_operand" ""))
4921 (plus:SI (match_dup 0)
4922 (match_operand:SI 2 "register_operand" "")))]
4923 "(TARGET_H8300H || TARGET_H8300S)
4924 && REG_P (operands[0]) && REG_P (operands[2])
4925 && REGNO (operands[0]) != REGNO (operands[2])
4926 && (satisfies_constraint_L (operands[1])
4927 || satisfies_constraint_N (operands[1]))"
4931 (plus:SI (match_dup 0)
4938 ;; add.l #10,er0 (takes 8 bytes)
4944 ;; add.l er7,er0 (takes 6 bytes)
4947 [(set (match_operand:SI 0 "register_operand" "")
4948 (match_operand:SI 1 "register_operand" ""))
4950 (plus:SI (match_dup 0)
4951 (match_operand:SI 2 "const_int_operand" "")))]
4952 "(TARGET_H8300H || TARGET_H8300S)
4953 && REG_P (operands[0]) && REG_P (operands[1])
4954 && REGNO (operands[0]) != REGNO (operands[1])
4955 && !satisfies_constraint_L (operands[2])
4956 && !satisfies_constraint_N (operands[2])
4957 && ((INTVAL (operands[2]) & 0xff) == INTVAL (operands[2])
4958 || (INTVAL (operands[2]) & 0xff00) == INTVAL (operands[2])
4959 || INTVAL (operands[2]) == 0xffff
4960 || INTVAL (operands[2]) == 0xfffe)"
4964 (plus:SI (match_dup 0)
4980 [(set (match_operand:HI 0 "register_operand" "")
4981 (plus:HI (match_dup 0)
4982 (match_operand 1 "incdec_operand" "")))
4983 (set (cc0) (compare (match_dup 0)
4986 (if_then_else (match_operator 3 "eqne_operator"
4987 [(cc0) (const_int 0)])
4988 (label_ref (match_operand 2 "" ""))
4990 "TARGET_H8300H || TARGET_H8300S"
4991 [(set (match_operand:HI 0 "register_operand" "")
4992 (unspec:HI [(match_dup 0)
4995 (set (cc0) (compare (match_dup 0)
4998 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4999 (label_ref (match_dup 2))
5003 ;; The SImode version of the previous pattern.
5006 [(set (match_operand:SI 0 "register_operand" "")
5007 (plus:SI (match_dup 0)
5008 (match_operand 1 "incdec_operand" "")))
5009 (set (cc0) (compare (match_dup 0)
5012 (if_then_else (match_operator 3 "eqne_operator"
5013 [(cc0) (const_int 0)])
5014 (label_ref (match_operand 2 "" ""))
5016 "TARGET_H8300H || TARGET_H8300S"
5017 [(set (match_operand:SI 0 "register_operand" "")
5018 (unspec:SI [(match_dup 0)
5021 (set (cc0) (compare (match_dup 0)
5024 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5025 (label_ref (match_dup 2))
5030 [(parallel [(set (cc0)
5031 (compare (zero_extract:SI (match_operand:QI 0 "register_operand" "")
5035 (clobber (scratch:QI))])
5037 (if_then_else (match_operator 1 "eqne_operator"
5038 [(cc0) (const_int 0)])
5039 (label_ref (match_operand 2 "" ""))
5041 "TARGET_H8300H || TARGET_H8300S"
5042 [(set (cc0) (compare (match_dup 0)
5045 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5046 (label_ref (match_dup 2))
5049 operands[3] = ((GET_CODE (operands[1]) == EQ)
5050 ? gen_rtx_GE (VOIDmode, cc0_rtx, const0_rtx)
5051 : gen_rtx_LT (VOIDmode, cc0_rtx, const0_rtx));
5054 ;; The next three peephole2's will try to transform
5056 ;; mov.b A,r0l (or mov.l A,er0)
5063 ;; and.b #CST,r0l (if CST is not 255)
5066 [(set (match_operand:QI 0 "register_operand" "")
5067 (match_operand:QI 1 "general_operand" ""))
5068 (set (match_operand:SI 2 "register_operand" "")
5069 (and:SI (match_dup 2)
5071 "(TARGET_H8300H || TARGET_H8300S)
5072 && !reg_overlap_mentioned_p (operands[2], operands[1])
5073 && REGNO (operands[0]) == REGNO (operands[2])"
5076 (set (strict_low_part (match_dup 0))
5081 [(set (match_operand:SI 0 "register_operand" "")
5082 (match_operand:SI 1 "general_operand" ""))
5084 (and:SI (match_dup 0)
5086 "(TARGET_H8300H || TARGET_H8300S)
5087 && !reg_overlap_mentioned_p (operands[0], operands[1])
5088 && !(GET_CODE (operands[1]) == MEM && !offsettable_memref_p (operands[1]))
5089 && !(GET_CODE (operands[1]) == MEM && MEM_VOLATILE_P (operands[1]))"
5092 (set (strict_low_part (match_dup 2))
5095 operands[2] = gen_lowpart (QImode, operands[0]);
5096 operands[3] = gen_lowpart (QImode, operands[1]);
5100 [(set (match_operand 0 "register_operand" "")
5101 (match_operand 1 "general_operand" ""))
5102 (set (match_operand:SI 2 "register_operand" "")
5103 (and:SI (match_dup 2)
5104 (match_operand:SI 3 "const_int_qi_operand" "")))]
5105 "(TARGET_H8300H || TARGET_H8300S)
5106 && (GET_MODE (operands[0]) == QImode
5107 || GET_MODE (operands[0]) == HImode
5108 || GET_MODE (operands[0]) == SImode)
5109 && GET_MODE (operands[0]) == GET_MODE (operands[1])
5110 && REGNO (operands[0]) == REGNO (operands[2])
5111 && !reg_overlap_mentioned_p (operands[2], operands[1])
5112 && !(GET_MODE (operands[1]) != QImode
5113 && GET_CODE (operands[1]) == MEM
5114 && !offsettable_memref_p (operands[1]))
5115 && !(GET_MODE (operands[1]) != QImode
5116 && GET_CODE (operands[1]) == MEM
5117 && MEM_VOLATILE_P (operands[1]))"
5120 (set (strict_low_part (match_dup 4))
5123 (and:SI (match_dup 2)
5126 operands[4] = gen_lowpart (QImode, operands[0]);
5127 operands[5] = gen_lowpart (QImode, operands[1]);
5128 operands[6] = GEN_INT (~0xff | INTVAL (operands[3]));
5132 [(set (match_operand:SI 0 "register_operand" "")
5133 (match_operand:SI 1 "register_operand" ""))
5135 (and:SI (match_dup 0)
5136 (const_int 65280)))]
5137 "(TARGET_H8300H || TARGET_H8300S)
5138 && !reg_overlap_mentioned_p (operands[0], operands[1])"
5141 (set (zero_extract:SI (match_dup 0)
5144 (lshiftrt:SI (match_dup 1)
5148 ;; If a load of mem:SI is followed by an AND that turns off the upper
5149 ;; half, then we can load mem:HI instead.
5152 [(set (match_operand:SI 0 "register_operand" "")
5153 (match_operand:SI 1 "memory_operand" ""))
5155 (and:SI (match_dup 0)
5156 (match_operand:SI 2 "const_int_operand" "")))]
5157 "(TARGET_H8300H || TARGET_H8300S)
5158 && !MEM_VOLATILE_P (operands[1])
5159 && offsettable_memref_p (operands[1])
5160 && (INTVAL (operands[2]) & ~0xffff) == 0
5161 && INTVAL (operands[2]) != 255"
5165 (and:SI (match_dup 0)
5168 operands[3] = gen_lowpart (HImode, operands[0]);
5169 operands[4] = gen_lowpart (HImode, operands[1]);
5172 ;; Convert a memory comparison to a move if there is a scratch register.
5175 [(match_scratch:QI 1 "r")
5177 (compare (match_operand:QI 0 "memory_operand" "")
5182 (set (cc0) (compare (match_dup 1)
5187 [(match_scratch:HI 1 "r")
5189 (compare (match_operand:HI 0 "memory_operand" "")
5191 "TARGET_H8300H || TARGET_H8300S"
5194 (set (cc0) (compare (match_dup 1)
5199 [(match_scratch:SI 1 "r")
5201 (compare (match_operand:SI 0 "memory_operand" "")
5203 "TARGET_H8300H || TARGET_H8300S"
5206 (set (cc0) (compare (match_dup 1)
5211 ;; (compare (reg:HI) (const_int)) takes 4 bytes, so we try to achieve
5212 ;; the equivalent with shorter sequences. Here is the summary. Cases
5213 ;; are grouped for each define_peephole2.
5215 ;; reg const_int use insn
5216 ;; --------------------------------------------------------
5217 ;; dead -2 eq/ne inc.l
5218 ;; dead -1 eq/ne inc.l
5219 ;; dead 1 eq/ne dec.l
5220 ;; dead 2 eq/ne dec.l
5222 ;; dead 1 ge/lt shar.l
5223 ;; dead 3 (H8S) ge/lt shar.l
5225 ;; dead 1 geu/ltu shar.l
5226 ;; dead 3 (H8S) geu/ltu shar.l
5228 ;; ---- 255 ge/lt mov.b
5230 ;; ---- 255 geu/ltu mov.b
5244 (compare (match_operand:HI 0 "register_operand" "")
5245 (match_operand:HI 1 "incdec_operand" "")))
5247 (if_then_else (match_operator 3 "eqne_operator"
5248 [(cc0) (const_int 0)])
5249 (label_ref (match_operand 2 "" ""))
5251 "(TARGET_H8300H || TARGET_H8300S)
5252 && INTVAL (operands[1]) != 0
5253 && peep2_reg_dead_p (1, operands[0])"
5255 (unspec:HI [(match_dup 0)
5258 (set (cc0) (compare (match_dup 0)
5261 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5262 (label_ref (match_dup 2))
5265 operands[4] = GEN_INT (- INTVAL (operands[1]));
5280 (compare (match_operand:HI 0 "register_operand" "")
5281 (match_operand:HI 1 "const_int_operand" "")))
5283 (if_then_else (match_operator 2 "gtle_operator"
5284 [(cc0) (const_int 0)])
5285 (label_ref (match_operand 3 "" ""))
5287 "(TARGET_H8300H || TARGET_H8300S)
5288 && peep2_reg_dead_p (1, operands[0])
5289 && (INTVAL (operands[1]) == 1
5290 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5291 [(parallel [(set (match_dup 0)
5292 (ashiftrt:HI (match_dup 0)
5294 (clobber (scratch:QI))])
5295 (set (cc0) (compare (match_dup 0)
5298 (if_then_else (match_dup 2)
5299 (label_ref (match_dup 3))
5302 operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5317 (compare (match_operand:HI 0 "register_operand" "")
5318 (match_operand:HI 1 "const_int_operand" "")))
5320 (if_then_else (match_operator 2 "gtuleu_operator"
5321 [(cc0) (const_int 0)])
5322 (label_ref (match_operand 3 "" ""))
5324 "(TARGET_H8300H || TARGET_H8300S)
5325 && peep2_reg_dead_p (1, operands[0])
5326 && (INTVAL (operands[1]) == 1
5327 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5328 [(parallel [(set (match_dup 0)
5329 (ashiftrt:HI (match_dup 0)
5331 (clobber (scratch:QI))])
5332 (set (cc0) (compare (match_dup 0)
5335 (if_then_else (match_dup 5)
5336 (label_ref (match_dup 3))
5339 operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5340 operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5341 VOIDmode, cc0_rtx, const0_rtx);
5356 (compare (match_operand:HI 0 "register_operand" "")
5359 (if_then_else (match_operator 1 "gtle_operator"
5360 [(cc0) (const_int 0)])
5361 (label_ref (match_operand 2 "" ""))
5363 "TARGET_H8300H || TARGET_H8300S"
5364 [(set (cc0) (compare (and:HI (match_dup 0)
5368 (if_then_else (match_dup 1)
5369 (label_ref (match_dup 2))
5385 (compare (match_operand:HI 0 "register_operand" "")
5388 (if_then_else (match_operator 1 "gtuleu_operator"
5389 [(cc0) (const_int 0)])
5390 (label_ref (match_operand 2 "" ""))
5392 "TARGET_H8300H || TARGET_H8300S"
5393 [(set (cc0) (compare (and:HI (match_dup 0)
5397 (if_then_else (match_dup 3)
5398 (label_ref (match_dup 2))
5401 operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[1]) == GTU ? NE : EQ,
5402 VOIDmode, cc0_rtx, const0_rtx);
5405 ;; (compare (reg:SI) (const_int)) takes 6 bytes, so we try to achieve
5406 ;; the equivalent with shorter sequences. Here is the summary. Cases
5407 ;; are grouped for each define_peephole2.
5409 ;; reg const_int use insn
5410 ;; --------------------------------------------------------
5411 ;; live -2 eq/ne copy and inc.l
5412 ;; live -1 eq/ne copy and inc.l
5413 ;; live 1 eq/ne copy and dec.l
5414 ;; live 2 eq/ne copy and dec.l
5416 ;; dead -2 eq/ne inc.l
5417 ;; dead -1 eq/ne inc.l
5418 ;; dead 1 eq/ne dec.l
5419 ;; dead 2 eq/ne dec.l
5421 ;; dead -131072 eq/ne inc.w and test
5422 ;; dead -65536 eq/ne inc.w and test
5423 ;; dead 65536 eq/ne dec.w and test
5424 ;; dead 131072 eq/ne dec.w and test
5426 ;; dead 0x000000?? except 1 and 2 eq/ne xor.b and test
5427 ;; dead 0x0000??00 eq/ne xor.b and test
5428 ;; dead 0x0000ffff eq/ne not.w and test
5430 ;; dead 0xffffff?? except -1 and -2 eq/ne xor.b and not.l
5431 ;; dead 0xffff??ff eq/ne xor.b and not.l
5432 ;; dead 0x40000000 (H8S) eq/ne rotl.l and dec.l
5433 ;; dead 0x80000000 eq/ne rotl.l and dec.l
5435 ;; live 1 ge/lt copy and shar.l
5436 ;; live 3 (H8S) ge/lt copy and shar.l
5438 ;; live 1 geu/ltu copy and shar.l
5439 ;; live 3 (H8S) geu/ltu copy and shar.l
5441 ;; dead 1 ge/lt shar.l
5442 ;; dead 3 (H8S) ge/lt shar.l
5444 ;; dead 1 geu/ltu shar.l
5445 ;; dead 3 (H8S) geu/ltu shar.l
5447 ;; dead 3 (H8/300H) ge/lt and.b and test
5448 ;; dead 7 ge/lt and.b and test
5449 ;; dead 15 ge/lt and.b and test
5450 ;; dead 31 ge/lt and.b and test
5451 ;; dead 63 ge/lt and.b and test
5452 ;; dead 127 ge/lt and.b and test
5453 ;; dead 255 ge/lt and.b and test
5455 ;; dead 3 (H8/300H) geu/ltu and.b and test
5456 ;; dead 7 geu/ltu and.b and test
5457 ;; dead 15 geu/ltu and.b and test
5458 ;; dead 31 geu/ltu and.b and test
5459 ;; dead 63 geu/ltu and.b and test
5460 ;; dead 127 geu/ltu and.b and test
5461 ;; dead 255 geu/ltu and.b and test
5463 ;; ---- 65535 ge/lt mov.w
5465 ;; ---- 65535 geu/ltu mov.w
5479 (compare (match_operand:SI 0 "register_operand" "")
5480 (match_operand:SI 1 "incdec_operand" "")))
5482 (if_then_else (match_operator 3 "eqne_operator"
5483 [(cc0) (const_int 0)])
5484 (label_ref (match_operand 2 "" ""))
5486 "(TARGET_H8300H || TARGET_H8300S)
5487 && INTVAL (operands[1]) != 0
5488 && peep2_reg_dead_p (1, operands[0])"
5490 (unspec:SI [(match_dup 0)
5493 (set (cc0) (compare (match_dup 0)
5496 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5497 (label_ref (match_dup 2))
5500 operands[4] = GEN_INT (- INTVAL (operands[1]));
5515 (compare (match_operand:SI 0 "register_operand" "")
5516 (match_operand:SI 1 "const_int_operand" "")))
5518 (if_then_else (match_operator 3 "eqne_operator"
5519 [(cc0) (const_int 0)])
5520 (label_ref (match_operand 2 "" ""))
5522 "(TARGET_H8300H || TARGET_H8300S)
5523 && peep2_reg_dead_p (1, operands[0])
5524 && (INTVAL (operands[1]) == -131072
5525 || INTVAL (operands[1]) == -65536
5526 || INTVAL (operands[1]) == 65536
5527 || INTVAL (operands[1]) == 131072)"
5529 (plus:SI (match_dup 0)
5531 (set (cc0) (compare (match_dup 0)
5534 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5535 (label_ref (match_dup 2))
5538 operands[4] = GEN_INT (- INTVAL (operands[1]));
5554 (compare (match_operand:SI 0 "register_operand" "")
5555 (match_operand:SI 1 "const_int_operand" "")))
5557 (if_then_else (match_operator 3 "eqne_operator"
5558 [(cc0) (const_int 0)])
5559 (label_ref (match_operand 2 "" ""))
5561 "(TARGET_H8300H || TARGET_H8300S)
5562 && peep2_reg_dead_p (1, operands[0])
5563 && ((INTVAL (operands[1]) & 0x00ff) == INTVAL (operands[1])
5564 || (INTVAL (operands[1]) & 0xff00) == INTVAL (operands[1])
5565 || INTVAL (operands[1]) == 0x0000ffff)
5566 && INTVAL (operands[1]) != 0
5567 && INTVAL (operands[1]) != 1
5568 && INTVAL (operands[1]) != 2"
5570 (xor:SI (match_dup 0)
5572 (set (cc0) (compare (match_dup 0)
5575 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5576 (label_ref (match_dup 2))
5593 (compare (match_operand:SI 0 "register_operand" "")
5594 (match_operand:SI 1 "const_int_operand" "")))
5596 (if_then_else (match_operator 3 "eqne_operator"
5597 [(cc0) (const_int 0)])
5598 (label_ref (match_operand 2 "" ""))
5600 "(TARGET_H8300H || TARGET_H8300S)
5601 && peep2_reg_dead_p (1, operands[0])
5602 && ((INTVAL (operands[1]) | 0x00ff) == -1
5603 || (INTVAL (operands[1]) | 0xff00) == -1)
5604 && INTVAL (operands[1]) != -1
5605 && INTVAL (operands[1]) != -2"
5607 (xor:SI (match_dup 0)
5610 (not:SI (match_dup 0)))
5611 (set (cc0) (compare (match_dup 0)
5614 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5615 (label_ref (match_dup 2))
5618 operands[4] = GEN_INT (INTVAL (operands[1]) ^ -1);
5623 ;; cmp.l #-2147483648,er0
5634 (compare (match_operand:SI 0 "register_operand" "")
5635 (match_operand:SI 1 "const_int_operand" "")))
5637 (if_then_else (match_operator 3 "eqne_operator"
5638 [(cc0) (const_int 0)])
5639 (label_ref (match_operand 2 "" ""))
5641 "(TARGET_H8300H || TARGET_H8300S)
5642 && peep2_reg_dead_p (1, operands[0])
5643 && (INTVAL (operands[1]) == -2147483647 - 1
5644 || (TARGET_H8300S && INTVAL (operands[1]) == 1073741824))"
5646 (rotate:SI (match_dup 0)
5649 (unspec:SI [(match_dup 0)
5652 (set (cc0) (compare (match_dup 0)
5655 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5656 (label_ref (match_dup 2))
5659 operands[4] = GEN_INT (INTVAL (operands[1]) == -2147483647 - 1 ? 1 : 2);
5673 ;; We avoid this transformation if we see more than one copy of the
5674 ;; same compare insn immediately before this one.
5677 [(match_scratch:SI 4 "r")
5679 (compare (match_operand:SI 0 "register_operand" "")
5680 (match_operand:SI 1 "const_int_operand" "")))
5682 (if_then_else (match_operator 2 "gtle_operator"
5683 [(cc0) (const_int 0)])
5684 (label_ref (match_operand 3 "" ""))
5686 "(TARGET_H8300H || TARGET_H8300S)
5687 && !peep2_reg_dead_p (1, operands[0])
5688 && (INTVAL (operands[1]) == 1
5689 || (TARGET_H8300S && INTVAL (operands[1]) == 3))
5690 && !same_cmp_preceding_p (insn)"
5693 (parallel [(set (match_dup 4)
5694 (ashiftrt:SI (match_dup 4)
5696 (clobber (scratch:QI))])
5697 (set (cc0) (compare (match_dup 4)
5700 (if_then_else (match_dup 2)
5701 (label_ref (match_dup 3))
5704 operands[5] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5718 ;; We avoid this transformation if we see more than one copy of the
5719 ;; same compare insn immediately before this one.
5722 [(match_scratch:SI 4 "r")
5724 (compare (match_operand:SI 0 "register_operand" "")
5725 (match_operand:SI 1 "const_int_operand" "")))
5727 (if_then_else (match_operator 2 "gtuleu_operator"
5728 [(cc0) (const_int 0)])
5729 (label_ref (match_operand 3 "" ""))
5731 "(TARGET_H8300H || TARGET_H8300S)
5732 && !peep2_reg_dead_p (1, operands[0])
5733 && (INTVAL (operands[1]) == 1
5734 || (TARGET_H8300S && INTVAL (operands[1]) == 3))
5735 && !same_cmp_preceding_p (insn)"
5738 (parallel [(set (match_dup 4)
5739 (ashiftrt:SI (match_dup 4)
5741 (clobber (scratch:QI))])
5742 (set (cc0) (compare (match_dup 4)
5745 (if_then_else (match_dup 6)
5746 (label_ref (match_dup 3))
5749 operands[5] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5750 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5751 VOIDmode, cc0_rtx, const0_rtx);
5766 (compare (match_operand:SI 0 "register_operand" "")
5767 (match_operand:SI 1 "const_int_operand" "")))
5769 (if_then_else (match_operator 2 "gtle_operator"
5770 [(cc0) (const_int 0)])
5771 (label_ref (match_operand 3 "" ""))
5773 "(TARGET_H8300H || TARGET_H8300S)
5774 && peep2_reg_dead_p (1, operands[0])
5775 && (INTVAL (operands[1]) == 1
5776 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5777 [(parallel [(set (match_dup 0)
5778 (ashiftrt:SI (match_dup 0)
5780 (clobber (scratch:QI))])
5781 (set (cc0) (compare (match_dup 0)
5784 (if_then_else (match_dup 2)
5785 (label_ref (match_dup 3))
5788 operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5803 (compare (match_operand:SI 0 "register_operand" "")
5804 (match_operand:SI 1 "const_int_operand" "")))
5806 (if_then_else (match_operator 2 "gtuleu_operator"
5807 [(cc0) (const_int 0)])
5808 (label_ref (match_operand 3 "" ""))
5810 "(TARGET_H8300H || TARGET_H8300S)
5811 && peep2_reg_dead_p (1, operands[0])
5812 && (INTVAL (operands[1]) == 1
5813 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5814 [(parallel [(set (match_dup 0)
5815 (ashiftrt:SI (match_dup 0)
5817 (clobber (scratch:QI))])
5818 (set (cc0) (compare (match_dup 0)
5821 (if_then_else (match_dup 5)
5822 (label_ref (match_dup 3))
5825 operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5826 operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5827 VOIDmode, cc0_rtx, const0_rtx);
5843 (compare (match_operand:SI 0 "register_operand" "")
5844 (match_operand:SI 1 "const_int_operand" "")))
5846 (if_then_else (match_operator 2 "gtle_operator"
5847 [(cc0) (const_int 0)])
5848 (label_ref (match_operand 3 "" ""))
5850 "(TARGET_H8300H || TARGET_H8300S)
5851 && peep2_reg_dead_p (1, operands[0])
5852 && ((TARGET_H8300H && INTVAL (operands[1]) == 3)
5853 || INTVAL (operands[1]) == 7
5854 || INTVAL (operands[1]) == 15
5855 || INTVAL (operands[1]) == 31
5856 || INTVAL (operands[1]) == 63
5857 || INTVAL (operands[1]) == 127
5858 || INTVAL (operands[1]) == 255)"
5860 (and:SI (match_dup 0)
5862 (set (cc0) (compare (match_dup 0)
5865 (if_then_else (match_dup 2)
5866 (label_ref (match_dup 3))
5869 operands[4] = GEN_INT (~INTVAL (operands[1]));
5885 (compare (match_operand:SI 0 "register_operand" "")
5886 (match_operand:SI 1 "const_int_operand" "")))
5888 (if_then_else (match_operator 2 "gtuleu_operator"
5889 [(cc0) (const_int 0)])
5890 (label_ref (match_operand 3 "" ""))
5892 "(TARGET_H8300H || TARGET_H8300S)
5893 && peep2_reg_dead_p (1, operands[0])
5894 && ((TARGET_H8300H && INTVAL (operands[1]) == 3)
5895 || INTVAL (operands[1]) == 7
5896 || INTVAL (operands[1]) == 15
5897 || INTVAL (operands[1]) == 31
5898 || INTVAL (operands[1]) == 63
5899 || INTVAL (operands[1]) == 127
5900 || INTVAL (operands[1]) == 255)"
5902 (and:SI (match_dup 0)
5904 (set (cc0) (compare (match_dup 0)
5907 (if_then_else (match_dup 5)
5908 (label_ref (match_dup 3))
5911 operands[4] = GEN_INT (~INTVAL (operands[1]));
5912 operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5913 VOIDmode, cc0_rtx, const0_rtx);
5928 (compare (match_operand:SI 0 "register_operand" "")
5931 (if_then_else (match_operator 1 "gtle_operator"
5932 [(cc0) (const_int 0)])
5933 (label_ref (match_operand 2 "" ""))
5935 "TARGET_H8300H || TARGET_H8300S"
5936 [(set (cc0) (compare (and:SI (match_dup 0)
5940 (if_then_else (match_dup 1)
5941 (label_ref (match_dup 2))
5957 (compare (match_operand:SI 0 "register_operand" "")
5960 (if_then_else (match_operator 1 "gtuleu_operator"
5961 [(cc0) (const_int 0)])
5962 (label_ref (match_operand 2 "" ""))
5964 "TARGET_H8300H || TARGET_H8300S"
5965 [(set (cc0) (compare (and:SI (match_dup 0)
5969 (if_then_else (match_dup 3)
5970 (label_ref (match_dup 2))
5973 operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[1]) == GTU ? NE : EQ,
5974 VOIDmode, cc0_rtx, const0_rtx);
5988 ;; We avoid this transformation if we see more than one copy of the
5989 ;; same compare insn.
5992 [(match_scratch:SI 4 "r")
5994 (compare (match_operand:SI 0 "register_operand" "")
5995 (match_operand:SI 1 "incdec_operand" "")))
5997 (if_then_else (match_operator 3 "eqne_operator"
5998 [(cc0) (const_int 0)])
5999 (label_ref (match_operand 2 "" ""))
6001 "(TARGET_H8300H || TARGET_H8300S)
6002 && INTVAL (operands[1]) != 0
6003 && !peep2_reg_dead_p (1, operands[0])
6004 && !same_cmp_following_p (insn)"
6008 (unspec:SI [(match_dup 4)
6011 (set (cc0) (compare (match_dup 4)
6014 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
6015 (label_ref (match_dup 2))
6018 operands[5] = GEN_INT (- INTVAL (operands[1]));
6020 ;; Narrow the mode of testing if possible.
6023 [(set (match_operand:HI 0 "register_operand" "")
6024 (and:HI (match_dup 0)
6025 (match_operand:HI 1 "const_int_qi_operand" "")))
6026 (set (cc0) (compare (match_dup 0)
6029 (if_then_else (match_operator 3 "eqne_operator"
6030 [(cc0) (const_int 0)])
6031 (label_ref (match_operand 2 "" ""))
6033 "peep2_reg_dead_p (2, operands[0])"
6035 (and:QI (match_dup 4)
6037 (set (cc0) (compare (match_dup 4)
6040 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
6041 (label_ref (match_dup 2))
6044 operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
6045 operands[5] = gen_int_mode (INTVAL (operands[1]), QImode);
6049 [(set (match_operand:SI 0 "register_operand" "")
6050 (and:SI (match_dup 0)
6051 (match_operand:SI 1 "const_int_qi_operand" "")))
6052 (set (cc0) (compare (match_dup 0)
6055 (if_then_else (match_operator 3 "eqne_operator"
6056 [(cc0) (const_int 0)])
6057 (label_ref (match_operand 2 "" ""))
6059 "peep2_reg_dead_p (2, operands[0])"
6061 (and:QI (match_dup 4)
6063 (set (cc0) (compare (match_dup 4)
6066 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
6067 (label_ref (match_dup 2))
6070 operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
6071 operands[5] = gen_int_mode (INTVAL (operands[1]), QImode);
6075 [(set (match_operand:SI 0 "register_operand" "")
6076 (and:SI (match_dup 0)
6077 (match_operand:SI 1 "const_int_hi_operand" "")))
6078 (set (cc0) (compare (match_dup 0)
6081 (if_then_else (match_operator 3 "eqne_operator"
6082 [(cc0) (const_int 0)])
6083 (label_ref (match_operand 2 "" ""))
6085 "peep2_reg_dead_p (2, operands[0])"
6087 (and:HI (match_dup 4)
6089 (set (cc0) (compare (match_dup 4)
6092 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
6093 (label_ref (match_dup 2))
6096 operands[4] = gen_rtx_REG (HImode, REGNO (operands[0]));
6097 operands[5] = gen_int_mode (INTVAL (operands[1]), HImode);
6101 [(set (match_operand:SI 0 "register_operand" "")
6102 (and:SI (match_dup 0)
6103 (match_operand:SI 1 "const_int_qi_operand" "")))
6105 (xor:SI (match_dup 0)
6106 (match_operand:SI 2 "const_int_qi_operand" "")))
6107 (set (cc0) (compare (match_dup 0)
6110 (if_then_else (match_operator 4 "eqne_operator"
6111 [(cc0) (const_int 0)])
6112 (label_ref (match_operand 3 "" ""))
6114 "peep2_reg_dead_p (3, operands[0])
6115 && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0"
6117 (and:QI (match_dup 5)
6120 (xor:QI (match_dup 5)
6122 (set (cc0) (compare (match_dup 5)
6125 (if_then_else (match_op_dup 4 [(cc0) (const_int 0)])
6126 (label_ref (match_dup 3))
6129 operands[5] = gen_rtx_REG (QImode, REGNO (operands[0]));
6130 operands[6] = gen_int_mode (INTVAL (operands[1]), QImode);
6131 operands[7] = gen_int_mode (INTVAL (operands[2]), QImode);
6134 ;; These triggers right at the end of allocation of locals in the
6135 ;; prologue (and possibly at other places).
6137 ;; stack adjustment of -4, generate one push
6139 ;; before : 6 bytes, 10 clocks
6140 ;; after : 4 bytes, 10 clocks
6143 [(set (reg:SI SP_REG)
6144 (plus:SI (reg:SI SP_REG)
6146 (set (mem:SI (reg:SI SP_REG))
6147 (match_operand:SI 0 "register_operand" ""))]
6148 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE
6149 && REGNO (operands[0]) != SP_REG"
6150 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
6154 ;; stack adjustment of -12, generate one push
6156 ;; before : 10 bytes, 14 clocks
6157 ;; after : 8 bytes, 14 clocks
6160 [(set (reg:SI SP_REG)
6161 (plus:SI (reg:SI SP_REG)
6163 (set (mem:SI (reg:SI SP_REG))
6164 (match_operand:SI 0 "register_operand" ""))]
6165 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE
6166 && REGNO (operands[0]) != SP_REG"
6167 [(set (reg:SI SP_REG)
6168 (plus:SI (reg:SI SP_REG)
6170 (set (reg:SI SP_REG)
6171 (plus:SI (reg:SI SP_REG)
6173 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
6187 ;; if "reg" dies at the end of the sequence.
6190 [(set (match_operand 0 "register_operand" "")
6191 (match_operand 1 "memory_operand" ""))
6193 (match_operator 2 "h8sx_binary_memory_operator"
6195 (match_operand 3 "h8300_src_operand" "")]))
6196 (set (match_operand 4 "memory_operand" "")
6198 "0 /* Disable because it breaks compiling fp-bit.c. */
6200 && peep2_reg_dead_p (3, operands[0])
6201 && !reg_overlap_mentioned_p (operands[0], operands[3])
6202 && !reg_overlap_mentioned_p (operands[0], operands[4])
6203 && h8sx_mergeable_memrefs_p (operands[4], operands[1])"
6207 operands[5] = shallow_copy_rtx (operands[2]);
6208 XEXP (operands[5], 0) = operands[1];
6220 ;; if "reg" dies in the second insn.
6223 [(set (match_operand 0 "register_operand" "")
6224 (match_operand 1 "h8300_src_operand" ""))
6225 (set (match_operand 2 "h8300_dst_operand" "")
6226 (match_operator 3 "h8sx_binary_memory_operator"
6227 [(match_operand 4 "h8300_dst_operand" "")
6229 "0 /* Disable because it breaks compiling fp-bit.c. */
6231 && peep2_reg_dead_p (2, operands[0])
6232 && !reg_overlap_mentioned_p (operands[0], operands[4])"
6236 operands[5] = shallow_copy_rtx (operands[3]);
6237 XEXP (operands[5], 1) = operands[1];
6250 ;; if "reg" dies at the end of the sequence.
6253 [(set (match_operand 0 "register_operand" "")
6254 (match_operand 1 "memory_operand" ""))
6256 (match_operator 2 "h8sx_unary_memory_operator"
6258 (set (match_operand 3 "memory_operand" "")
6261 && peep2_reg_dead_p (3, operands[0])
6262 && !reg_overlap_mentioned_p (operands[0], operands[3])
6263 && h8sx_mergeable_memrefs_p (operands[3], operands[1])"
6267 operands[4] = shallow_copy_rtx (operands[2]);
6268 XEXP (operands[4], 0) = operands[1];
6280 ;; if "reg" dies in the comparison.
6283 [(set (match_operand 0 "register_operand" "")
6284 (match_operand 1 "h8300_dst_operand" ""))
6286 (compare (match_dup 0)
6287 (match_operand 2 "h8300_src_operand" "")))]
6289 && peep2_reg_dead_p (2, operands[0])
6290 && !reg_overlap_mentioned_p (operands[0], operands[2])
6291 && operands[2] != const0_rtx"
6293 (compare (match_dup 1)
6296 ;; Likewise for the second operand.
6299 [(set (match_operand 0 "register_operand" "")
6300 (match_operand 1 "h8300_src_operand" ""))
6302 (compare (match_operand 2 "h8300_dst_operand" "")
6305 && peep2_reg_dead_p (2, operands[0])
6306 && !reg_overlap_mentioned_p (operands[0], operands[2])"
6308 (compare (match_dup 2)
6311 ;; Combine two moves.
6314 [(set (match_operand 0 "register_operand" "")
6315 (match_operand 1 "h8300_src_operand" ""))
6316 (set (match_operand 2 "h8300_dst_operand" "")
6319 && peep2_reg_dead_p (2, operands[0])
6320 && !reg_overlap_mentioned_p (operands[0], operands[2])"