]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/h8300/h8300.md
h8300.c (h8300_current_function_monitor_function_p): New function.
[thirdparty/gcc.git] / gcc / config / h8300 / h8300.md
1 ;; GCC machine description for Renesas H8/300
2 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
4 ;; Free Software Foundation, Inc.
5
6 ;; Contributed by Steve Chamberlain (sac@cygnus.com),
7 ;; Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
8
9 ;; This file is part of GCC.
10
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)
14 ;; any later version.
15
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.
20
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/>.
24
25 ;; We compute exact length on each instruction for most of the time.
26 ;; In some case, most notably bit operations that may involve memory
27 ;; operands, the lengths in this file are "worst case".
28
29 ;; On the H8/300H and H8S, adds/subs operate on the 32bit "er"
30 ;; registers. Right now GCC doesn't expose the "e" half to the
31 ;; compiler, so using add/subs for addhi and subhi is safe. Long
32 ;; term, we want to expose the "e" half to the compiler (gives us 8
33 ;; more 16bit registers). At that point addhi and subhi can't use
34 ;; adds/subs.
35
36 ;; There's currently no way to have an insv/extzv expander for the H8/300H
37 ;; because word_mode is different for the H8/300 and H8/300H.
38
39 ;; Shifts/rotates by small constants should be handled by special
40 ;; patterns so we get the length and cc status correct.
41
42 ;; Bitfield operations no longer accept memory operands. We need
43 ;; to add variants which operate on memory back to the MD.
44
45 ;; ??? Implement remaining bit ops available on the h8300
46
47 ;; ----------------------------------------------------------------------
48 ;; CONSTANTS
49 ;; ----------------------------------------------------------------------
50
51 (define_constants
52 [(UNSPEC_INCDEC 0)
53 (UNSPEC_MONITOR 1)])
54
55 (define_constants
56 [(UNSPEC_MOVMD 100)
57 (UNSPEC_STPCPY 101)])
58
59 (define_constants
60 [(R0_REG 0)
61 (SC_REG 3)
62 (COUNTER_REG 4)
63 (SOURCE_REG 5)
64 (DESTINATION_REG 6)
65 (HFP_REG 6)
66 (SP_REG 7)
67 (MAC_REG 8)
68 (AP_REG 9)
69 (RAP_REG 10)
70 (FP_REG 11)])
71
72 ;; ----------------------------------------------------------------------
73 ;; ATTRIBUTES
74 ;; ----------------------------------------------------------------------
75
76 (define_attr "cpu" "h8300,h8300h"
77 (const (symbol_ref "cpu_type")))
78
79 (define_attr "type" "branch,arith,bitbranch,call"
80 (const_string "arith"))
81
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"))
84
85 ;; The size of instructions in bytes.
86
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))
92 (const_int -126))
93 (le (plus (minus (match_dup 0) (pc))
94 (symbol_ref "DELAY_SLOT_LENGTH (insn)"))
95 (const_int 125)))
96 (const_int 2)
97 (if_then_else (and (eq_attr "cpu" "h8300h")
98 (and (ge (minus (pc) (match_dup 0))
99 (const_int -32000))
100 (le (minus (pc) (match_dup 0))
101 (const_int 32000))))
102 (const_int 4)
103 (const_int 6)))
104 (eq_attr "type" "bitbranch")
105 (if_then_else
106 (and (ge (minus (match_dup 0) (pc))
107 (const_int -126))
108 (le (minus (match_dup 0) (pc))
109 (const_int 126)))
110 (plus
111 (symbol_ref "h8300_insn_length_from_table (insn, operands)")
112 (const_int 2))
113 (if_then_else
114 (and (eq_attr "cpu" "h8300h")
115 (and (ge (minus (pc) (match_dup 0))
116 (const_int -32000))
117 (le (minus (pc) (match_dup 0))
118 (const_int 32000))))
119 (plus
120 (symbol_ref "h8300_insn_length_from_table (insn, operands)")
121 (const_int 4))
122 (plus
123 (symbol_ref "h8300_insn_length_from_table (insn, operands)")
124 (const_int 6))))
125 (eq_attr "length_table" "!none")
126 (symbol_ref "h8300_insn_length_from_table (insn, operands)")]
127 (const_int 200)))
128
129 ;; Condition code settings.
130 ;;
131 ;; none - insn does not affect cc
132 ;; none_0hit - insn does not affect cc but it does modify operand 0
133 ;; This attribute is used to keep track of when operand 0 changes.
134 ;; See the description of NOTICE_UPDATE_CC for more info.
135 ;; set_znv - insn sets z,n,v to usable values (like a tst insn); c is unknown.
136 ;; set_zn - insn sets z,n to usable values; v,c are unknown.
137 ;; compare - compare instruction
138 ;; clobber - value of cc is unknown
139
140 (define_attr "cc" "none,none_0hit,set_znv,set_zn,compare,clobber"
141 (const_string "clobber"))
142
143 ;; Type of delay slot. NONE means the instruction has no delay slot.
144 ;; JUMP means it is an unconditional jump that (if short enough)
145 ;; could be implemented using bra/s.
146 (define_attr "delay_slot" "none,jump"
147 (const_string "none"))
148
149 ;; "yes" if the instruction can be put into a delay slot. It's not
150 ;; entirely clear that jsr is not valid in delay slots, but it
151 ;; definitely doesn't have the effect of causing the called function
152 ;; to return to the target of the delayed branch.
153 (define_attr "can_delay" "no,yes"
154 (cond [(eq_attr "type" "branch,bitbranch,call")
155 (const_string "no")
156 (geu (symbol_ref "get_attr_length (insn)") (const_int 2))
157 (const_string "no")]
158 (const_string "yes")))
159
160 ;; Only allow jumps to have a delay slot if we think they might
161 ;; be short enough. This is just an optimization: we don't know
162 ;; for certain whether they will be or not.
163 (define_delay (and (eq_attr "delay_slot" "jump")
164 (eq (symbol_ref "get_attr_length (insn)") (const_int 2)))
165 [(eq_attr "can_delay" "yes")
166 (nil)
167 (nil)])
168
169 ;; Provide the maximum length of an assembly instruction in an asm
170 ;; statement. The maximum length of 14 bytes is achieved on H8SX.
171
172 (define_asm_attributes
173 [(set (attr "length")
174 (cond [(match_test "TARGET_H8300") (const_int 4)
175 (match_test "TARGET_H8300H") (const_int 10)
176 (match_test "TARGET_H8300S") (const_int 10)]
177 (const_int 14)))])
178
179 (include "predicates.md")
180 (include "constraints.md")
181 \f
182 ;; ----------------------------------------------------------------------
183 ;; MACRO DEFINITIONS
184 ;; ----------------------------------------------------------------------
185
186 ;; This mode iterator allows :P to be used for patterns that operate on
187 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
188 (define_mode_iterator P [(HI "Pmode == HImode") (SI "Pmode == SImode")])
189
190 \f
191 ;; ----------------------------------------------------------------------
192 ;; MOVE INSTRUCTIONS
193 ;; ----------------------------------------------------------------------
194
195 ;; movqi
196
197 (define_insn "*movqi_h8300"
198 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
199 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
200 "TARGET_H8300
201 && h8300_move_ok (operands[0], operands[1])"
202 "@
203 sub.b %X0,%X0
204 mov.b %R1,%X0
205 mov.b %X1,%R0
206 mov.b %R1,%X0
207 mov.b %R1,%X0
208 mov.b %X1,%R0"
209 [(set_attr "length" "2,2,2,2,4,4")
210 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
211
212 (define_insn "*movqi_h8300hs"
213 [(set (match_operand:QI 0 "general_operand_dst" "=r,r ,<,r,r,m")
214 (match_operand:QI 1 "general_operand_src" " I,r>,r,n,m,r"))]
215 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
216 && h8300_move_ok (operands[0], operands[1])"
217 "@
218 sub.b %X0,%X0
219 mov.b %R1,%X0
220 mov.b %X1,%R0
221 mov.b %R1,%X0
222 mov.b %R1,%X0
223 mov.b %X1,%R0"
224 [(set (attr "length")
225 (symbol_ref "compute_mov_length (operands)"))
226 (set_attr "cc" "set_zn,set_znv,set_znv,clobber,set_znv,set_znv")])
227
228 (define_insn "*movqi_h8sx"
229 [(set (match_operand:QI 0 "general_operand_dst" "=Z,rQ")
230 (match_operand:QI 1 "general_operand_src" "P4>X,rQi"))]
231 "TARGET_H8300SX"
232 "@
233 mov.b %X1:4,%X0
234 mov.b %X1,%X0"
235 [(set_attr "length_table" "mov_imm4,movb")
236 (set_attr "cc" "set_znv")])
237
238 (define_expand "movqi"
239 [(set (match_operand:QI 0 "general_operand_dst" "")
240 (match_operand:QI 1 "general_operand_src" ""))]
241 ""
242 {
243 /* One of the ops has to be in a register. */
244 if (!TARGET_H8300SX && !h8300_move_ok (operands[0], operands[1]))
245 operands[1] = copy_to_mode_reg (QImode, operands[1]);
246 })
247
248 (define_insn "movstrictqi"
249 [(set (strict_low_part (match_operand:QI 0 "general_operand_dst" "+r,r"))
250 (match_operand:QI 1 "general_operand_src" "I,rmi>"))]
251 ""
252 "@
253 sub.b %X0,%X0
254 mov.b %X1,%X0"
255 [(set_attr "length" "2,*")
256 (set_attr "length_table" "*,movb")
257 (set_attr "cc" "set_zn,set_znv")])
258
259 ;; movhi
260
261 (define_insn "*movhi_h8300"
262 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
263 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
264 "TARGET_H8300
265 && h8300_move_ok (operands[0], operands[1])"
266 "@
267 sub.w %T0,%T0
268 mov.w %T1,%T0
269 mov.w %T1,%T0
270 mov.w %T1,%T0
271 mov.w %T1,%T0
272 mov.w %T1,%T0"
273 [(set (attr "length")
274 (symbol_ref "compute_mov_length (operands)"))
275 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
276
277 (define_insn "*movhi_h8300hs"
278 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,<,r,r,m")
279 (match_operand:HI 1 "general_operand_src" "I,r>,r,i,m,r"))]
280 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
281 && h8300_move_ok (operands[0], operands[1])"
282 "@
283 sub.w %T0,%T0
284 mov.w %T1,%T0
285 mov.w %T1,%T0
286 mov.w %T1,%T0
287 mov.w %T1,%T0
288 mov.w %T1,%T0"
289 [(set (attr "length")
290 (symbol_ref "compute_mov_length (operands)"))
291 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
292
293 (define_insn "*movhi_h8sx"
294 [(set (match_operand:HI 0 "general_operand_dst" "=r,r,Z,Q,rQ")
295 (match_operand:HI 1 "general_operand_src" "I,P3>X,P4>X,IP8>X,rQi"))]
296 "TARGET_H8300SX"
297 "@
298 sub.w %T0,%T0
299 mov.w %T1:3,%T0
300 mov.w %T1:4,%T0
301 mov.w %T1,%T0
302 mov.w %T1,%T0"
303 [(set_attr "length_table" "*,*,mov_imm4,short_immediate,movw")
304 (set_attr "length" "2,2,*,*,*")
305 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv")])
306
307 (define_expand "movhi"
308 [(set (match_operand:HI 0 "general_operand_dst" "")
309 (match_operand:HI 1 "general_operand_src" ""))]
310 ""
311 {
312 /* One of the ops has to be in a register. */
313 if (!h8300_move_ok (operands[0], operands[1]))
314 operands[1] = copy_to_mode_reg (HImode, operand1);
315 })
316
317 (define_insn "movstricthi"
318 [(set (strict_low_part (match_operand:HI 0 "general_operand_dst" "+r,r,r"))
319 (match_operand:HI 1 "general_operand_src" "I,P3>X,rmi"))]
320 ""
321 "@
322 sub.w %T0,%T0
323 mov.w %T1,%T0
324 mov.w %T1,%T0"
325 [(set_attr "length" "2,2,*")
326 (set_attr "length_table" "*,*,movw")
327 (set_attr "cc" "set_zn,set_znv,set_znv")])
328
329 ;; movsi
330
331 (define_expand "movsi"
332 [(set (match_operand:SI 0 "general_operand_dst" "")
333 (match_operand:SI 1 "general_operand_src" ""))]
334 ""
335 {
336 if (TARGET_H8300)
337 {
338 if (h8300_expand_movsi (operands))
339 DONE;
340 }
341 else if (!TARGET_H8300SX)
342 {
343 /* One of the ops has to be in a register. */
344 if (!h8300_move_ok (operands[0], operands[1]))
345 operands[1] = copy_to_mode_reg (SImode, operand1);
346 }
347 })
348
349 (define_insn "*movsi_h8300"
350 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,o,<,r")
351 (match_operand:SI 1 "general_operand_src" "I,r,io,r,r,>"))]
352 "TARGET_H8300
353 && h8300_move_ok (operands[0], operands[1])"
354 "*
355 {
356 unsigned int rn = -1;
357 switch (which_alternative)
358 {
359 case 0:
360 return \"sub.w %e0,%e0\;sub.w %f0,%f0\";
361 case 1:
362 if (REGNO (operands[0]) < REGNO (operands[1]))
363 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
364 else
365 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
366 case 2:
367 /* Make sure we don't trample the register we index with. */
368 if (GET_CODE (operands[1]) == MEM)
369 {
370 rtx inside = XEXP (operands[1], 0);
371 if (REG_P (inside))
372 {
373 rn = REGNO (inside);
374 }
375 else if (GET_CODE (inside) == PLUS)
376 {
377 rtx lhs = XEXP (inside, 0);
378 rtx rhs = XEXP (inside, 1);
379 if (REG_P (lhs)) rn = REGNO (lhs);
380 if (REG_P (rhs)) rn = REGNO (rhs);
381 }
382 }
383 if (rn == REGNO (operands[0]))
384 {
385 /* Move the second word first. */
386 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
387 }
388 else
389 {
390 if (GET_CODE (operands[1]) == CONST_INT)
391 {
392 /* If either half is zero, use sub.w to clear that
393 half. */
394 if ((INTVAL (operands[1]) & 0xffff) == 0)
395 return \"mov.w %e1,%e0\;sub.w %f0,%f0\";
396 if (((INTVAL (operands[1]) >> 16) & 0xffff) == 0)
397 return \"sub.w %e0,%e0\;mov.w %f1,%f0\";
398 /* If the upper half and the lower half are the same,
399 copy one half to the other. */
400 if ((INTVAL (operands[1]) & 0xffff)
401 == ((INTVAL (operands[1]) >> 16) & 0xffff))
402 return \"mov.w\\t%e1,%e0\;mov.w\\t%e0,%f0\";
403 }
404 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
405 }
406 case 3:
407 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
408 case 4:
409 return \"mov.w %f1,%T0\;mov.w %e1,%T0\";
410 case 5:
411 return \"mov.w %T1,%e0\;mov.w %T1,%f0\";
412 default:
413 gcc_unreachable ();
414 }
415 }"
416 [(set (attr "length")
417 (symbol_ref "compute_mov_length (operands)"))])
418
419 (define_insn "*movsi_h8300hs"
420 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,r,<,r,r,m,*a,*a,r")
421 (match_operand:SI 1 "general_operand_src" "I,r,i,r,>,m,r,I,r,*a"))]
422 "(TARGET_H8300S || TARGET_H8300H) && !TARGET_H8300SX
423 && h8300_move_ok (operands[0], operands[1])"
424 "*
425 {
426 switch (which_alternative)
427 {
428 case 0:
429 return \"sub.l %S0,%S0\";
430 case 7:
431 return \"clrmac\";
432 case 8:
433 return \"clrmac\;ldmac %1,macl\";
434 case 9:
435 return \"stmac macl,%0\";
436 default:
437 if (GET_CODE (operands[1]) == CONST_INT)
438 {
439 int val = INTVAL (operands[1]);
440
441 /* Look for constants which can be made by adding an 8-bit
442 number to zero in one of the two low bytes. */
443 if (val == (val & 0xff))
444 {
445 operands[1] = GEN_INT ((char) val & 0xff);
446 return \"sub.l\\t%S0,%S0\;add.b\\t%1,%w0\";
447 }
448
449 if (val == (val & 0xff00))
450 {
451 operands[1] = GEN_INT ((char) (val >> 8) & 0xff);
452 return \"sub.l\\t%S0,%S0\;add.b\\t%1,%x0\";
453 }
454
455 /* Look for constants that can be obtained by subs, inc, and
456 dec to 0. */
457 switch (val & 0xffffffff)
458 {
459 case 0xffffffff:
460 return \"sub.l\\t%S0,%S0\;subs\\t#1,%S0\";
461 case 0xfffffffe:
462 return \"sub.l\\t%S0,%S0\;subs\\t#2,%S0\";
463 case 0xfffffffc:
464 return \"sub.l\\t%S0,%S0\;subs\\t#4,%S0\";
465
466 case 0x0000ffff:
467 return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%f0\";
468 case 0x0000fffe:
469 return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%f0\";
470
471 case 0xffff0000:
472 return \"sub.l\\t%S0,%S0\;dec.w\\t#1,%e0\";
473 case 0xfffe0000:
474 return \"sub.l\\t%S0,%S0\;dec.w\\t#2,%e0\";
475
476 case 0x00010000:
477 return \"sub.l\\t%S0,%S0\;inc.w\\t#1,%e0\";
478 case 0x00020000:
479 return \"sub.l\\t%S0,%S0\;inc.w\\t#2,%e0\";
480 }
481 }
482 }
483 return \"mov.l %S1,%S0\";
484 }"
485 [(set (attr "length")
486 (symbol_ref "compute_mov_length (operands)"))
487 (set_attr "cc" "set_zn,set_znv,clobber,set_znv,set_znv,set_znv,set_znv,none_0hit,none_0hit,set_znv")])
488
489 (define_insn "*movsi_h8sx"
490 [(set (match_operand:SI 0 "general_operand_dst" "=r,r,Q,rQ,*a,*a,r")
491 (match_operand:SI 1 "general_operand_src" "I,P3>X,IP8>X,rQi,I,r,*a"))]
492 "TARGET_H8300SX"
493 "@
494 sub.l %S0,%S0
495 mov.l %S1:3,%S0
496 mov.l %S1,%S0
497 mov.l %S1,%S0
498 clrmac
499 clrmac\;ldmac %1,macl
500 stmac macl,%0"
501 [(set_attr "length_table" "*,*,short_immediate,movl,*,*,*")
502 (set_attr "length" "2,2,*,*,2,6,4")
503 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,none_0hit,none_0hit,set_znv")])
504
505 (define_insn "*movsf_h8sx"
506 [(set (match_operand:SF 0 "general_operand_dst" "=r,rQ")
507 (match_operand:SF 1 "general_operand_src" "G,rQi"))]
508 "TARGET_H8300SX"
509 "@
510 sub.l %S0,%S0
511 mov.l %S1,%S0"
512 [(set_attr "length" "2,*")
513 (set_attr "length_table" "*,movl")
514 (set_attr "cc" "set_zn,set_znv")])
515
516 ;; Implement block moves using movmd. Defining movmemsi allows the full
517 ;; range of constant lengths (up to 0x40000 bytes when using movmd.l).
518 ;; See h8sx_emit_movmd for details.
519 (define_expand "movmemsi"
520 [(use (match_operand:BLK 0 "memory_operand" ""))
521 (use (match_operand:BLK 1 "memory_operand" ""))
522 (use (match_operand:SI 2 "" ""))
523 (use (match_operand:SI 3 "const_int_operand" ""))]
524 "TARGET_H8300SX"
525 {
526 if (h8sx_emit_movmd (operands[0], operands[1], operands[2],
527 INTVAL (operands[3])))
528 DONE;
529 else
530 FAIL;
531 })
532
533 ;; Expander for generating movmd insns. Operand 0 is the destination
534 ;; memory region, operand 1 is the source, operand 2 is the counter
535 ;; register and operand 3 is the chunk size (1, 2 or 4).
536 (define_expand "movmd"
537 [(parallel
538 [(set (match_operand:BLK 0 "memory_operand" "")
539 (match_operand:BLK 1 "memory_operand" ""))
540 (unspec [(match_operand:HI 2 "register_operand" "")
541 (match_operand:HI 3 "const_int_operand" "")] UNSPEC_MOVMD)
542 (clobber (match_dup 4))
543 (clobber (match_dup 5))
544 (set (match_dup 2)
545 (const_int 0))])]
546 "TARGET_H8300SX"
547 {
548 operands[4] = copy_rtx (XEXP (operands[0], 0));
549 operands[5] = copy_rtx (XEXP (operands[1], 0));
550 })
551
552
553 ;; This is a difficult instruction to reload since operand 0 must be the
554 ;; frame pointer. See h8300_reg_class_from_letter for an explanation.
555 (define_insn "movmd_internal_normal"
556 [(set (mem:BLK (match_operand:HI 3 "register_operand" "0,r"))
557 (mem:BLK (match_operand:HI 4 "register_operand" "1,1")))
558 (unspec [(match_operand:HI 5 "register_operand" "2,2")
559 (match_operand:HI 6 "const_int_operand" "n,n")] UNSPEC_MOVMD)
560 (clobber (match_operand:HI 0 "register_operand" "=d,??D"))
561 (clobber (match_operand:HI 1 "register_operand" "=f,f"))
562 (set (match_operand:HI 2 "register_operand" "=c,c")
563 (const_int 0))]
564 "TARGET_H8300SX && TARGET_NORMAL_MODE"
565 "@
566 movmd%m6
567 #"
568 [(set_attr "length" "2,14")
569 (set_attr "can_delay" "no")
570 (set_attr "cc" "none,clobber")])
571
572 (define_insn "movmd_internal"
573 [(set (mem:BLK (match_operand:SI 3 "register_operand" "0,r"))
574 (mem:BLK (match_operand:SI 4 "register_operand" "1,1")))
575 (unspec [(match_operand:HI 5 "register_operand" "2,2")
576 (match_operand:HI 6 "const_int_operand" "n,n")] UNSPEC_MOVMD)
577 (clobber (match_operand:SI 0 "register_operand" "=d,??D"))
578 (clobber (match_operand:SI 1 "register_operand" "=f,f"))
579 (set (match_operand:HI 2 "register_operand" "=c,c")
580 (const_int 0))]
581 "TARGET_H8300SX && !TARGET_NORMAL_MODE"
582 "@
583 movmd%m6
584 #"
585 [(set_attr "length" "2,14")
586 (set_attr "can_delay" "no")
587 (set_attr "cc" "none,clobber")])
588
589 ;; Split the above instruction if the destination register isn't er6.
590 ;; We need a sequence like:
591 ;;
592 ;; mov.l er6,@-er7
593 ;; mov.l <dest>,er6
594 ;; movmd.sz
595 ;; mov.l er6,<dest>
596 ;; mov.l @er7+,er6
597 ;;
598 ;; where <dest> is the current destination register (operand 4).
599 ;; The fourth instruction will be deleted if <dest> dies here.
600 (define_split
601 [(set (match_operand:BLK 0 "memory_operand" "")
602 (match_operand:BLK 1 "memory_operand" ""))
603 (unspec [(match_operand:HI 2 "register_operand" "")
604 (match_operand:HI 3 "const_int_operand" "")] UNSPEC_MOVMD)
605 (clobber (match_operand:HI 4 "register_operand" ""))
606 (clobber (match_operand:HI 5 "register_operand" ""))
607 (set (match_dup 2)
608 (const_int 0))]
609 "TARGET_H8300SX && TARGET_NORMAL_MODE
610 && reload_completed
611 && REGNO (operands[4]) != DESTINATION_REG"
612 [(const_int 0)]
613 {
614 rtx dest;
615
616 h8300_swap_into_er6 (XEXP (operands[0], 0));
617 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
618 emit_insn (gen_movmd (dest, operands[1], operands[2], operands[3]));
619 h8300_swap_out_of_er6 (operands[4]);
620 DONE;
621 })
622
623 (define_split
624 [(set (match_operand:BLK 0 "memory_operand" "")
625 (match_operand:BLK 1 "memory_operand" ""))
626 (unspec [(match_operand:HI 2 "register_operand" "")
627 (match_operand:HI 3 "const_int_operand" "")] UNSPEC_MOVMD)
628 (clobber (match_operand:SI 4 "register_operand" ""))
629 (clobber (match_operand:SI 5 "register_operand" ""))
630 (set (match_dup 2)
631 (const_int 0))]
632 "TARGET_H8300SX && !TARGET_NORMAL_MODE
633 && reload_completed
634 && REGNO (operands[4]) != DESTINATION_REG"
635 [(const_int 0)]
636 {
637 rtx dest;
638
639 h8300_swap_into_er6 (XEXP (operands[0], 0));
640 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
641 emit_insn (gen_movmd (dest, operands[1], operands[2], operands[3]));
642 h8300_swap_out_of_er6 (operands[4]);
643 DONE;
644 })
645
646 ;; Expand a call to stpcpy() using movsd. Operand 0 should point to
647 ;; the final character, but movsd leaves it pointing to the character
648 ;; after that.
649 (define_expand "movstr"
650 [(use (match_operand 0 "register_operand" ""))
651 (use (match_operand:BLK 1 "memory_operand" ""))
652 (use (match_operand:BLK 2 "memory_operand" ""))]
653 "TARGET_H8300SX"
654 {
655 operands[1] = replace_equiv_address
656 (operands[1], copy_to_mode_reg (Pmode, XEXP (operands[1], 0)));
657 operands[2] = replace_equiv_address
658 (operands[2], copy_to_mode_reg (Pmode, XEXP (operands[2], 0)));
659 emit_insn (gen_movsd (operands[1], operands[2], gen_reg_rtx (Pmode)));
660 emit_insn (gen_add3_insn (operands[0],
661 XEXP (operands[1], 0),
662 constm1_rtx));
663 DONE;
664 })
665
666 ;; Expander for generating a movsd instruction. Operand 0 is the
667 ;; destination string, operand 1 is the source string and operand 2
668 ;; is a scratch register.
669 (define_expand "movsd"
670 [(parallel
671 [(set (match_operand:BLK 0 "memory_operand" "")
672 (unspec:BLK [(match_operand:BLK 1 "memory_operand" "")]
673 UNSPEC_STPCPY))
674 (clobber (match_dup 3))
675 (clobber (match_dup 4))
676 (clobber (match_operand 2 "register_operand" ""))])]
677 "TARGET_H8300SX"
678 {
679 operands[3] = copy_rtx (XEXP (operands[0], 0));
680 operands[4] = copy_rtx (XEXP (operands[1], 0));
681 })
682
683 ;; See comments above memcpy_internal().
684 (define_insn "stpcpy_internal_normal"
685 [(set (mem:BLK (match_operand:HI 3 "register_operand" "0,r"))
686 (unspec:BLK [(mem:BLK (match_operand:HI 4 "register_operand" "1,1"))]
687 UNSPEC_STPCPY))
688 (clobber (match_operand:HI 0 "register_operand" "=d,??D"))
689 (clobber (match_operand:HI 1 "register_operand" "=f,f"))
690 (clobber (match_operand:HI 2 "register_operand" "=c,c"))]
691 "TARGET_H8300SX && TARGET_NORMAL_MODE"
692 "@
693 \n1:\tmovsd\t2f\;bra\t1b\n2:
694 #"
695 [(set_attr "length" "6,18")
696 (set_attr "cc" "none,clobber")])
697
698 (define_insn "stpcpy_internal"
699 [(set (mem:BLK (match_operand:SI 3 "register_operand" "0,r"))
700 (unspec:BLK [(mem:BLK (match_operand:SI 4 "register_operand" "1,1"))]
701 UNSPEC_STPCPY))
702 (clobber (match_operand:SI 0 "register_operand" "=d,??D"))
703 (clobber (match_operand:SI 1 "register_operand" "=f,f"))
704 (clobber (match_operand:SI 2 "register_operand" "=c,c"))]
705 "TARGET_H8300SX && !TARGET_NORMAL_MODE"
706 "@
707 \n1:\tmovsd\t2f\;bra\t1b\n2:
708 #"
709 [(set_attr "length" "6,18")
710 (set_attr "cc" "none,clobber")])
711
712 ;; Split the above instruction if the destination isn't er6. This works
713 ;; in the same way as the movmd splitter.
714 (define_split
715 [(set (match_operand:BLK 0 "memory_operand" "")
716 (unspec:BLK [(match_operand:BLK 1 "memory_operand" "")] UNSPEC_STPCPY))
717 (clobber (match_operand:HI 2 "register_operand" ""))
718 (clobber (match_operand:HI 3 "register_operand" ""))
719 (clobber (match_operand:HI 4 "register_operand" ""))]
720 "TARGET_H8300SX && TARGET_NORMAL_MODE
721 && reload_completed
722 && REGNO (operands[2]) != DESTINATION_REG"
723 [(const_int 0)]
724 {
725 rtx dest;
726
727 h8300_swap_into_er6 (XEXP (operands[0], 0));
728 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
729 emit_insn (gen_movsd (dest, operands[1], operands[4]));
730 h8300_swap_out_of_er6 (operands[2]);
731 DONE;
732 })
733
734 (define_split
735 [(set (match_operand:BLK 0 "memory_operand" "")
736 (unspec:BLK [(match_operand:BLK 1 "memory_operand" "")] UNSPEC_STPCPY))
737 (clobber (match_operand:SI 2 "register_operand" ""))
738 (clobber (match_operand:SI 3 "register_operand" ""))
739 (clobber (match_operand:SI 4 "register_operand" ""))]
740 "TARGET_H8300SX && !TARGET_NORMAL_MODE
741 && reload_completed
742 && REGNO (operands[2]) != DESTINATION_REG"
743 [(const_int 0)]
744 {
745 rtx dest;
746
747 h8300_swap_into_er6 (XEXP (operands[0], 0));
748 dest = replace_equiv_address (operands[0], hard_frame_pointer_rtx);
749 emit_insn (gen_movsd (dest, operands[1], operands[4]));
750 h8300_swap_out_of_er6 (operands[2]);
751 DONE;
752 })
753
754 (include "mova.md")
755
756 (define_expand "movsf"
757 [(set (match_operand:SF 0 "general_operand_dst" "")
758 (match_operand:SF 1 "general_operand_src" ""))]
759 ""
760 "
761 {
762 if (TARGET_H8300)
763 {
764 if (h8300_expand_movsi (operands))
765 DONE;
766 }
767 else if (!TARGET_H8300SX)
768 {
769 /* One of the ops has to be in a register. */
770 if (!register_operand (operand1, SFmode)
771 && !register_operand (operand0, SFmode))
772 {
773 operands[1] = copy_to_mode_reg (SFmode, operand1);
774 }
775 }
776 }")
777
778 (define_insn "*movsf_h8300"
779 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,o,<,r")
780 (match_operand:SF 1 "general_operand_src" "G,r,io,r,r,>"))]
781 "TARGET_H8300
782 && (register_operand (operands[0], SFmode)
783 || register_operand (operands[1], SFmode))"
784 "*
785 {
786 /* Copy of the movsi stuff. */
787 unsigned int rn = -1;
788 switch (which_alternative)
789 {
790 case 0:
791 return \"sub.w %e0,%e0\;sub.w %f0,%f0\";
792 case 1:
793 if (REGNO (operands[0]) < REGNO (operands[1]))
794 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
795 else
796 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
797 case 2:
798 /* Make sure we don't trample the register we index with. */
799 if (GET_CODE (operands[1]) == MEM)
800 {
801 rtx inside = XEXP (operands[1], 0);
802 if (REG_P (inside))
803 {
804 rn = REGNO (inside);
805 }
806 else if (GET_CODE (inside) == PLUS)
807 {
808 rtx lhs = XEXP (inside, 0);
809 rtx rhs = XEXP (inside, 1);
810 if (REG_P (lhs)) rn = REGNO (lhs);
811 if (REG_P (rhs)) rn = REGNO (rhs);
812 }
813 }
814 if (rn == REGNO (operands[0]))
815 /* Move the second word first. */
816 return \"mov.w %f1,%f0\;mov.w %e1,%e0\";
817 else
818 /* Move the first word first. */
819 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
820
821 case 3:
822 return \"mov.w %e1,%e0\;mov.w %f1,%f0\";
823 case 4:
824 return \"mov.w %f1,%T0\;mov.w %e1,%T0\";
825 case 5:
826 return \"mov.w %T1,%e0\;mov.w %T1,%f0\";
827 default:
828 gcc_unreachable ();
829 }
830 }"
831 [(set (attr "length")
832 (symbol_ref "compute_mov_length (operands)"))])
833
834 (define_insn "*movsf_h8300hs"
835 [(set (match_operand:SF 0 "general_operand_dst" "=r,r,r,m,<,r")
836 (match_operand:SF 1 "general_operand_src" "G,r,im,r,r,>"))]
837 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
838 && (register_operand (operands[0], SFmode)
839 || register_operand (operands[1], SFmode))"
840 "@
841 sub.l %S0,%S0
842 mov.l %S1,%S0
843 mov.l %S1,%S0
844 mov.l %S1,%S0
845 mov.l %S1,%S0
846 mov.l %S1,%S0"
847 [(set (attr "length")
848 (symbol_ref "compute_mov_length (operands)"))
849 (set_attr "cc" "set_zn,set_znv,set_znv,set_znv,set_znv,set_znv")])
850 \f
851 ;; ----------------------------------------------------------------------
852 ;; PUSH INSTRUCTIONS
853 ;; ----------------------------------------------------------------------
854
855 (define_insn "*pushqi1_h8300"
856 [(set (mem:QI
857 (pre_modify:HI
858 (reg:HI SP_REG)
859 (plus:HI (reg:HI SP_REG) (const_int -2))))
860 (match_operand:QI 0 "register_no_sp_elim_operand" "r"))]
861 "TARGET_H8300"
862 "mov.w\\t%T0,@-r7"
863 [(set_attr "length" "2")])
864
865 (define_insn "*pushqi1_h8300hs_<mode>"
866 [(set (mem:QI
867 (pre_modify:P
868 (reg:P SP_REG)
869 (plus:P (reg:P SP_REG) (const_int -4))))
870 (match_operand:QI 0 "register_no_sp_elim_operand" "r"))]
871 "TARGET_H8300H || TARGET_H8300S"
872 "mov.l\\t%S0,@-er7"
873 [(set_attr "length" "4")])
874
875 (define_insn "*pushhi1_h8300hs_<mode>"
876 [(set (mem:HI
877 (pre_modify:P
878 (reg:P SP_REG)
879 (plus:P (reg:P SP_REG) (const_int -4))))
880 (match_operand:HI 0 "register_no_sp_elim_operand" "r"))]
881 "TARGET_H8300H || TARGET_H8300S"
882 "mov.l\\t%S0,@-er7"
883 [(set_attr "length" "4")])
884 \f
885 ;; ----------------------------------------------------------------------
886 ;; TEST INSTRUCTIONS
887 ;; ----------------------------------------------------------------------
888
889 (define_insn ""
890 [(set (cc0) (compare
891 (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "r,U")
892 (const_int 1)
893 (match_operand 1 "const_int_operand" "n,n"))
894 (const_int 0)))]
895 "TARGET_H8300"
896 "btst %Z1,%Y0"
897 [(set_attr "length" "2,4")
898 (set_attr "cc" "set_zn,set_zn")])
899
900 (define_insn ""
901 [(set (cc0) (compare
902 (zero_extract:HI (match_operand:HI 0 "register_operand" "r")
903 (const_int 1)
904 (match_operand 1 "const_int_operand" "n"))
905 (const_int 0)))]
906 "TARGET_H8300"
907 "btst %Z1,%Y0"
908 [(set_attr "length" "2")
909 (set_attr "cc" "set_zn")])
910
911 (define_insn_and_split "*tst_extzv_1_n"
912 [(set (cc0) (compare
913 (zero_extract:SI (match_operand:QI 0 "general_operand_src" "r,U,mn>")
914 (const_int 1)
915 (match_operand 1 "const_int_operand" "n,n,n"))
916 (const_int 0)))
917 (clobber (match_scratch:QI 2 "=X,X,&r"))]
918 "(TARGET_H8300H || TARGET_H8300S)"
919 "@
920 btst\\t%Z1,%Y0
921 btst\\t%Z1,%Y0
922 #"
923 "&& reload_completed
924 && !satisfies_constraint_U (operands[0])"
925 [(set (match_dup 2)
926 (match_dup 0))
927 (parallel [(set (cc0) (compare (zero_extract:SI (match_dup 2)
928 (const_int 1)
929 (match_dup 1))
930 (const_int 0)))
931 (clobber (scratch:QI))])]
932 ""
933 [(set_attr "length" "2,8,10")
934 (set_attr "cc" "set_zn,set_zn,set_zn")])
935
936 (define_insn ""
937 [(set (cc0) (compare (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
938 (const_int 1)
939 (match_operand 1 "const_int_operand" "n"))
940 (const_int 0)))]
941 "(TARGET_H8300H || TARGET_H8300S)
942 && INTVAL (operands[1]) <= 15"
943 "btst %Z1,%Y0"
944 [(set_attr "length" "2")
945 (set_attr "cc" "set_zn")])
946
947 (define_insn_and_split "*tstsi_upper_bit"
948 [(set (cc0) (compare (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
949 (const_int 1)
950 (match_operand 1 "const_int_operand" "n"))
951 (const_int 0)))
952 (clobber (match_scratch:SI 2 "=&r"))]
953 "(TARGET_H8300H || TARGET_H8300S)
954 && INTVAL (operands[1]) >= 16"
955 "#"
956 "&& reload_completed"
957 [(set (match_dup 2)
958 (ior:SI (and:SI (match_dup 2)
959 (const_int -65536))
960 (lshiftrt:SI (match_dup 0)
961 (const_int 16))))
962 (set (cc0) (compare (zero_extract:SI (match_dup 2)
963 (const_int 1)
964 (match_dup 3))
965 (const_int 0)))]
966 "operands[3] = GEN_INT (INTVAL (operands[1]) - 16);")
967
968 (define_insn "*tstsi_variable_bit"
969 [(set (cc0) (compare (zero_extract:SI (match_operand:SI 0 "register_operand" "r")
970 (const_int 1)
971 (and:SI (match_operand:SI 1 "register_operand" "r")
972 (const_int 7)))
973 (const_int 0)))]
974 "TARGET_H8300H || TARGET_H8300S"
975 "btst %w1,%w0"
976 [(set_attr "length" "2")
977 (set_attr "cc" "set_zn")])
978
979 (define_insn_and_split "*tstsi_variable_bit_qi"
980 [(set (cc0)
981 (compare
982 (zero_extract:SI (zero_extend:SI (match_operand:QI 0 "general_operand_src" "r,U,mn>"))
983 (const_int 1)
984 (and:SI (match_operand:SI 1 "register_operand" "r,r,r")
985 (const_int 7)))
986 (const_int 0)))
987 (clobber (match_scratch:QI 2 "=X,X,&r"))]
988 "(TARGET_H8300H || TARGET_H8300S)"
989 "@
990 btst\\t%w1,%X0
991 btst\\t%w1,%X0
992 #"
993 "&& reload_completed
994 && !satisfies_constraint_U (operands[0])"
995 [(set (match_dup 2)
996 (match_dup 0))
997 (parallel [(set (cc0) (compare (zero_extract:SI (zero_extend:SI (match_dup 2))
998 (const_int 1)
999 (and:SI (match_dup 1)
1000 (const_int 7)))
1001 (const_int 0)))
1002 (clobber (scratch:QI))])]
1003 ""
1004 [(set_attr "length" "2,8,10")
1005 (set_attr "cc" "set_zn,set_zn,set_zn")])
1006
1007 (define_insn "*tstqi"
1008 [(set (cc0) (compare (match_operand:QI 0 "register_operand" "r")
1009 (const_int 0)))]
1010 ""
1011 "mov.b %X0,%X0"
1012 [(set_attr "length" "2")
1013 (set_attr "cc" "set_znv")])
1014
1015 (define_insn "*tsthi"
1016 [(set (cc0) (compare (match_operand:HI 0 "register_operand" "r")
1017 (const_int 0)))]
1018 ""
1019 "mov.w %T0,%T0"
1020 [(set_attr "length" "2")
1021 (set_attr "cc" "set_znv")])
1022
1023 (define_insn "*tsthi_upper"
1024 [(set (cc0) (compare (and:HI (match_operand:HI 0 "register_operand" "r")
1025 (const_int -256))
1026 (const_int 0)))]
1027 ""
1028 "mov.b %t0,%t0"
1029 [(set_attr "length" "2")
1030 (set_attr "cc" "set_znv")])
1031
1032 (define_insn "*tstsi"
1033 [(set (cc0) (compare (match_operand:SI 0 "register_operand" "r")
1034 (const_int 0)))]
1035 "TARGET_H8300H || TARGET_H8300S"
1036 "mov.l %S0,%S0"
1037 [(set_attr "length" "2")
1038 (set_attr "cc" "set_znv")])
1039
1040 (define_insn "*tstsi_upper"
1041 [(set (cc0) (compare (and:SI (match_operand:SI 0 "register_operand" "r")
1042 (const_int -65536))
1043 (const_int 0)))]
1044 ""
1045 "mov.w %e0,%e0"
1046 [(set_attr "length" "2")
1047 (set_attr "cc" "set_znv")])
1048
1049 (define_insn "*cmpqi"
1050 [(set (cc0)
1051 (compare (match_operand:QI 0 "h8300_dst_operand" "rQ")
1052 (match_operand:QI 1 "h8300_src_operand" "rQi")))]
1053 ""
1054 "cmp.b %X1,%X0"
1055 [(set_attr "length_table" "addb")
1056 (set_attr "cc" "compare")])
1057
1058 (define_insn "*cmphi_h8300_znvc"
1059 [(set (cc0)
1060 (compare (match_operand:HI 0 "register_operand" "r")
1061 (match_operand:HI 1 "register_operand" "r")))]
1062 "TARGET_H8300"
1063 "cmp.w %T1,%T0"
1064 [(set_attr "length" "2")
1065 (set_attr "cc" "compare")])
1066
1067 (define_insn "*cmphi_h8300hs_znvc"
1068 [(set (cc0)
1069 (compare (match_operand:HI 0 "h8300_dst_operand" "rU,rQ")
1070 (match_operand:HI 1 "h8300_src_operand" "P3>X,rQi")))]
1071 "TARGET_H8300H || TARGET_H8300S"
1072 "*
1073 {
1074 switch (which_alternative)
1075 {
1076 case 0:
1077 if (!TARGET_H8300SX)
1078 return \"cmp.w %T1,%T0\";
1079 else
1080 return \"cmp.w %T1:3,%T0\";
1081 case 1:
1082 return \"cmp.w %T1,%T0\";
1083 default:
1084 gcc_unreachable ();
1085 }
1086 }"
1087 [(set_attr "length_table" "short_immediate,addw")
1088 (set_attr "cc" "compare,compare")])
1089
1090 (define_insn "cmpsi"
1091 [(set (cc0)
1092 (compare (match_operand:SI 0 "h8300_dst_operand" "r,rQ")
1093 (match_operand:SI 1 "h8300_src_operand" "P3>X,rQi")))]
1094 "TARGET_H8300H || TARGET_H8300S"
1095 "*
1096 {
1097 switch (which_alternative)
1098 {
1099 case 0:
1100 if (!TARGET_H8300SX)
1101 return \"cmp.l %S1,%S0\";
1102 else
1103 return \"cmp.l %S1:3,%S0\";
1104 case 1:
1105 return \"cmp.l %S1,%S0\";
1106 default:
1107 gcc_unreachable ();
1108 }
1109 }"
1110 [(set_attr "length" "2,*")
1111 (set_attr "length_table" "*,addl")
1112 (set_attr "cc" "compare,compare")])
1113 \f
1114 ;; ----------------------------------------------------------------------
1115 ;; ADD INSTRUCTIONS
1116 ;; ----------------------------------------------------------------------
1117
1118 (define_expand "addqi3"
1119 [(set (match_operand:QI 0 "register_operand" "")
1120 (plus:QI (match_operand:QI 1 "register_operand" "")
1121 (match_operand:QI 2 "h8300_src_operand" "")))]
1122 ""
1123 "")
1124
1125 (define_insn "*addqi3"
1126 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
1127 (plus:QI (match_operand:QI 1 "h8300_dst_operand" "%0")
1128 (match_operand:QI 2 "h8300_src_operand" "rQi")))]
1129 "h8300_operands_match_p (operands)"
1130 "add.b %X2,%X0"
1131 [(set_attr "length_table" "addb")
1132 (set_attr "cc" "set_zn")])
1133
1134 (define_expand "addhi3"
1135 [(set (match_operand:HI 0 "register_operand" "")
1136 (plus:HI (match_operand:HI 1 "register_operand" "")
1137 (match_operand:HI 2 "h8300_src_operand" "")))]
1138 ""
1139 "")
1140
1141 (define_insn "*addhi3_h8300"
1142 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1143 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
1144 (match_operand:HI 2 "h8300_src_operand" "L,N,J,n,r")))]
1145 "TARGET_H8300"
1146 "@
1147 adds %2,%T0
1148 subs %G2,%T0
1149 add.b %t2,%t0
1150 add.b %s2,%s0\;addx %t2,%t0
1151 add.w %T2,%T0"
1152 [(set_attr "length" "2,2,2,4,2")
1153 (set_attr "cc" "none_0hit,none_0hit,clobber,clobber,set_zn")])
1154
1155 ;; This splitter is very important to make the stack adjustment
1156 ;; interrupt-safe. The combination of add.b and addx is unsafe!
1157 ;;
1158 ;; We apply this split after the peephole2 pass so that we won't end
1159 ;; up creating too many adds/subs when a scratch register is
1160 ;; available, which is actually a common case because stack unrolling
1161 ;; tends to happen immediately after a function call.
1162
1163 (define_split
1164 [(set (match_operand:HI 0 "stack_pointer_operand" "")
1165 (plus:HI (match_dup 0)
1166 (match_operand 1 "const_int_gt_2_operand" "")))]
1167 "TARGET_H8300 && epilogue_completed"
1168 [(const_int 0)]
1169 "split_adds_subs (HImode, operands); DONE;")
1170
1171 (define_peephole2
1172 [(match_scratch:HI 2 "r")
1173 (set (match_operand:HI 0 "stack_pointer_operand" "")
1174 (plus:HI (match_dup 0)
1175 (match_operand:HI 1 "const_int_ge_8_operand" "")))]
1176 "TARGET_H8300"
1177 [(set (match_dup 2)
1178 (match_dup 1))
1179 (set (match_dup 0)
1180 (plus:HI (match_dup 0)
1181 (match_dup 2)))]
1182 "")
1183
1184 (define_insn "*addhi3_h8300hs"
1185 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1186 (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0")
1187 (match_operand:HI 2 "h8300_src_operand" "L,N,J,n,r")))]
1188 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX"
1189 "@
1190 adds %2,%S0
1191 subs %G2,%S0
1192 add.b %t2,%t0
1193 add.w %T2,%T0
1194 add.w %T2,%T0"
1195 [(set_attr "length" "2,2,2,4,2")
1196 (set_attr "cc" "none_0hit,none_0hit,clobber,set_zn,set_zn")])
1197
1198 (define_insn "*addhi3_incdec"
1199 [(set (match_operand:HI 0 "register_operand" "=r,r")
1200 (unspec:HI [(match_operand:HI 1 "register_operand" "0,0")
1201 (match_operand:HI 2 "incdec_operand" "M,O")]
1202 UNSPEC_INCDEC))]
1203 "TARGET_H8300H || TARGET_H8300S"
1204 "@
1205 inc.w %2,%T0
1206 dec.w %G2,%T0"
1207 [(set_attr "length" "2,2")
1208 (set_attr "cc" "set_zn,set_zn")])
1209
1210 (define_insn "*addhi3_h8sx"
1211 [(set (match_operand:HI 0 "h8300_dst_operand" "=rU,rU,r,rQ")
1212 (plus:HI (match_operand:HI 1 "h8300_dst_operand" "%0,0,0,0")
1213 (match_operand:HI 2 "h8300_src_operand" "P3>X,P3<X,J,rQi")))]
1214 "TARGET_H8300SX && h8300_operands_match_p (operands)"
1215 "@
1216 add.w %T2:3,%T0
1217 sub.w %G2:3,%T0
1218 add.b %t2,%t0
1219 add.w %T2,%T0"
1220 [(set_attr "length_table" "short_immediate,short_immediate,*,addw")
1221 (set_attr "length" "*,*,2,*")
1222 (set_attr "cc" "set_zn")])
1223
1224 (define_split
1225 [(set (match_operand:HI 0 "register_operand" "")
1226 (plus:HI (match_dup 0)
1227 (match_operand:HI 1 "two_insn_adds_subs_operand" "")))]
1228 ""
1229 [(const_int 0)]
1230 "split_adds_subs (HImode, operands); DONE;")
1231
1232 (define_expand "addsi3"
1233 [(set (match_operand:SI 0 "register_operand" "")
1234 (plus:SI (match_operand:SI 1 "register_operand" "")
1235 (match_operand:SI 2 "h8300_src_operand" "")))]
1236 ""
1237 "")
1238
1239 (define_insn "*addsi_h8300"
1240 [(set (match_operand:SI 0 "register_operand" "=r,r")
1241 (plus:SI (match_operand:SI 1 "register_operand" "%0,0")
1242 (match_operand:SI 2 "h8300_src_operand" "n,r")))]
1243 "TARGET_H8300"
1244 "* return output_plussi (operands);"
1245 [(set (attr "length")
1246 (symbol_ref "compute_plussi_length (operands)"))
1247 (set (attr "cc")
1248 (symbol_ref "compute_plussi_cc (operands)"))])
1249
1250 (define_insn "*addsi_h8300hs"
1251 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ,rQ")
1252 (plus:SI (match_operand:SI 1 "h8300_dst_operand" "%0,0")
1253 (match_operand:SI 2 "h8300_src_operand" "i,rQ")))]
1254 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
1255 "* return output_plussi (operands);"
1256 [(set (attr "length")
1257 (symbol_ref "compute_plussi_length (operands)"))
1258 (set (attr "cc")
1259 (symbol_ref "compute_plussi_cc (operands)"))])
1260
1261 (define_insn "*addsi3_incdec"
1262 [(set (match_operand:SI 0 "register_operand" "=r,r")
1263 (unspec:SI [(match_operand:SI 1 "register_operand" "0,0")
1264 (match_operand:SI 2 "incdec_operand" "M,O")]
1265 UNSPEC_INCDEC))]
1266 "TARGET_H8300H || TARGET_H8300S"
1267 "@
1268 inc.l %2,%S0
1269 dec.l %G2,%S0"
1270 [(set_attr "length" "2,2")
1271 (set_attr "cc" "set_zn,set_zn")])
1272
1273 (define_split
1274 [(set (match_operand:SI 0 "register_operand" "")
1275 (plus:SI (match_dup 0)
1276 (match_operand:SI 1 "two_insn_adds_subs_operand" "")))]
1277 "TARGET_H8300H || TARGET_H8300S"
1278 [(const_int 0)]
1279 "split_adds_subs (SImode, operands); DONE;")
1280
1281 ;; ----------------------------------------------------------------------
1282 ;; SUBTRACT INSTRUCTIONS
1283 ;; ----------------------------------------------------------------------
1284
1285 (define_expand "subqi3"
1286 [(set (match_operand:QI 0 "register_operand" "")
1287 (minus:QI (match_operand:QI 1 "register_operand" "")
1288 (match_operand:QI 2 "h8300_src_operand" "")))]
1289 ""
1290 "")
1291
1292 (define_insn "*subqi3"
1293 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
1294 (minus:QI (match_operand:QI 1 "h8300_dst_operand" "0")
1295 (match_operand:QI 2 "h8300_dst_operand" "rQ")))]
1296 "h8300_operands_match_p (operands)"
1297 "sub.b %X2,%X0"
1298 [(set_attr "length_table" "addb")
1299 (set_attr "cc" "set_zn")])
1300
1301 (define_expand "subhi3"
1302 [(set (match_operand:HI 0 "register_operand" "")
1303 (minus:HI (match_operand:HI 1 "register_operand" "")
1304 (match_operand:HI 2 "h8300_src_operand" "")))]
1305 ""
1306 "")
1307
1308 (define_insn "*subhi3_h8300"
1309 [(set (match_operand:HI 0 "register_operand" "=r,r")
1310 (minus:HI (match_operand:HI 1 "register_operand" "0,0")
1311 (match_operand:HI 2 "h8300_src_operand" "r,n")))]
1312 "TARGET_H8300"
1313 "@
1314 sub.w %T2,%T0
1315 add.b %E2,%s0\;addx %F2,%t0"
1316 [(set_attr "length" "2,4")
1317 (set_attr "cc" "set_zn,clobber")])
1318
1319 (define_insn "*subhi3_h8300hs"
1320 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ,rQ")
1321 (minus:HI (match_operand:HI 1 "h8300_dst_operand" "0,0")
1322 (match_operand:HI 2 "h8300_src_operand" "rQ,i")))]
1323 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
1324 "@
1325 sub.w %T2,%T0
1326 sub.w %T2,%T0"
1327 [(set_attr "length_table" "addw")
1328 (set_attr "cc" "set_zn")])
1329
1330 (define_expand "subsi3"
1331 [(set (match_operand:SI 0 "register_operand" "")
1332 (minus:SI (match_operand:SI 1 "register_operand" "")
1333 (match_operand:SI 2 "h8300_src_operand" "")))]
1334 ""
1335 {
1336 if (TARGET_H8300)
1337 operands[2] = force_reg (SImode, operands[2]);
1338 })
1339
1340 (define_insn "*subsi3_h8300"
1341 [(set (match_operand:SI 0 "register_operand" "=r")
1342 (minus:SI (match_operand:SI 1 "register_operand" "0")
1343 (match_operand:SI 2 "register_operand" "r")))]
1344 "TARGET_H8300"
1345 "sub.w %f2,%f0\;subx %y2,%y0\;subx %z2,%z0"
1346 [(set_attr "length" "6")])
1347
1348 (define_insn "*subsi3_h8300hs"
1349 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ,rQ")
1350 (minus:SI (match_operand:SI 1 "h8300_dst_operand" "0,0")
1351 (match_operand:SI 2 "h8300_src_operand" "rQ,i")))]
1352 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
1353 "@
1354 sub.l %S2,%S0
1355 sub.l %S2,%S0"
1356 [(set_attr "length_table" "addl")
1357 (set_attr "cc" "set_zn")])
1358 \f
1359 ;; ----------------------------------------------------------------------
1360 ;; MULTIPLY INSTRUCTIONS
1361 ;; ----------------------------------------------------------------------
1362
1363 ;; Note that the H8/300 can only handle umulqihi3.
1364
1365 (define_expand "mulqihi3"
1366 [(set (match_operand:HI 0 "register_operand" "")
1367 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" ""))
1368 ;; intentionally-mismatched modes
1369 (match_operand:QI 2 "reg_or_nibble_operand" "")))]
1370 "TARGET_H8300H || TARGET_H8300S"
1371 "
1372 {
1373 if (GET_MODE (operands[2]) != VOIDmode)
1374 operands[2] = gen_rtx_SIGN_EXTEND (HImode, operands[2]);
1375 }")
1376
1377 (define_insn "*mulqihi3_const"
1378 [(set (match_operand:HI 0 "register_operand" "=r")
1379 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1380 (match_operand:QI 2 "nibble_operand" "IP4>X")))]
1381 "TARGET_H8300SX"
1382 "mulxs.b %X2,%T0"
1383 [(set_attr "length" "4")
1384 (set_attr "cc" "set_zn")])
1385
1386 (define_insn "*mulqihi3"
1387 [(set (match_operand:HI 0 "register_operand" "=r")
1388 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1389 (sign_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1390 "TARGET_H8300H || TARGET_H8300S"
1391 "mulxs.b %X2,%T0"
1392 [(set_attr "length" "4")
1393 (set_attr "cc" "set_zn")])
1394
1395 (define_expand "mulhisi3"
1396 [(set (match_operand:SI 0 "register_operand" "")
1397 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" ""))
1398 ;; intentionally-mismatched modes
1399 (match_operand:HI 2 "reg_or_nibble_operand" "")))]
1400 "TARGET_H8300H || TARGET_H8300S"
1401 "
1402 {
1403 if (GET_MODE (operands[2]) != VOIDmode)
1404 operands[2] = gen_rtx_SIGN_EXTEND (SImode, operands[2]);
1405 }")
1406
1407 (define_insn "*mulhisi3_const"
1408 [(set (match_operand:SI 0 "register_operand" "=r")
1409 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1410 (match_operand:SI 2 "nibble_operand" "IP4>X")))]
1411 "TARGET_H8300SX"
1412 "mulxs.w %T2,%S0"
1413 [(set_attr "length" "4")
1414 (set_attr "cc" "set_zn")])
1415
1416 (define_insn "*mulhisi3"
1417 [(set (match_operand:SI 0 "register_operand" "=r")
1418 (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1419 (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
1420 "TARGET_H8300H || TARGET_H8300S"
1421 "mulxs.w %T2,%S0"
1422 [(set_attr "length" "4")
1423 (set_attr "cc" "set_zn")])
1424
1425 (define_expand "umulqihi3"
1426 [(set (match_operand:HI 0 "register_operand" "")
1427 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" ""))
1428 ;; intentionally-mismatched modes
1429 (match_operand:QI 2 "reg_or_nibble_operand" "")))]
1430 "TARGET_H8300H || TARGET_H8300S"
1431 "
1432 {
1433 if (GET_MODE (operands[2]) != VOIDmode)
1434 operands[2] = gen_rtx_ZERO_EXTEND (HImode, operands[2]);
1435 }")
1436
1437 (define_insn "*umulqihi3_const"
1438 [(set (match_operand:HI 0 "register_operand" "=r")
1439 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1440 (match_operand:QI 2 "nibble_operand" "IP4>X")))]
1441 "TARGET_H8300SX"
1442 "mulxu.b %X2,%T0"
1443 [(set_attr "length" "4")
1444 (set_attr "cc" "set_zn")])
1445
1446 (define_insn "*umulqihi3"
1447 [(set (match_operand:HI 0 "register_operand" "=r")
1448 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
1449 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
1450 ""
1451 "mulxu.b %X2,%T0"
1452 [(set_attr "length" "2")
1453 (set_attr "cc" "none_0hit")])
1454
1455 (define_expand "umulhisi3"
1456 [(set (match_operand:SI 0 "register_operand" "")
1457 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" ""))
1458 ;; intentionally-mismatched modes
1459 (match_operand:HI 2 "reg_or_nibble_operand" "")))]
1460 "TARGET_H8300H || TARGET_H8300S"
1461 "
1462 {
1463 if (GET_MODE (operands[2]) != VOIDmode)
1464 operands[2] = gen_rtx_ZERO_EXTEND (SImode, operands[2]);
1465 }")
1466
1467 (define_insn "*umulhisi3_const"
1468 [(set (match_operand:SI 0 "register_operand" "=r")
1469 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1470 (match_operand:SI 2 "nibble_operand" "IP4>X")))]
1471 "TARGET_H8300SX"
1472 "mulxu.w %T2,%S0"
1473 [(set_attr "length" "4")
1474 (set_attr "cc" "set_zn")])
1475
1476 (define_insn "*umulhisi3"
1477 [(set (match_operand:SI 0 "register_operand" "=r")
1478 (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%0"))
1479 (zero_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
1480 "TARGET_H8300H || TARGET_H8300S"
1481 "mulxu.w %T2,%S0"
1482 [(set_attr "length" "2")
1483 (set_attr "cc" "none_0hit")])
1484
1485 ;; We could have used mulu.[wl] here, but mulu.[lw] is only available
1486 ;; on a H8SX with a multiplier, whereas muls.w seems to be available
1487 ;; on all H8SX variants.
1488 (define_insn "mulhi3"
1489 [(set (match_operand:HI 0 "register_operand" "=r")
1490 (mult:HI (match_operand:HI 1 "register_operand" "%0")
1491 (match_operand:HI 2 "reg_or_nibble_operand" "r IP4>X")))]
1492 "TARGET_H8300SX"
1493 "muls.w\\t%T2,%T0"
1494 [(set_attr "length" "2")
1495 (set_attr "cc" "set_zn")])
1496
1497 (define_insn "mulsi3"
1498 [(set (match_operand:SI 0 "register_operand" "=r")
1499 (mult:SI (match_operand:SI 1 "register_operand" "%0")
1500 (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))]
1501 "TARGET_H8300SX"
1502 "muls.l\\t%S2,%S0"
1503 [(set_attr "length" "2")
1504 (set_attr "cc" "set_zn")])
1505
1506 (define_insn "smulsi3_highpart"
1507 [(set (match_operand:SI 0 "register_operand" "=r")
1508 (truncate:SI
1509 (lshiftrt:DI
1510 (mult:DI
1511 (sign_extend:DI (match_operand:SI 1 "register_operand" "%0"))
1512 (sign_extend:DI (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))
1513 (const_int 32))))]
1514 "TARGET_H8300SXMUL"
1515 "muls/u.l\\t%S2,%S0"
1516 [(set_attr "length" "2")
1517 (set_attr "cc" "set_zn")])
1518
1519 (define_insn "umulsi3_highpart"
1520 [(set (match_operand:SI 0 "register_operand" "=r")
1521 (truncate:SI
1522 (ashiftrt:DI
1523 (mult:DI
1524 (zero_extend:DI (match_operand:SI 1 "register_operand" "%0"))
1525 (zero_extend:DI (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))
1526 (const_int 32))))]
1527 "TARGET_H8300SX"
1528 "mulu/u.l\\t%S2,%S0"
1529 [(set_attr "length" "2")
1530 (set_attr "cc" "none_0hit")])
1531
1532 ;; This is a "bridge" instruction. Combine can't cram enough insns
1533 ;; together to crate a MAC instruction directly, but it can create
1534 ;; this instruction, which then allows combine to create the real
1535 ;; MAC insn.
1536 ;;
1537 ;; Unfortunately, if combine doesn't create a MAC instruction, this
1538 ;; insn must generate reasonably correct code. Egad.
1539 (define_insn ""
1540 [(set (match_operand:SI 0 "register_operand" "=a")
1541 (mult:SI
1542 (sign_extend:SI
1543 (mem:HI (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
1544 (sign_extend:SI
1545 (mem:HI (post_inc:SI (match_operand:SI 2 "register_operand" "r"))))))]
1546 "TARGET_MAC"
1547 "clrmac\;mac @%2+,@%1+"
1548 [(set_attr "length" "6")
1549 (set_attr "cc" "none_0hit")])
1550
1551 (define_insn ""
1552 [(set (match_operand:SI 0 "register_operand" "=a")
1553 (plus:SI (mult:SI
1554 (sign_extend:SI (mem:HI
1555 (post_inc:SI (match_operand:SI 1 "register_operand" "r"))))
1556 (sign_extend:SI (mem:HI
1557 (post_inc:SI (match_operand:SI 2 "register_operand" "r")))))
1558 (match_operand:SI 3 "register_operand" "0")))]
1559 "TARGET_MAC"
1560 "mac @%2+,@%1+"
1561 [(set_attr "length" "4")
1562 (set_attr "cc" "none_0hit")])
1563
1564 ;; ----------------------------------------------------------------------
1565 ;; DIVIDE/MOD INSTRUCTIONS
1566 ;; ----------------------------------------------------------------------
1567
1568 (define_insn "udivhi3"
1569 [(set (match_operand:HI 0 "register_operand" "=r")
1570 (udiv:HI
1571 (match_operand:HI 1 "register_operand" "0")
1572 (match_operand:HI 2 "reg_or_nibble_operand" "r IP4>X")))]
1573 "TARGET_H8300SX"
1574 "divu.w\\t%T2,%T0"
1575 [(set_attr "length" "2")])
1576
1577 (define_insn "divhi3"
1578 [(set (match_operand:HI 0 "register_operand" "=r")
1579 (div:HI
1580 (match_operand:HI 1 "register_operand" "0")
1581 (match_operand:HI 2 "reg_or_nibble_operand" "r IP4>X")))]
1582 "TARGET_H8300SX"
1583 "divs.w\\t%T2,%T0"
1584 [(set_attr "length" "2")])
1585
1586 (define_insn "udivsi3"
1587 [(set (match_operand:SI 0 "register_operand" "=r")
1588 (udiv:SI
1589 (match_operand:SI 1 "register_operand" "0")
1590 (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))]
1591 "TARGET_H8300SX"
1592 "divu.l\\t%S2,%S0"
1593 [(set_attr "length" "2")])
1594
1595 (define_insn "divsi3"
1596 [(set (match_operand:SI 0 "register_operand" "=r")
1597 (div:SI
1598 (match_operand:SI 1 "register_operand" "0")
1599 (match_operand:SI 2 "reg_or_nibble_operand" "r IP4>X")))]
1600 "TARGET_H8300SX"
1601 "divs.l\\t%S2,%S0"
1602 [(set_attr "length" "2")])
1603
1604 (define_insn "udivmodqi4"
1605 [(set (match_operand:QI 0 "register_operand" "=r")
1606 (truncate:QI
1607 (udiv:HI
1608 (match_operand:HI 1 "register_operand" "0")
1609 (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1610 (set (match_operand:QI 3 "register_operand" "=r")
1611 (truncate:QI
1612 (umod:HI
1613 (match_dup 1)
1614 (zero_extend:HI (match_dup 2)))))]
1615 ""
1616 "*
1617 {
1618 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1619 return \"divxu.b\\t%X2,%T0\";
1620 else
1621 return \"divxu.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1622 }"
1623 [(set_attr "length" "4")])
1624
1625 (define_insn "divmodqi4"
1626 [(set (match_operand:QI 0 "register_operand" "=r")
1627 (truncate:QI
1628 (div:HI
1629 (match_operand:HI 1 "register_operand" "0")
1630 (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))))
1631 (set (match_operand:QI 3 "register_operand" "=r")
1632 (truncate:QI
1633 (mod:HI
1634 (match_dup 1)
1635 (sign_extend:HI (match_dup 2)))))]
1636 "TARGET_H8300H || TARGET_H8300S"
1637 "*
1638 {
1639 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1640 return \"divxs.b\\t%X2,%T0\";
1641 else
1642 return \"divxs.b\\t%X2,%T0\;mov.b\\t%t0,%s3\";
1643 }"
1644 [(set_attr "length" "6")])
1645
1646 (define_insn "udivmodhi4"
1647 [(set (match_operand:HI 0 "register_operand" "=r")
1648 (truncate:HI
1649 (udiv:SI
1650 (match_operand:SI 1 "register_operand" "0")
1651 (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1652 (set (match_operand:HI 3 "register_operand" "=r")
1653 (truncate:HI
1654 (umod:SI
1655 (match_dup 1)
1656 (zero_extend:SI (match_dup 2)))))]
1657 "TARGET_H8300H || TARGET_H8300S"
1658 "*
1659 {
1660 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1661 return \"divxu.w\\t%T2,%S0\";
1662 else
1663 return \"divxu.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1664 }"
1665 [(set_attr "length" "4")])
1666
1667 (define_insn "divmodhi4"
1668 [(set (match_operand:HI 0 "register_operand" "=r")
1669 (truncate:HI
1670 (div:SI
1671 (match_operand:SI 1 "register_operand" "0")
1672 (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))))
1673 (set (match_operand:HI 3 "register_operand" "=r")
1674 (truncate:HI
1675 (mod:SI
1676 (match_dup 1)
1677 (sign_extend:SI (match_dup 2)))))]
1678 "TARGET_H8300H || TARGET_H8300S"
1679 "*
1680 {
1681 if (find_reg_note (insn, REG_UNUSED, operands[3]))
1682 return \"divxs.w\\t%T2,%S0\";
1683 else
1684 return \"divxs.w\\t%T2,%S0\;mov.w\\t%e0,%f3\";
1685 }"
1686 [(set_attr "length" "6")])
1687 \f
1688 ;; ----------------------------------------------------------------------
1689 ;; AND INSTRUCTIONS
1690 ;; ----------------------------------------------------------------------
1691 (define_insn "bclrqi_msx"
1692 [(set (match_operand:QI 0 "bit_register_indirect_operand" "=WU")
1693 (and:QI (match_operand:QI 1 "bit_register_indirect_operand" "%0")
1694 (match_operand:QI 2 "single_zero_operand" "Y0")))]
1695 "TARGET_H8300SX
1696 && rtx_equal_p(operands[0], operands[1])"
1697 "bclr\\t%W2,%0"
1698 [(set_attr "length" "8")])
1699
1700 (define_split
1701 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=U")
1702 (and:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1703 (match_operand:HI 2 "single_zero_operand" "Y0")))]
1704 "TARGET_H8300SX"
1705 [(set (match_dup 0)
1706 (and:QI (match_dup 1)
1707 (match_dup 2)))]
1708 {
1709 if (abs (INTVAL (operands[2])) > 0xFF)
1710 {
1711 operands[0] = adjust_address (operands[0], QImode, 0);
1712 operands[1] = adjust_address (operands[1], QImode, 0);
1713 operands[2] = GEN_INT ((INTVAL (operands[2])) >> 8);
1714 }
1715 else
1716 {
1717 operands[0] = adjust_address (operands[0], QImode, 1);
1718 operands[1] = adjust_address (operands[1], QImode, 1);
1719 }
1720 })
1721
1722 (define_insn "bclrhi_msx"
1723 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=m")
1724 (and:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1725 (match_operand:HI 2 "single_zero_operand" "Y0")))]
1726 "TARGET_H8300SX"
1727 "bclr\\t%W2,%0"
1728 [(set_attr "length" "8")])
1729
1730 (define_insn "*andqi3_2"
1731 [(set (match_operand:QI 0 "bit_operand" "=U,rQ,r")
1732 (and:QI (match_operand:QI 1 "bit_operand" "%0,0,WU")
1733 (match_operand:QI 2 "h8300_src_operand" "Y0,rQi,IP1>X")))]
1734 "TARGET_H8300SX"
1735 "@
1736 bclr\\t %W2,%R0
1737 and %X2,%X0
1738 bfld %2,%1,%R0"
1739 [(set_attr "length" "8,*,8")
1740 (set_attr "length_table" "*,logicb,*")
1741 (set_attr "cc" "none_0hit,set_znv,none_0hit")])
1742
1743 (define_insn "andqi3_1"
1744 [(set (match_operand:QI 0 "bit_operand" "=U,r")
1745 (and:QI (match_operand:QI 1 "bit_operand" "%0,0")
1746 (match_operand:QI 2 "h8300_src_operand" "Y0,rn")))]
1747 "register_operand (operands[0], QImode)
1748 || single_zero_operand (operands[2], QImode)"
1749 "@
1750 bclr %W2,%R0
1751 and %X2,%X0"
1752 [(set_attr "length" "2,8")
1753 (set_attr "cc" "none_0hit,set_znv")])
1754
1755 (define_expand "andqi3"
1756 [(set (match_operand:QI 0 "register_operand" "")
1757 (and:QI (match_operand:QI 1 "register_operand" "")
1758 (match_operand:QI 2 "h8300_src_operand" "")))]
1759 ""
1760 "")
1761
1762 (define_expand "andhi3"
1763 [(set (match_operand:HI 0 "register_operand" "")
1764 (and:HI (match_operand:HI 1 "register_operand" "")
1765 (match_operand:HI 2 "h8300_src_operand" "")))]
1766 ""
1767 "")
1768
1769 (define_insn "*andorqi3"
1770 [(set (match_operand:QI 0 "register_operand" "=r")
1771 (ior:QI (and:QI (match_operand:QI 2 "register_operand" "r")
1772 (match_operand:QI 3 "single_one_operand" "n"))
1773 (match_operand:QI 1 "register_operand" "0")))]
1774 ""
1775 "bld\\t%V3,%X2\;bor\\t%V3,%X0\;bst\\t%V3,%X0"
1776 [(set_attr "length" "6")])
1777
1778 (define_insn "*andorhi3"
1779 [(set (match_operand:HI 0 "register_operand" "=r")
1780 (ior:HI (and:HI (match_operand:HI 2 "register_operand" "r")
1781 (match_operand:HI 3 "single_one_operand" "n"))
1782 (match_operand:HI 1 "register_operand" "0")))]
1783 ""
1784 "*
1785 {
1786 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1787 if (INTVAL (operands[3]) > 128)
1788 {
1789 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1790 return \"bld\\t%V3,%t2\;bor\\t%V3,%t0\;bst\\t%V3,%t0\";
1791 }
1792 return \"bld\\t%V3,%s2\;bor\\t%V3,%s0\;bst\\t%V3,%s0\";
1793 }"
1794 [(set_attr "length" "6")])
1795
1796 (define_insn "*andorsi3"
1797 [(set (match_operand:SI 0 "register_operand" "=r")
1798 (ior:SI (and:SI (match_operand:SI 2 "register_operand" "r")
1799 (match_operand:SI 3 "single_one_operand" "n"))
1800 (match_operand:SI 1 "register_operand" "0")))]
1801 "(INTVAL (operands[3]) & 0xffff) != 0"
1802 "*
1803 {
1804 operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff);
1805 if (INTVAL (operands[3]) > 128)
1806 {
1807 operands[3] = GEN_INT (INTVAL (operands[3]) >> 8);
1808 return \"bld\\t%V3,%x2\;bor\\t%V3,%x0\;bst\\t%V3,%x0\";
1809 }
1810 return \"bld\\t%V3,%w2\;bor\\t%V3,%w0\;bst\\t%V3,%w0\";
1811 }"
1812 [(set_attr "length" "6")])
1813
1814 (define_insn "*andorsi3_shift_8"
1815 [(set (match_operand:SI 0 "register_operand" "=r")
1816 (ior:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
1817 (const_int 8))
1818 (const_int 65280))
1819 (match_operand:SI 1 "register_operand" "0")))]
1820 ""
1821 "or.b\\t%w2,%x0"
1822 [(set_attr "length" "2")])
1823
1824 (define_expand "andsi3"
1825 [(set (match_operand:SI 0 "register_operand" "")
1826 (and:SI (match_operand:SI 1 "register_operand" "")
1827 (match_operand:SI 2 "h8300_src_operand" "")))]
1828 ""
1829 "")
1830
1831 ;; ----------------------------------------------------------------------
1832 ;; OR INSTRUCTIONS
1833 ;; ----------------------------------------------------------------------
1834
1835 (define_insn "bsetqi_msx"
1836 [(set (match_operand:QI 0 "bit_register_indirect_operand" "=WU")
1837 (ior:QI (match_operand:QI 1 "bit_register_indirect_operand" "%0")
1838 (match_operand:QI 2 "single_one_operand" "Y2")))]
1839 "TARGET_H8300SX
1840 && rtx_equal_p(operands[0], operands[1])"
1841 "bset\\t%V2,%0"
1842 [(set_attr "length" "8")])
1843
1844 (define_split
1845 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=U")
1846 (ior:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1847 (match_operand:HI 2 "single_one_operand" "Y2")))]
1848 "TARGET_H8300SX"
1849 [(set (match_dup 0)
1850 (ior:QI (match_dup 1)
1851 (match_dup 2)))]
1852 {
1853 if (abs (INTVAL (operands[2])) > 0xFF)
1854 {
1855 operands[0] = adjust_address (operands[0], QImode, 0);
1856 operands[1] = adjust_address (operands[1], QImode, 0);
1857 operands[2] = GEN_INT ((INTVAL (operands[2])) >> 8);
1858 }
1859 else
1860 {
1861 operands[0] = adjust_address (operands[0], QImode, 1);
1862 operands[1] = adjust_address (operands[1], QImode, 1);
1863 }
1864 })
1865
1866 (define_insn "bsethi_msx"
1867 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=m")
1868 (ior:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1869 (match_operand:HI 2 "single_one_operand" "Y2")))]
1870 "TARGET_H8300SX"
1871 "bset\\t%V2,%0"
1872 [(set_attr "length" "8")])
1873
1874 (define_insn "iorqi3_1"
1875 [(set (match_operand:QI 0 "bit_operand" "=U,rQ")
1876 (ior:QI (match_operand:QI 1 "bit_operand" "%0,0")
1877 (match_operand:QI 2 "h8300_src_operand" "Y2,rQi")))]
1878 "TARGET_H8300SX || register_operand (operands[0], QImode)
1879 || single_one_operand (operands[2], QImode)"
1880 "@
1881 bset\\t%V2,%R0
1882 or\\t%X2,%X0"
1883 [(set_attr "length" "8,*")
1884 (set_attr "length_table" "*,logicb")
1885 (set_attr "cc" "none_0hit,set_znv")])
1886
1887
1888 (define_expand "iorqi3"
1889 [(set (match_operand:QI 0 "register_operand" "")
1890 (ior:QI (match_operand:QI 1 "register_operand" "")
1891 (match_operand:QI 2 "h8300_src_operand" "")))]
1892 ""
1893 "")
1894
1895 (define_expand "iorhi3"
1896 [(set (match_operand:HI 0 "register_operand" "")
1897 (ior:HI (match_operand:HI 1 "register_operand" "")
1898 (match_operand:HI 2 "h8300_src_operand" "")))]
1899 ""
1900 "")
1901
1902 (define_expand "iorsi3"
1903 [(set (match_operand:SI 0 "register_operand" "")
1904 (ior:SI (match_operand:SI 1 "register_operand" "")
1905 (match_operand:SI 2 "h8300_src_operand" "")))]
1906 ""
1907 "")
1908
1909 ;; ----------------------------------------------------------------------
1910 ;; XOR INSTRUCTIONS
1911 ;; ----------------------------------------------------------------------
1912 (define_insn "bnotqi_msx"
1913 [(set (match_operand:QI 0 "bit_register_indirect_operand" "=WU")
1914 (xor:QI (match_operand:QI 1 "bit_register_indirect_operand" "%0")
1915 (match_operand:QI 2 "single_one_operand" "Y2")))]
1916 "TARGET_H8300SX
1917 && rtx_equal_p(operands[0], operands[1])"
1918 "bnot\\t%V2,%0"
1919 [(set_attr "length" "8")])
1920
1921 (define_split
1922 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=U")
1923 (xor:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1924 (match_operand:HI 2 "single_one_operand" "Y2")))]
1925 "TARGET_H8300SX"
1926 [(set (match_dup 0)
1927 (xor:QI (match_dup 1)
1928 (match_dup 2)))]
1929 {
1930 if (abs (INTVAL (operands[2])) > 0xFF)
1931 {
1932 operands[0] = adjust_address (operands[0], QImode, 0);
1933 operands[1] = adjust_address (operands[1], QImode, 0);
1934 operands[2] = GEN_INT ((INTVAL (operands[2])) >> 8);
1935 }
1936 else
1937 {
1938 operands[0] = adjust_address (operands[0], QImode, 1);
1939 operands[1] = adjust_address (operands[1], QImode, 1);
1940 }
1941 })
1942
1943 (define_insn "bnothi_msx"
1944 [(set (match_operand:HI 0 "bit_register_indirect_operand" "=m")
1945 (xor:HI (match_operand:HI 1 "bit_register_indirect_operand" "%0")
1946 (match_operand:HI 2 "single_one_operand" "Y2")))]
1947 "TARGET_H8300SX"
1948 "bnot\\t%V2,%0"
1949 [(set_attr "length" "8")])
1950
1951 (define_insn "xorqi3_1"
1952 [(set (match_operand:QI 0 "bit_operand" "=U,r")
1953 (xor:QI (match_operand:QI 1 "bit_operand" "%0,0")
1954 (match_operand:QI 2 "h8300_src_operand" "Y2,rQi")))]
1955 "TARGET_H8300SX || register_operand (operands[0], QImode)
1956 || single_one_operand (operands[2], QImode)"
1957 "@
1958 bnot\\t%V2,%R0
1959 xor\\t%X2,%X0"
1960 [(set_attr "length" "8,*")
1961 (set_attr "length_table" "*,logicb")
1962 (set_attr "cc" "none_0hit,set_znv")])
1963
1964
1965 (define_expand "xorqi3"
1966 [(set (match_operand:QI 0 "register_operand" "")
1967 (xor:QI (match_operand:QI 1 "register_operand" "")
1968 (match_operand:QI 2 "h8300_src_operand" "")))]
1969 ""
1970 "")
1971
1972 (define_expand "xorhi3"
1973 [(set (match_operand:HI 0 "register_operand" "")
1974 (xor:HI (match_operand:HI 1 "register_operand" "")
1975 (match_operand:HI 2 "h8300_src_operand" "")))]
1976 ""
1977 "")
1978
1979 (define_expand "xorsi3"
1980 [(set (match_operand:SI 0 "register_operand" "")
1981 (xor:SI (match_operand:SI 1 "register_operand" "")
1982 (match_operand:SI 2 "h8300_src_operand" "")))]
1983 ""
1984 "")
1985
1986 ;; ----------------------------------------------------------------------
1987 ;; {AND,IOR,XOR}{HI3,SI3} PATTERNS
1988 ;; ----------------------------------------------------------------------
1989
1990 ;; We need a separate pattern here because machines other than the
1991 ;; original H8300 don't have to split the 16-bit operand into a pair
1992 ;; of high/low instructions, so we can accept literal addresses, that
1993 ;; have to be loaded into a register on H8300.
1994 (define_insn "*logicalhi3_sn"
1995 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
1996 (match_operator:HI 3 "bit_operator"
1997 [(match_operand:HI 1 "h8300_dst_operand" "%0")
1998 (match_operand:HI 2 "h8300_src_operand" "rQi")]))]
1999 "(TARGET_H8300S || TARGET_H8300H) && h8300_operands_match_p (operands)"
2000 "* return output_logical_op (HImode, operands);"
2001 [(set (attr "length")
2002 (symbol_ref "compute_logical_op_length (HImode, operands)"))
2003 (set (attr "cc")
2004 (symbol_ref "compute_logical_op_cc (HImode, operands)"))])
2005
2006 (define_insn "*logicalsi3_sn"
2007 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2008 (match_operator:SI 3 "bit_operator"
2009 [(match_operand:SI 1 "h8300_dst_operand" "%0")
2010 (match_operand:SI 2 "h8300_src_operand" "rQi")]))]
2011 "(TARGET_H8300S || TARGET_H8300H) && h8300_operands_match_p (operands)"
2012 "* return output_logical_op (SImode, operands);"
2013 [(set (attr "length")
2014 (symbol_ref "compute_logical_op_length (SImode, operands)"))
2015 (set (attr "cc")
2016 (symbol_ref "compute_logical_op_cc (SImode, operands)"))])
2017
2018 (define_insn "*logicalhi3"
2019 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2020 (match_operator:HI 3 "bit_operator"
2021 [(match_operand:HI 1 "h8300_dst_operand" "%0")
2022 (match_operand:HI 2 "h8300_src_operand" "rQi")]))]
2023 "h8300_operands_match_p (operands)"
2024 "* return output_logical_op (HImode, operands);"
2025 [(set (attr "length")
2026 (symbol_ref "compute_logical_op_length (HImode, operands)"))
2027 (set (attr "cc")
2028 (symbol_ref "compute_logical_op_cc (HImode, operands)"))])
2029
2030 (define_insn "*logicalsi3"
2031 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2032 (match_operator:SI 3 "bit_operator"
2033 [(match_operand:SI 1 "h8300_dst_operand" "%0")
2034 (match_operand:SI 2 "h8300_src_operand" "rQi")]))]
2035 "h8300_operands_match_p (operands)"
2036 "* return output_logical_op (SImode, operands);"
2037 [(set (attr "length")
2038 (symbol_ref "compute_logical_op_length (SImode, operands)"))
2039 (set (attr "cc")
2040 (symbol_ref "compute_logical_op_cc (SImode, operands)"))])
2041 \f
2042 ;; ----------------------------------------------------------------------
2043 ;; NEGATION INSTRUCTIONS
2044 ;; ----------------------------------------------------------------------
2045
2046 (define_expand "negqi2"
2047 [(set (match_operand:QI 0 "register_operand" "")
2048 (neg:QI (match_operand:QI 1 "register_operand" "")))]
2049 ""
2050 "")
2051
2052 (define_insn "*negqi2"
2053 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
2054 (neg:QI (match_operand:QI 1 "h8300_dst_operand" "0")))]
2055 ""
2056 "neg %X0"
2057 [(set_attr "length_table" "unary")
2058 (set_attr "cc" "set_zn")])
2059
2060 (define_expand "neghi2"
2061 [(set (match_operand:HI 0 "register_operand" "")
2062 (neg:HI (match_operand:HI 1 "register_operand" "")))]
2063 ""
2064 "
2065 {
2066 if (TARGET_H8300)
2067 {
2068 emit_insn (gen_neghi2_h8300 (operands[0], operands[1]));
2069 DONE;
2070 }
2071 }")
2072
2073 (define_expand "neghi2_h8300"
2074 [(set (match_dup 2)
2075 (not:HI (match_operand:HI 1 "register_operand" "")))
2076 (set (match_dup 2) (plus:HI (match_dup 2) (const_int 1)))
2077 (set (match_operand:HI 0 "register_operand" "")
2078 (match_dup 2))]
2079 ""
2080 "operands[2] = gen_reg_rtx (HImode);")
2081
2082 (define_insn "*neghi2_h8300hs"
2083 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2084 (neg:HI (match_operand:HI 1 "h8300_dst_operand" "0")))]
2085 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2086 "neg.w %T0"
2087 [(set_attr "length_table" "unary")
2088 (set_attr "cc" "set_zn")])
2089
2090 (define_expand "negsi2"
2091 [(set (match_operand:SI 0 "register_operand" "")
2092 (neg:SI (match_operand:SI 1 "register_operand" "")))]
2093 ""
2094 "
2095 {
2096 if (TARGET_H8300)
2097 {
2098 emit_insn (gen_negsi2_h8300 (operands[0], operands[1]));
2099 DONE;
2100 }
2101 }")
2102
2103 (define_expand "negsi2_h8300"
2104 [(set (match_dup 2)
2105 (not:SI (match_operand:SI 1 "register_operand" "")))
2106 (set (match_dup 2) (plus:SI (match_dup 2) (const_int 1)))
2107 (set (match_operand:SI 0 "register_operand" "")
2108 (match_dup 2))]
2109 ""
2110 "operands[2] = gen_reg_rtx (SImode);")
2111
2112 (define_insn "*negsi2_h8300hs"
2113 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2114 (neg:SI (match_operand:SI 1 "h8300_dst_operand" "0")))]
2115 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2116 "neg.l %S0"
2117 [(set_attr "length_table" "unary")
2118 (set_attr "cc" "set_zn")])
2119
2120 (define_expand "negsf2"
2121 [(set (match_operand:SF 0 "register_operand" "")
2122 (neg:SF (match_operand:SF 1 "register_operand" "")))]
2123 ""
2124 "")
2125
2126 (define_insn "*negsf2_h8300"
2127 [(set (match_operand:SF 0 "register_operand" "=r")
2128 (neg:SF (match_operand:SF 1 "register_operand" "0")))]
2129 "TARGET_H8300"
2130 "xor.b\\t#128,%z0"
2131 [(set_attr "length" "2")])
2132
2133 (define_insn "*negsf2_h8300hs"
2134 [(set (match_operand:SF 0 "register_operand" "=r")
2135 (neg:SF (match_operand:SF 1 "register_operand" "0")))]
2136 "TARGET_H8300H || TARGET_H8300S"
2137 "xor.w\\t#32768,%e0"
2138 [(set_attr "length" "4")])
2139 \f
2140 ;; ----------------------------------------------------------------------
2141 ;; ABSOLUTE VALUE INSTRUCTIONS
2142 ;; ----------------------------------------------------------------------
2143
2144 (define_expand "abssf2"
2145 [(set (match_operand:SF 0 "register_operand" "")
2146 (abs:SF (match_operand:SF 1 "register_operand" "")))]
2147 ""
2148 "")
2149
2150 (define_insn "*abssf2_h8300"
2151 [(set (match_operand:SF 0 "register_operand" "=r")
2152 (abs:SF (match_operand:SF 1 "register_operand" "0")))]
2153 "TARGET_H8300"
2154 "and.b\\t#127,%z0"
2155 [(set_attr "length" "2")])
2156
2157 (define_insn "*abssf2_h8300hs"
2158 [(set (match_operand:SF 0 "register_operand" "=r")
2159 (abs:SF (match_operand:SF 1 "register_operand" "0")))]
2160 "TARGET_H8300H || TARGET_H8300S"
2161 "and.w\\t#32767,%e0"
2162 [(set_attr "length" "4")])
2163 \f
2164 ;; ----------------------------------------------------------------------
2165 ;; NOT INSTRUCTIONS
2166 ;; ----------------------------------------------------------------------
2167
2168 (define_expand "one_cmplqi2"
2169 [(set (match_operand:QI 0 "register_operand" "")
2170 (not:QI (match_operand:QI 1 "register_operand" "")))]
2171 ""
2172 "")
2173
2174 (define_insn "*one_cmplqi2"
2175 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
2176 (not:QI (match_operand:QI 1 "h8300_dst_operand" "0")))]
2177 ""
2178 "not %X0"
2179 [(set_attr "length_table" "unary")
2180 (set_attr "cc" "set_znv")])
2181
2182 (define_expand "one_cmplhi2"
2183 [(set (match_operand:HI 0 "register_operand" "")
2184 (not:HI (match_operand:HI 1 "register_operand" "")))]
2185 ""
2186 "")
2187
2188 (define_insn "*one_cmplhi2_h8300"
2189 [(set (match_operand:HI 0 "register_operand" "=r")
2190 (not:HI (match_operand:HI 1 "register_operand" "0")))]
2191 "TARGET_H8300"
2192 "not %s0\;not %t0"
2193 [(set_attr "length" "4")])
2194
2195 (define_insn "*one_cmplhi2_h8300hs"
2196 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2197 (not:HI (match_operand:HI 1 "h8300_dst_operand" "0")))]
2198 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2199 "not.w %T0"
2200 [(set_attr "cc" "set_znv")
2201 (set_attr "length_table" "unary")])
2202
2203 (define_expand "one_cmplsi2"
2204 [(set (match_operand:SI 0 "register_operand" "")
2205 (not:SI (match_operand:SI 1 "register_operand" "")))]
2206 ""
2207 "")
2208
2209 (define_insn "*one_cmplsi2_h8300"
2210 [(set (match_operand:SI 0 "register_operand" "=r")
2211 (not:SI (match_operand:SI 1 "register_operand" "0")))]
2212 "TARGET_H8300"
2213 "not %w0\;not %x0\;not %y0\;not %z0"
2214 [(set_attr "length" "8")])
2215
2216 (define_insn "*one_cmplsi2_h8300hs"
2217 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
2218 (not:SI (match_operand:SI 1 "h8300_dst_operand" "0")))]
2219 "(TARGET_H8300H || TARGET_H8300S) && h8300_operands_match_p (operands)"
2220 "not.l %S0"
2221 [(set_attr "cc" "set_znv")
2222 (set_attr "length_table" "unary")])
2223 \f
2224 ;; ----------------------------------------------------------------------
2225 ;; JUMP INSTRUCTIONS
2226 ;; ----------------------------------------------------------------------
2227
2228 ;; Conditional jump instructions
2229
2230 (define_expand "cbranchqi4"
2231 [(use (match_operator 0 "ordered_comparison_operator"
2232 [(match_operand:QI 1 "h8300_dst_operand" "")
2233 (match_operand:QI 2 "h8300_src_operand" "")]))
2234 (use (match_operand 3 ""))]
2235 ""
2236 "h8300_expand_branch (operands); DONE;")
2237
2238 (define_expand "cbranchhi4"
2239 [(use (match_operator 0 "ordered_comparison_operator"
2240 [(match_operand:HI 1 "h8300_dst_operand" "")
2241 (match_operand:HI 2 "h8300_src_operand" "")]))
2242 (use (match_operand 3 ""))]
2243 ""
2244 "
2245 {
2246 /* Force operand1 into a register if we're compiling
2247 for the H8/300. */
2248 if ((GET_CODE (operands[2]) != REG && operands[2] != const0_rtx)
2249 && TARGET_H8300)
2250 operands[2] = force_reg (HImode, operands[2]);
2251 h8300_expand_branch (operands); DONE;
2252 }")
2253
2254 (define_expand "cbranchsi4"
2255 [(use (match_operator 0 "ordered_comparison_operator"
2256 [(match_operand:SI 1 "h8300_dst_operand" "")
2257 (match_operand:SI 2 "h8300_src_operand" "")]))
2258 (use (match_operand 3 ""))]
2259 "TARGET_H8300H || TARGET_H8300S"
2260 "h8300_expand_branch (operands); DONE;")
2261
2262 (define_insn "branch_true"
2263 [(set (pc)
2264 (if_then_else (match_operator 1 "comparison_operator"
2265 [(cc0) (const_int 0)])
2266 (label_ref (match_operand 0 "" ""))
2267 (pc)))]
2268 ""
2269 "*
2270 {
2271 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
2272 && (GET_CODE (operands[1]) == GT
2273 || GET_CODE (operands[1]) == GE
2274 || GET_CODE (operands[1]) == LE
2275 || GET_CODE (operands[1]) == LT))
2276 {
2277 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
2278 return 0;
2279 }
2280
2281 if (get_attr_length (insn) == 2)
2282 return \"b%j1 %l0\";
2283 else if (get_attr_length (insn) == 4)
2284 return \"b%j1 %l0:16\";
2285 else
2286 return \"b%k1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
2287 }"
2288 [(set_attr "type" "branch")
2289 (set_attr "cc" "none")])
2290
2291 (define_insn "branch_false"
2292 [(set (pc)
2293 (if_then_else (match_operator 1 "comparison_operator"
2294 [(cc0) (const_int 0)])
2295 (pc)
2296 (label_ref (match_operand 0 "" ""))))]
2297 ""
2298 "*
2299 {
2300 if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
2301 && (GET_CODE (operands[1]) == GT
2302 || GET_CODE (operands[1]) == GE
2303 || GET_CODE (operands[1]) == LE
2304 || GET_CODE (operands[1]) == LT))
2305 {
2306 cc_status.flags &= ~CC_OVERFLOW_UNUSABLE;
2307 return 0;
2308 }
2309
2310 if (get_attr_length (insn) == 2)
2311 return \"b%k1 %l0\";
2312 else if (get_attr_length (insn) == 4)
2313 return \"b%k1 %l0:16\";
2314 else
2315 return \"b%j1 .Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
2316 }"
2317 [(set_attr "type" "branch")
2318 (set_attr "cc" "none")])
2319
2320 (define_insn "*brabc"
2321 [(set (pc)
2322 (if_then_else
2323 (eq (zero_extract (match_operand:QI 1 "bit_memory_operand" "WU")
2324 (const_int 1)
2325 (match_operand:QI 2 "immediate_operand" "n"))
2326 (const_int 0))
2327 (label_ref (match_operand 0 "" ""))
2328 (pc)))]
2329 "TARGET_H8300SX"
2330 "*
2331 {
2332 switch (get_attr_length (insn)
2333 - h8300_insn_length_from_table (insn, operands))
2334 {
2335 case 2:
2336 return \"bra/bc %2,%R1,%l0\";
2337
2338 case 4:
2339 return \"bra/bc %2,%R1,%l0:16\";
2340
2341 default:
2342 return \"bra/bs %2,%R1,.Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
2343 }
2344 }"
2345 [(set_attr "type" "bitbranch")
2346 (set_attr "length_table" "bitbranch")
2347 (set_attr "cc" "none")])
2348
2349 (define_insn "*brabs"
2350 [(set (pc)
2351 (if_then_else
2352 (ne (zero_extract (match_operand:QI 1 "bit_memory_operand" "WU")
2353 (const_int 1)
2354 (match_operand:QI 2 "immediate_operand" "n"))
2355 (const_int 0))
2356 (label_ref (match_operand 0 "" ""))
2357 (pc)))]
2358 "TARGET_H8300SX"
2359 "*
2360 {
2361 switch (get_attr_length (insn)
2362 - h8300_insn_length_from_table (insn, operands))
2363 {
2364 case 2:
2365 return \"bra/bs %2,%R1,%l0\";
2366
2367 case 4:
2368 return \"bra/bs %2,%R1,%l0:16\";
2369
2370 default:
2371 return \"bra/bc %2,%R1,.Lh8BR%=\;jmp @%l0\\n.Lh8BR%=:\";
2372 }
2373 }"
2374 [(set_attr "type" "bitbranch")
2375 (set_attr "length_table" "bitbranch")
2376 (set_attr "cc" "none")])
2377
2378 ;; Unconditional and other jump instructions.
2379
2380 (define_insn "jump"
2381 [(set (pc)
2382 (label_ref (match_operand 0 "" "")))]
2383 ""
2384 "*
2385 {
2386 if (final_sequence != 0)
2387 {
2388 if (get_attr_length (insn) == 2)
2389 return \"bra/s %l0\";
2390 else
2391 {
2392 /* The branch isn't short enough to use bra/s. Output the
2393 branch and delay slot in their normal order.
2394
2395 If this is a backward branch, it will now be branching two
2396 bytes further than previously thought. The length-based
2397 test for bra vs. jump is very conservative though, so the
2398 branch will still be within range. */
2399 rtvec vec;
2400 int seen;
2401
2402 vec = XVEC (final_sequence, 0);
2403 final_sequence = 0;
2404 final_scan_insn (RTVEC_ELT (vec, 1), asm_out_file, optimize, 1, & seen);
2405 final_scan_insn (RTVEC_ELT (vec, 0), asm_out_file, optimize, 1, & seen);
2406 INSN_DELETED_P (RTVEC_ELT (vec, 1)) = 1;
2407 return \"\";
2408 }
2409 }
2410 else if (get_attr_length (insn) == 2)
2411 return \"bra %l0\";
2412 else if (get_attr_length (insn) == 4)
2413 return \"bra %l0:16\";
2414 else
2415 return \"jmp @%l0\";
2416 }"
2417 [(set_attr "type" "branch")
2418 (set (attr "delay_slot")
2419 (if_then_else (match_test "TARGET_H8300SX")
2420 (const_string "jump")
2421 (const_string "none")))
2422 (set_attr "cc" "none")])
2423
2424 ;; This is a define expand, because pointers may be either 16 or 32 bits.
2425
2426 (define_expand "tablejump"
2427 [(parallel [(set (pc) (match_operand 0 "register_operand" ""))
2428 (use (label_ref (match_operand 1 "" "")))])]
2429 ""
2430 "")
2431
2432 (define_insn "*tablejump_h8300"
2433 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
2434 (use (label_ref (match_operand 1 "" "")))]
2435 "TARGET_H8300"
2436 "jmp @%0"
2437 [(set_attr "cc" "none")
2438 (set_attr "length" "2")])
2439
2440 (define_insn "*tablejump_h8300hs_advanced"
2441 [(set (pc) (match_operand:SI 0 "register_operand" "r"))
2442 (use (label_ref (match_operand 1 "" "")))]
2443 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE"
2444 "jmp @%0"
2445 [(set_attr "cc" "none")
2446 (set_attr "length" "2")])
2447
2448 (define_insn "*tablejump_h8300hs_normal"
2449 [(set (pc) (match_operand:HI 0 "register_operand" "r"))
2450 (use (label_ref (match_operand 1 "" "")))]
2451 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
2452 "jmp @%S0"
2453 [(set_attr "cc" "none")
2454 (set_attr "length" "2")])
2455
2456 ;; This is a define expand, because pointers may be either 16 or 32 bits.
2457
2458 (define_expand "indirect_jump"
2459 [(set (pc) (match_operand 0 "jump_address_operand" ""))]
2460 ""
2461 "")
2462
2463 (define_insn "*indirect_jump_h8300"
2464 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
2465 "TARGET_H8300"
2466 "jmp @%0"
2467 [(set_attr "cc" "none")
2468 (set_attr "length" "2")])
2469
2470 (define_insn "*indirect_jump_h8300hs_advanced"
2471 [(set (pc) (match_operand:SI 0 "jump_address_operand" "Vr"))]
2472 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE"
2473 "jmp @%0"
2474 [(set_attr "cc" "none")
2475 (set_attr "length" "2")])
2476
2477 (define_insn "*indirect_jump_h8300hs_normal"
2478 [(set (pc) (match_operand:HI 0 "jump_address_operand" "Vr"))]
2479 "(TARGET_H8300H || TARGET_H8300S) && TARGET_NORMAL_MODE"
2480 "jmp @%S0"
2481 [(set_attr "cc" "none")
2482 (set_attr "length" "2")])
2483
2484 ;; Call subroutine with no return value.
2485
2486 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
2487
2488 (define_insn "call"
2489 [(call (match_operand:QI 0 "call_insn_operand" "or")
2490 (match_operand:HI 1 "general_operand" "g"))]
2491 ""
2492 "*
2493 {
2494 if (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
2495 && SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
2496 return \"jsr\\t@%0:8\";
2497 else
2498 return \"jsr\\t%0\";
2499 }"
2500 [(set_attr "type" "call")
2501 (set (attr "length")
2502 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
2503 (const_int 2)
2504 (const_int 4)))])
2505
2506 ;; Call subroutine, returning value in operand 0
2507 ;; (which must be a hard register).
2508
2509 ;; ??? Even though we use HImode here, this works on the H8/300H and H8S.
2510
2511 (define_insn "call_value"
2512 [(set (match_operand 0 "" "=r")
2513 (call (match_operand:QI 1 "call_insn_operand" "or")
2514 (match_operand:HI 2 "general_operand" "g")))]
2515 ""
2516 "*
2517 {
2518 if (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
2519 && SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
2520 return \"jsr\\t@%1:8\";
2521 else
2522 return \"jsr\\t%1\";
2523 }"
2524 [(set_attr "type" "call")
2525 (set (attr "length")
2526 (if_then_else (match_operand:QI 0 "small_call_insn_operand" "")
2527 (const_int 2)
2528 (const_int 4)))])
2529
2530 (define_insn "nop"
2531 [(const_int 0)]
2532 ""
2533 "nop"
2534 [(set_attr "cc" "none")
2535 (set_attr "length" "2")])
2536 \f
2537 ;; ----------------------------------------------------------------------
2538 ;; PROLOGUE/EPILOGUE-RELATED INSTRUCTIONS
2539 ;; ----------------------------------------------------------------------
2540
2541 (define_expand "push_h8300"
2542 [(set (mem:HI (pre_dec:HI (reg:HI SP_REG)))
2543 (match_operand:HI 0 "register_operand" ""))]
2544 "TARGET_H8300"
2545 "")
2546
2547 (define_expand "push_h8300hs_advanced"
2548 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
2549 (match_operand:SI 0 "register_operand" ""))]
2550 "TARGET_H8300H && TARGET_H8300S && !TARGET_NORMAL_MODE"
2551 "")
2552
2553 (define_expand "push_h8300hs_normal"
2554 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
2555 (match_operand:SI 0 "register_operand" ""))]
2556 "TARGET_H8300H && TARGET_H8300S && TARGET_NORMAL_MODE"
2557 "")
2558
2559 (define_expand "pop_h8300"
2560 [(set (match_operand:HI 0 "register_operand" "")
2561 (mem:HI (post_inc:HI (reg:HI SP_REG))))]
2562 "TARGET_H8300"
2563 "")
2564
2565 (define_expand "pop_h8300hs_advanced"
2566 [(set (match_operand:SI 0 "register_operand" "")
2567 (mem:SI (post_inc:SI (reg:SI SP_REG))))]
2568 "TARGET_H8300H && TARGET_H8300S && !TARGET_NORMAL_MODE"
2569 "")
2570
2571 (define_expand "pop_h8300hs_normal"
2572 [(set (match_operand:SI 0 "register_operand" "")
2573 (mem:SI (post_inc:HI (reg:HI SP_REG))))]
2574 "TARGET_H8300H && TARGET_H8300S && TARGET_NORMAL_MODE"
2575 "")
2576
2577 (define_insn "ldm_h8300sx"
2578 [(match_parallel 0 "h8300_ldm_parallel"
2579 [(set (match_operand:SI 1 "register_operand" "")
2580 (match_operand:SI 2 "memory_operand" ""))])]
2581 "TARGET_H8300S"
2582 {
2583 operands[3] = SET_DEST (XVECEXP (operands[0], 0,
2584 XVECLEN (operands[0], 0) - 2));
2585 return "ldm.l\t@er7+,%S1-%S3";
2586 }
2587 [(set_attr "cc" "none")
2588 (set_attr "length" "4")])
2589
2590 (define_insn "stm_h8300sx"
2591 [(match_parallel 0 "h8300_stm_parallel"
2592 [(set (match_operand:SI 1 "memory_operand" "")
2593 (match_operand:SI 2 "register_operand" ""))])]
2594 "TARGET_H8300S"
2595 {
2596 operands[3] = SET_SRC (XVECEXP (operands[0], 0,
2597 XVECLEN (operands[0], 0) - 2));
2598 return "stm.l\t%S2-%S3,@-er7";
2599 }
2600 [(set_attr "cc" "none")
2601 (set_attr "length" "4")])
2602
2603 (define_insn "return_h8sx"
2604 [(match_parallel 0 "h8300_return_parallel"
2605 [(return)
2606 (set (match_operand:SI 1 "register_operand" "")
2607 (match_operand:SI 2 "memory_operand" ""))])]
2608 "TARGET_H8300SX"
2609 {
2610 operands[3] = SET_DEST (XVECEXP (operands[0], 0,
2611 XVECLEN (operands[0], 0) - 2));
2612 if (h8300_current_function_interrupt_function_p ()
2613 || h8300_current_function_monitor_function_p ())
2614 return "rte/l\t%S1-%S3";
2615 else
2616 return "rts/l\t%S1-%S3";
2617 }
2618 [(set_attr "cc" "none")
2619 (set_attr "can_delay" "no")
2620 (set_attr "length" "2")])
2621
2622 (define_expand "return"
2623 [(return)]
2624 "h8300_can_use_return_insn_p ()"
2625 "")
2626
2627 (define_insn "*return_1"
2628 [(return)]
2629 "reload_completed"
2630 "*
2631 {
2632 if (h8300_current_function_interrupt_function_p ()
2633 || h8300_current_function_monitor_function_p ())
2634 return \"rte\";
2635 else
2636 return \"rts\";
2637 }"
2638 [(set_attr "cc" "none")
2639 (set_attr "can_delay" "no")
2640 (set_attr "length" "2")])
2641
2642 (define_expand "prologue"
2643 [(const_int 0)]
2644 ""
2645 "h8300_expand_prologue (); DONE;")
2646
2647 (define_expand "epilogue"
2648 [(return)]
2649 ""
2650 "h8300_expand_epilogue (); DONE;")
2651
2652 (define_insn "monitor_prologue"
2653 [(unspec_volatile [(const_int 0)] UNSPEC_MONITOR)]
2654 ""
2655 "*
2656 {
2657 if (TARGET_H8300)
2658 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\";
2659 else if (TARGET_H8300H && TARGET_NORMAL_MODE)
2660 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\";
2661 else if (TARGET_H8300H)
2662 return \"mov.l\\ter0,@-er7\;stc\\tccr,r0l\;mov.b\\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\\t#128,ccr\";
2663 else if (TARGET_H8300S && TARGET_NEXR )
2664 return \"mov.l\\ter0,@-er7\;stc\tccr,r0l\;mov.b\tr0l,@(4,er7)\;mov.l\\t@er7+,er0\;orc\t#128,ccr\";
2665 else if (TARGET_H8300S && TARGET_NEXR && TARGET_NORMAL_MODE)
2666 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\";
2667 else if (TARGET_H8300S && TARGET_NORMAL_MODE)
2668 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\";
2669 else if (TARGET_H8300S)
2670 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\";
2671 gcc_unreachable ();
2672 }"
2673 [(set_attr "length" "20")])
2674 \f
2675 ;; ----------------------------------------------------------------------
2676 ;; EXTEND INSTRUCTIONS
2677 ;; ----------------------------------------------------------------------
2678
2679 (define_expand "zero_extendqihi2"
2680 [(set (match_operand:HI 0 "register_operand" "")
2681 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
2682 ""
2683 "")
2684
2685 (define_insn "*zero_extendqihi2_h8300"
2686 [(set (match_operand:HI 0 "register_operand" "=r,r")
2687 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2688 "TARGET_H8300"
2689 "@
2690 mov.b #0,%t0
2691 #"
2692 [(set_attr "length" "2,10")])
2693
2694 (define_insn "*zero_extendqihi2_h8300hs"
2695 [(set (match_operand:HI 0 "register_operand" "=r,r")
2696 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2697 "TARGET_H8300H || TARGET_H8300S"
2698 "@
2699 extu.w %T0
2700 #"
2701 [(set_attr "length" "2,10")
2702 (set_attr "cc" "set_znv,set_znv")])
2703
2704 ;; Split the zero extension of a general operand (actually a memory
2705 ;; operand) into a load of the operand and the actual zero extension
2706 ;; so that 1) the length will be accurate, and 2) the zero extensions
2707 ;; appearing at the end of basic blocks may be merged.
2708
2709 (define_split
2710 [(set (match_operand:HI 0 "register_operand" "")
2711 (zero_extend:HI (match_operand:QI 1 "general_operand_src" "")))]
2712 "reload_completed"
2713 [(set (match_dup 2)
2714 (match_dup 1))
2715 (set (match_dup 0)
2716 (zero_extend:HI (match_dup 2)))]
2717 "operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));")
2718
2719 (define_expand "zero_extendqisi2"
2720 [(set (match_operand:SI 0 "register_operand" "")
2721 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2722 ""
2723 {
2724 if (TARGET_H8300SX)
2725 operands[1] = force_reg (QImode, operands[1]);
2726 })
2727
2728 (define_insn "*zero_extendqisi2_h8300"
2729 [(set (match_operand:SI 0 "register_operand" "=r,r")
2730 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2731 "TARGET_H8300"
2732 "@
2733 mov.b #0,%x0\;sub.w %e0,%e0
2734 mov.b %R1,%w0\;mov.b #0,%x0\;sub.w %e0,%e0"
2735 [(set_attr "length" "4,8")])
2736
2737 (define_insn "*zero_extendqisi2_h8300hs"
2738 [(set (match_operand:SI 0 "register_operand" "=r,r")
2739 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2740 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX"
2741 "#")
2742
2743 (define_split
2744 [(set (match_operand:SI 0 "register_operand" "")
2745 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2746 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
2747 && reg_overlap_mentioned_p (operands[0], operands[1])
2748 && reload_completed"
2749 [(set (match_dup 2)
2750 (match_dup 1))
2751 (set (match_dup 3)
2752 (zero_extend:HI (match_dup 2)))
2753 (set (match_dup 0)
2754 (zero_extend:SI (match_dup 3)))]
2755 "operands[2] = gen_lowpart (QImode, operands[0]);
2756 operands[3] = gen_lowpart (HImode, operands[0]);")
2757
2758 (define_split
2759 [(set (match_operand:SI 0 "register_operand" "")
2760 (zero_extend:SI (match_operand:QI 1 "general_operand_src" "")))]
2761 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX
2762 && !reg_overlap_mentioned_p (operands[0], operands[1])
2763 && reload_completed"
2764 [(set (match_dup 0)
2765 (const_int 0))
2766 (set (strict_low_part (match_dup 2))
2767 (match_dup 1))]
2768 "operands[2] = gen_rtx_REG (QImode, REGNO (operands[0]));")
2769
2770 (define_insn "*zero_extendqisi2_h8sx"
2771 [(set (match_operand:SI 0 "register_operand" "=r")
2772 (zero_extend:SI (match_operand:QI 1 "register_operand" "0")))]
2773 "TARGET_H8300SX"
2774 "extu.l\t#2,%0"
2775 [(set_attr "length" "2")
2776 (set_attr "cc" "set_znv")])
2777
2778 (define_expand "zero_extendhisi2"
2779 [(set (match_operand:SI 0 "register_operand" "")
2780 (zero_extend:SI (match_operand:HI 1 "register_operand" "")))]
2781 ""
2782 "")
2783
2784 ;; %e prints the high part of a CONST_INT, not the low part. Arggh.
2785 (define_insn "*zero_extendhisi2_h8300"
2786 [(set (match_operand:SI 0 "register_operand" "=r,r,r")
2787 (zero_extend:SI (match_operand:HI 1 "general_operand_src" "0,i,g>")))]
2788 "TARGET_H8300"
2789 "@
2790 sub.w %e0,%e0
2791 mov.w %f1,%f0\;sub.w %e0,%e0
2792 mov.w %e1,%f0\;sub.w %e0,%e0"
2793 [(set_attr "length" "2,4,6")])
2794
2795 (define_insn "*zero_extendhisi2_h8300hs"
2796 [(set (match_operand:SI 0 "register_operand" "=r")
2797 (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))]
2798 "TARGET_H8300H || TARGET_H8300S"
2799 "extu.l %S0"
2800 [(set_attr "length" "2")
2801 (set_attr "cc" "set_znv")])
2802
2803 (define_expand "extendqihi2"
2804 [(set (match_operand:HI 0 "register_operand" "")
2805 (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
2806 ""
2807 "")
2808
2809 (define_insn "*extendqihi2_h8300"
2810 [(set (match_operand:HI 0 "register_operand" "=r,r")
2811 (sign_extend:HI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2812 "TARGET_H8300"
2813 "@
2814 bld #7,%s0\;subx %t0,%t0
2815 mov.b %R1,%s0\;bld #7,%s0\;subx %t0,%t0"
2816 [(set_attr "length" "4,8")])
2817
2818 (define_insn "*extendqihi2_h8300hs"
2819 [(set (match_operand:HI 0 "register_operand" "=r")
2820 (sign_extend:HI (match_operand:QI 1 "register_operand" "0")))]
2821 "TARGET_H8300H || TARGET_H8300S"
2822 "exts.w %T0"
2823 [(set_attr "length" "2")
2824 (set_attr "cc" "set_znv")])
2825
2826 (define_expand "extendqisi2"
2827 [(set (match_operand:SI 0 "register_operand" "")
2828 (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
2829 ""
2830 "")
2831
2832 (define_insn "*extendqisi2_h8300"
2833 [(set (match_operand:SI 0 "register_operand" "=r,r")
2834 (sign_extend:SI (match_operand:QI 1 "general_operand_src" "0,g>")))]
2835 "TARGET_H8300"
2836 "@
2837 bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0
2838 mov.b %R1,%w0\;bld #7,%w0\;subx %x0,%x0\;subx %y0,%y0\;subx %z0,%z0"
2839 [(set_attr "length" "8,12")])
2840
2841 ;; The following pattern is needed because without the pattern, the
2842 ;; combiner would split (sign_extend:SI (reg:QI)) into two 24-bit
2843 ;; shifts, one ashift and one ashiftrt.
2844
2845 (define_insn_and_split "*extendqisi2_h8300hs"
2846 [(set (match_operand:SI 0 "register_operand" "=r")
2847 (sign_extend:SI (match_operand:QI 1 "register_operand" "0")))]
2848 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_H8300SX"
2849 "#"
2850 "&& reload_completed"
2851 [(set (match_dup 2)
2852 (sign_extend:HI (match_dup 1)))
2853 (set (match_dup 0)
2854 (sign_extend:SI (match_dup 2)))]
2855 "operands[2] = gen_rtx_REG (HImode, REGNO (operands[0]));")
2856
2857 (define_insn "*extendqisi2_h8sx"
2858 [(set (match_operand:SI 0 "register_operand" "=r")
2859 (sign_extend:SI (match_operand:QI 1 "register_operand" "0")))]
2860 "TARGET_H8300SX"
2861 "exts.l\t#2,%0"
2862 [(set_attr "length" "2")
2863 (set_attr "cc" "set_znv")])
2864
2865 (define_expand "extendhisi2"
2866 [(set (match_operand:SI 0 "register_operand" "")
2867 (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
2868 ""
2869 "")
2870
2871 (define_insn "*extendhisi2_h8300"
2872 [(set (match_operand:SI 0 "register_operand" "=r,r")
2873 (sign_extend:SI (match_operand:HI 1 "general_operand_src" "0,g>")))]
2874 "TARGET_H8300"
2875 "@
2876 bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0
2877 mov.w %T1,%f0\;bld #7,%x0\;subx %y0,%y0\;subx %z0,%z0"
2878 [(set_attr "length" "6,10")])
2879
2880 (define_insn "*extendhisi2_h8300hs"
2881 [(set (match_operand:SI 0 "register_operand" "=r")
2882 (sign_extend:SI (match_operand:HI 1 "register_operand" "0")))]
2883 "TARGET_H8300H || TARGET_H8300S"
2884 "exts.l %S0"
2885 [(set_attr "length" "2")
2886 (set_attr "cc" "set_znv")])
2887 \f
2888 ;; ----------------------------------------------------------------------
2889 ;; SHIFTS
2890 ;; ----------------------------------------------------------------------
2891 ;;
2892 ;; We make some attempt to provide real efficient shifting. One example is
2893 ;; doing an 8-bit shift of a 16-bit value by moving a byte reg into the other
2894 ;; reg and moving 0 into the former reg.
2895 ;;
2896 ;; We also try to achieve this in a uniform way. IE: We don't try to achieve
2897 ;; this in both rtl and at insn emit time. Ideally, we'd use rtl as that would
2898 ;; give the optimizer more cracks at the code. However, we wish to do things
2899 ;; like optimizing shifting the sign bit to bit 0 by rotating the other way.
2900 ;; There is rtl to handle this (rotate + and), but the H8/300 doesn't handle
2901 ;; 16-bit rotates. Also, if we emit complicated rtl, combine may not be able
2902 ;; to detect cases it can optimize.
2903 ;;
2904 ;; For these and other fuzzy reasons, I've decided to go the less pretty but
2905 ;; easier "do it at insn emit time" route.
2906
2907 ;; QI BIT SHIFTS
2908
2909 (define_expand "ashlqi3"
2910 [(set (match_operand:QI 0 "register_operand" "")
2911 (ashift:QI (match_operand:QI 1 "register_operand" "")
2912 (match_operand:QI 2 "nonmemory_operand" "")))]
2913 ""
2914 "if (expand_a_shift (QImode, ASHIFT, operands)) DONE;")
2915
2916 (define_expand "ashrqi3"
2917 [(set (match_operand:QI 0 "register_operand" "")
2918 (ashiftrt:QI (match_operand:QI 1 "register_operand" "")
2919 (match_operand:QI 2 "nonmemory_operand" "")))]
2920 ""
2921 "if (expand_a_shift (QImode, ASHIFTRT, operands)) DONE;")
2922
2923 (define_expand "lshrqi3"
2924 [(set (match_operand:QI 0 "register_operand" "")
2925 (lshiftrt:QI (match_operand:QI 1 "register_operand" "")
2926 (match_operand:QI 2 "nonmemory_operand" "")))]
2927 ""
2928 "if (expand_a_shift (QImode, LSHIFTRT, operands)) DONE;")
2929
2930 (define_insn ""
2931 [(set (match_operand:QI 0 "h8300_dst_operand" "=rQ")
2932 (match_operator:QI 3 "h8sx_unary_shift_operator"
2933 [(match_operand:QI 1 "h8300_dst_operand" "0")
2934 (match_operand:QI 2 "const_int_operand" "")]))]
2935 "h8300_operands_match_p (operands)"
2936 { return output_h8sx_shift (operands, 'b', 'X'); }
2937 [(set_attr "length_table" "unary")
2938 (set_attr "cc" "set_znv")])
2939
2940 (define_insn ""
2941 [(set (match_operand:QI 0 "register_operand" "=r")
2942 (match_operator:QI 3 "h8sx_binary_shift_operator"
2943 [(match_operand:QI 1 "register_operand" "0")
2944 (match_operand:QI 2 "nonmemory_operand" "r P3>X")]))]
2945 ""
2946 { return output_h8sx_shift (operands, 'b', 'X'); }
2947 [(set_attr "length" "4")
2948 (set_attr "cc" "set_znv")])
2949
2950 (define_insn "*shiftqi"
2951 [(set (match_operand:QI 0 "register_operand" "=r,r")
2952 (match_operator:QI 3 "nshift_operator"
2953 [ (match_operand:QI 1 "register_operand" "0,0")
2954 (match_operand:QI 2 "nonmemory_operand" "R,rn")]))
2955 (clobber (match_scratch:QI 4 "=X,&r"))]
2956 ""
2957 "* return output_a_shift (operands);"
2958 [(set (attr "length")
2959 (symbol_ref "compute_a_shift_length (insn, operands)"))
2960 (set (attr "cc")
2961 (symbol_ref "compute_a_shift_cc (insn, operands)"))])
2962
2963 ;; HI BIT SHIFTS
2964
2965 (define_expand "ashlhi3"
2966 [(set (match_operand:HI 0 "register_operand" "")
2967 (ashift:HI (match_operand:HI 1 "register_operand" "")
2968 (match_operand:QI 2 "nonmemory_operand" "")))]
2969 ""
2970 "if (expand_a_shift (HImode, ASHIFT, operands)) DONE;")
2971
2972 (define_expand "lshrhi3"
2973 [(set (match_operand:HI 0 "register_operand" "")
2974 (lshiftrt:HI (match_operand:HI 1 "register_operand" "")
2975 (match_operand:QI 2 "nonmemory_operand" "")))]
2976 ""
2977 "if (expand_a_shift (HImode, LSHIFTRT, operands)) DONE;")
2978
2979 (define_expand "ashrhi3"
2980 [(set (match_operand:HI 0 "register_operand" "")
2981 (ashiftrt:HI (match_operand:HI 1 "register_operand" "")
2982 (match_operand:QI 2 "nonmemory_operand" "")))]
2983 ""
2984 "if (expand_a_shift (HImode, ASHIFTRT, operands)) DONE;")
2985
2986 (define_insn ""
2987 [(set (match_operand:HI 0 "h8300_dst_operand" "=rQ")
2988 (match_operator:HI 3 "h8sx_unary_shift_operator"
2989 [(match_operand:HI 1 "h8300_dst_operand" "0")
2990 (match_operand:QI 2 "const_int_operand" "")]))]
2991 "h8300_operands_match_p (operands)"
2992 { return output_h8sx_shift (operands, 'w', 'T'); }
2993 [(set_attr "length_table" "unary")
2994 (set_attr "cc" "set_znv")])
2995
2996 (define_insn ""
2997 [(set (match_operand:HI 0 "register_operand" "=r")
2998 (match_operator:HI 3 "h8sx_binary_shift_operator"
2999 [(match_operand:HI 1 "register_operand" "0")
3000 (match_operand:QI 2 "nonmemory_operand" "r P4>X")]))]
3001 ""
3002 { return output_h8sx_shift (operands, 'w', 'T'); }
3003 [(set_attr "length" "4")
3004 (set_attr "cc" "set_znv")])
3005
3006 (define_insn "*shifthi"
3007 [(set (match_operand:HI 0 "register_operand" "=r,r")
3008 (match_operator:HI 3 "nshift_operator"
3009 [ (match_operand:HI 1 "register_operand" "0,0")
3010 (match_operand:QI 2 "nonmemory_operand" "S,rn")]))
3011 (clobber (match_scratch:QI 4 "=X,&r"))]
3012 ""
3013 "* return output_a_shift (operands);"
3014 [(set (attr "length")
3015 (symbol_ref "compute_a_shift_length (insn, operands)"))
3016 (set (attr "cc")
3017 (symbol_ref "compute_a_shift_cc (insn, operands)"))])
3018
3019 ;; SI BIT SHIFTS
3020
3021 (define_expand "ashlsi3"
3022 [(set (match_operand:SI 0 "register_operand" "")
3023 (ashift:SI (match_operand:SI 1 "register_operand" "")
3024 (match_operand:QI 2 "nonmemory_operand" "")))]
3025 ""
3026 "if (expand_a_shift (SImode, ASHIFT, operands)) DONE;")
3027
3028 (define_expand "lshrsi3"
3029 [(set (match_operand:SI 0 "register_operand" "")
3030 (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
3031 (match_operand:QI 2 "nonmemory_operand" "")))]
3032 ""
3033 "if (expand_a_shift (SImode, LSHIFTRT, operands)) DONE;")
3034
3035 (define_expand "ashrsi3"
3036 [(set (match_operand:SI 0 "register_operand" "")
3037 (ashiftrt:SI (match_operand:SI 1 "register_operand" "")
3038 (match_operand:QI 2 "nonmemory_operand" "")))]
3039 ""
3040 "if (expand_a_shift (SImode, ASHIFTRT, operands)) DONE;")
3041
3042 (define_insn ""
3043 [(set (match_operand:SI 0 "h8300_dst_operand" "=rQ")
3044 (match_operator:SI 3 "h8sx_unary_shift_operator"
3045 [(match_operand:SI 1 "h8300_dst_operand" "0")
3046 (match_operand:QI 2 "const_int_operand" "")]))]
3047 "h8300_operands_match_p (operands)"
3048 { return output_h8sx_shift (operands, 'l', 'S'); }
3049 [(set_attr "length_table" "unary")
3050 (set_attr "cc" "set_znv")])
3051
3052 (define_insn ""
3053 [(set (match_operand:SI 0 "register_operand" "=r")
3054 (match_operator:SI 3 "h8sx_binary_shift_operator"
3055 [(match_operand:SI 1 "register_operand" "0")
3056 (match_operand:QI 2 "nonmemory_operand" "r P5>X")]))]
3057 ""
3058 { return output_h8sx_shift (operands, 'l', 'S'); }
3059 [(set_attr "length" "4")
3060 (set_attr "cc" "set_znv")])
3061
3062 (define_insn "*shiftsi"
3063 [(set (match_operand:SI 0 "register_operand" "=r,r")
3064 (match_operator:SI 3 "nshift_operator"
3065 [ (match_operand:SI 1 "register_operand" "0,0")
3066 (match_operand:QI 2 "nonmemory_operand" "T,rn")]))
3067 (clobber (match_scratch:QI 4 "=X,&r"))]
3068 ""
3069 "* return output_a_shift (operands);"
3070 [(set (attr "length")
3071 (symbol_ref "compute_a_shift_length (insn, operands)"))
3072 (set (attr "cc")
3073 (symbol_ref "compute_a_shift_cc (insn, operands)"))])
3074
3075 ;; Split a variable shift into a loop. If the register containing
3076 ;; the shift count dies, then we just use that register.
3077
3078 (define_split
3079 [(set (match_operand 0 "register_operand" "")
3080 (match_operator 2 "nshift_operator"
3081 [(match_dup 0)
3082 (match_operand:QI 1 "register_operand" "")]))
3083 (clobber (match_operand:QI 3 "register_operand" ""))]
3084 "epilogue_completed
3085 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))"
3086 [(set (cc0) (compare (match_dup 1)
3087 (const_int 0)))
3088 (set (pc)
3089 (if_then_else (le (cc0) (const_int 0))
3090 (label_ref (match_dup 5))
3091 (pc)))
3092 (match_dup 4)
3093 (parallel
3094 [(set (match_dup 0)
3095 (match_op_dup 2 [(match_dup 0) (const_int 1)]))
3096 (clobber (scratch:QI))])
3097 (set (match_dup 1)
3098 (plus:QI (match_dup 1) (const_int -1)))
3099 (set (cc0) (compare (match_dup 1)
3100 (const_int 0)))
3101 (set (pc)
3102 (if_then_else (ne (cc0) (const_int 0))
3103 (label_ref (match_dup 4))
3104 (pc)))
3105 (match_dup 5)]
3106 "operands[4] = gen_label_rtx ();
3107 operands[5] = gen_label_rtx ();")
3108
3109 (define_split
3110 [(set (match_operand 0 "register_operand" "")
3111 (match_operator 2 "nshift_operator"
3112 [(match_dup 0)
3113 (match_operand:QI 1 "register_operand" "")]))
3114 (clobber (match_operand:QI 3 "register_operand" ""))]
3115 "epilogue_completed
3116 && !find_regno_note (insn, REG_DEAD, REGNO (operands[1]))"
3117 [(set (match_dup 3)
3118 (match_dup 1))
3119 (set (cc0) (compare (match_dup 3)
3120 (const_int 0)))
3121 (set (pc)
3122 (if_then_else (le (cc0) (const_int 0))
3123 (label_ref (match_dup 5))
3124 (pc)))
3125 (match_dup 4)
3126 (parallel
3127 [(set (match_dup 0)
3128 (match_op_dup 2 [(match_dup 0) (const_int 1)]))
3129 (clobber (scratch:QI))])
3130 (set (match_dup 3)
3131 (plus:QI (match_dup 3) (const_int -1)))
3132 (set (cc0) (compare (match_dup 3)
3133 (const_int 0)))
3134 (set (pc)
3135 (if_then_else (ne (cc0) (const_int 0))
3136 (label_ref (match_dup 4))
3137 (pc)))
3138 (match_dup 5)]
3139 "operands[4] = gen_label_rtx ();
3140 operands[5] = gen_label_rtx ();")
3141 \f
3142 ;; ----------------------------------------------------------------------
3143 ;; ROTATIONS
3144 ;; ----------------------------------------------------------------------
3145
3146 (define_expand "rotlqi3"
3147 [(set (match_operand:QI 0 "register_operand" "")
3148 (rotate:QI (match_operand:QI 1 "register_operand" "")
3149 (match_operand:QI 2 "nonmemory_operand" "")))]
3150 ""
3151 "if (expand_a_rotate (operands)) DONE;")
3152
3153 (define_insn "rotlqi3_1"
3154 [(set (match_operand:QI 0 "register_operand" "=r")
3155 (rotate:QI (match_operand:QI 1 "register_operand" "0")
3156 (match_operand:QI 2 "immediate_operand" "")))]
3157 ""
3158 "* return output_a_rotate (ROTATE, operands);"
3159 [(set (attr "length")
3160 (symbol_ref "compute_a_rotate_length (operands)"))])
3161
3162 (define_expand "rotlhi3"
3163 [(set (match_operand:HI 0 "register_operand" "")
3164 (rotate:HI (match_operand:HI 1 "register_operand" "")
3165 (match_operand:QI 2 "nonmemory_operand" "")))]
3166 ""
3167 "if (expand_a_rotate (operands)) DONE;")
3168
3169 (define_insn "rotlhi3_1"
3170 [(set (match_operand:HI 0 "register_operand" "=r")
3171 (rotate:HI (match_operand:HI 1 "register_operand" "0")
3172 (match_operand:QI 2 "immediate_operand" "")))]
3173 ""
3174 "* return output_a_rotate (ROTATE, operands);"
3175 [(set (attr "length")
3176 (symbol_ref "compute_a_rotate_length (operands)"))])
3177
3178 (define_expand "rotlsi3"
3179 [(set (match_operand:SI 0 "register_operand" "")
3180 (rotate:SI (match_operand:SI 1 "register_operand" "")
3181 (match_operand:QI 2 "nonmemory_operand" "")))]
3182 "TARGET_H8300H || TARGET_H8300S"
3183 "if (expand_a_rotate (operands)) DONE;")
3184
3185 (define_insn "rotlsi3_1"
3186 [(set (match_operand:SI 0 "register_operand" "=r")
3187 (rotate:SI (match_operand:SI 1 "register_operand" "0")
3188 (match_operand:QI 2 "immediate_operand" "")))]
3189 "TARGET_H8300H || TARGET_H8300S"
3190 "* return output_a_rotate (ROTATE, operands);"
3191 [(set (attr "length")
3192 (symbol_ref "compute_a_rotate_length (operands)"))])
3193 \f
3194 ;; -----------------------------------------------------------------
3195 ;; BIT FIELDS
3196 ;; -----------------------------------------------------------------
3197 ;; The H8/300 has given 1/8th of its opcode space to bitfield
3198 ;; instructions so let's use them as well as we can.
3199
3200 ;; You'll never believe all these patterns perform one basic action --
3201 ;; load a bit from the source, optionally invert the bit, then store it
3202 ;; in the destination (which is known to be zero).
3203 ;;
3204 ;; Combine obviously need some work to better identify this situation and
3205 ;; canonicalize the form better.
3206
3207 ;;
3208 ;; Normal loads with a 16bit destination.
3209 ;;
3210
3211 (define_insn ""
3212 [(set (match_operand:HI 0 "register_operand" "=&r")
3213 (zero_extract:HI (match_operand:HI 1 "register_operand" "r")
3214 (const_int 1)
3215 (match_operand:HI 2 "immediate_operand" "n")))]
3216 "TARGET_H8300"
3217 "sub.w %0,%0\;bld %Z2,%Y1\;bst #0,%X0"
3218 [(set_attr "length" "6")])
3219
3220 ;;
3221 ;; Inverted loads with a 16bit destination.
3222 ;;
3223
3224 (define_insn ""
3225 [(set (match_operand:HI 0 "register_operand" "=&r")
3226 (zero_extract:HI (xor:HI (match_operand:HI 1 "register_operand" "r")
3227 (match_operand:HI 3 "const_int_operand" "n"))
3228 (const_int 1)
3229 (match_operand:HI 2 "const_int_operand" "n")))]
3230 "(TARGET_H8300 || TARGET_H8300SX)
3231 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
3232 "sub.w %0,%0\;bild %Z2,%Y1\;bst #0,%X0"
3233 [(set_attr "length" "8")])
3234
3235 ;;
3236 ;; Normal loads with a 32bit destination.
3237 ;;
3238
3239 (define_insn "*extzv_1_r_h8300"
3240 [(set (match_operand:SI 0 "register_operand" "=&r")
3241 (zero_extract:SI (match_operand:HI 1 "register_operand" "r")
3242 (const_int 1)
3243 (match_operand 2 "const_int_operand" "n")))]
3244 "TARGET_H8300
3245 && INTVAL (operands[2]) < 16"
3246 "* return output_simode_bld (0, operands);"
3247 [(set_attr "length" "8")])
3248
3249 (define_insn "*extzv_1_r_h8300hs"
3250 [(set (match_operand:SI 0 "register_operand" "=r,r")
3251 (zero_extract:SI (match_operand:SI 1 "register_operand" "?0,r")
3252 (const_int 1)
3253 (match_operand 2 "const_int_operand" "n,n")))]
3254 "(TARGET_H8300H || TARGET_H8300S)
3255 && INTVAL (operands[2]) < 16"
3256 "* return output_simode_bld (0, operands);"
3257 [(set_attr "cc" "set_znv,set_znv")
3258 (set_attr "length" "8,6")])
3259
3260 ;;
3261 ;; Inverted loads with a 32bit destination.
3262 ;;
3263
3264 (define_insn "*extzv_1_r_inv_h8300"
3265 [(set (match_operand:SI 0 "register_operand" "=&r")
3266 (zero_extract:SI (xor:HI (match_operand:HI 1 "register_operand" "r")
3267 (match_operand:HI 3 "const_int_operand" "n"))
3268 (const_int 1)
3269 (match_operand 2 "const_int_operand" "n")))]
3270 "TARGET_H8300
3271 && INTVAL (operands[2]) < 16
3272 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
3273 "* return output_simode_bld (1, operands);"
3274 [(set_attr "length" "8")])
3275
3276 (define_insn "*extzv_1_r_inv_h8300hs"
3277 [(set (match_operand:SI 0 "register_operand" "=r,r")
3278 (zero_extract:SI (xor:SI (match_operand:SI 1 "register_operand" "?0,r")
3279 (match_operand 3 "const_int_operand" "n,n"))
3280 (const_int 1)
3281 (match_operand 2 "const_int_operand" "n,n")))]
3282 "(TARGET_H8300H || TARGET_H8300S)
3283 && INTVAL (operands[2]) < 16
3284 && (1 << INTVAL (operands[2])) == INTVAL (operands[3])"
3285 "* return output_simode_bld (1, operands);"
3286 [(set_attr "cc" "set_znv,set_znv")
3287 (set_attr "length" "8,6")])
3288
3289 (define_expand "insv"
3290 [(set (zero_extract:HI (match_operand:HI 0 "general_operand" "")
3291 (match_operand:HI 1 "general_operand" "")
3292 (match_operand:HI 2 "general_operand" ""))
3293 (match_operand:HI 3 "general_operand" ""))]
3294 "TARGET_H8300 || TARGET_H8300SX"
3295 "
3296 {
3297 if (TARGET_H8300SX)
3298 {
3299 if (GET_CODE (operands[1]) == CONST_INT
3300 && GET_CODE (operands[2]) == CONST_INT
3301 && INTVAL (operands[1]) <= 8
3302 && INTVAL (operands[2]) >= 0
3303 && INTVAL (operands[1]) + INTVAL (operands[2]) <= 8
3304 && memory_operand (operands[0], GET_MODE (operands[0])))
3305 {
3306 /* If the source operand is zero, it's better to use AND rather
3307 than BFST. Likewise OR if the operand is all ones. */
3308 if (GET_CODE (operands[3]) == CONST_INT)
3309 {
3310 HOST_WIDE_INT mask = (1 << INTVAL (operands[1])) - 1;
3311 if ((INTVAL (operands[3]) & mask) == 0)
3312 FAIL;
3313 if ((INTVAL (operands[3]) & mask) == mask)
3314 FAIL;
3315 }
3316 if (! bit_memory_operand (operands[0], GET_MODE (operands[0])))
3317 {
3318 if (!can_create_pseudo_p ())
3319 FAIL;
3320 operands[0] =
3321 replace_equiv_address (operands[0],
3322 force_reg (Pmode,
3323 XEXP (operands[0], 0)));
3324 }
3325 operands[3] = gen_lowpart (QImode, operands[3]);
3326 if (! operands[3])
3327 FAIL;
3328 if (! register_operand (operands[3], QImode))
3329 {
3330 if (!can_create_pseudo_p ())
3331 FAIL;
3332 operands[3] = force_reg (QImode, operands[3]);
3333 }
3334 emit_insn (gen_bfst (adjust_address (operands[0], QImode, 0),
3335 operands[3], operands[1], operands[2]));
3336 DONE;
3337 }
3338
3339 FAIL;
3340 }
3341
3342 /* We only have single bit bit-field instructions. */
3343 if (INTVAL (operands[1]) != 1)
3344 FAIL;
3345
3346 /* For now, we don't allow memory operands. */
3347 if (GET_CODE (operands[0]) == MEM
3348 || GET_CODE (operands[3]) == MEM)
3349 FAIL;
3350
3351 if (GET_CODE (operands[3]) != REG)
3352 operands[3] = force_reg (HImode, operands[3]);
3353 }")
3354
3355 (define_insn ""
3356 [(set (zero_extract:HI (match_operand:HI 0 "register_operand" "+r")
3357 (const_int 1)
3358 (match_operand:HI 1 "immediate_operand" "n"))
3359 (match_operand:HI 2 "register_operand" "r"))]
3360 ""
3361 "bld #0,%R2\;bst %Z1,%Y0 ; i1"
3362 [(set_attr "length" "4")])
3363
3364 (define_expand "extzv"
3365 [(set (match_operand:HI 0 "register_operand" "")
3366 (zero_extract:HI (match_operand:HI 1 "bit_operand" "")
3367 (match_operand:HI 2 "general_operand" "")
3368 (match_operand:HI 3 "general_operand" "")))]
3369 "TARGET_H8300 || TARGET_H8300SX"
3370 "
3371 {
3372 if (TARGET_H8300SX)
3373 {
3374 if (GET_CODE (operands[2]) == CONST_INT
3375 && GET_CODE (operands[3]) == CONST_INT
3376 && INTVAL (operands[2]) <= 8
3377 && INTVAL (operands[3]) >= 0
3378 && INTVAL (operands[2]) + INTVAL (operands[3]) <= 8
3379 && memory_operand (operands[1], QImode))
3380 {
3381 rtx temp;
3382
3383 /* Optimize the case where we're extracting into a paradoxical
3384 subreg. It's only necessary to extend to the inner reg. */
3385 if (GET_CODE (operands[0]) == SUBREG
3386 && subreg_lowpart_p (operands[0])
3387 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0])))
3388 < GET_MODE_SIZE (GET_MODE (operands[0])))
3389 && (GET_MODE_CLASS (GET_MODE (SUBREG_REG (operands[0])))
3390 == MODE_INT))
3391 operands[0] = SUBREG_REG (operands[0]);
3392
3393 if (!can_create_pseudo_p ())
3394 temp = gen_lowpart (QImode, operands[0]);
3395 else
3396 temp = gen_reg_rtx (QImode);
3397 if (! temp)
3398 FAIL;
3399 if (! bit_memory_operand (operands[1], QImode))
3400 {
3401 if (!can_create_pseudo_p ())
3402 FAIL;
3403 operands[1] =
3404 replace_equiv_address (operands[1],
3405 force_reg (Pmode,
3406 XEXP (operands[1], 0)));
3407 }
3408 emit_insn (gen_bfld (temp, operands[1], operands[2], operands[3]));
3409 convert_move (operands[0], temp, 1);
3410 DONE;
3411 }
3412 FAIL;
3413 }
3414
3415 /* We only have single bit bit-field instructions. */
3416 if (INTVAL (operands[2]) != 1)
3417 FAIL;
3418
3419 /* For now, we don't allow memory operands. */
3420 if (GET_CODE (operands[1]) == MEM)
3421 FAIL;
3422 }")
3423
3424 ;; BAND, BOR, and BXOR patterns
3425
3426 (define_insn ""
3427 [(set (match_operand:HI 0 "bit_operand" "=Ur")
3428 (match_operator:HI 4 "bit_operator"
3429 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
3430 (const_int 1)
3431 (match_operand:HI 2 "immediate_operand" "n"))
3432 (match_operand:HI 3 "bit_operand" "0")]))]
3433 ""
3434 "bld %Z2,%Y1\;b%c4 #0,%R0\;bst #0,%R0; bl1"
3435 [(set_attr "length" "6")])
3436
3437 (define_insn ""
3438 [(set (match_operand:HI 0 "bit_operand" "=Ur")
3439 (match_operator:HI 5 "bit_operator"
3440 [(zero_extract:HI (match_operand:HI 1 "register_operand" "r")
3441 (const_int 1)
3442 (match_operand:HI 2 "immediate_operand" "n"))
3443 (zero_extract:HI (match_operand:HI 3 "register_operand" "r")
3444 (const_int 1)
3445 (match_operand:HI 4 "immediate_operand" "n"))]))]
3446 ""
3447 "bld %Z2,%Y1\;b%c5 %Z4,%Y3\;bst #0,%R0; bl3"
3448 [(set_attr "length" "6")])
3449
3450 (define_insn "bfld"
3451 [(set (match_operand:QI 0 "register_operand" "=r")
3452 (zero_extract:QI (match_operand:QI 1 "bit_memory_operand" "WU")
3453 (match_operand:QI 2 "immediate_operand" "n")
3454 (match_operand:QI 3 "immediate_operand" "n")))]
3455 "TARGET_H8300SX && INTVAL (operands[2]) + INTVAL (operands[3]) <= 8"
3456 "*
3457 {
3458 operands[2] = GEN_INT ((1 << (INTVAL (operands[2]) + INTVAL (operands[3])))
3459 - (1 << INTVAL (operands[3])));
3460 return \"bfld %2,%1,%R0\";
3461 }"
3462 [(set_attr "cc" "none_0hit")
3463 (set_attr "length_table" "bitfield")])
3464
3465 (define_insn "bfst"
3466 [(set (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "+WU")
3467 (match_operand:QI 2 "immediate_operand" "n")
3468 (match_operand:QI 3 "immediate_operand" "n"))
3469 (match_operand:QI 1 "register_operand" "r"))]
3470 "TARGET_H8300SX && INTVAL (operands[2]) + INTVAL (operands[3]) <= 8"
3471 "*
3472 {
3473 operands[2] = GEN_INT ((1 << (INTVAL (operands[2]) + INTVAL (operands[3])))
3474 - (1 << INTVAL (operands[3])));
3475 return \"bfst %R1,%2,%0\";
3476 }"
3477 [(set_attr "cc" "none_0hit")
3478 (set_attr "length_table" "bitfield")])
3479
3480 (define_expand "cstoreqi4"
3481 [(use (match_operator 1 "eqne_operator"
3482 [(match_operand:QI 2 "h8300_dst_operand" "")
3483 (match_operand:QI 3 "h8300_src_operand" "")]))
3484 (clobber (match_operand:HI 0 "register_operand"))]
3485 "TARGET_H8300SX"
3486 "h8300_expand_store (operands); DONE;")
3487
3488 (define_expand "cstorehi4"
3489 [(use (match_operator 1 "eqne_operator"
3490 [(match_operand:HI 2 "h8300_dst_operand" "")
3491 (match_operand:HI 3 "h8300_src_operand" "")]))
3492 (clobber (match_operand:HI 0 "register_operand"))]
3493 "TARGET_H8300SX"
3494 "h8300_expand_store (operands); DONE;")
3495
3496 (define_expand "cstoresi4"
3497 [(use (match_operator 1 "eqne_operator"
3498 [(match_operand:SI 2 "h8300_dst_operand" "")
3499 (match_operand:SI 3 "h8300_src_operand" "")]))
3500 (clobber (match_operand:HI 0 "register_operand"))]
3501 "TARGET_H8300SX"
3502 "h8300_expand_store (operands); DONE;")
3503
3504 (define_insn "*bstzhireg"
3505 [(set (match_operand:HI 0 "register_operand" "=r")
3506 (match_operator:HI 1 "eqne_operator" [(cc0) (const_int 0)]))]
3507 "TARGET_H8300SX"
3508 "mulu.w #0,%T0\;b%k1 .Lh8BR%=\;inc.w #1,%T0\\n.Lh8BR%=:"
3509 [(set_attr "cc" "clobber")])
3510
3511 (define_insn_and_split "*cmpstz"
3512 [(set (zero_extract:QI
3513 (match_operand:QI 0 "bit_memory_operand" "+WU,+WU")
3514 (const_int 1)
3515 (match_operand:QI 1 "immediate_operand" "n,n"))
3516 (match_operator:QI
3517 2 "eqne_operator"
3518 [(match_operand 3 "h8300_dst_operand" "r,rQ")
3519 (match_operand 4 "h8300_src_operand" "I,rQi")]))]
3520 "TARGET_H8300SX
3521 && (GET_MODE (operands[3]) == GET_MODE (operands[4])
3522 || GET_CODE (operands[4]) == CONST_INT)
3523 && GET_MODE_CLASS (GET_MODE (operands[3])) == MODE_INT
3524 && GET_MODE_SIZE (GET_MODE (operands[3])) <= 4"
3525 "#"
3526 "reload_completed"
3527 [(set (cc0) (match_dup 5))
3528 (set (zero_extract:QI (match_dup 0) (const_int 1) (match_dup 1))
3529 (match_op_dup:QI 2 [(cc0) (const_int 0)]))]
3530 "operands[5] = gen_rtx_COMPARE (VOIDmode, operands[3], operands[4]);"
3531 [(set_attr "cc" "set_znv,compare")])
3532
3533 (define_insn "*bstz"
3534 [(set (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "+WU")
3535 (const_int 1)
3536 (match_operand:QI 1 "immediate_operand" "n"))
3537 (eq:QI (cc0) (const_int 0)))]
3538 "TARGET_H8300SX && reload_completed"
3539 "bstz %1,%0"
3540 [(set_attr "cc" "none_0hit")
3541 (set_attr "length_table" "unary")])
3542
3543 (define_insn "*bistz"
3544 [(set (zero_extract:QI (match_operand:QI 0 "bit_memory_operand" "+WU")
3545 (const_int 1)
3546 (match_operand:QI 1 "immediate_operand" "n"))
3547 (ne:QI (cc0) (const_int 0)))]
3548 "TARGET_H8300SX && reload_completed"
3549 "bistz %1,%0"
3550 [(set_attr "cc" "none_0hit")
3551 (set_attr "length_table" "unary")])
3552
3553 (define_insn_and_split "*cmpcondbset"
3554 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3555 (if_then_else:QI
3556 (match_operator
3557 1 "eqne_operator"
3558 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3559 (match_operand 3 "h8300_src_operand" "I,rQi")])
3560 (ior:QI
3561 (match_operand:QI 4 "bit_memory_operand" "0,0")
3562 (match_operand:QI 5 "single_one_operand" "n,n"))
3563 (match_dup 4)))]
3564 "TARGET_H8300SX"
3565 "#"
3566 "reload_completed"
3567 [(set (cc0) (match_dup 6))
3568 (set (match_dup 0)
3569 (if_then_else:QI
3570 (match_op_dup 1 [(cc0) (const_int 0)])
3571 (ior:QI (match_dup 4) (match_dup 5)) (match_dup 4)))]
3572 "operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);"
3573 [(set_attr "cc" "set_znv,compare")])
3574
3575 (define_insn "*condbset"
3576 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3577 (if_then_else:QI
3578 (match_operator:QI 2 "eqne_operator"
3579 [(cc0) (const_int 0)])
3580 (ior:QI
3581 (match_operand:QI 3 "bit_memory_operand" "0")
3582 (match_operand:QI 1 "single_one_operand" "n"))
3583 (match_dup 3)))]
3584 "TARGET_H8300SX && reload_completed"
3585 "bset/%j2\t%V1,%0"
3586 [(set_attr "cc" "none_0hit")
3587 (set_attr "length_table" "logicb")])
3588
3589 (define_insn_and_split "*cmpcondbclr"
3590 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3591 (if_then_else:QI
3592 (match_operator
3593 1 "eqne_operator"
3594 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3595 (match_operand 3 "h8300_src_operand" "I,rQi")])
3596 (and:QI
3597 (match_operand:QI 4 "bit_memory_operand" "0,0")
3598 (match_operand:QI 5 "single_zero_operand" "n,n"))
3599 (match_dup 4)))]
3600 "TARGET_H8300SX"
3601 "#"
3602 "reload_completed"
3603 [(set (cc0) (match_dup 6))
3604 (set (match_dup 0)
3605 (if_then_else:QI
3606 (match_op_dup 1 [(cc0) (const_int 0)])
3607 (and:QI (match_dup 4) (match_dup 5)) (match_dup 4)))]
3608 "operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);"
3609 [(set_attr "cc" "set_znv,compare")])
3610
3611 (define_insn "*condbclr"
3612 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3613 (if_then_else:QI
3614 (match_operator:QI 2 "eqne_operator"
3615 [(cc0) (const_int 0)])
3616 (and:QI
3617 (match_operand:QI 3 "bit_memory_operand" "0")
3618 (match_operand:QI 1 "single_zero_operand" "n"))
3619 (match_dup 3)))]
3620 "TARGET_H8300SX && reload_completed"
3621 "bclr/%j2\t%W1,%0"
3622 [(set_attr "cc" "none_0hit")
3623 (set_attr "length_table" "logicb")])
3624
3625 (define_insn_and_split "*cmpcondbsetreg"
3626 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3627 (if_then_else:QI
3628 (match_operator
3629 1 "eqne_operator"
3630 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3631 (match_operand 3 "h8300_src_operand" "I,rQi")])
3632 (ior:QI
3633 (match_operand:QI 4 "bit_memory_operand" "0,0")
3634 (ashift:QI (const_int 1)
3635 (match_operand:QI 5 "register_operand" "r,r")))
3636 (match_dup 4)))]
3637 "TARGET_H8300SX"
3638 "#"
3639 "reload_completed"
3640 [(set (cc0) (match_dup 6))
3641 (set (match_dup 0)
3642 (if_then_else:QI
3643 (match_op_dup 1 [(cc0) (const_int 0)])
3644 (ior:QI (match_dup 4)
3645 (ashift:QI (const_int 1)
3646 (match_operand:QI 5 "register_operand" "r,r")))
3647 (match_dup 4)))]
3648 "operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);"
3649 [(set_attr "cc" "set_znv,compare")])
3650
3651 (define_insn "*condbsetreg"
3652 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3653 (if_then_else:QI
3654 (match_operator:QI 2 "eqne_operator"
3655 [(cc0) (const_int 0)])
3656 (ior:QI
3657 (match_operand:QI 3 "bit_memory_operand" "0")
3658 (ashift:QI (const_int 1)
3659 (match_operand:QI 1 "register_operand" "r")))
3660 (match_dup 3)))]
3661 "TARGET_H8300SX && reload_completed"
3662 "bset/%j2\t%R1,%0"
3663 [(set_attr "cc" "none_0hit")
3664 (set_attr "length_table" "logicb")])
3665
3666 (define_insn_and_split "*cmpcondbclrreg"
3667 [(set (match_operand:QI 0 "nonimmediate_operand" "=WU,WU")
3668 (if_then_else:QI
3669 (match_operator
3670 1 "eqne_operator"
3671 [(match_operand 2 "h8300_dst_operand" "r,rQ")
3672 (match_operand 3 "h8300_src_operand" "I,rQi")])
3673 (and:QI
3674 (match_operand:QI 4 "bit_memory_operand" "0,0")
3675 (ashift:QI (const_int 1)
3676 (match_operand:QI 5 "register_operand" "r,r")))
3677 (match_dup 4)))]
3678 "TARGET_H8300SX"
3679 "#"
3680 "reload_completed"
3681 [(set (cc0) (match_dup 6))
3682 (set (match_dup 0)
3683 (if_then_else:QI
3684 (match_op_dup 1 [(cc0) (const_int 0)])
3685 (and:QI (match_dup 4)
3686 (ashift:QI (const_int 1)
3687 (match_operand:QI 5 "register_operand" "r,r")))
3688 (match_dup 4)))]
3689 "operands[6] = gen_rtx_COMPARE (VOIDmode, operands[2], operands[3]);"
3690 [(set_attr "cc" "set_znv,compare")])
3691
3692 (define_insn "*condbclrreg"
3693 [(set (match_operand:QI 0 "bit_memory_operand" "=WU")
3694 (if_then_else:QI
3695 (match_operator:QI 2 "eqne_operator"
3696 [(cc0) (const_int 0)])
3697 (and:QI
3698 (match_operand:QI 3 "bit_memory_operand" "0")
3699 (ashift:QI (const_int 1)
3700 (match_operand:QI 1 "register_operand" "r")))
3701 (match_dup 3)))]
3702 "TARGET_H8300SX && reload_completed"
3703 "bclr/%j2\t%R1,%0"
3704 [(set_attr "cc" "none_0hit")
3705 (set_attr "length_table" "logicb")])
3706
3707 \f
3708 ;; -----------------------------------------------------------------
3709 ;; COMBINE PATTERNS
3710 ;; -----------------------------------------------------------------
3711
3712 ;; insv:SI
3713
3714 (define_insn "*insv_si_1_n"
3715 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3716 (const_int 1)
3717 (match_operand:SI 1 "const_int_operand" "n"))
3718 (match_operand:SI 2 "register_operand" "r"))]
3719 "(TARGET_H8300H || TARGET_H8300S)
3720 && INTVAL (operands[1]) < 16"
3721 "bld\\t#0,%w2\;bst\\t%Z1,%Y0"
3722 [(set_attr "length" "4")])
3723
3724 (define_insn "*insv_si_1_n_lshiftrt"
3725 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3726 (const_int 1)
3727 (match_operand:SI 1 "const_int_operand" "n"))
3728 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
3729 (match_operand:SI 3 "const_int_operand" "n")))]
3730 "(TARGET_H8300H || TARGET_H8300S)
3731 && INTVAL (operands[1]) < 16
3732 && INTVAL (operands[3]) < 16"
3733 "bld\\t%Z3,%Y2\;bst\\t%Z1,%Y0"
3734 [(set_attr "length" "4")])
3735
3736 (define_insn "*insv_si_1_n_lshiftrt_16"
3737 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3738 (const_int 1)
3739 (match_operand:SI 1 "const_int_operand" "n"))
3740 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
3741 (const_int 16)))]
3742 "(TARGET_H8300H || TARGET_H8300S)
3743 && INTVAL (operands[1]) < 16"
3744 "rotr.w\\t%e2\;rotl.w\\t%e2\;bst\\t%Z1,%Y0"
3745 [(set_attr "length" "6")])
3746
3747 (define_insn "*insv_si_8_8"
3748 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3749 (const_int 8)
3750 (const_int 8))
3751 (match_operand:SI 1 "register_operand" "r"))]
3752 "TARGET_H8300H || TARGET_H8300S"
3753 "mov.b\\t%w1,%x0"
3754 [(set_attr "length" "2")])
3755
3756 (define_insn "*insv_si_8_8_lshiftrt_8"
3757 [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
3758 (const_int 8)
3759 (const_int 8))
3760 (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3761 (const_int 8)))]
3762 "TARGET_H8300H || TARGET_H8300S"
3763 "mov.b\\t%x1,%x0"
3764 [(set_attr "length" "2")])
3765
3766 ;; extzv:SI
3767
3768 (define_insn "*extzv_8_8"
3769 [(set (match_operand:SI 0 "register_operand" "=r,r")
3770 (zero_extract:SI (match_operand:SI 1 "register_operand" "?0,r")
3771 (const_int 8)
3772 (const_int 8)))]
3773 "TARGET_H8300H || TARGET_H8300S"
3774 "@
3775 mov.b\\t%x1,%w0\;extu.w\\t%f0\;extu.l\\t%S0
3776 sub.l\\t%S0,%S0\;mov.b\\t%x1,%w0"
3777 [(set_attr "cc" "set_znv,clobber")
3778 (set_attr "length" "6,4")])
3779
3780 (define_insn "*extzv_8_16"
3781 [(set (match_operand:SI 0 "register_operand" "=r")
3782 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
3783 (const_int 8)
3784 (const_int 16)))]
3785 "TARGET_H8300H || TARGET_H8300S"
3786 "mov.w\\t%e1,%f0\;extu.w\\t%f0\;extu.l\\t%S0"
3787 [(set_attr "cc" "set_znv")
3788 (set_attr "length" "6")])
3789
3790 (define_insn "*extzv_16_8"
3791 [(set (match_operand:SI 0 "register_operand" "=r")
3792 (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
3793 (const_int 16)
3794 (const_int 8)))
3795 (clobber (match_scratch:SI 2 "=&r"))]
3796 "TARGET_H8300H"
3797 "mov.w\\t%e1,%f2\;mov.b\\t%x1,%w0\;mov.b\\t%w2,%x0\;extu.l\\t%S0"
3798 [(set_attr "length" "8")
3799 (set_attr "cc" "set_znv")])
3800
3801 ;; Extract the exponent of a float.
3802
3803 (define_insn_and_split "*extzv_8_23"
3804 [(set (match_operand:SI 0 "register_operand" "=r")
3805 (zero_extract:SI (match_operand:SI 1 "register_operand" "0")
3806 (const_int 8)
3807 (const_int 23)))]
3808 "(TARGET_H8300H || TARGET_H8300S)"
3809 "#"
3810 "&& reload_completed"
3811 [(parallel [(set (match_dup 0)
3812 (ashift:SI (match_dup 0)
3813 (const_int 1)))
3814 (clobber (scratch:QI))])
3815 (parallel [(set (match_dup 0)
3816 (lshiftrt:SI (match_dup 0)
3817 (const_int 24)))
3818 (clobber (scratch:QI))])]
3819 "")
3820
3821 ;; and:SI
3822
3823 ;; ((SImode) HImode) << 15
3824
3825 (define_insn_and_split "*twoshifts_l16_r1"
3826 [(set (match_operand:SI 0 "register_operand" "=r")
3827 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
3828 (const_int 15))
3829 (const_int 2147450880)))]
3830 "(TARGET_H8300H || TARGET_H8300S)"
3831 "#"
3832 "&& reload_completed"
3833 [(parallel [(set (match_dup 0)
3834 (ashift:SI (match_dup 0)
3835 (const_int 16)))
3836 (clobber (scratch:QI))])
3837 (parallel [(set (match_dup 0)
3838 (lshiftrt:SI (match_dup 0)
3839 (const_int 1)))
3840 (clobber (scratch:QI))])]
3841 "")
3842
3843 ;; Transform (SImode << B) & 0xffff into (SImode) (HImode << B).
3844
3845 (define_insn_and_split "*andsi3_ashift_n_lower"
3846 [(set (match_operand:SI 0 "register_operand" "=r,r")
3847 (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0,0")
3848 (match_operand:QI 2 "const_int_operand" "S,n"))
3849 (match_operand:SI 3 "const_int_operand" "n,n")))
3850 (clobber (match_scratch:QI 4 "=X,&r"))]
3851 "(TARGET_H8300H || TARGET_H8300S)
3852 && INTVAL (operands[2]) <= 15
3853 && INTVAL (operands[3]) == ((-1 << INTVAL (operands[2])) & 0xffff)"
3854 "#"
3855 "&& reload_completed"
3856 [(parallel [(set (match_dup 5)
3857 (ashift:HI (match_dup 5)
3858 (match_dup 2)))
3859 (clobber (match_dup 4))])
3860 (set (match_dup 0)
3861 (zero_extend:SI (match_dup 5)))]
3862 "operands[5] = gen_rtx_REG (HImode, REGNO (operands[0]));")
3863
3864 ;; Accept (A >> 30) & 2 and the like.
3865
3866 (define_insn "*andsi3_lshiftrt_n_sb"
3867 [(set (match_operand:SI 0 "register_operand" "=r")
3868 (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
3869 (match_operand:SI 2 "const_int_operand" "n"))
3870 (match_operand:SI 3 "single_one_operand" "n")))]
3871 "(TARGET_H8300H || TARGET_H8300S)
3872 && exact_log2 (INTVAL (operands[3])) < 16
3873 && INTVAL (operands[2]) + exact_log2 (INTVAL (operands[3])) == 31"
3874 "*
3875 {
3876 operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
3877 return \"shll.l\\t%S0\;xor.l\\t%S0,%S0\;bst\\t%Z3,%Y0\";
3878 }"
3879 [(set_attr "length" "8")])
3880
3881 (define_insn_and_split "*andsi3_lshiftrt_9_sb"
3882 [(set (match_operand:SI 0 "register_operand" "=r")
3883 (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
3884 (const_int 9))
3885 (const_int 4194304)))]
3886 "(TARGET_H8300H || TARGET_H8300S)"
3887 "#"
3888 "&& reload_completed"
3889 [(set (match_dup 0)
3890 (and:SI (lshiftrt:SI (match_dup 0)
3891 (const_int 25))
3892 (const_int 64)))
3893 (parallel [(set (match_dup 0)
3894 (ashift:SI (match_dup 0)
3895 (const_int 16)))
3896 (clobber (scratch:QI))])]
3897 "")
3898
3899 ;; plus:SI
3900
3901 (define_insn "*addsi3_upper"
3902 [(set (match_operand:SI 0 "register_operand" "=r")
3903 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
3904 (const_int 65536))
3905 (match_operand:SI 2 "register_operand" "0")))]
3906 "TARGET_H8300H || TARGET_H8300S"
3907 "add.w\\t%f1,%e0"
3908 [(set_attr "length" "2")])
3909
3910 (define_insn "*addsi3_lshiftrt_16_zexthi"
3911 [(set (match_operand:SI 0 "register_operand" "=r")
3912 (plus:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
3913 (const_int 16))
3914 (zero_extend:SI (match_operand:HI 2 "register_operand" "0"))))]
3915 "TARGET_H8300H || TARGET_H8300S"
3916 "add.w\\t%e1,%f0\;xor.w\\t%e0,%e0\;rotxl.w\\t%e0"
3917 [(set_attr "length" "6")])
3918
3919 (define_insn_and_split "*addsi3_and_r_1"
3920 [(set (match_operand:SI 0 "register_operand" "=r")
3921 (plus:SI (and:SI (match_operand:SI 1 "register_operand" "r")
3922 (const_int 1))
3923 (match_operand:SI 2 "register_operand" "0")))]
3924 "(TARGET_H8300H || TARGET_H8300S)"
3925 "#"
3926 "&& reload_completed"
3927 [(set (cc0) (compare (zero_extract:SI (match_dup 1)
3928 (const_int 1)
3929 (const_int 0))
3930 (const_int 0)))
3931 (set (pc)
3932 (if_then_else (eq (cc0)
3933 (const_int 0))
3934 (label_ref (match_dup 3))
3935 (pc)))
3936 (set (match_dup 2)
3937 (plus:SI (match_dup 2)
3938 (const_int 1)))
3939 (match_dup 3)]
3940 "operands[3] = gen_label_rtx ();")
3941
3942 (define_insn_and_split "*addsi3_and_not_r_1"
3943 [(set (match_operand:SI 0 "register_operand" "=r")
3944 (plus:SI (and:SI (not:SI (match_operand:SI 1 "register_operand" "r"))
3945 (const_int 1))
3946 (match_operand:SI 2 "register_operand" "0")))]
3947 "(TARGET_H8300H || TARGET_H8300S)"
3948 "#"
3949 "&& reload_completed"
3950 [(set (cc0) (compare (zero_extract:SI (match_dup 1)
3951 (const_int 1)
3952 (const_int 0))
3953 (const_int 0)))
3954 (set (pc)
3955 (if_then_else (ne (cc0)
3956 (const_int 0))
3957 (label_ref (match_dup 3))
3958 (pc)))
3959 (set (match_dup 2)
3960 (plus:SI (match_dup 2)
3961 (const_int 1)))
3962 (match_dup 3)]
3963 "operands[3] = gen_label_rtx ();")
3964
3965 ;; [ix]or:HI
3966
3967 (define_insn "*ixorhi3_zext"
3968 [(set (match_operand:HI 0 "register_operand" "=r")
3969 (match_operator:HI 1 "iorxor_operator"
3970 [(zero_extend:HI (match_operand:QI 2 "register_operand" "r"))
3971 (match_operand:HI 3 "register_operand" "0")]))]
3972 ""
3973 "%c1.b\\t%X2,%s0"
3974 [(set_attr "length" "2")])
3975
3976 ;; [ix]or:SI
3977
3978 (define_insn "*ixorsi3_zext_qi"
3979 [(set (match_operand:SI 0 "register_operand" "=r")
3980 (match_operator:SI 1 "iorxor_operator"
3981 [(zero_extend:SI (match_operand:QI 2 "register_operand" "r"))
3982 (match_operand:SI 3 "register_operand" "0")]))]
3983 ""
3984 "%c1.b\\t%X2,%w0"
3985 [(set_attr "length" "2")])
3986
3987 (define_insn "*ixorsi3_zext_hi"
3988 [(set (match_operand:SI 0 "register_operand" "=r")
3989 (match_operator:SI 1 "iorxor_operator"
3990 [(zero_extend:SI (match_operand:HI 2 "register_operand" "r"))
3991 (match_operand:SI 3 "register_operand" "0")]))]
3992 "TARGET_H8300H || TARGET_H8300S"
3993 "%c1.w\\t%T2,%f0"
3994 [(set_attr "length" "2")])
3995
3996 (define_insn "*ixorsi3_ashift_16"
3997 [(set (match_operand:SI 0 "register_operand" "=r")
3998 (match_operator:SI 1 "iorxor_operator"
3999 [(ashift:SI (match_operand:SI 2 "register_operand" "r")
4000 (const_int 16))
4001 (match_operand:SI 3 "register_operand" "0")]))]
4002 "TARGET_H8300H || TARGET_H8300S"
4003 "%c1.w\\t%f2,%e0"
4004 [(set_attr "length" "2")])
4005
4006 (define_insn "*ixorsi3_lshiftrt_16"
4007 [(set (match_operand:SI 0 "register_operand" "=r")
4008 (match_operator:SI 1 "iorxor_operator"
4009 [(lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
4010 (const_int 16))
4011 (match_operand:SI 3 "register_operand" "0")]))]
4012 "TARGET_H8300H || TARGET_H8300S"
4013 "%c1.w\\t%e2,%f0"
4014 [(set_attr "length" "2")])
4015
4016 ;; ior:HI
4017
4018 (define_insn "*iorhi3_ashift_8"
4019 [(set (match_operand:HI 0 "register_operand" "=r")
4020 (ior:HI (ashift:HI (match_operand:HI 1 "register_operand" "r")
4021 (const_int 8))
4022 (match_operand:HI 2 "register_operand" "0")))]
4023 ""
4024 "or.b\\t%s1,%t0"
4025 [(set_attr "length" "2")])
4026
4027 (define_insn "*iorhi3_lshiftrt_8"
4028 [(set (match_operand:HI 0 "register_operand" "=r")
4029 (ior:HI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
4030 (const_int 8))
4031 (match_operand:HI 2 "register_operand" "0")))]
4032 ""
4033 "or.b\\t%t1,%s0"
4034 [(set_attr "length" "2")])
4035
4036 (define_insn "*iorhi3_two_qi"
4037 [(set (match_operand:HI 0 "register_operand" "=r")
4038 (ior:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "0"))
4039 (ashift:HI (match_operand:HI 2 "register_operand" "r")
4040 (const_int 8))))]
4041 ""
4042 "mov.b\\t%s2,%t0"
4043 [(set_attr "length" "2")])
4044
4045 (define_insn "*iorhi3_two_qi_mem"
4046 [(set (match_operand:HI 0 "register_operand" "=&r")
4047 (ior:HI (zero_extend:HI (match_operand:QI 1 "memory_operand" "m"))
4048 (ashift:HI (subreg:HI (match_operand:QI 2 "memory_operand" "m") 0)
4049 (const_int 8))))]
4050 ""
4051 "mov.b\\t%X2,%t0\;mov.b\\t%X1,%s0"
4052 [(set_attr "length" "16")])
4053
4054 (define_split
4055 [(set (match_operand:HI 0 "register_operand" "")
4056 (ior:HI (zero_extend:HI (match_operand:QI 1 "memory_operand" ""))
4057 (ashift:HI (subreg:HI (match_operand:QI 2 "memory_operand" "") 0)
4058 (const_int 8))))]
4059 "(TARGET_H8300H || TARGET_H8300S)
4060 && reload_completed
4061 && byte_accesses_mergeable_p (XEXP (operands[2], 0), XEXP (operands[1], 0))"
4062 [(set (match_dup 0)
4063 (match_dup 3))]
4064 "operands[3] = gen_rtx_MEM (HImode, XEXP (operands[2], 0));")
4065
4066 ;; ior:SI
4067
4068 (define_insn "*iorsi3_two_hi"
4069 [(set (match_operand:SI 0 "register_operand" "=r")
4070 (ior:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "0"))
4071 (ashift:SI (match_operand:SI 2 "register_operand" "r")
4072 (const_int 16))))]
4073 "TARGET_H8300H || TARGET_H8300S"
4074 "mov.w\\t%f2,%e0"
4075 [(set_attr "length" "2")])
4076
4077 (define_insn_and_split "*iorsi3_two_qi_zext"
4078 [(set (match_operand:SI 0 "register_operand" "=&r")
4079 (ior:SI (zero_extend:SI (match_operand:QI 1 "memory_operand" "m"))
4080
4081 (and:SI (ashift:SI (subreg:SI (match_operand:QI 2 "memory_operand" "m") 0)
4082 (const_int 8))
4083 (const_int 65280))))]
4084 "(TARGET_H8300H || TARGET_H8300S)"
4085 "#"
4086 "&& reload_completed"
4087 [(set (match_dup 3)
4088 (ior:HI (zero_extend:HI (match_dup 1))
4089 (ashift:HI (subreg:HI (match_dup 2) 0)
4090 (const_int 8))))
4091 (set (match_dup 0)
4092 (zero_extend:SI (match_dup 3)))]
4093 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));")
4094
4095 (define_insn "*iorsi3_e2f"
4096 [(set (match_operand:SI 0 "register_operand" "=r")
4097 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0")
4098 (const_int -65536))
4099 (lshiftrt:SI (match_operand:SI 2 "register_operand" "r")
4100 (const_int 16))))]
4101 "TARGET_H8300H || TARGET_H8300S"
4102 "mov.w\\t%e2,%f0"
4103 [(set_attr "length" "2")])
4104
4105 (define_insn_and_split "*iorsi3_two_qi_sext"
4106 [(set (match_operand:SI 0 "register_operand" "=r")
4107 (ior:SI (zero_extend:SI (match_operand:QI 1 "register_operand" "0"))
4108 (ashift:SI (sign_extend:SI (match_operand:QI 2 "register_operand" "r"))
4109 (const_int 8))))]
4110 "(TARGET_H8300H || TARGET_H8300S)"
4111 "#"
4112 "&& reload_completed"
4113 [(set (match_dup 3)
4114 (ior:HI (zero_extend:HI (match_dup 1))
4115 (ashift:HI (match_dup 4)
4116 (const_int 8))))
4117 (set (match_dup 0)
4118 (sign_extend:SI (match_dup 3)))]
4119 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4120 operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));")
4121
4122 (define_insn "*iorsi3_w"
4123 [(set (match_operand:SI 0 "register_operand" "=r,&r")
4124 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0,0")
4125 (const_int -256))
4126 (zero_extend:SI (match_operand:QI 2 "general_operand_src" "r,g>"))))]
4127 "TARGET_H8300H || TARGET_H8300S"
4128 "mov.b\\t%X2,%w0"
4129 [(set_attr "length" "2,8")])
4130
4131 (define_insn "*iorsi3_ashift_31"
4132 [(set (match_operand:SI 0 "register_operand" "=&r")
4133 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
4134 (const_int 31))
4135 (match_operand:SI 2 "register_operand" "0")))]
4136 "TARGET_H8300H || TARGET_H8300S"
4137 "rotxl.l\\t%S0\;bor\\t#0,%w1\;rotxr.l\\t%S0"
4138 [(set_attr "length" "6")
4139 (set_attr "cc" "set_znv")])
4140
4141 (define_insn "*iorsi3_and_ashift"
4142 [(set (match_operand:SI 0 "register_operand" "=r")
4143 (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
4144 (match_operand:SI 2 "const_int_operand" "n"))
4145 (match_operand:SI 3 "single_one_operand" "n"))
4146 (match_operand:SI 4 "register_operand" "0")))]
4147 "(TARGET_H8300H || TARGET_H8300S)
4148 && (INTVAL (operands[3]) & ~0xffff) == 0"
4149 "*
4150 {
4151 rtx srcpos = GEN_INT (exact_log2 (INTVAL (operands[3]))
4152 - INTVAL (operands[2]));
4153 rtx dstpos = GEN_INT (exact_log2 (INTVAL (operands[3])));
4154 operands[2] = srcpos;
4155 operands[3] = dstpos;
4156 return \"bld\\t%Z2,%Y1\;bor\\t%Z3,%Y0\;bst\\t%Z3,%Y0\";
4157 }"
4158 [(set_attr "length" "6")])
4159
4160 (define_insn "*iorsi3_and_lshiftrt"
4161 [(set (match_operand:SI 0 "register_operand" "=r")
4162 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4163 (match_operand:SI 2 "const_int_operand" "n"))
4164 (match_operand:SI 3 "single_one_operand" "n"))
4165 (match_operand:SI 4 "register_operand" "0")))]
4166 "(TARGET_H8300H || TARGET_H8300S)
4167 && ((INTVAL (operands[3]) << INTVAL (operands[2])) & ~0xffff) == 0"
4168 "*
4169 {
4170 rtx srcpos = GEN_INT (exact_log2 (INTVAL (operands[3]))
4171 + INTVAL (operands[2]));
4172 rtx dstpos = GEN_INT (exact_log2 (INTVAL (operands[3])));
4173 operands[2] = srcpos;
4174 operands[3] = dstpos;
4175 return \"bld\\t%Z2,%Y1\;bor\\t%Z3,%Y0\;bst\\t%Z3,%Y0\";
4176 }"
4177 [(set_attr "length" "6")])
4178
4179 (define_insn "*iorsi3_zero_extract"
4180 [(set (match_operand:SI 0 "register_operand" "=r")
4181 (ior:SI (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
4182 (const_int 1)
4183 (match_operand:SI 2 "const_int_operand" "n"))
4184 (match_operand:SI 3 "register_operand" "0")))]
4185 "(TARGET_H8300H || TARGET_H8300S)
4186 && INTVAL (operands[2]) < 16"
4187 "bld\\t%Z2,%Y1\;bor\\t#0,%w0\;bst\\t#0,%w0"
4188 [(set_attr "length" "6")])
4189
4190 (define_insn "*iorsi3_and_lshiftrt_n_sb"
4191 [(set (match_operand:SI 0 "register_operand" "=r")
4192 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4193 (const_int 30))
4194 (const_int 2))
4195 (match_operand:SI 2 "register_operand" "0")))]
4196 "(TARGET_H8300H || TARGET_H8300S)"
4197 "rotl.l\\t%S1\;rotr.l\\t%S1\;bor\\t#1,%w0\;bst\\t#1,%w0"
4198 [(set_attr "length" "8")])
4199
4200 (define_insn "*iorsi3_and_lshiftrt_9_sb"
4201 [(set (match_operand:SI 0 "register_operand" "=r")
4202 (ior:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4203 (const_int 9))
4204 (const_int 4194304))
4205 (match_operand:SI 2 "register_operand" "0")))
4206 (clobber (match_scratch:HI 3 "=&r"))]
4207 "(TARGET_H8300H || TARGET_H8300S)"
4208 "*
4209 {
4210 if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
4211 return \"shll.l\\t%S1\;xor.w\\t%T3,%T3\;bst\\t#6,%s3\;or.w\\t%T3,%e0\";
4212 else
4213 return \"rotl.l\\t%S1\;rotr.l\\t%S1\;xor.w\\t%T3,%T3\;bst\\t#6,%s3\;or.w\\t%T3,%e0\";
4214 }"
4215 [(set_attr "length" "10")])
4216
4217 ;; Used to OR the exponent of a float.
4218
4219 (define_insn "*iorsi3_shift"
4220 [(set (match_operand:SI 0 "register_operand" "=r")
4221 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
4222 (const_int 23))
4223 (match_operand:SI 2 "register_operand" "0")))
4224 (clobber (match_scratch:SI 3 "=&r"))]
4225 "TARGET_H8300H || TARGET_H8300S"
4226 "#")
4227
4228 (define_split
4229 [(set (match_operand:SI 0 "register_operand" "")
4230 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4231 (const_int 23))
4232 (match_dup 0)))
4233 (clobber (match_operand:SI 2 "register_operand" ""))]
4234 "(TARGET_H8300H || TARGET_H8300S)
4235 && epilogue_completed
4236 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4237 && REGNO (operands[0]) != REGNO (operands[1])"
4238 [(parallel [(set (match_dup 3)
4239 (ashift:HI (match_dup 3)
4240 (const_int 7)))
4241 (clobber (scratch:QI))])
4242 (set (match_dup 0)
4243 (ior:SI (ashift:SI (match_dup 1)
4244 (const_int 16))
4245 (match_dup 0)))]
4246 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[1]));")
4247
4248 (define_split
4249 [(set (match_operand:SI 0 "register_operand" "")
4250 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
4251 (const_int 23))
4252 (match_dup 0)))
4253 (clobber (match_operand:SI 2 "register_operand" ""))]
4254 "(TARGET_H8300H || TARGET_H8300S)
4255 && epilogue_completed
4256 && !(find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4257 && REGNO (operands[0]) != REGNO (operands[1]))"
4258 [(set (match_dup 2)
4259 (match_dup 1))
4260 (parallel [(set (match_dup 3)
4261 (ashift:HI (match_dup 3)
4262 (const_int 7)))
4263 (clobber (scratch:QI))])
4264 (set (match_dup 0)
4265 (ior:SI (ashift:SI (match_dup 2)
4266 (const_int 16))
4267 (match_dup 0)))]
4268 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[2]));")
4269
4270 (define_insn "*iorsi2_and_1_lshiftrt_1"
4271 [(set (match_operand:SI 0 "register_operand" "=r")
4272 (ior:SI (and:SI (match_operand:SI 1 "register_operand" "0")
4273 (const_int 1))
4274 (lshiftrt:SI (match_dup 1)
4275 (const_int 1))))]
4276 "TARGET_H8300H || TARGET_H8300S"
4277 "shlr.l\\t%S0\;bor\\t#0,%w0\;bst\\t#0,%w0"
4278 [(set_attr "length" "6")])
4279
4280 (define_insn_and_split "*iorsi3_ashift_16_ashift_24"
4281 [(set (match_operand:SI 0 "register_operand" "=r")
4282 (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
4283 (const_int 16))
4284 (ashift:SI (match_operand:SI 2 "register_operand" "r")
4285 (const_int 24))))]
4286 "(TARGET_H8300H || TARGET_H8300S)"
4287 "#"
4288 "&& reload_completed"
4289 [(set (match_dup 3)
4290 (ior:HI (ashift:HI (match_dup 4)
4291 (const_int 8))
4292 (match_dup 3)))
4293 (parallel [(set (match_dup 0)
4294 (ashift:SI (match_dup 0)
4295 (const_int 16)))
4296 (clobber (scratch:QI))])]
4297 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));
4298 operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));")
4299
4300 (define_insn_and_split "*iorsi3_ashift_16_ashift_24_mem"
4301 [(set (match_operand:SI 0 "register_operand" "=&r")
4302 (ior:SI (and:SI (ashift:SI (subreg:SI (match_operand:QI 1 "memory_operand" "m") 0)
4303 (const_int 16))
4304 (const_int 16711680))
4305 (ashift:SI (subreg:SI (match_operand:QI 2 "memory_operand" "m") 0)
4306 (const_int 24))))]
4307 "(TARGET_H8300H || TARGET_H8300S)"
4308 "#"
4309 "&& reload_completed"
4310 [(set (match_dup 3)
4311 (ior:HI (zero_extend:HI (match_dup 1))
4312 (ashift:HI (subreg:HI (match_dup 2) 0)
4313 (const_int 8))))
4314 (parallel [(set (match_dup 0)
4315 (ashift:SI (match_dup 0)
4316 (const_int 16)))
4317 (clobber (scratch:QI))])]
4318 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[0]));")
4319
4320 ;; Used to add the exponent of a float.
4321
4322 (define_insn "*addsi3_shift"
4323 [(set (match_operand:SI 0 "register_operand" "=r")
4324 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
4325 (const_int 8388608))
4326 (match_operand:SI 2 "register_operand" "0")))
4327 (clobber (match_scratch:SI 3 "=&r"))]
4328 "TARGET_H8300H || TARGET_H8300S"
4329 "#")
4330
4331 (define_split
4332 [(set (match_operand:SI 0 "register_operand" "")
4333 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
4334 (const_int 8388608))
4335 (match_dup 0)))
4336 (clobber (match_operand:SI 2 "register_operand" ""))]
4337 "(TARGET_H8300H || TARGET_H8300S)
4338 && epilogue_completed
4339 && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4340 && REGNO (operands[0]) != REGNO (operands[1])"
4341 [(parallel [(set (match_dup 3)
4342 (ashift:HI (match_dup 3)
4343 (const_int 7)))
4344 (clobber (scratch:QI))])
4345 (set (match_dup 0)
4346 (plus:SI (mult:SI (match_dup 1)
4347 (const_int 65536))
4348 (match_dup 0)))]
4349 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[1]));")
4350
4351 (define_split
4352 [(set (match_operand:SI 0 "register_operand" "")
4353 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
4354 (const_int 8388608))
4355 (match_dup 0)))
4356 (clobber (match_operand:SI 2 "register_operand" ""))]
4357 "(TARGET_H8300H || TARGET_H8300S)
4358 && epilogue_completed
4359 && !(find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
4360 && REGNO (operands[0]) != REGNO (operands[1]))"
4361 [(set (match_dup 2)
4362 (match_dup 1))
4363 (parallel [(set (match_dup 3)
4364 (ashift:HI (match_dup 3)
4365 (const_int 7)))
4366 (clobber (scratch:QI))])
4367 (set (match_dup 0)
4368 (plus:SI (mult:SI (match_dup 2)
4369 (const_int 65536))
4370 (match_dup 0)))]
4371 "operands[3] = gen_rtx_REG (HImode, REGNO (operands[2]));")
4372
4373 ;; ashift:SI
4374
4375 (define_insn_and_split "*ashiftsi_sextqi_7"
4376 [(set (match_operand:SI 0 "register_operand" "=r")
4377 (ashift:SI (sign_extend:SI (match_operand:QI 1 "register_operand" "0"))
4378 (const_int 7)))]
4379 "(TARGET_H8300H || TARGET_H8300S)"
4380 "#"
4381 "&& reload_completed"
4382 [(parallel [(set (match_dup 2)
4383 (ashift:HI (match_dup 2)
4384 (const_int 8)))
4385 (clobber (scratch:QI))])
4386 (set (match_dup 0)
4387 (sign_extend:SI (match_dup 2)))
4388 (parallel [(set (match_dup 0)
4389 (ashiftrt:SI (match_dup 0)
4390 (const_int 1)))
4391 (clobber (scratch:QI))])]
4392 "operands[2] = gen_rtx_REG (HImode, REGNO (operands[0]));")
4393
4394 ;; Storing a part of HImode to QImode.
4395
4396 (define_insn ""
4397 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4398 (subreg:QI (lshiftrt:HI (match_operand:HI 1 "register_operand" "r")
4399 (const_int 8)) 1))]
4400 ""
4401 "mov.b\\t%t1,%R0"
4402 [(set_attr "cc" "set_znv")
4403 (set_attr "length" "8")])
4404
4405 ;; Storing a part of SImode to QImode.
4406
4407 (define_insn ""
4408 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4409 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4410 (const_int 8)) 3))]
4411 ""
4412 "mov.b\\t%x1,%R0"
4413 [(set_attr "cc" "set_znv")
4414 (set_attr "length" "8")])
4415
4416 (define_insn ""
4417 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4418 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4419 (const_int 16)) 3))
4420 (clobber (match_scratch:SI 2 "=&r"))]
4421 "TARGET_H8300H || TARGET_H8300S"
4422 "mov.w\\t%e1,%f2\;mov.b\\t%w2,%R0"
4423 [(set_attr "cc" "set_znv")
4424 (set_attr "length" "10")])
4425
4426 (define_insn ""
4427 [(set (match_operand:QI 0 "general_operand_dst" "=rm<")
4428 (subreg:QI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r")
4429 (const_int 24)) 3))
4430 (clobber (match_scratch:SI 2 "=&r"))]
4431 "TARGET_H8300H || TARGET_H8300S"
4432 "mov.w\\t%e1,%f2\;mov.b\\t%x2,%R0"
4433 [(set_attr "cc" "set_znv")
4434 (set_attr "length" "10")])
4435
4436 (define_insn_and_split ""
4437 [(set (pc)
4438 (if_then_else (eq (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
4439 (const_int 1)
4440 (const_int 7))
4441 (const_int 0))
4442 (label_ref (match_operand 1 "" ""))
4443 (pc)))]
4444 ""
4445 "#"
4446 ""
4447 [(set (cc0) (compare (match_dup 0)
4448 (const_int 0)))
4449 (set (pc)
4450 (if_then_else (ge (cc0)
4451 (const_int 0))
4452 (label_ref (match_dup 1))
4453 (pc)))]
4454 "")
4455
4456 (define_insn_and_split ""
4457 [(set (pc)
4458 (if_then_else (ne (zero_extract:SI (subreg:SI (match_operand:QI 0 "register_operand" "") 0)
4459 (const_int 1)
4460 (const_int 7))
4461 (const_int 0))
4462 (label_ref (match_operand 1 "" ""))
4463 (pc)))]
4464 ""
4465 "#"
4466 ""
4467 [(set (cc0) (compare (match_dup 0)
4468 (const_int 0)))
4469 (set (pc)
4470 (if_then_else (lt (cc0)
4471 (const_int 0))
4472 (label_ref (match_dup 1))
4473 (pc)))]
4474 "")
4475 \f
4476 ;; -----------------------------------------------------------------
4477 ;; PEEPHOLE PATTERNS
4478 ;; -----------------------------------------------------------------
4479
4480 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
4481
4482 (define_peephole2
4483 [(parallel [(set (match_operand:HI 0 "register_operand" "")
4484 (lshiftrt:HI (match_dup 0)
4485 (match_operand:HI 1 "const_int_operand" "")))
4486 (clobber (match_operand:HI 2 "" ""))])
4487 (set (match_dup 0)
4488 (and:HI (match_dup 0)
4489 (match_operand:HI 3 "const_int_operand" "")))]
4490 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
4491 [(set (match_dup 0)
4492 (and:HI (match_dup 0)
4493 (const_int 255)))
4494 (parallel
4495 [(set (match_dup 0)
4496 (lshiftrt:HI (match_dup 0)
4497 (match_dup 1)))
4498 (clobber (match_dup 2))])]
4499 "")
4500
4501 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
4502
4503 (define_peephole2
4504 [(parallel [(set (match_operand:HI 0 "register_operand" "")
4505 (ashift:HI (match_dup 0)
4506 (match_operand:HI 1 "const_int_operand" "")))
4507 (clobber (match_operand:HI 2 "" ""))])
4508 (set (match_dup 0)
4509 (and:HI (match_dup 0)
4510 (match_operand:HI 3 "const_int_operand" "")))]
4511 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
4512 [(set (match_dup 0)
4513 (and:HI (match_dup 0)
4514 (const_int 255)))
4515 (parallel
4516 [(set (match_dup 0)
4517 (ashift:HI (match_dup 0)
4518 (match_dup 1)))
4519 (clobber (match_dup 2))])]
4520 "")
4521
4522 ;; Convert (A >> B) & C to (A & 255) >> B if C == 255 >> B.
4523
4524 (define_peephole2
4525 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4526 (lshiftrt:SI (match_dup 0)
4527 (match_operand:SI 1 "const_int_operand" "")))
4528 (clobber (match_operand:SI 2 "" ""))])
4529 (set (match_dup 0)
4530 (and:SI (match_dup 0)
4531 (match_operand:SI 3 "const_int_operand" "")))]
4532 "INTVAL (operands[3]) == (255 >> INTVAL (operands[1]))"
4533 [(set (match_dup 0)
4534 (and:SI (match_dup 0)
4535 (const_int 255)))
4536 (parallel
4537 [(set (match_dup 0)
4538 (lshiftrt:SI (match_dup 0)
4539 (match_dup 1)))
4540 (clobber (match_dup 2))])]
4541 "")
4542
4543 ;; Convert (A << B) & C to (A & 255) << B if C == 255 << B.
4544
4545 (define_peephole2
4546 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4547 (ashift:SI (match_dup 0)
4548 (match_operand:SI 1 "const_int_operand" "")))
4549 (clobber (match_operand:SI 2 "" ""))])
4550 (set (match_dup 0)
4551 (and:SI (match_dup 0)
4552 (match_operand:SI 3 "const_int_operand" "")))]
4553 "INTVAL (operands[3]) == (255 << INTVAL (operands[1]))"
4554 [(set (match_dup 0)
4555 (and:SI (match_dup 0)
4556 (const_int 255)))
4557 (parallel
4558 [(set (match_dup 0)
4559 (ashift:SI (match_dup 0)
4560 (match_dup 1)))
4561 (clobber (match_dup 2))])]
4562 "")
4563
4564 ;; Convert (A >> B) & C to (A & 65535) >> B if C == 65535 >> B.
4565
4566 (define_peephole2
4567 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4568 (lshiftrt:SI (match_dup 0)
4569 (match_operand:SI 1 "const_int_operand" "")))
4570 (clobber (match_operand:SI 2 "" ""))])
4571 (set (match_dup 0)
4572 (and:SI (match_dup 0)
4573 (match_operand:SI 3 "const_int_operand" "")))]
4574 "INTVAL (operands[3]) == (65535 >> INTVAL (operands[1]))"
4575 [(set (match_dup 0)
4576 (and:SI (match_dup 0)
4577 (const_int 65535)))
4578 (parallel
4579 [(set (match_dup 0)
4580 (lshiftrt:SI (match_dup 0)
4581 (match_dup 1)))
4582 (clobber (match_dup 2))])]
4583 "")
4584
4585 ;; Convert (A << B) & C to (A & 65535) << B if C == 65535 << B.
4586
4587 (define_peephole2
4588 [(parallel [(set (match_operand:SI 0 "register_operand" "")
4589 (ashift:SI (match_dup 0)
4590 (match_operand:SI 1 "const_int_operand" "")))
4591 (clobber (match_operand:SI 2 "" ""))])
4592 (set (match_dup 0)
4593 (and:SI (match_dup 0)
4594 (match_operand:SI 3 "const_int_operand" "")))]
4595 "INTVAL (operands[3]) == (65535 << INTVAL (operands[1]))"
4596 [(set (match_dup 0)
4597 (and:SI (match_dup 0)
4598 (const_int 65535)))
4599 (parallel
4600 [(set (match_dup 0)
4601 (ashift:SI (match_dup 0)
4602 (match_dup 1)))
4603 (clobber (match_dup 2))])]
4604 "")
4605
4606 ;; Convert a QImode push into an SImode push so that the
4607 ;; define_peephole2 below can cram multiple pushes into one stm.l.
4608
4609 (define_peephole2
4610 [(parallel [(set (reg:SI SP_REG)
4611 (plus:SI (reg:SI SP_REG) (const_int -4)))
4612 (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int -3)))
4613 (match_operand:QI 0 "register_operand" ""))])]
4614 "TARGET_H8300S && !TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4615 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4616 (match_dup 0))]
4617 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
4618
4619 (define_peephole2
4620 [(parallel [(set (reg:HI SP_REG)
4621 (plus:HI (reg:HI SP_REG) (const_int -4)))
4622 (set (mem:QI (plus:HI (reg:HI SP_REG) (const_int -3)))
4623 (match_operand:QI 0 "register_operand" ""))])]
4624 "TARGET_H8300S && TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4625 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4626 (match_dup 0))]
4627 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
4628
4629 ;; Convert a HImode push into an SImode push so that the
4630 ;; define_peephole2 below can cram multiple pushes into one stm.l.
4631
4632 (define_peephole2
4633 [(parallel [(set (reg:SI SP_REG)
4634 (plus:SI (reg:SI SP_REG) (const_int -4)))
4635 (set (mem:HI (plus:SI (reg:SI SP_REG) (const_int -2)))
4636 (match_operand:HI 0 "register_operand" ""))])]
4637 "TARGET_H8300S && !TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4638 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4639 (match_dup 0))]
4640 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
4641
4642 (define_peephole2
4643 [(parallel [(set (reg:HI SP_REG)
4644 (plus:HI (reg:HI SP_REG) (const_int -4)))
4645 (set (mem:HI (plus:HI (reg:HI SP_REG) (const_int -2)))
4646 (match_operand:HI 0 "register_operand" ""))])]
4647 "TARGET_H8300S && TARGET_NORMAL_MODE && REGNO (operands[0]) != SP_REG"
4648 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4649 (match_dup 0))]
4650 "operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));")
4651
4652 ;; Cram four pushes into stm.l.
4653
4654 (define_peephole2
4655 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4656 (match_operand:SI 0 "register_operand" ""))
4657 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4658 (match_operand:SI 1 "register_operand" ""))
4659 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4660 (match_operand:SI 2 "register_operand" ""))
4661 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4662 (match_operand:SI 3 "register_operand" ""))]
4663 "TARGET_H8300S && !TARGET_NORMAL_MODE
4664 && (REGNO_REG_CLASS (REGNO (operands[3])) == GENERAL_REGS
4665 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4666 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4667 && REGNO (operands[3]) == REGNO (operands[0]) + 3
4668 && (TARGET_H8300SX || REGNO (operands[0]) == 0))"
4669 [(parallel [(set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
4670 (match_dup 0))
4671 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
4672 (match_dup 1))
4673 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
4674 (match_dup 2))
4675 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -16)))
4676 (match_dup 3))
4677 (set (reg:SI SP_REG)
4678 (plus:SI (reg:SI SP_REG)
4679 (const_int -16)))])]
4680 "")
4681
4682 (define_peephole2
4683 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4684 (match_operand:SI 0 "register_operand" ""))
4685 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4686 (match_operand:SI 1 "register_operand" ""))
4687 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4688 (match_operand:SI 2 "register_operand" ""))
4689 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4690 (match_operand:SI 3 "register_operand" ""))]
4691 "TARGET_H8300S && TARGET_NORMAL_MODE
4692 && (REGNO_REG_CLASS (REGNO (operands[3])) == GENERAL_REGS
4693 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4694 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4695 && REGNO (operands[3]) == REGNO (operands[0]) + 3
4696 && (TARGET_H8300SX || REGNO (operands[0]) == 0))"
4697 [(parallel [(set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -4)))
4698 (match_dup 0))
4699 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -8)))
4700 (match_dup 1))
4701 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -12)))
4702 (match_dup 2))
4703 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -16)))
4704 (match_dup 3))
4705 (set (reg:HI SP_REG)
4706 (plus:HI (reg:HI SP_REG)
4707 (const_int -16)))])]
4708 "")
4709
4710 ;; Cram three pushes into stm.l.
4711
4712 (define_peephole2
4713 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4714 (match_operand:SI 0 "register_operand" ""))
4715 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4716 (match_operand:SI 1 "register_operand" ""))
4717 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4718 (match_operand:SI 2 "register_operand" ""))]
4719 "TARGET_H8300S && !TARGET_NORMAL_MODE
4720 && (REGNO_REG_CLASS (REGNO (operands[2])) == GENERAL_REGS
4721 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4722 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4723 && (TARGET_H8300SX || (REGNO (operands[0]) & 3) == 0))"
4724 [(parallel [(set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
4725 (match_dup 0))
4726 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
4727 (match_dup 1))
4728 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -12)))
4729 (match_dup 2))
4730 (set (reg:SI SP_REG)
4731 (plus:SI (reg:SI SP_REG)
4732 (const_int -12)))])]
4733 "")
4734
4735 (define_peephole2
4736 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4737 (match_operand:SI 0 "register_operand" ""))
4738 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4739 (match_operand:SI 1 "register_operand" ""))
4740 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4741 (match_operand:SI 2 "register_operand" ""))]
4742 "TARGET_H8300S && TARGET_NORMAL_MODE
4743 && (REGNO_REG_CLASS (REGNO (operands[2])) == GENERAL_REGS
4744 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4745 && REGNO (operands[2]) == REGNO (operands[0]) + 2
4746 && (TARGET_H8300SX || (REGNO (operands[0]) & 3) == 0))"
4747 [(parallel [(set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -4)))
4748 (match_dup 0))
4749 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -8)))
4750 (match_dup 1))
4751 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -12)))
4752 (match_dup 2))
4753 (set (reg:HI SP_REG)
4754 (plus:HI (reg:HI SP_REG)
4755 (const_int -12)))])]
4756 "")
4757
4758 ;; Cram two pushes into stm.l.
4759
4760 (define_peephole2
4761 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4762 (match_operand:SI 0 "register_operand" ""))
4763 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
4764 (match_operand:SI 1 "register_operand" ""))]
4765 "TARGET_H8300S && !TARGET_NORMAL_MODE
4766 && (REGNO_REG_CLASS (REGNO (operands[1])) == GENERAL_REGS
4767 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4768 && (TARGET_H8300SX || (REGNO (operands[0]) & 1) == 0))"
4769 [(parallel [(set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
4770 (match_dup 0))
4771 (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -8)))
4772 (match_dup 1))
4773 (set (reg:SI SP_REG)
4774 (plus:SI (reg:SI SP_REG)
4775 (const_int -8)))])]
4776 "")
4777
4778 (define_peephole2
4779 [(set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4780 (match_operand:SI 0 "register_operand" ""))
4781 (set (mem:SI (pre_dec:HI (reg:HI SP_REG)))
4782 (match_operand:SI 1 "register_operand" ""))]
4783 "TARGET_H8300S && TARGET_NORMAL_MODE
4784 && (REGNO_REG_CLASS (REGNO (operands[1])) == GENERAL_REGS
4785 && REGNO (operands[1]) == REGNO (operands[0]) + 1
4786 && (TARGET_H8300SX || (REGNO (operands[0]) & 1) == 0))"
4787 [(parallel [(set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -4)))
4788 (match_dup 0))
4789 (set (mem:SI (plus:HI (reg:HI SP_REG) (const_int -8)))
4790 (match_dup 1))
4791 (set (reg:HI SP_REG)
4792 (plus:HI (reg:HI SP_REG)
4793 (const_int -8)))])]
4794 "")
4795
4796 ;; Turn
4797 ;;
4798 ;; mov.w #2,r0
4799 ;; add.w r7,r0 (6 bytes)
4800 ;;
4801 ;; into
4802 ;;
4803 ;; mov.w r7,r0
4804 ;; adds #2,r0 (4 bytes)
4805
4806 (define_peephole2
4807 [(set (match_operand:HI 0 "register_operand" "")
4808 (match_operand:HI 1 "const_int_operand" ""))
4809 (set (match_dup 0)
4810 (plus:HI (match_dup 0)
4811 (match_operand:HI 2 "register_operand" "")))]
4812 "REG_P (operands[0]) && REG_P (operands[2])
4813 && REGNO (operands[0]) != REGNO (operands[2])
4814 && (satisfies_constraint_J (operands[1])
4815 || satisfies_constraint_L (operands[1])
4816 || satisfies_constraint_N (operands[1]))"
4817 [(set (match_dup 0)
4818 (match_dup 2))
4819 (set (match_dup 0)
4820 (plus:HI (match_dup 0)
4821 (match_dup 1)))]
4822 "")
4823
4824 ;; Turn
4825 ;;
4826 ;; sub.l er0,er0
4827 ;; add.b #4,r0l
4828 ;; add.l er7,er0 (6 bytes)
4829 ;;
4830 ;; into
4831 ;;
4832 ;; mov.l er7,er0
4833 ;; adds #4,er0 (4 bytes)
4834
4835 (define_peephole2
4836 [(set (match_operand:SI 0 "register_operand" "")
4837 (match_operand:SI 1 "const_int_operand" ""))
4838 (set (match_dup 0)
4839 (plus:SI (match_dup 0)
4840 (match_operand:SI 2 "register_operand" "")))]
4841 "(TARGET_H8300H || TARGET_H8300S)
4842 && REG_P (operands[0]) && REG_P (operands[2])
4843 && REGNO (operands[0]) != REGNO (operands[2])
4844 && (satisfies_constraint_L (operands[1])
4845 || satisfies_constraint_N (operands[1]))"
4846 [(set (match_dup 0)
4847 (match_dup 2))
4848 (set (match_dup 0)
4849 (plus:SI (match_dup 0)
4850 (match_dup 1)))]
4851 "")
4852
4853 ;; Turn
4854 ;;
4855 ;; mov.l er7,er0
4856 ;; add.l #10,er0 (takes 8 bytes)
4857 ;;
4858 ;; into
4859 ;;
4860 ;; sub.l er0,er0
4861 ;; add.b #10,r0l
4862 ;; add.l er7,er0 (takes 6 bytes)
4863
4864 (define_peephole2
4865 [(set (match_operand:SI 0 "register_operand" "")
4866 (match_operand:SI 1 "register_operand" ""))
4867 (set (match_dup 0)
4868 (plus:SI (match_dup 0)
4869 (match_operand:SI 2 "const_int_operand" "")))]
4870 "(TARGET_H8300H || TARGET_H8300S)
4871 && REG_P (operands[0]) && REG_P (operands[1])
4872 && REGNO (operands[0]) != REGNO (operands[1])
4873 && !satisfies_constraint_L (operands[2])
4874 && !satisfies_constraint_N (operands[2])
4875 && ((INTVAL (operands[2]) & 0xff) == INTVAL (operands[2])
4876 || (INTVAL (operands[2]) & 0xff00) == INTVAL (operands[2])
4877 || INTVAL (operands[2]) == 0xffff
4878 || INTVAL (operands[2]) == 0xfffe)"
4879 [(set (match_dup 0)
4880 (match_dup 2))
4881 (set (match_dup 0)
4882 (plus:SI (match_dup 0)
4883 (match_dup 1)))]
4884 "")
4885
4886 ;; Turn
4887 ;;
4888 ;; subs #1,er4
4889 ;; mov.w r4,r4
4890 ;; bne .L2028
4891 ;;
4892 ;; into
4893 ;;
4894 ;; dec.w #1,r4
4895 ;; bne .L2028
4896
4897 (define_peephole2
4898 [(set (match_operand:HI 0 "register_operand" "")
4899 (plus:HI (match_dup 0)
4900 (match_operand 1 "incdec_operand" "")))
4901 (set (cc0) (compare (match_dup 0)
4902 (const_int 0)))
4903 (set (pc)
4904 (if_then_else (match_operator 3 "eqne_operator"
4905 [(cc0) (const_int 0)])
4906 (label_ref (match_operand 2 "" ""))
4907 (pc)))]
4908 "TARGET_H8300H || TARGET_H8300S"
4909 [(set (match_operand:HI 0 "register_operand" "")
4910 (unspec:HI [(match_dup 0)
4911 (match_dup 1)]
4912 UNSPEC_INCDEC))
4913 (set (cc0) (compare (match_dup 0)
4914 (const_int 0)))
4915 (set (pc)
4916 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4917 (label_ref (match_dup 2))
4918 (pc)))]
4919 "")
4920
4921 ;; The SImode version of the previous pattern.
4922
4923 (define_peephole2
4924 [(set (match_operand:SI 0 "register_operand" "")
4925 (plus:SI (match_dup 0)
4926 (match_operand 1 "incdec_operand" "")))
4927 (set (cc0) (compare (match_dup 0)
4928 (const_int 0)))
4929 (set (pc)
4930 (if_then_else (match_operator 3 "eqne_operator"
4931 [(cc0) (const_int 0)])
4932 (label_ref (match_operand 2 "" ""))
4933 (pc)))]
4934 "TARGET_H8300H || TARGET_H8300S"
4935 [(set (match_operand:SI 0 "register_operand" "")
4936 (unspec:SI [(match_dup 0)
4937 (match_dup 1)]
4938 UNSPEC_INCDEC))
4939 (set (cc0) (compare (match_dup 0)
4940 (const_int 0)))
4941 (set (pc)
4942 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4943 (label_ref (match_dup 2))
4944 (pc)))]
4945 "")
4946
4947 (define_peephole2
4948 [(parallel [(set (cc0)
4949 (compare (zero_extract:SI (match_operand:QI 0 "register_operand" "")
4950 (const_int 1)
4951 (const_int 7))
4952 (const_int 0)))
4953 (clobber (scratch:QI))])
4954 (set (pc)
4955 (if_then_else (match_operator 1 "eqne_operator"
4956 [(cc0) (const_int 0)])
4957 (label_ref (match_operand 2 "" ""))
4958 (pc)))]
4959 "(TARGET_H8300H || TARGET_H8300S)"
4960 [(set (cc0) (compare (match_dup 0)
4961 (const_int 0)))
4962 (set (pc)
4963 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
4964 (label_ref (match_dup 2))
4965 (pc)))]
4966 "operands[3] = ((GET_CODE (operands[1]) == EQ)
4967 ? gen_rtx_GE (VOIDmode, cc0_rtx, const0_rtx)
4968 : gen_rtx_LT (VOIDmode, cc0_rtx, const0_rtx));")
4969
4970 ;; The next three peephole2's will try to transform
4971 ;;
4972 ;; mov.b A,r0l (or mov.l A,er0)
4973 ;; and.l #CST,er0
4974 ;;
4975 ;; into
4976 ;;
4977 ;; sub.l er0
4978 ;; mov.b A,r0l
4979 ;; and.b #CST,r0l (if CST is not 255)
4980
4981 (define_peephole2
4982 [(set (match_operand:QI 0 "register_operand" "")
4983 (match_operand:QI 1 "general_operand" ""))
4984 (set (match_operand:SI 2 "register_operand" "")
4985 (and:SI (match_dup 2)
4986 (const_int 255)))]
4987 "(TARGET_H8300H || TARGET_H8300S)
4988 && !reg_overlap_mentioned_p (operands[2], operands[1])
4989 && REGNO (operands[0]) == REGNO (operands[2])"
4990 [(set (match_dup 2)
4991 (const_int 0))
4992 (set (strict_low_part (match_dup 0))
4993 (match_dup 1))]
4994 "")
4995
4996 (define_peephole2
4997 [(set (match_operand:SI 0 "register_operand" "")
4998 (match_operand:SI 1 "general_operand" ""))
4999 (set (match_dup 0)
5000 (and:SI (match_dup 0)
5001 (const_int 255)))]
5002 "(TARGET_H8300H || TARGET_H8300S)
5003 && !reg_overlap_mentioned_p (operands[0], operands[1])
5004 && !(GET_CODE (operands[1]) == MEM && !offsettable_memref_p (operands[1]))
5005 && !(GET_CODE (operands[1]) == MEM && MEM_VOLATILE_P (operands[1]))"
5006 [(set (match_dup 0)
5007 (const_int 0))
5008 (set (strict_low_part (match_dup 2))
5009 (match_dup 3))]
5010 "operands[2] = gen_lowpart (QImode, operands[0]);
5011 operands[3] = gen_lowpart (QImode, operands[1]);")
5012
5013 (define_peephole2
5014 [(set (match_operand 0 "register_operand" "")
5015 (match_operand 1 "general_operand" ""))
5016 (set (match_operand:SI 2 "register_operand" "")
5017 (and:SI (match_dup 2)
5018 (match_operand:SI 3 "const_int_qi_operand" "")))]
5019 "(TARGET_H8300H || TARGET_H8300S)
5020 && (GET_MODE (operands[0]) == QImode
5021 || GET_MODE (operands[0]) == HImode
5022 || GET_MODE (operands[0]) == SImode)
5023 && GET_MODE (operands[0]) == GET_MODE (operands[1])
5024 && REGNO (operands[0]) == REGNO (operands[2])
5025 && !reg_overlap_mentioned_p (operands[2], operands[1])
5026 && !(GET_MODE (operands[1]) != QImode
5027 && GET_CODE (operands[1]) == MEM
5028 && !offsettable_memref_p (operands[1]))
5029 && !(GET_MODE (operands[1]) != QImode
5030 && GET_CODE (operands[1]) == MEM
5031 && MEM_VOLATILE_P (operands[1]))"
5032 [(set (match_dup 2)
5033 (const_int 0))
5034 (set (strict_low_part (match_dup 4))
5035 (match_dup 5))
5036 (set (match_dup 2)
5037 (and:SI (match_dup 2)
5038 (match_dup 6)))]
5039 "operands[4] = gen_lowpart (QImode, operands[0]);
5040 operands[5] = gen_lowpart (QImode, operands[1]);
5041 operands[6] = GEN_INT (~0xff | INTVAL (operands[3]));")
5042
5043 (define_peephole2
5044 [(set (match_operand:SI 0 "register_operand" "")
5045 (match_operand:SI 1 "register_operand" ""))
5046 (set (match_dup 0)
5047 (and:SI (match_dup 0)
5048 (const_int 65280)))]
5049 "(TARGET_H8300H || TARGET_H8300S)
5050 && !reg_overlap_mentioned_p (operands[0], operands[1])"
5051 [(set (match_dup 0)
5052 (const_int 0))
5053 (set (zero_extract:SI (match_dup 0)
5054 (const_int 8)
5055 (const_int 8))
5056 (lshiftrt:SI (match_dup 1)
5057 (const_int 8)))]
5058 "")
5059
5060 ;; If a load of mem:SI is followed by an AND that turns off the upper
5061 ;; half, then we can load mem:HI instead.
5062
5063 (define_peephole2
5064 [(set (match_operand:SI 0 "register_operand" "")
5065 (match_operand:SI 1 "memory_operand" ""))
5066 (set (match_dup 0)
5067 (and:SI (match_dup 0)
5068 (match_operand:SI 2 "const_int_operand" "")))]
5069 "(TARGET_H8300H || TARGET_H8300S)
5070 && !MEM_VOLATILE_P (operands[1])
5071 && offsettable_memref_p (operands[1])
5072 && (INTVAL (operands[2]) & ~0xffff) == 0
5073 && INTVAL (operands[2]) != 255"
5074 [(set (match_dup 3)
5075 (match_dup 4))
5076 (set (match_dup 0)
5077 (and:SI (match_dup 0)
5078 (match_dup 2)))]
5079 "operands[3] = gen_lowpart (HImode, operands[0]);
5080 operands[4] = gen_lowpart (HImode, operands[1]);")
5081
5082 ;; Convert a memory comparison to a move if there is a scratch register.
5083
5084 (define_peephole2
5085 [(match_scratch:QI 1 "r")
5086 (set (cc0)
5087 (compare (match_operand:QI 0 "memory_operand" "")
5088 (const_int 0)))]
5089 ""
5090 [(set (match_dup 1)
5091 (match_dup 0))
5092 (set (cc0) (compare (match_dup 1)
5093 (const_int 0)))]
5094 "")
5095
5096 (define_peephole2
5097 [(match_scratch:HI 1 "r")
5098 (set (cc0)
5099 (compare (match_operand:HI 0 "memory_operand" "")
5100 (const_int 0)))]
5101 "(TARGET_H8300H || TARGET_H8300S)"
5102 [(set (match_dup 1)
5103 (match_dup 0))
5104 (set (cc0) (compare (match_dup 1)
5105 (const_int 0)))]
5106 "")
5107
5108 (define_peephole2
5109 [(match_scratch:SI 1 "r")
5110 (set (cc0)
5111 (compare (match_operand:SI 0 "memory_operand" "")
5112 (const_int 0)))]
5113 "(TARGET_H8300H || TARGET_H8300S)"
5114 [(set (match_dup 1)
5115 (match_dup 0))
5116 (set (cc0) (compare (match_dup 1)
5117 (const_int 0)))]
5118 "")
5119
5120
5121 ;; (compare (reg:HI) (const_int)) takes 4 bytes, so we try to achieve
5122 ;; the equivalent with shorter sequences. Here is the summary. Cases
5123 ;; are grouped for each define_peephole2.
5124 ;;
5125 ;; reg const_int use insn
5126 ;; --------------------------------------------------------
5127 ;; dead -2 eq/ne inc.l
5128 ;; dead -1 eq/ne inc.l
5129 ;; dead 1 eq/ne dec.l
5130 ;; dead 2 eq/ne dec.l
5131 ;;
5132 ;; dead 1 ge/lt shar.l
5133 ;; dead 3 (H8S) ge/lt shar.l
5134 ;;
5135 ;; dead 1 geu/ltu shar.l
5136 ;; dead 3 (H8S) geu/ltu shar.l
5137 ;;
5138 ;; ---- 255 ge/lt mov.b
5139 ;;
5140 ;; ---- 255 geu/ltu mov.b
5141
5142 ;; Transform
5143 ;;
5144 ;; cmp.w #1,r0
5145 ;; bne .L1
5146 ;;
5147 ;; into
5148 ;;
5149 ;; dec.w #1,r0
5150 ;; bne .L1
5151
5152 (define_peephole2
5153 [(set (cc0)
5154 (compare (match_operand:HI 0 "register_operand" "")
5155 (match_operand:HI 1 "incdec_operand" "")))
5156 (set (pc)
5157 (if_then_else (match_operator 3 "eqne_operator"
5158 [(cc0) (const_int 0)])
5159 (label_ref (match_operand 2 "" ""))
5160 (pc)))]
5161 "(TARGET_H8300H || TARGET_H8300S)
5162 && INTVAL (operands[1]) != 0
5163 && peep2_reg_dead_p (1, operands[0])"
5164 [(set (match_dup 0)
5165 (unspec:HI [(match_dup 0)
5166 (match_dup 4)]
5167 UNSPEC_INCDEC))
5168 (set (cc0) (compare (match_dup 0)
5169 (const_int 0)))
5170 (set (pc)
5171 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5172 (label_ref (match_dup 2))
5173 (pc)))]
5174 "operands[4] = GEN_INT (- INTVAL (operands[1]));")
5175
5176 ;; Transform
5177 ;;
5178 ;; cmp.w #1,r0
5179 ;; bgt .L1
5180 ;;
5181 ;; into
5182 ;;
5183 ;; shar.w r0
5184 ;; bgt .L1
5185
5186 (define_peephole2
5187 [(set (cc0)
5188 (compare (match_operand:HI 0 "register_operand" "")
5189 (match_operand:HI 1 "const_int_operand" "")))
5190 (set (pc)
5191 (if_then_else (match_operator 2 "gtle_operator"
5192 [(cc0) (const_int 0)])
5193 (label_ref (match_operand 3 "" ""))
5194 (pc)))]
5195 "(TARGET_H8300H || TARGET_H8300S)
5196 && peep2_reg_dead_p (1, operands[0])
5197 && (INTVAL (operands[1]) == 1
5198 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5199 [(parallel [(set (match_dup 0)
5200 (ashiftrt:HI (match_dup 0)
5201 (match_dup 4)))
5202 (clobber (scratch:QI))])
5203 (set (cc0) (compare (match_dup 0)
5204 (const_int 0)))
5205 (set (pc)
5206 (if_then_else (match_dup 2)
5207 (label_ref (match_dup 3))
5208 (pc)))]
5209 "operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));")
5210
5211 ;; Transform
5212 ;;
5213 ;; cmp.w #1,r0
5214 ;; bhi .L1
5215 ;;
5216 ;; into
5217 ;;
5218 ;; shar.w r0
5219 ;; bne .L1
5220
5221 (define_peephole2
5222 [(set (cc0)
5223 (compare (match_operand:HI 0 "register_operand" "")
5224 (match_operand:HI 1 "const_int_operand" "")))
5225 (set (pc)
5226 (if_then_else (match_operator 2 "gtuleu_operator"
5227 [(cc0) (const_int 0)])
5228 (label_ref (match_operand 3 "" ""))
5229 (pc)))]
5230 "(TARGET_H8300H || TARGET_H8300S)
5231 && peep2_reg_dead_p (1, operands[0])
5232 && (INTVAL (operands[1]) == 1
5233 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5234 [(parallel [(set (match_dup 0)
5235 (ashiftrt:HI (match_dup 0)
5236 (match_dup 4)))
5237 (clobber (scratch:QI))])
5238 (set (cc0) (compare (match_dup 0)
5239 (const_int 0)))
5240 (set (pc)
5241 (if_then_else (match_dup 5)
5242 (label_ref (match_dup 3))
5243 (pc)))]
5244 {
5245 operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5246 operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5247 VOIDmode,
5248 cc0_rtx,
5249 const0_rtx);
5250 })
5251
5252 ;; Transform
5253 ;;
5254 ;; cmp.w #255,r0
5255 ;; bgt .L1
5256 ;;
5257 ;; into
5258 ;;
5259 ;; mov.b r0h,r0h
5260 ;; bgt .L1
5261
5262 (define_peephole2
5263 [(set (cc0)
5264 (compare (match_operand:HI 0 "register_operand" "")
5265 (const_int 255)))
5266 (set (pc)
5267 (if_then_else (match_operator 1 "gtle_operator"
5268 [(cc0) (const_int 0)])
5269 (label_ref (match_operand 2 "" ""))
5270 (pc)))]
5271 "TARGET_H8300H || TARGET_H8300S"
5272 [(set (cc0) (compare (and:HI (match_dup 0)
5273 (const_int -256))
5274 (const_int 0)))
5275 (set (pc)
5276 (if_then_else (match_dup 1)
5277 (label_ref (match_dup 2))
5278 (pc)))]
5279 "")
5280
5281 ;; Transform
5282 ;;
5283 ;; cmp.w #255,r0
5284 ;; bhi .L1
5285 ;;
5286 ;; into
5287 ;;
5288 ;; mov.b r0h,r0h
5289 ;; bne .L1
5290
5291 (define_peephole2
5292 [(set (cc0)
5293 (compare (match_operand:HI 0 "register_operand" "")
5294 (const_int 255)))
5295 (set (pc)
5296 (if_then_else (match_operator 1 "gtuleu_operator"
5297 [(cc0) (const_int 0)])
5298 (label_ref (match_operand 2 "" ""))
5299 (pc)))]
5300 "TARGET_H8300H || TARGET_H8300S"
5301 [(set (cc0) (compare (and:HI (match_dup 0)
5302 (const_int -256))
5303 (const_int 0)))
5304 (set (pc)
5305 (if_then_else (match_dup 3)
5306 (label_ref (match_dup 2))
5307 (pc)))]
5308 {
5309 operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[1]) == GTU ? NE : EQ,
5310 VOIDmode,
5311 cc0_rtx,
5312 const0_rtx);
5313 })
5314
5315 ;; (compare (reg:SI) (const_int)) takes 6 bytes, so we try to achieve
5316 ;; the equivalent with shorter sequences. Here is the summary. Cases
5317 ;; are grouped for each define_peephole2.
5318 ;;
5319 ;; reg const_int use insn
5320 ;; --------------------------------------------------------
5321 ;; live -2 eq/ne copy and inc.l
5322 ;; live -1 eq/ne copy and inc.l
5323 ;; live 1 eq/ne copy and dec.l
5324 ;; live 2 eq/ne copy and dec.l
5325 ;;
5326 ;; dead -2 eq/ne inc.l
5327 ;; dead -1 eq/ne inc.l
5328 ;; dead 1 eq/ne dec.l
5329 ;; dead 2 eq/ne dec.l
5330 ;;
5331 ;; dead -131072 eq/ne inc.w and test
5332 ;; dead -65536 eq/ne inc.w and test
5333 ;; dead 65536 eq/ne dec.w and test
5334 ;; dead 131072 eq/ne dec.w and test
5335 ;;
5336 ;; dead 0x000000?? except 1 and 2 eq/ne xor.b and test
5337 ;; dead 0x0000??00 eq/ne xor.b and test
5338 ;; dead 0x0000ffff eq/ne not.w and test
5339 ;;
5340 ;; dead 0xffffff?? except -1 and -2 eq/ne xor.b and not.l
5341 ;; dead 0xffff??ff eq/ne xor.b and not.l
5342 ;; dead 0x40000000 (H8S) eq/ne rotl.l and dec.l
5343 ;; dead 0x80000000 eq/ne rotl.l and dec.l
5344 ;;
5345 ;; live 1 ge/lt copy and shar.l
5346 ;; live 3 (H8S) ge/lt copy and shar.l
5347 ;;
5348 ;; live 1 geu/ltu copy and shar.l
5349 ;; live 3 (H8S) geu/ltu copy and shar.l
5350 ;;
5351 ;; dead 1 ge/lt shar.l
5352 ;; dead 3 (H8S) ge/lt shar.l
5353 ;;
5354 ;; dead 1 geu/ltu shar.l
5355 ;; dead 3 (H8S) geu/ltu shar.l
5356 ;;
5357 ;; dead 3 (H8/300H) ge/lt and.b and test
5358 ;; dead 7 ge/lt and.b and test
5359 ;; dead 15 ge/lt and.b and test
5360 ;; dead 31 ge/lt and.b and test
5361 ;; dead 63 ge/lt and.b and test
5362 ;; dead 127 ge/lt and.b and test
5363 ;; dead 255 ge/lt and.b and test
5364 ;;
5365 ;; dead 3 (H8/300H) geu/ltu and.b and test
5366 ;; dead 7 geu/ltu and.b and test
5367 ;; dead 15 geu/ltu and.b and test
5368 ;; dead 31 geu/ltu and.b and test
5369 ;; dead 63 geu/ltu and.b and test
5370 ;; dead 127 geu/ltu and.b and test
5371 ;; dead 255 geu/ltu and.b and test
5372 ;;
5373 ;; ---- 65535 ge/lt mov.w
5374 ;;
5375 ;; ---- 65535 geu/ltu mov.w
5376
5377 ;; Transform
5378 ;;
5379 ;; cmp.l #1,er0
5380 ;; beq .L1
5381 ;;
5382 ;; into
5383 ;;
5384 ;; dec.l #1,er0
5385 ;; beq .L1
5386
5387 (define_peephole2
5388 [(set (cc0)
5389 (compare (match_operand:SI 0 "register_operand" "")
5390 (match_operand:SI 1 "incdec_operand" "")))
5391 (set (pc)
5392 (if_then_else (match_operator 3 "eqne_operator"
5393 [(cc0) (const_int 0)])
5394 (label_ref (match_operand 2 "" ""))
5395 (pc)))]
5396 "(TARGET_H8300H || TARGET_H8300S)
5397 && INTVAL (operands[1]) != 0
5398 && peep2_reg_dead_p (1, operands[0])"
5399 [(set (match_dup 0)
5400 (unspec:SI [(match_dup 0)
5401 (match_dup 4)]
5402 UNSPEC_INCDEC))
5403 (set (cc0) (compare (match_dup 0)
5404 (const_int 0)))
5405 (set (pc)
5406 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5407 (label_ref (match_dup 2))
5408 (pc)))]
5409 "operands[4] = GEN_INT (- INTVAL (operands[1]));")
5410
5411 ;; Transform
5412 ;;
5413 ;; cmp.l #65536,er0
5414 ;; beq .L1
5415 ;;
5416 ;; into
5417 ;;
5418 ;; dec.l #1,e0
5419 ;; beq .L1
5420
5421 (define_peephole2
5422 [(set (cc0)
5423 (compare (match_operand:SI 0 "register_operand" "")
5424 (match_operand:SI 1 "const_int_operand" "")))
5425 (set (pc)
5426 (if_then_else (match_operator 3 "eqne_operator"
5427 [(cc0) (const_int 0)])
5428 (label_ref (match_operand 2 "" ""))
5429 (pc)))]
5430 "(TARGET_H8300H || TARGET_H8300S)
5431 && peep2_reg_dead_p (1, operands[0])
5432 && (INTVAL (operands[1]) == -131072
5433 || INTVAL (operands[1]) == -65536
5434 || INTVAL (operands[1]) == 65536
5435 || INTVAL (operands[1]) == 131072)"
5436 [(set (match_dup 0)
5437 (plus:SI (match_dup 0)
5438 (match_dup 4)))
5439 (set (cc0) (compare (match_dup 0)
5440 (const_int 0)))
5441 (set (pc)
5442 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5443 (label_ref (match_dup 2))
5444 (pc)))]
5445 "operands[4] = GEN_INT (- INTVAL (operands[1]));")
5446
5447 ;; Transform
5448 ;;
5449 ;; cmp.l #100,er0
5450 ;; beq .L1
5451 ;;
5452 ;; into
5453 ;;
5454 ;; xor.b #100,er0
5455 ;; mov.l er0,er0
5456 ;; beq .L1
5457
5458 (define_peephole2
5459 [(set (cc0)
5460 (compare (match_operand:SI 0 "register_operand" "")
5461 (match_operand:SI 1 "const_int_operand" "")))
5462 (set (pc)
5463 (if_then_else (match_operator 3 "eqne_operator"
5464 [(cc0) (const_int 0)])
5465 (label_ref (match_operand 2 "" ""))
5466 (pc)))]
5467 "(TARGET_H8300H || TARGET_H8300S)
5468 && peep2_reg_dead_p (1, operands[0])
5469 && ((INTVAL (operands[1]) & 0x00ff) == INTVAL (operands[1])
5470 || (INTVAL (operands[1]) & 0xff00) == INTVAL (operands[1])
5471 || INTVAL (operands[1]) == 0x0000ffff)
5472 && INTVAL (operands[1]) != 0
5473 && INTVAL (operands[1]) != 1
5474 && INTVAL (operands[1]) != 2"
5475 [(set (match_dup 0)
5476 (xor:SI (match_dup 0)
5477 (match_dup 1)))
5478 (set (cc0) (compare (match_dup 0)
5479 (const_int 0)))
5480 (set (pc)
5481 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5482 (label_ref (match_dup 2))
5483 (pc)))]
5484 "")
5485
5486 ;; Transform
5487 ;;
5488 ;; cmp.l #-100,er0
5489 ;; beq .L1
5490 ;;
5491 ;; into
5492 ;;
5493 ;; xor.b #99,er0
5494 ;; not.l er0
5495 ;; beq .L1
5496
5497 (define_peephole2
5498 [(set (cc0)
5499 (compare (match_operand:SI 0 "register_operand" "")
5500 (match_operand:SI 1 "const_int_operand" "")))
5501 (set (pc)
5502 (if_then_else (match_operator 3 "eqne_operator"
5503 [(cc0) (const_int 0)])
5504 (label_ref (match_operand 2 "" ""))
5505 (pc)))]
5506 "(TARGET_H8300H || TARGET_H8300S)
5507 && peep2_reg_dead_p (1, operands[0])
5508 && ((INTVAL (operands[1]) | 0x00ff) == -1
5509 || (INTVAL (operands[1]) | 0xff00) == -1)
5510 && INTVAL (operands[1]) != -1
5511 && INTVAL (operands[1]) != -2"
5512 [(set (match_dup 0)
5513 (xor:SI (match_dup 0)
5514 (match_dup 4)))
5515 (set (match_dup 0)
5516 (not:SI (match_dup 0)))
5517 (set (cc0) (compare (match_dup 0)
5518 (const_int 0)))
5519 (set (pc)
5520 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5521 (label_ref (match_dup 2))
5522 (pc)))]
5523 "operands[4] = GEN_INT (INTVAL (operands[1]) ^ -1);")
5524
5525 ;; Transform
5526 ;;
5527 ;; cmp.l #-2147483648,er0
5528 ;; beq .L1
5529 ;;
5530 ;; into
5531 ;;
5532 ;; rotl.l er0
5533 ;; dec.l #1,er0
5534 ;; beq .L1
5535
5536 (define_peephole2
5537 [(set (cc0)
5538 (compare (match_operand:SI 0 "register_operand" "")
5539 (match_operand:SI 1 "const_int_operand" "")))
5540 (set (pc)
5541 (if_then_else (match_operator 3 "eqne_operator"
5542 [(cc0) (const_int 0)])
5543 (label_ref (match_operand 2 "" ""))
5544 (pc)))]
5545 "(TARGET_H8300H || TARGET_H8300S)
5546 && peep2_reg_dead_p (1, operands[0])
5547 && (INTVAL (operands[1]) == -2147483647 - 1
5548 || (TARGET_H8300S && INTVAL (operands[1]) == 1073741824))"
5549 [(set (match_dup 0)
5550 (rotate:SI (match_dup 0)
5551 (match_dup 4)))
5552 (set (match_dup 0)
5553 (unspec:SI [(match_dup 0)
5554 (const_int -1)]
5555 UNSPEC_INCDEC))
5556 (set (cc0) (compare (match_dup 0)
5557 (const_int 0)))
5558 (set (pc)
5559 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5560 (label_ref (match_dup 2))
5561 (pc)))]
5562 "operands[4] = GEN_INT (INTVAL (operands[1]) == -2147483647 - 1 ? 1 : 2);")
5563
5564 ;; Transform
5565 ;;
5566 ;; cmp.l #1,er0
5567 ;; bgt .L1
5568 ;;
5569 ;; into
5570 ;;
5571 ;; mov.l er0,er1
5572 ;; shar.l er1
5573 ;; bgt .L1
5574
5575 ;; We avoid this transformation if we see more than one copy of the
5576 ;; same compare insn immediately before this one.
5577
5578 (define_peephole2
5579 [(match_scratch:SI 4 "r")
5580 (set (cc0)
5581 (compare (match_operand:SI 0 "register_operand" "")
5582 (match_operand:SI 1 "const_int_operand" "")))
5583 (set (pc)
5584 (if_then_else (match_operator 2 "gtle_operator"
5585 [(cc0) (const_int 0)])
5586 (label_ref (match_operand 3 "" ""))
5587 (pc)))]
5588 "(TARGET_H8300H || TARGET_H8300S)
5589 && !peep2_reg_dead_p (1, operands[0])
5590 && (INTVAL (operands[1]) == 1
5591 || (TARGET_H8300S && INTVAL (operands[1]) == 3))
5592 && !same_cmp_preceding_p (insn)"
5593 [(set (match_dup 4)
5594 (match_dup 0))
5595 (parallel [(set (match_dup 4)
5596 (ashiftrt:SI (match_dup 4)
5597 (match_dup 5)))
5598 (clobber (scratch:QI))])
5599 (set (cc0) (compare (match_dup 4)
5600 (const_int 0)))
5601 (set (pc)
5602 (if_then_else (match_dup 2)
5603 (label_ref (match_dup 3))
5604 (pc)))]
5605 "operands[5] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));")
5606
5607 ;; Transform
5608 ;;
5609 ;; cmp.l #1,er0
5610 ;; bhi .L1
5611 ;;
5612 ;; into
5613 ;;
5614 ;; mov.l er0,er1
5615 ;; shar.l er1
5616 ;; bne .L1
5617
5618 ;; We avoid this transformation if we see more than one copy of the
5619 ;; same compare insn immediately before this one.
5620
5621 (define_peephole2
5622 [(match_scratch:SI 4 "r")
5623 (set (cc0)
5624 (compare (match_operand:SI 0 "register_operand" "")
5625 (match_operand:SI 1 "const_int_operand" "")))
5626 (set (pc)
5627 (if_then_else (match_operator 2 "gtuleu_operator"
5628 [(cc0) (const_int 0)])
5629 (label_ref (match_operand 3 "" ""))
5630 (pc)))]
5631 "(TARGET_H8300H || TARGET_H8300S)
5632 && !peep2_reg_dead_p (1, operands[0])
5633 && (INTVAL (operands[1]) == 1
5634 || (TARGET_H8300S && INTVAL (operands[1]) == 3))
5635 && !same_cmp_preceding_p (insn)"
5636 [(set (match_dup 4)
5637 (match_dup 0))
5638 (parallel [(set (match_dup 4)
5639 (ashiftrt:SI (match_dup 4)
5640 (match_dup 5)))
5641 (clobber (scratch:QI))])
5642 (set (cc0) (compare (match_dup 4)
5643 (const_int 0)))
5644 (set (pc)
5645 (if_then_else (match_dup 6)
5646 (label_ref (match_dup 3))
5647 (pc)))]
5648 {
5649 operands[5] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5650 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5651 VOIDmode,
5652 cc0_rtx,
5653 const0_rtx);
5654 })
5655
5656 ;; Transform
5657 ;;
5658 ;; cmp.l #1,er0
5659 ;; bgt .L1
5660 ;;
5661 ;; into
5662 ;;
5663 ;; shar.l er0
5664 ;; bgt .L1
5665
5666 (define_peephole2
5667 [(set (cc0)
5668 (compare (match_operand:SI 0 "register_operand" "")
5669 (match_operand:SI 1 "const_int_operand" "")))
5670 (set (pc)
5671 (if_then_else (match_operator 2 "gtle_operator"
5672 [(cc0) (const_int 0)])
5673 (label_ref (match_operand 3 "" ""))
5674 (pc)))]
5675 "(TARGET_H8300H || TARGET_H8300S)
5676 && peep2_reg_dead_p (1, operands[0])
5677 && (INTVAL (operands[1]) == 1
5678 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5679 [(parallel [(set (match_dup 0)
5680 (ashiftrt:SI (match_dup 0)
5681 (match_dup 4)))
5682 (clobber (scratch:QI))])
5683 (set (cc0) (compare (match_dup 0)
5684 (const_int 0)))
5685 (set (pc)
5686 (if_then_else (match_dup 2)
5687 (label_ref (match_dup 3))
5688 (pc)))]
5689 "operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));")
5690
5691 ;; Transform
5692 ;;
5693 ;; cmp.l #1,er0
5694 ;; bhi .L1
5695 ;;
5696 ;; into
5697 ;;
5698 ;; shar.l er0
5699 ;; bne .L1
5700
5701 (define_peephole2
5702 [(set (cc0)
5703 (compare (match_operand:SI 0 "register_operand" "")
5704 (match_operand:SI 1 "const_int_operand" "")))
5705 (set (pc)
5706 (if_then_else (match_operator 2 "gtuleu_operator"
5707 [(cc0) (const_int 0)])
5708 (label_ref (match_operand 3 "" ""))
5709 (pc)))]
5710 "(TARGET_H8300H || TARGET_H8300S)
5711 && peep2_reg_dead_p (1, operands[0])
5712 && (INTVAL (operands[1]) == 1
5713 || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
5714 [(parallel [(set (match_dup 0)
5715 (ashiftrt:SI (match_dup 0)
5716 (match_dup 4)))
5717 (clobber (scratch:QI))])
5718 (set (cc0) (compare (match_dup 0)
5719 (const_int 0)))
5720 (set (pc)
5721 (if_then_else (match_dup 5)
5722 (label_ref (match_dup 3))
5723 (pc)))]
5724 {
5725 operands[4] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));
5726 operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5727 VOIDmode,
5728 cc0_rtx,
5729 const0_rtx);
5730 })
5731
5732 ;; Transform
5733 ;;
5734 ;; cmp.l #15,er0
5735 ;; bgt .L1
5736 ;;
5737 ;; into
5738 ;;
5739 ;; and #240,r0l
5740 ;; mov.l er0,er0
5741 ;; bgt .L1
5742
5743 (define_peephole2
5744 [(set (cc0)
5745 (compare (match_operand:SI 0 "register_operand" "")
5746 (match_operand:SI 1 "const_int_operand" "")))
5747 (set (pc)
5748 (if_then_else (match_operator 2 "gtle_operator"
5749 [(cc0) (const_int 0)])
5750 (label_ref (match_operand 3 "" ""))
5751 (pc)))]
5752 "(TARGET_H8300H || TARGET_H8300S)
5753 && peep2_reg_dead_p (1, operands[0])
5754 && ((TARGET_H8300H && INTVAL (operands[1]) == 3)
5755 || INTVAL (operands[1]) == 7
5756 || INTVAL (operands[1]) == 15
5757 || INTVAL (operands[1]) == 31
5758 || INTVAL (operands[1]) == 63
5759 || INTVAL (operands[1]) == 127
5760 || INTVAL (operands[1]) == 255)"
5761 [(set (match_dup 0)
5762 (and:SI (match_dup 0)
5763 (match_dup 4)))
5764 (set (cc0) (compare (match_dup 0)
5765 (const_int 0)))
5766 (set (pc)
5767 (if_then_else (match_dup 2)
5768 (label_ref (match_dup 3))
5769 (pc)))]
5770 "operands[4] = GEN_INT (~INTVAL (operands[1]));")
5771
5772 ;; Transform
5773 ;;
5774 ;; cmp.l #15,er0
5775 ;; bhi .L1
5776 ;;
5777 ;; into
5778 ;;
5779 ;; and #240,r0l
5780 ;; mov.l er0,er0
5781 ;; bne .L1
5782
5783 (define_peephole2
5784 [(set (cc0)
5785 (compare (match_operand:SI 0 "register_operand" "")
5786 (match_operand:SI 1 "const_int_operand" "")))
5787 (set (pc)
5788 (if_then_else (match_operator 2 "gtuleu_operator"
5789 [(cc0) (const_int 0)])
5790 (label_ref (match_operand 3 "" ""))
5791 (pc)))]
5792 "(TARGET_H8300H || TARGET_H8300S)
5793 && peep2_reg_dead_p (1, operands[0])
5794 && ((TARGET_H8300H && INTVAL (operands[1]) == 3)
5795 || INTVAL (operands[1]) == 7
5796 || INTVAL (operands[1]) == 15
5797 || INTVAL (operands[1]) == 31
5798 || INTVAL (operands[1]) == 63
5799 || INTVAL (operands[1]) == 127
5800 || INTVAL (operands[1]) == 255)"
5801 [(set (match_dup 0)
5802 (and:SI (match_dup 0)
5803 (match_dup 4)))
5804 (set (cc0) (compare (match_dup 0)
5805 (const_int 0)))
5806 (set (pc)
5807 (if_then_else (match_dup 5)
5808 (label_ref (match_dup 3))
5809 (pc)))]
5810 {
5811 operands[4] = GEN_INT (~INTVAL (operands[1]));
5812 operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[2]) == GTU ? NE : EQ,
5813 VOIDmode,
5814 cc0_rtx,
5815 const0_rtx);
5816 })
5817
5818 ;; Transform
5819 ;;
5820 ;; cmp.l #65535,er0
5821 ;; bgt .L1
5822 ;;
5823 ;; into
5824 ;;
5825 ;; mov.l e0,e0
5826 ;; bgt .L1
5827
5828 (define_peephole2
5829 [(set (cc0)
5830 (compare (match_operand:SI 0 "register_operand" "")
5831 (const_int 65535)))
5832 (set (pc)
5833 (if_then_else (match_operator 1 "gtle_operator"
5834 [(cc0) (const_int 0)])
5835 (label_ref (match_operand 2 "" ""))
5836 (pc)))]
5837 "TARGET_H8300H || TARGET_H8300S"
5838 [(set (cc0) (compare (and:SI (match_dup 0)
5839 (const_int -65536))
5840 (const_int 0)))
5841 (set (pc)
5842 (if_then_else (match_dup 1)
5843 (label_ref (match_dup 2))
5844 (pc)))]
5845 "")
5846
5847 ;; Transform
5848 ;;
5849 ;; cmp.l #65535,er0
5850 ;; bhi .L1
5851 ;;
5852 ;; into
5853 ;;
5854 ;; mov.l e0,e0
5855 ;; bne .L1
5856
5857 (define_peephole2
5858 [(set (cc0)
5859 (compare (match_operand:SI 0 "register_operand" "")
5860 (const_int 65535)))
5861 (set (pc)
5862 (if_then_else (match_operator 1 "gtuleu_operator"
5863 [(cc0) (const_int 0)])
5864 (label_ref (match_operand 2 "" ""))
5865 (pc)))]
5866 "TARGET_H8300H || TARGET_H8300S"
5867 [(set (cc0) (compare (and:SI (match_dup 0)
5868 (const_int -65536))
5869 (const_int 0)))
5870 (set (pc)
5871 (if_then_else (match_dup 3)
5872 (label_ref (match_dup 2))
5873 (pc)))]
5874 {
5875 operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[1]) == GTU ? NE : EQ,
5876 VOIDmode,
5877 cc0_rtx,
5878 const0_rtx);
5879 })
5880
5881 ;; Transform
5882 ;;
5883 ;; cmp.l #1,er0
5884 ;; beq .L1
5885 ;;
5886 ;; into
5887 ;;
5888 ;; mov.l er0,er1
5889 ;; dec.l #1,er1
5890 ;; beq .L1
5891
5892 ;; We avoid this transformation if we see more than one copy of the
5893 ;; same compare insn.
5894
5895 (define_peephole2
5896 [(match_scratch:SI 4 "r")
5897 (set (cc0)
5898 (compare (match_operand:SI 0 "register_operand" "")
5899 (match_operand:SI 1 "incdec_operand" "")))
5900 (set (pc)
5901 (if_then_else (match_operator 3 "eqne_operator"
5902 [(cc0) (const_int 0)])
5903 (label_ref (match_operand 2 "" ""))
5904 (pc)))]
5905 "(TARGET_H8300H || TARGET_H8300S)
5906 && INTVAL (operands[1]) != 0
5907 && !peep2_reg_dead_p (1, operands[0])
5908 && !same_cmp_following_p (insn)"
5909 [(set (match_dup 4)
5910 (match_dup 0))
5911 (set (match_dup 4)
5912 (unspec:SI [(match_dup 4)
5913 (match_dup 5)]
5914 UNSPEC_INCDEC))
5915 (set (cc0) (compare (match_dup 4)
5916 (const_int 0)))
5917 (set (pc)
5918 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5919 (label_ref (match_dup 2))
5920 (pc)))]
5921 "operands[5] = GEN_INT (- INTVAL (operands[1]));")
5922
5923 ;; Narrow the mode of testing if possible.
5924
5925 (define_peephole2
5926 [(set (match_operand:HI 0 "register_operand" "")
5927 (and:HI (match_dup 0)
5928 (match_operand:HI 1 "const_int_qi_operand" "")))
5929 (set (cc0) (compare (match_dup 0)
5930 (const_int 0)))
5931 (set (pc)
5932 (if_then_else (match_operator 3 "eqne_operator"
5933 [(cc0) (const_int 0)])
5934 (label_ref (match_operand 2 "" ""))
5935 (pc)))]
5936 "peep2_reg_dead_p (2, operands[0])"
5937 [(set (match_dup 4)
5938 (and:QI (match_dup 4)
5939 (match_dup 5)))
5940 (set (cc0) (compare (match_dup 4)
5941 (const_int 0)))
5942 (set (pc)
5943 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5944 (label_ref (match_dup 2))
5945 (pc)))]
5946 "operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
5947 operands[5] = gen_int_mode (INTVAL (operands[1]), QImode);")
5948
5949 (define_peephole2
5950 [(set (match_operand:SI 0 "register_operand" "")
5951 (and:SI (match_dup 0)
5952 (match_operand:SI 1 "const_int_qi_operand" "")))
5953 (set (cc0) (compare (match_dup 0)
5954 (const_int 0)))
5955 (set (pc)
5956 (if_then_else (match_operator 3 "eqne_operator"
5957 [(cc0) (const_int 0)])
5958 (label_ref (match_operand 2 "" ""))
5959 (pc)))]
5960 "peep2_reg_dead_p (2, operands[0])"
5961 [(set (match_dup 4)
5962 (and:QI (match_dup 4)
5963 (match_dup 5)))
5964 (set (cc0) (compare (match_dup 4)
5965 (const_int 0)))
5966 (set (pc)
5967 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5968 (label_ref (match_dup 2))
5969 (pc)))]
5970 "operands[4] = gen_rtx_REG (QImode, REGNO (operands[0]));
5971 operands[5] = gen_int_mode (INTVAL (operands[1]), QImode);")
5972
5973 (define_peephole2
5974 [(set (match_operand:SI 0 "register_operand" "")
5975 (and:SI (match_dup 0)
5976 (match_operand:SI 1 "const_int_hi_operand" "")))
5977 (set (cc0) (compare (match_dup 0)
5978 (const_int 0)))
5979 (set (pc)
5980 (if_then_else (match_operator 3 "eqne_operator"
5981 [(cc0) (const_int 0)])
5982 (label_ref (match_operand 2 "" ""))
5983 (pc)))]
5984 "peep2_reg_dead_p (2, operands[0])"
5985 [(set (match_dup 4)
5986 (and:HI (match_dup 4)
5987 (match_dup 5)))
5988 (set (cc0) (compare (match_dup 4)
5989 (const_int 0)))
5990 (set (pc)
5991 (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
5992 (label_ref (match_dup 2))
5993 (pc)))]
5994 "operands[4] = gen_rtx_REG (HImode, REGNO (operands[0]));
5995 operands[5] = gen_int_mode (INTVAL (operands[1]), HImode);")
5996
5997 (define_peephole2
5998 [(set (match_operand:SI 0 "register_operand" "")
5999 (and:SI (match_dup 0)
6000 (match_operand:SI 1 "const_int_qi_operand" "")))
6001 (set (match_dup 0)
6002 (xor:SI (match_dup 0)
6003 (match_operand:SI 2 "const_int_qi_operand" "")))
6004 (set (cc0) (compare (match_dup 0)
6005 (const_int 0)))
6006 (set (pc)
6007 (if_then_else (match_operator 4 "eqne_operator"
6008 [(cc0) (const_int 0)])
6009 (label_ref (match_operand 3 "" ""))
6010 (pc)))]
6011 "peep2_reg_dead_p (3, operands[0])
6012 && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0"
6013 [(set (match_dup 5)
6014 (and:QI (match_dup 5)
6015 (match_dup 6)))
6016 (set (match_dup 5)
6017 (xor:QI (match_dup 5)
6018 (match_dup 7)))
6019 (set (cc0) (compare (match_dup 5)
6020 (const_int 0)))
6021 (set (pc)
6022 (if_then_else (match_op_dup 4 [(cc0) (const_int 0)])
6023 (label_ref (match_dup 3))
6024 (pc)))]
6025 "operands[5] = gen_rtx_REG (QImode, REGNO (operands[0]));
6026 operands[6] = gen_int_mode (INTVAL (operands[1]), QImode);
6027 operands[7] = gen_int_mode (INTVAL (operands[2]), QImode);")
6028
6029 ;; These triggers right at the end of allocation of locals in the
6030 ;; prologue (and possibly at other places).
6031
6032 ;; stack adjustment of -4, generate one push
6033 ;;
6034 ;; before : 6 bytes, 10 clocks
6035 ;; after : 4 bytes, 10 clocks
6036
6037 (define_peephole2
6038 [(set (reg:SI SP_REG)
6039 (plus:SI (reg:SI SP_REG)
6040 (const_int -4)))
6041 (set (mem:SI (reg:SI SP_REG))
6042 (match_operand:SI 0 "register_operand" ""))]
6043 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE
6044 && REGNO (operands[0]) != SP_REG"
6045 [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
6046 (match_dup 0))]
6047 "")
6048
6049 ;; stack adjustment of -12, generate one push
6050 ;;
6051 ;; before : 10 bytes, 14 clocks
6052 ;; after : 8 bytes, 14 clocks
6053
6054 (define_peephole2
6055 [(set (reg:SI SP_REG)
6056 (plus:SI (reg:SI SP_REG)
6057 (const_int -12)))
6058 (set (mem:SI (reg:SI SP_REG))
6059 (match_operand:SI 0 "register_operand" ""))]
6060 "(TARGET_H8300H || TARGET_H8300S) && !TARGET_NORMAL_MODE
6061 && REGNO (operands[0]) != SP_REG"
6062 [(set (reg:SI SP_REG)
6063 (plus:SI (reg:SI SP_REG)
6064 (const_int -4)))
6065 (set (reg:SI SP_REG)
6066 (plus:SI (reg:SI SP_REG)
6067 (const_int -4)))
6068 (set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
6069 (match_dup 0))]
6070 "")
6071
6072 ;; Transform
6073 ;;
6074 ;; mov dst,reg
6075 ;; op src,reg
6076 ;; mov reg,dst
6077 ;;
6078 ;; into
6079 ;;
6080 ;; op src,dst
6081 ;;
6082 ;; if "reg" dies at the end of the sequence.
6083 (define_peephole2
6084 [(set (match_operand 0 "register_operand" "")
6085 (match_operand 1 "memory_operand" ""))
6086 (set (match_dup 0)
6087 (match_operator 2 "h8sx_binary_memory_operator"
6088 [(match_dup 0)
6089 (match_operand 3 "h8300_src_operand" "")]))
6090 (set (match_operand 4 "memory_operand" "")
6091 (match_dup 0))]
6092 "0 /* Disable because it breaks compiling fp-bit.c. */
6093 && TARGET_H8300SX
6094 && peep2_reg_dead_p (3, operands[0])
6095 && !reg_overlap_mentioned_p (operands[0], operands[3])
6096 && !reg_overlap_mentioned_p (operands[0], operands[4])
6097 && h8sx_mergeable_memrefs_p (operands[4], operands[1])"
6098 [(set (match_dup 4)
6099 (match_dup 5))]
6100 {
6101 operands[5] = shallow_copy_rtx (operands[2]);
6102 XEXP (operands[5], 0) = operands[1];
6103 })
6104
6105 ;; Transform
6106 ;;
6107 ;; mov src,reg
6108 ;; op reg,dst
6109 ;;
6110 ;; into
6111 ;;
6112 ;; op src,dst
6113 ;;
6114 ;; if "reg" dies in the second insn.
6115 (define_peephole2
6116 [(set (match_operand 0 "register_operand" "")
6117 (match_operand 1 "h8300_src_operand" ""))
6118 (set (match_operand 2 "h8300_dst_operand" "")
6119 (match_operator 3 "h8sx_binary_memory_operator"
6120 [(match_operand 4 "h8300_dst_operand" "")
6121 (match_dup 0)]))]
6122 "0 /* Disable because it breaks compiling fp-bit.c. */
6123 && TARGET_H8300SX
6124 && peep2_reg_dead_p (2, operands[0])
6125 && !reg_overlap_mentioned_p (operands[0], operands[4])"
6126 [(set (match_dup 2)
6127 (match_dup 5))]
6128 {
6129 operands[5] = shallow_copy_rtx (operands[3]);
6130 XEXP (operands[5], 1) = operands[1];
6131 })
6132
6133 ;; Transform
6134 ;;
6135 ;; mov dst,reg
6136 ;; op reg
6137 ;; mov reg,dst
6138 ;;
6139 ;; into
6140 ;;
6141 ;; op dst
6142 ;;
6143 ;; if "reg" dies at the end of the sequence.
6144 (define_peephole2
6145 [(set (match_operand 0 "register_operand" "")
6146 (match_operand 1 "memory_operand" ""))
6147 (set (match_dup 0)
6148 (match_operator 2 "h8sx_unary_memory_operator"
6149 [(match_dup 0)]))
6150 (set (match_operand 3 "memory_operand" "")
6151 (match_dup 0))]
6152 "TARGET_H8300SX
6153 && peep2_reg_dead_p (3, operands[0])
6154 && !reg_overlap_mentioned_p (operands[0], operands[3])
6155 && h8sx_mergeable_memrefs_p (operands[3], operands[1])"
6156 [(set (match_dup 3)
6157 (match_dup 4))]
6158 {
6159 operands[4] = shallow_copy_rtx (operands[2]);
6160 XEXP (operands[4], 0) = operands[1];
6161 })
6162
6163 ;; Transform
6164 ;;
6165 ;; mov src1,reg
6166 ;; cmp reg,src2
6167 ;;
6168 ;; into
6169 ;;
6170 ;; cmp src1,src2
6171 ;;
6172 ;; if "reg" dies in the comparison.
6173 (define_peephole2
6174 [(set (match_operand 0 "register_operand" "")
6175 (match_operand 1 "h8300_dst_operand" ""))
6176 (set (cc0)
6177 (compare (match_dup 0)
6178 (match_operand 2 "h8300_src_operand" "")))]
6179 "TARGET_H8300SX
6180 && peep2_reg_dead_p (2, operands[0])
6181 && !reg_overlap_mentioned_p (operands[0], operands[2])
6182 && operands[2] != const0_rtx"
6183 [(set (cc0)
6184 (compare (match_dup 1)
6185 (match_dup 2)))])
6186
6187 ;; Likewise for the second operand.
6188 (define_peephole2
6189 [(set (match_operand 0 "register_operand" "")
6190 (match_operand 1 "h8300_src_operand" ""))
6191 (set (cc0)
6192 (compare (match_operand 2 "h8300_dst_operand" "")
6193 (match_dup 0)))]
6194 "TARGET_H8300SX
6195 && peep2_reg_dead_p (2, operands[0])
6196 && !reg_overlap_mentioned_p (operands[0], operands[2])"
6197 [(set (cc0)
6198 (compare (match_dup 2)
6199 (match_dup 1)))])
6200
6201 ;; Combine two moves.
6202 (define_peephole2
6203 [(set (match_operand 0 "register_operand" "")
6204 (match_operand 1 "h8300_src_operand" ""))
6205 (set (match_operand 2 "h8300_dst_operand" "")
6206 (match_dup 0))]
6207 "TARGET_H8300SX
6208 && peep2_reg_dead_p (2, operands[0])
6209 && !reg_overlap_mentioned_p (operands[0], operands[2])"
6210 [(set (match_dup 2)
6211 (match_dup 1))])
6212
6213