1 ;; -*- Mode: Scheme -*-
2 ;; Machine description for GNU compiler,
3 ;; for ATMEL AVR micro controllers.
4 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005
5 ;; Free Software Foundation, Inc.
6 ;; Contributed by Denis Chertykov (denisc@overta.ru)
8 ;; This file is part of GCC.
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
25 ;; Special characters after '%':
26 ;; A No effect (add 0).
27 ;; B Add 1 to REG number, MEM address or CONST_INT.
30 ;; j Branch condition.
31 ;; k Reverse branch condition.
32 ;; o Displacement for (mem (plus (reg) (const_int))) operands.
33 ;; p POST_INC or PRE_DEC address as a pointer (X, Y, Z)
34 ;; r POST_INC or PRE_DEC address as a register (r26, r28, r30)
35 ;; ~ Output 'r' if not AVR_MEGA.
38 ;; 0 Length of a string, see "strlenhi".
39 ;; 1 Read from a word address in program memory, see "casesi".
41 ;; Condition code settings.
42 (define_attr "cc" "none,set_czn,set_zn,set_n,compare,clobber"
43 (const_string "none"))
45 (define_attr "type" "branch,branch1,arith,xcall"
46 (const_string "arith"))
48 (define_attr "mcu_enhanced" "yes,no"
49 (const (if_then_else (symbol_ref "AVR_ENHANCED")
51 (const_string "no"))))
53 (define_attr "mcu_mega" "yes,no"
54 (const (if_then_else (symbol_ref "AVR_MEGA")
56 (const_string "no"))))
59 ;; The size of instructions in bytes.
60 ;; XXX may depend from "cc"
62 (define_attr "length" ""
63 (cond [(eq_attr "type" "branch")
64 (if_then_else (and (ge (minus (pc) (match_dup 0))
66 (le (minus (pc) (match_dup 0))
69 (if_then_else (and (ge (minus (pc) (match_dup 0))
71 (le (minus (pc) (match_dup 0))
75 (eq_attr "type" "branch1")
76 (if_then_else (and (ge (minus (pc) (match_dup 0))
78 (le (minus (pc) (match_dup 0))
81 (if_then_else (and (ge (minus (pc) (match_dup 0))
83 (le (minus (pc) (match_dup 0))
87 (eq_attr "type" "xcall")
88 (if_then_else (eq_attr "mcu_mega" "no")
94 [(set (reg:HI 32) (plus:HI (reg:HI 32) (const_int 1)))]
97 [(set_attr "length" "1")])
100 [(set (reg:HI 32) (plus:HI (reg:HI 32) (const_int 2)))]
104 [(set_attr "length" "2")])
107 [(set (reg:HI 32) (plus:HI (reg:HI 32) (const_int 3)))]
112 [(set_attr "length" "3")])
115 [(set (reg:HI 32) (plus:HI (reg:HI 32) (const_int 4)))]
121 [(set_attr "length" "4")])
124 [(set (reg:HI 32) (plus:HI (reg:HI 32) (const_int 5)))]
131 [(set_attr "length" "5")])
133 (define_insn "*pushqi"
134 [(set (mem:QI (post_dec (reg:HI 32)))
135 (match_operand:QI 0 "nonmemory_operand" "r,L"))]
136 "(operands[0] == const0_rtx || register_operand (operands[0], QImode))"
140 [(set_attr "length" "1,1")])
143 (define_insn "*pushhi"
144 [(set (mem:HI (post_dec (reg:HI 32)))
145 (match_operand:HI 0 "nonmemory_operand" "r,L"))]
146 "(operands[0] == const0_rtx || register_operand (operands[0], HImode))"
149 push __zero_reg__\;push __zero_reg__"
150 [(set_attr "length" "2,2")])
152 (define_insn "*pushsi"
153 [(set (mem:SI (post_dec (reg:HI 32)))
154 (match_operand:SI 0 "nonmemory_operand" "r,L"))]
155 "(operands[0] == const0_rtx || register_operand (operands[0], SImode))"
157 push %D0\;push %C0\;push %B0\;push %A0
158 push __zero_reg__\;push __zero_reg__\;push __zero_reg__\;push __zero_reg__"
159 [(set_attr "length" "4,4")])
161 (define_insn "*pushsf"
162 [(set (mem:SF (post_dec (reg:HI 32)))
163 (match_operand:SF 0 "register_operand" "r"))]
169 [(set_attr "length" "4")])
171 ;;========================================================================
173 ;; The last alternative (any immediate constant to any register) is
174 ;; very expensive. It should be optimized by peephole2 if a scratch
175 ;; register is available, but then that register could just as well be
176 ;; allocated for the variable we are loading. But, most of NO_LD_REGS
177 ;; are call-saved registers, and most of LD_REGS are call-used registers,
178 ;; so this may still be a win for registers live across function calls.
180 (define_expand "movqi"
181 [(set (match_operand:QI 0 "nonimmediate_operand" "")
182 (match_operand:QI 1 "general_operand" ""))]
184 "/* One of the ops has to be in a register. */
185 if (!register_operand(operand0, QImode)
186 && ! (register_operand(operand1, QImode) || const0_rtx == operand1))
187 operands[1] = copy_to_mode_reg(QImode, operand1);
190 (define_insn "*movqi"
191 [(set (match_operand:QI 0 "nonimmediate_operand" "=r,d,Qm,r,q,r,*r")
192 (match_operand:QI 1 "general_operand" "r,i,rL,Qm,r,q,i"))]
193 "(register_operand (operands[0],QImode)
194 || register_operand (operands[1], QImode) || const0_rtx == operands[1])"
195 "* return output_movqi (insn, operands, NULL);"
196 [(set_attr "length" "1,1,5,5,1,1,4")
197 (set_attr "cc" "none,none,clobber,clobber,none,none,clobber")])
199 ;; This is used in peephole2 to optimize loading immediate constants
200 ;; if a scratch register from LD_REGS happens to be available.
202 (define_insn "*reload_inqi"
203 [(set (match_operand:QI 0 "register_operand" "=l")
204 (match_operand:QI 1 "immediate_operand" "i"))
205 (clobber (match_operand:QI 2 "register_operand" "=&d"))]
209 [(set_attr "length" "2")
210 (set_attr "cc" "none")])
213 [(match_scratch:QI 2 "d")
214 (set (match_operand:QI 0 "register_operand" "")
215 (match_operand:QI 1 "immediate_operand" ""))]
216 "(operands[1] != const0_rtx
217 && test_hard_reg_class (NO_LD_REGS, operands[0]))"
218 [(parallel [(set (match_dup 0) (match_dup 1))
219 (clobber (match_dup 2))])]
220 "if (!avr_peep2_scratch_safe (operands[2]))
223 ;;============================================================================
224 ;; move word (16 bit)
226 (define_expand "movhi"
227 [(set (match_operand:HI 0 "nonimmediate_operand" "")
228 (match_operand:HI 1 "general_operand" ""))]
232 /* One of the ops has to be in a register. */
233 if (!register_operand(operand0, HImode)
234 && !(register_operand(operand1, HImode) || const0_rtx == operands[1]))
236 operands[1] = copy_to_mode_reg(HImode, operand1);
242 [(match_scratch:QI 2 "d")
243 (set (match_operand:HI 0 "register_operand" "")
244 (match_operand:HI 1 "immediate_operand" ""))]
245 "(operands[1] != const0_rtx
246 && test_hard_reg_class (NO_LD_REGS, operands[0]))"
247 [(parallel [(set (match_dup 0) (match_dup 1))
248 (clobber (match_dup 2))])]
249 "if (!avr_peep2_scratch_safe (operands[2]))
252 ;; '*' because it is not used in rtl generation, only in above peephole
253 (define_insn "*reload_inhi"
254 [(set (match_operand:HI 0 "register_operand" "=r")
255 (match_operand:HI 1 "immediate_operand" "i"))
256 (clobber (match_operand:QI 2 "register_operand" "=&d"))]
258 "* return output_reload_inhi (insn, operands, NULL);"
259 [(set_attr "length" "4")
260 (set_attr "cc" "none")])
262 (define_insn "*movhi"
263 [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,d,*r,q,r")
264 (match_operand:HI 1 "general_operand" "r,m,rL,i,i,r,q"))]
265 "(register_operand (operands[0],HImode)
266 || register_operand (operands[1],HImode) || const0_rtx == operands[1])"
267 "* return output_movhi (insn, operands, NULL);"
268 [(set_attr "length" "2,6,7,2,6,5,2")
269 (set_attr "cc" "none,clobber,clobber,none,clobber,none,none")])
271 ;;==========================================================================
272 ;; move double word (32 bit)
274 (define_expand "movsi"
275 [(set (match_operand:SI 0 "nonimmediate_operand" "")
276 (match_operand:SI 1 "general_operand" ""))]
280 /* One of the ops has to be in a register. */
281 if (!register_operand (operand0, SImode)
282 && !(register_operand (operand1, SImode) || const0_rtx == operand1))
284 operands[1] = copy_to_mode_reg (SImode, operand1);
291 [(match_scratch:QI 2 "d")
292 (set (match_operand:SI 0 "register_operand" "")
293 (match_operand:SI 1 "immediate_operand" ""))]
294 "(operands[1] != const0_rtx
295 && test_hard_reg_class (NO_LD_REGS, operands[0]))"
296 [(parallel [(set (match_dup 0) (match_dup 1))
297 (clobber (match_dup 2))])]
298 "if (!avr_peep2_scratch_safe (operands[2]))
301 ;; '*' because it is not used in rtl generation.
302 (define_insn "*reload_insi"
303 [(set (match_operand:SI 0 "register_operand" "=r")
304 (match_operand:SI 1 "immediate_operand" "i"))
305 (clobber (match_operand:QI 2 "register_operand" "=&d"))]
307 "* return output_reload_insisf (insn, operands, NULL);"
308 [(set_attr "length" "8")
309 (set_attr "cc" "none")])
312 (define_insn "*movsi"
313 [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,Qm,!d,r")
314 (match_operand:SI 1 "general_operand" "r,L,Qm,rL,i,i"))]
315 "(register_operand (operands[0],SImode)
316 || register_operand (operands[1],SImode) || const0_rtx == operands[1])"
317 "* return output_movsisf (insn, operands, NULL);"
318 [(set_attr "length" "4,4,8,9,4,10")
319 (set_attr "cc" "none,set_zn,clobber,clobber,none,clobber")])
321 ;; fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
322 ;; move floating point numbers (32 bit)
324 (define_expand "movsf"
325 [(set (match_operand:SF 0 "nonimmediate_operand" "")
326 (match_operand:SF 1 "general_operand" ""))]
330 /* One of the ops has to be in a register. */
331 if (!register_operand (operand1, SFmode)
332 && !register_operand (operand0, SFmode))
334 operands[1] = copy_to_mode_reg (SFmode, operand1);
338 (define_insn "*movsf"
339 [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,r,Qm,!d,r")
340 (match_operand:SF 1 "general_operand" "r,G,Qm,r,F,F"))]
341 "register_operand (operands[0], SFmode)
342 || register_operand (operands[1], SFmode)"
343 "* return output_movsisf (insn, operands, NULL);"
344 [(set_attr "length" "4,4,8,9,4,10")
345 (set_attr "cc" "none,set_zn,clobber,clobber,none,clobber")])
347 ;;=========================================================================
348 ;; move string (like memcpy)
349 ;; implement as RTL loop
351 (define_expand "movmemhi"
352 [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
353 (match_operand:BLK 1 "memory_operand" ""))
354 (use (match_operand:HI 2 "const_int_operand" ""))
355 (use (match_operand:HI 3 "const_int_operand" ""))])]
360 enum machine_mode mode;
361 rtx label = gen_label_rtx ();
365 /* Copy pointers into new psuedos - they will be changed. */
366 rtx addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
367 rtx addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
369 /* Create rtx for tmp register - we use this as scratch. */
370 rtx tmp_reg_rtx = gen_rtx_REG (QImode, TMP_REGNO);
372 if (GET_CODE (operands[2]) != CONST_INT)
375 count = INTVAL (operands[2]);
379 /* Work out branch probability for latter use. */
380 prob = REG_BR_PROB_BASE - REG_BR_PROB_BASE / count;
382 /* See if constant fit 8 bits. */
383 mode = (count < 0x100) ? QImode : HImode;
384 /* Create loop counter register. */
385 loop_reg = copy_to_mode_reg (mode, gen_int_mode (count, mode));
387 /* Now create RTL code for move loop. */
388 /* Label at top of loop. */
391 /* Move one byte into scratch and inc pointer. */
392 emit_move_insn (tmp_reg_rtx, gen_rtx_MEM (QImode, addr1));
393 emit_move_insn (addr1, gen_rtx_PLUS (Pmode, addr1, const1_rtx));
395 /* Move to mem and inc pointer. */
396 emit_move_insn (gen_rtx_MEM (QImode, addr0), tmp_reg_rtx);
397 emit_move_insn (addr0, gen_rtx_PLUS (Pmode, addr0, const1_rtx));
399 /* Decrement count. */
400 emit_move_insn (loop_reg, gen_rtx_PLUS (mode, loop_reg, constm1_rtx));
402 /* Compare with zero and jump if not equal. */
403 emit_cmp_and_jump_insns (loop_reg, const0_rtx, NE, NULL_RTX, mode, 1,
405 /* Set jump probability based on loop count. */
406 jump = get_last_insn ();
407 REG_NOTES (jump) = gen_rtx_EXPR_LIST (REG_BR_PROB,
413 ;; =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2
414 ;; memset (%0, %2, %1)
416 (define_expand "setmemhi"
417 [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
418 (match_operand 2 "const_int_operand" ""))
419 (use (match_operand:HI 1 "const_int_operand" ""))
420 (use (match_operand:HI 3 "const_int_operand" "n"))
421 (clobber (match_scratch:HI 4 ""))
422 (clobber (match_dup 5))])]
427 enum machine_mode mode;
429 /* If value to set is not zero, use the library routine. */
430 if (operands[2] != const0_rtx)
433 if (GET_CODE (operands[1]) != CONST_INT)
436 cnt8 = byte_immediate_operand (operands[1], GET_MODE (operands[1]));
437 mode = cnt8 ? QImode : HImode;
438 operands[5] = gen_rtx_SCRATCH (mode);
439 operands[1] = copy_to_mode_reg (mode,
440 gen_int_mode (INTVAL (operands[1]), mode));
441 addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
442 operands[0] = gen_rtx_MEM (BLKmode, addr0);
445 (define_insn "*clrmemqi"
446 [(set (mem:BLK (match_operand:HI 0 "register_operand" "e"))
448 (use (match_operand:QI 1 "register_operand" "r"))
449 (use (match_operand:QI 2 "const_int_operand" "n"))
450 (clobber (match_scratch:HI 3 "=0"))
451 (clobber (match_scratch:QI 4 "=1"))]
453 "st %a0+,__zero_reg__
456 [(set_attr "length" "3")
457 (set_attr "cc" "clobber")])
459 (define_insn "*clrmemhi"
460 [(set (mem:BLK (match_operand:HI 0 "register_operand" "e,e"))
462 (use (match_operand:HI 1 "register_operand" "!w,d"))
463 (use (match_operand:HI 2 "const_int_operand" "n,n"))
464 (clobber (match_scratch:HI 3 "=0,0"))
465 (clobber (match_scratch:HI 4 "=1,1"))]
468 if (which_alternative==0)
469 return (AS2 (st,%a0+,__zero_reg__) CR_TAB
470 AS2 (sbiw,%A1,1) CR_TAB
473 return (AS2 (st,%a0+,__zero_reg__) CR_TAB
474 AS2 (subi,%A1,1) CR_TAB
475 AS2 (sbci,%B1,0) CR_TAB
478 [(set_attr "length" "3,4")
479 (set_attr "cc" "clobber,clobber")])
481 (define_expand "strlenhi"
483 (unspec:HI [(match_operand:BLK 1 "memory_operand" "")
484 (match_operand:QI 2 "const_int_operand" "")
485 (match_operand:HI 3 "immediate_operand" "")] 0))
486 (set (match_dup 4) (plus:HI (match_dup 4)
488 (set (match_operand:HI 0 "register_operand" "")
489 (minus:HI (match_dup 4)
494 if (! (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 0))
496 addr = copy_to_mode_reg (Pmode, XEXP (operands[1],0));
497 operands[1] = gen_rtx_MEM (BLKmode, addr);
499 operands[4] = gen_reg_rtx (HImode);
502 (define_insn "*strlenhi"
503 [(set (match_operand:HI 0 "register_operand" "=e")
504 (unspec:HI [(mem:BLK (match_operand:HI 1 "register_operand" "%0"))
506 (match_operand:HI 2 "immediate_operand" "i")] 0))]
511 [(set_attr "length" "3")
512 (set_attr "cc" "clobber")])
514 ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
517 (define_insn "addqi3"
518 [(set (match_operand:QI 0 "register_operand" "=r,d,r,r")
519 (plus:QI (match_operand:QI 1 "register_operand" "%0,0,0,0")
520 (match_operand:QI 2 "nonmemory_operand" "r,i,P,N")))]
527 [(set_attr "length" "1,1,1,1")
528 (set_attr "cc" "set_czn,set_czn,set_zn,set_zn")])
531 (define_expand "addhi3"
532 [(set (match_operand:HI 0 "register_operand" "")
533 (plus:HI (match_operand:HI 1 "register_operand" "")
534 (match_operand:HI 2 "nonmemory_operand" "")))]
538 if (GET_CODE (operands[2]) == CONST_INT)
540 short tmp = INTVAL (operands[2]);
541 operands[2] = GEN_INT(tmp);
546 (define_insn "*addhi3_zero_extend"
547 [(set (match_operand:HI 0 "register_operand" "=r")
548 (plus:HI (zero_extend:HI
549 (match_operand:QI 1 "register_operand" "r"))
550 (match_operand:HI 2 "register_operand" "0")))]
553 adc %B0,__zero_reg__"
554 [(set_attr "length" "2")
555 (set_attr "cc" "set_n")])
557 (define_insn "*addhi3_zero_extend1"
558 [(set (match_operand:HI 0 "register_operand" "=r")
559 (plus:HI (match_operand:HI 1 "register_operand" "%0")
561 (match_operand:QI 2 "register_operand" "r"))))]
564 adc %B0,__zero_reg__"
565 [(set_attr "length" "2")
566 (set_attr "cc" "set_n")])
568 (define_insn "*addhi3_zero_extend2"
569 [(set (match_operand:HI 0 "register_operand" "=r")
571 (zero_extend:HI (match_operand:QI 1 "register_operand" "%0"))
572 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
576 adc %B0,__zero_reg__"
577 [(set_attr "length" "3")
578 (set_attr "cc" "set_n")])
580 (define_insn "*addhi3"
581 [(set (match_operand:HI 0 "register_operand" "=r,!w,!w,d,r,r")
583 (match_operand:HI 1 "register_operand" "%0,0,0,0,0,0")
584 (match_operand:HI 2 "nonmemory_operand" "r,I,J,i,P,N")))]
587 add %A0,%A2\;adc %B0,%B2
590 subi %A0,lo8(-(%2))\;sbci %B0,hi8(-(%2))
591 sec\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__
592 sec\;sbc %A0,__zero_reg__\;sbc %B0,__zero_reg__"
593 [(set_attr "length" "2,1,1,2,3,3")
594 (set_attr "cc" "set_n,set_czn,set_czn,set_czn,set_n,set_n")])
596 (define_insn "addsi3"
597 [(set (match_operand:SI 0 "register_operand" "=r,!w,!w,d,r,r")
599 (match_operand:SI 1 "register_operand" "%0,0,0,0,0,0")
600 (match_operand:SI 2 "nonmemory_operand" "r,I,J,i,P,N")))]
603 add %A0,%A2\;adc %B0,%B2\;adc %C0,%C2\;adc %D0,%D2
604 adiw %0,%2\;adc %C0,__zero_reg__\;adc %D0,__zero_reg__
605 sbiw %0,%n2\;sbc %C0,__zero_reg__\;sbc %D0,__zero_reg__
606 subi %0,lo8(-(%2))\;sbci %B0,hi8(-(%2))\;sbci %C0,hlo8(-(%2))\;sbci %D0,hhi8(-(%2))
607 sec\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__\;adc %C0,__zero_reg__\;adc %D0,__zero_reg__
608 sec\;sbc %A0,__zero_reg__\;sbc %B0,__zero_reg__\;sbc %C0,__zero_reg__\;sbc %D0,__zero_reg__"
609 [(set_attr "length" "4,3,3,4,5,5")
610 (set_attr "cc" "set_n,set_n,set_czn,set_czn,set_n,set_n")])
612 (define_insn "*addsi3_zero_extend"
613 [(set (match_operand:SI 0 "register_operand" "=r")
614 (plus:SI (zero_extend:SI
615 (match_operand:QI 1 "register_operand" "r"))
616 (match_operand:SI 2 "register_operand" "0")))]
621 adc %D0,__zero_reg__"
622 [(set_attr "length" "4")
623 (set_attr "cc" "set_n")])
625 ;-----------------------------------------------------------------------------
627 (define_insn "subqi3"
628 [(set (match_operand:QI 0 "register_operand" "=r,d")
629 (minus:QI (match_operand:QI 1 "register_operand" "0,0")
630 (match_operand:QI 2 "nonmemory_operand" "r,i")))]
635 [(set_attr "length" "1,1")
636 (set_attr "cc" "set_czn,set_czn")])
638 (define_insn "subhi3"
639 [(set (match_operand:HI 0 "register_operand" "=r,d")
640 (minus:HI (match_operand:HI 1 "register_operand" "0,0")
641 (match_operand:HI 2 "nonmemory_operand" "r,i")))]
644 sub %A0,%A2\;sbc %B0,%B2
645 subi %A0,lo8(%2)\;sbci %B0,hi8(%2)"
646 [(set_attr "length" "2,2")
647 (set_attr "cc" "set_czn,set_czn")])
649 (define_insn "*subhi3_zero_extend1"
650 [(set (match_operand:HI 0 "register_operand" "=r")
651 (minus:HI (match_operand:HI 1 "register_operand" "0")
653 (match_operand:QI 2 "register_operand" "r"))))]
656 sbc %B0,__zero_reg__"
657 [(set_attr "length" "2")
658 (set_attr "cc" "set_n")])
660 (define_insn "subsi3"
661 [(set (match_operand:SI 0 "register_operand" "=r,d")
662 (minus:SI (match_operand:SI 1 "register_operand" "0,0")
663 (match_operand:SI 2 "nonmemory_operand" "r,i")))]
666 sub %0,%2\;sbc %B0,%B2\;sbc %C0,%C2\;sbc %D0,%D2
667 subi %A0,lo8(%2)\;sbci %B0,hi8(%2)\;sbci %C0,hlo8(%2)\;sbci %D0,hhi8(%2)"
668 [(set_attr "length" "4,4")
669 (set_attr "cc" "set_czn,set_czn")])
671 (define_insn "*subsi3_zero_extend"
672 [(set (match_operand:SI 0 "register_operand" "=r")
673 (minus:SI (match_operand:SI 1 "register_operand" "0")
675 (match_operand:QI 2 "register_operand" "r"))))]
680 sbc %D0,__zero_reg__"
681 [(set_attr "length" "4")
682 (set_attr "cc" "set_n")])
684 ;******************************************************************************
687 (define_expand "mulqi3"
688 [(set (match_operand:QI 0 "register_operand" "")
689 (mult:QI (match_operand:QI 1 "register_operand" "")
690 (match_operand:QI 2 "register_operand" "")))]
695 emit_insn (gen_mulqi3_call (operands[0], operands[1], operands[2]));
700 (define_insn "*mulqi3_enh"
701 [(set (match_operand:QI 0 "register_operand" "=r")
702 (mult:QI (match_operand:QI 1 "register_operand" "r")
703 (match_operand:QI 2 "register_operand" "r")))]
708 [(set_attr "length" "3")
709 (set_attr "cc" "clobber")])
711 (define_expand "mulqi3_call"
712 [(set (reg:QI 24) (match_operand:QI 1 "register_operand" ""))
713 (set (reg:QI 22) (match_operand:QI 2 "register_operand" ""))
714 (parallel [(set (reg:QI 24) (mult:QI (reg:QI 24) (reg:QI 22)))
715 (clobber (reg:QI 22))])
716 (set (match_operand:QI 0 "register_operand" "") (reg:QI 24))]
720 (define_insn "*mulqi3_call"
721 [(set (reg:QI 24) (mult:QI (reg:QI 24) (reg:QI 22)))
722 (clobber (reg:QI 22))]
725 [(set_attr "type" "xcall")
726 (set_attr "cc" "clobber")])
728 (define_insn "mulqihi3"
729 [(set (match_operand:HI 0 "register_operand" "=r")
730 (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "d"))
731 (sign_extend:HI (match_operand:QI 2 "register_operand" "d"))))]
736 [(set_attr "length" "3")
737 (set_attr "cc" "clobber")])
739 (define_insn "umulqihi3"
740 [(set (match_operand:HI 0 "register_operand" "=r")
741 (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
742 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
747 [(set_attr "length" "3")
748 (set_attr "cc" "clobber")])
750 (define_expand "mulhi3"
751 [(set (match_operand:HI 0 "register_operand" "")
752 (mult:HI (match_operand:HI 1 "register_operand" "")
753 (match_operand:HI 2 "register_operand" "")))]
759 emit_insn (gen_mulhi3_call (operands[0], operands[1], operands[2]));
764 (define_insn "*mulhi3_enh"
765 [(set (match_operand:HI 0 "register_operand" "=&r")
766 (mult:HI (match_operand:HI 1 "register_operand" "r")
767 (match_operand:HI 2 "register_operand" "r")))]
776 [(set_attr "length" "7")
777 (set_attr "cc" "clobber")])
779 (define_expand "mulhi3_call"
780 [(set (reg:HI 24) (match_operand:HI 1 "register_operand" ""))
781 (set (reg:HI 22) (match_operand:HI 2 "register_operand" ""))
782 (parallel [(set (reg:HI 24) (mult:HI (reg:HI 24) (reg:HI 22)))
783 (clobber (reg:HI 22))
784 (clobber (reg:QI 21))])
785 (set (match_operand:HI 0 "register_operand" "") (reg:HI 24))]
789 (define_insn "*mulhi3_call"
790 [(set (reg:HI 24) (mult:HI (reg:HI 24) (reg:HI 22)))
791 (clobber (reg:HI 22))
792 (clobber (reg:QI 21))]
795 [(set_attr "type" "xcall")
796 (set_attr "cc" "clobber")])
798 ;; Operand 2 (reg:SI 18) not clobbered on the enhanced core.
799 ;; All call-used registers clobbered otherwise - normal library call.
800 (define_expand "mulsi3"
801 [(set (reg:SI 22) (match_operand:SI 1 "register_operand" ""))
802 (set (reg:SI 18) (match_operand:SI 2 "register_operand" ""))
803 (parallel [(set (reg:SI 22) (mult:SI (reg:SI 22) (reg:SI 18)))
804 (clobber (reg:HI 26))
805 (clobber (reg:HI 30))])
806 (set (match_operand:SI 0 "register_operand" "") (reg:SI 22))]
810 (define_insn "*mulsi3_call"
811 [(set (reg:SI 22) (mult:SI (reg:SI 22) (reg:SI 18)))
812 (clobber (reg:HI 26))
813 (clobber (reg:HI 30))]
816 [(set_attr "type" "xcall")
817 (set_attr "cc" "clobber")])
819 ; / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / %
822 ;; Generate libgcc.S calls ourselves, because:
823 ;; - we know exactly which registers are clobbered (for QI and HI
824 ;; modes, some of the call-used registers are preserved)
825 ;; - we get both the quotient and the remainder at no extra cost
827 (define_expand "divmodqi4"
828 [(set (reg:QI 24) (match_operand:QI 1 "register_operand" ""))
829 (set (reg:QI 22) (match_operand:QI 2 "register_operand" ""))
830 (parallel [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
831 (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
832 (clobber (reg:QI 22))
833 (clobber (reg:QI 23))])
834 (set (match_operand:QI 0 "register_operand" "") (reg:QI 24))
835 (set (match_operand:QI 3 "register_operand" "") (reg:QI 25))]
839 (define_insn "*divmodqi4_call"
840 [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
841 (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
842 (clobber (reg:QI 22))
843 (clobber (reg:QI 23))]
846 [(set_attr "type" "xcall")
847 (set_attr "cc" "clobber")])
849 (define_expand "udivmodqi4"
850 [(set (reg:QI 24) (match_operand:QI 1 "register_operand" ""))
851 (set (reg:QI 22) (match_operand:QI 2 "register_operand" ""))
852 (parallel [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
853 (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
854 (clobber (reg:QI 23))])
855 (set (match_operand:QI 0 "register_operand" "") (reg:QI 24))
856 (set (match_operand:QI 3 "register_operand" "") (reg:QI 25))]
860 (define_insn "*udivmodqi4_call"
861 [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
862 (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
863 (clobber (reg:QI 23))]
865 "%~call __udivmodqi4"
866 [(set_attr "type" "xcall")
867 (set_attr "cc" "clobber")])
869 (define_expand "divmodhi4"
870 [(set (reg:HI 24) (match_operand:HI 1 "register_operand" ""))
871 (set (reg:HI 22) (match_operand:HI 2 "register_operand" ""))
872 (parallel [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
873 (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
874 (clobber (reg:HI 26))
875 (clobber (reg:QI 21))])
876 (set (match_operand:HI 0 "register_operand" "") (reg:HI 22))
877 (set (match_operand:HI 3 "register_operand" "") (reg:HI 24))]
881 (define_insn "*divmodhi4_call"
882 [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
883 (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
884 (clobber (reg:HI 26))
885 (clobber (reg:QI 21))]
888 [(set_attr "type" "xcall")
889 (set_attr "cc" "clobber")])
891 (define_expand "udivmodhi4"
892 [(set (reg:HI 24) (match_operand:HI 1 "register_operand" ""))
893 (set (reg:HI 22) (match_operand:HI 2 "register_operand" ""))
894 (parallel [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
895 (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
896 (clobber (reg:HI 26))
897 (clobber (reg:QI 21))])
898 (set (match_operand:HI 0 "register_operand" "") (reg:HI 22))
899 (set (match_operand:HI 3 "register_operand" "") (reg:HI 24))]
903 (define_insn "*udivmodhi4_call"
904 [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
905 (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
906 (clobber (reg:HI 26))
907 (clobber (reg:QI 21))]
909 "%~call __udivmodhi4"
910 [(set_attr "type" "xcall")
911 (set_attr "cc" "clobber")])
913 (define_expand "divmodsi4"
914 [(set (reg:SI 22) (match_operand:SI 1 "register_operand" ""))
915 (set (reg:SI 18) (match_operand:SI 2 "register_operand" ""))
916 (parallel [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
917 (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
918 (clobber (reg:HI 26))
919 (clobber (reg:HI 30))])
920 (set (match_operand:SI 0 "register_operand" "") (reg:SI 18))
921 (set (match_operand:SI 3 "register_operand" "") (reg:SI 22))]
925 (define_insn "*divmodsi4_call"
926 [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
927 (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
928 (clobber (reg:HI 26))
929 (clobber (reg:HI 30))]
932 [(set_attr "type" "xcall")
933 (set_attr "cc" "clobber")])
935 (define_expand "udivmodsi4"
936 [(set (reg:SI 22) (match_operand:SI 1 "register_operand" ""))
937 (set (reg:SI 18) (match_operand:SI 2 "register_operand" ""))
938 (parallel [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
939 (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
940 (clobber (reg:HI 26))
941 (clobber (reg:HI 30))])
942 (set (match_operand:SI 0 "register_operand" "") (reg:SI 18))
943 (set (match_operand:SI 3 "register_operand" "") (reg:SI 22))]
947 (define_insn "*udivmodsi4_call"
948 [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
949 (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
950 (clobber (reg:HI 26))
951 (clobber (reg:HI 30))]
953 "%~call __udivmodsi4"
954 [(set_attr "type" "xcall")
955 (set_attr "cc" "clobber")])
957 ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
960 (define_insn "andqi3"
961 [(set (match_operand:QI 0 "register_operand" "=r,d")
962 (and:QI (match_operand:QI 1 "register_operand" "%0,0")
963 (match_operand:QI 2 "nonmemory_operand" "r,i")))]
968 [(set_attr "length" "1,1")
969 (set_attr "cc" "set_zn,set_zn")])
971 (define_insn "andhi3"
972 [(set (match_operand:HI 0 "register_operand" "=r,d,r")
973 (and:HI (match_operand:HI 1 "register_operand" "%0,0,0")
974 (match_operand:HI 2 "nonmemory_operand" "r,i,M")))
975 (clobber (match_scratch:QI 3 "=X,X,&d"))]
978 if (which_alternative==0)
979 return (AS2 (and,%A0,%A2) CR_TAB
981 else if (which_alternative==1)
983 if (GET_CODE (operands[2]) == CONST_INT)
985 int mask = INTVAL (operands[2]);
986 if ((mask & 0xff) != 0xff)
987 output_asm_insn (AS2 (andi,%A0,lo8(%2)), operands);
988 if ((mask & 0xff00) != 0xff00)
989 output_asm_insn (AS2 (andi,%B0,hi8(%2)), operands);
992 return (AS2 (andi,%A0,lo8(%2)) CR_TAB
993 AS2 (andi,%B0,hi8(%2)));
995 return (AS2 (ldi,%3,lo8(%2)) CR_TAB
996 AS2 (and,%A0,%3) CR_TAB
999 [(set_attr "length" "2,2,3")
1000 (set_attr "cc" "set_n,clobber,set_n")])
1002 (define_insn "andsi3"
1003 [(set (match_operand:SI 0 "register_operand" "=r,d")
1004 (and:SI (match_operand:SI 1 "register_operand" "%0,0")
1005 (match_operand:SI 2 "nonmemory_operand" "r,i")))]
1008 if (which_alternative==0)
1009 return (AS2 (and, %0,%2) CR_TAB
1010 AS2 (and, %B0,%B2) CR_TAB
1011 AS2 (and, %C0,%C2) CR_TAB
1012 AS2 (and, %D0,%D2));
1013 else if (which_alternative==1)
1015 if (GET_CODE (operands[2]) == CONST_INT)
1017 HOST_WIDE_INT mask = INTVAL (operands[2]);
1018 if ((mask & 0xff) != 0xff)
1019 output_asm_insn (AS2 (andi,%A0,lo8(%2)), operands);
1020 if ((mask & 0xff00) != 0xff00)
1021 output_asm_insn (AS2 (andi,%B0,hi8(%2)), operands);
1022 if ((mask & 0xff0000L) != 0xff0000L)
1023 output_asm_insn (AS2 (andi,%C0,hlo8(%2)), operands);
1024 if ((mask & 0xff000000L) != 0xff000000L)
1025 output_asm_insn (AS2 (andi,%D0,hhi8(%2)), operands);
1028 return (AS2 (andi, %A0,lo8(%2)) CR_TAB
1029 AS2 (andi, %B0,hi8(%2)) CR_TAB
1030 AS2 (andi, %C0,hlo8(%2)) CR_TAB
1031 AS2 (andi, %D0,hhi8(%2)));
1035 [(set_attr "length" "4,4")
1036 (set_attr "cc" "set_n,set_n")])
1038 ;;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1041 (define_insn "iorqi3"
1042 [(set (match_operand:QI 0 "register_operand" "=r,d")
1043 (ior:QI (match_operand:QI 1 "register_operand" "%0,0")
1044 (match_operand:QI 2 "nonmemory_operand" "r,i")))]
1049 [(set_attr "length" "1,1")
1050 (set_attr "cc" "set_zn,set_zn")])
1052 (define_insn "iorhi3"
1053 [(set (match_operand:HI 0 "register_operand" "=r,d")
1054 (ior:HI (match_operand:HI 1 "register_operand" "%0,0")
1055 (match_operand:HI 2 "nonmemory_operand" "r,i")))]
1058 if (which_alternative==0)
1059 return (AS2 (or,%A0,%A2) CR_TAB
1061 if (GET_CODE (operands[2]) == CONST_INT)
1063 int mask = INTVAL (operands[2]);
1065 output_asm_insn (AS2 (ori,%A0,lo8(%2)), operands);
1067 output_asm_insn (AS2 (ori,%B0,hi8(%2)), operands);
1070 return (AS2 (ori,%0,lo8(%2)) CR_TAB
1071 AS2 (ori,%B0,hi8(%2)));
1073 [(set_attr "length" "2,2")
1074 (set_attr "cc" "set_n,clobber")])
1076 (define_insn "*iorhi3_clobber"
1077 [(set (match_operand:HI 0 "register_operand" "=r,r")
1078 (ior:HI (match_operand:HI 1 "register_operand" "%0,0")
1079 (match_operand:HI 2 "immediate_operand" "M,i")))
1080 (clobber (match_scratch:QI 3 "=&d,&d"))]
1083 ldi %3,lo8(%2)\;or %A0,%3
1084 ldi %3,lo8(%2)\;or %A0,%3\;ldi %3,hi8(%2)\;or %B0,%3"
1085 [(set_attr "length" "2,4")
1086 (set_attr "cc" "clobber,set_n")])
1088 (define_insn "iorsi3"
1089 [(set (match_operand:SI 0 "register_operand" "=r,d")
1090 (ior:SI (match_operand:SI 1 "register_operand" "%0,0")
1091 (match_operand:SI 2 "nonmemory_operand" "r,i")))]
1094 if (which_alternative==0)
1095 return (AS2 (or, %0,%2) CR_TAB
1096 AS2 (or, %B0,%B2) CR_TAB
1097 AS2 (or, %C0,%C2) CR_TAB
1099 if (GET_CODE (operands[2]) == CONST_INT)
1101 HOST_WIDE_INT mask = INTVAL (operands[2]);
1103 output_asm_insn (AS2 (ori,%A0,lo8(%2)), operands);
1105 output_asm_insn (AS2 (ori,%B0,hi8(%2)), operands);
1106 if (mask & 0xff0000L)
1107 output_asm_insn (AS2 (ori,%C0,hlo8(%2)), operands);
1108 if (mask & 0xff000000L)
1109 output_asm_insn (AS2 (ori,%D0,hhi8(%2)), operands);
1112 return (AS2 (ori, %A0,lo8(%2)) CR_TAB
1113 AS2 (ori, %B0,hi8(%2)) CR_TAB
1114 AS2 (ori, %C0,hlo8(%2)) CR_TAB
1115 AS2 (ori, %D0,hhi8(%2)));
1117 [(set_attr "length" "4,4")
1118 (set_attr "cc" "set_n,clobber")])
1120 (define_insn "*iorsi3_clobber"
1121 [(set (match_operand:SI 0 "register_operand" "=r,r")
1122 (ior:SI (match_operand:SI 1 "register_operand" "%0,0")
1123 (match_operand:SI 2 "immediate_operand" "M,i")))
1124 (clobber (match_scratch:QI 3 "=&d,&d"))]
1127 ldi %3,lo8(%2)\;or %A0,%3
1128 ldi %3,lo8(%2)\;or %A0,%3\;ldi %3,hi8(%2)\;or %B0,%3\;ldi %3,hlo8(%2)\;or %C0,%3\;ldi %3,hhi8(%2)\;or %D0,%3"
1129 [(set_attr "length" "2,8")
1130 (set_attr "cc" "clobber,set_n")])
1132 ;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1135 (define_insn "xorqi3"
1136 [(set (match_operand:QI 0 "register_operand" "=r")
1137 (xor:QI (match_operand:QI 1 "register_operand" "%0")
1138 (match_operand:QI 2 "register_operand" "r")))]
1141 [(set_attr "length" "1")
1142 (set_attr "cc" "set_zn")])
1144 (define_insn "xorhi3"
1145 [(set (match_operand:HI 0 "register_operand" "=r")
1146 (xor:HI (match_operand:HI 1 "register_operand" "%0")
1147 (match_operand:HI 2 "register_operand" "r")))]
1151 [(set_attr "length" "2")
1152 (set_attr "cc" "set_n")])
1154 (define_insn "xorsi3"
1155 [(set (match_operand:SI 0 "register_operand" "=r")
1156 (xor:SI (match_operand:SI 1 "register_operand" "%0")
1157 (match_operand:SI 2 "register_operand" "r")))]
1163 [(set_attr "length" "4")
1164 (set_attr "cc" "set_n")])
1166 ;;<< << << << << << << << << << << << << << << << << << << << << << << << << <<
1167 ;; arithmetic shift left
1169 (define_insn "ashlqi3"
1170 [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,!d,r,r")
1171 (ashift:QI (match_operand:QI 1 "register_operand" "0,0,0,0,0,0,0")
1172 (match_operand:QI 2 "general_operand" "r,L,P,K,n,n,Qm")))]
1174 "* return ashlqi3_out (insn, operands, NULL);"
1175 [(set_attr "length" "5,0,1,2,4,6,9")
1176 (set_attr "cc" "clobber,none,set_czn,set_czn,set_czn,set_czn,clobber")])
1178 (define_insn "ashlhi3"
1179 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r,r")
1180 (ashift:HI (match_operand:HI 1 "register_operand" "0,0,0,r,0,0,0")
1181 (match_operand:QI 2 "general_operand" "r,L,P,O,K,n,Qm")))]
1183 "* return ashlhi3_out (insn, operands, NULL);"
1184 [(set_attr "length" "6,0,2,2,4,10,10")
1185 (set_attr "cc" "clobber,none,set_n,clobber,set_n,clobber,clobber")])
1187 (define_insn "ashlsi3"
1188 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,r")
1189 (ashift:SI (match_operand:SI 1 "register_operand" "0,0,0,r,0,0,0")
1190 (match_operand:QI 2 "general_operand" "r,L,P,O,K,n,Qm")))]
1192 "* return ashlsi3_out (insn, operands, NULL);"
1193 [(set_attr "length" "8,0,4,4,8,10,12")
1194 (set_attr "cc" "clobber,none,set_n,clobber,set_n,clobber,clobber")])
1196 ;; Optimize if a scratch register from LD_REGS happens to be available.
1199 [(match_scratch:QI 3 "d")
1200 (set (match_operand:HI 0 "register_operand" "")
1201 (ashift:HI (match_operand:HI 1 "register_operand" "")
1202 (match_operand:QI 2 "const_int_operand" "")))]
1204 [(parallel [(set (match_dup 0) (ashift:HI (match_dup 1) (match_dup 2)))
1205 (clobber (match_dup 3))])]
1206 "if (!avr_peep2_scratch_safe (operands[3]))
1209 (define_insn "*ashlhi3_const"
1210 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1211 (ashift:HI (match_operand:HI 1 "register_operand" "0,0,r,0,0")
1212 (match_operand:QI 2 "const_int_operand" "L,P,O,K,n")))
1213 (clobber (match_scratch:QI 3 "=X,X,X,X,&d"))]
1215 "* return ashlhi3_out (insn, operands, NULL);"
1216 [(set_attr "length" "0,2,2,4,10")
1217 (set_attr "cc" "none,set_n,clobber,set_n,clobber")])
1220 [(match_scratch:QI 3 "d")
1221 (set (match_operand:SI 0 "register_operand" "")
1222 (ashift:SI (match_operand:SI 1 "register_operand" "")
1223 (match_operand:QI 2 "const_int_operand" "")))]
1225 [(parallel [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
1226 (clobber (match_dup 3))])]
1227 "if (!avr_peep2_scratch_safe (operands[3]))
1230 (define_insn "*ashlsi3_const"
1231 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1232 (ashift:SI (match_operand:SI 1 "register_operand" "0,0,r,0")
1233 (match_operand:QI 2 "const_int_operand" "L,P,O,n")))
1234 (clobber (match_scratch:QI 3 "=X,X,X,&d"))]
1236 "* return ashlsi3_out (insn, operands, NULL);"
1237 [(set_attr "length" "0,4,4,10")
1238 (set_attr "cc" "none,set_n,clobber,clobber")])
1240 ;; >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
1241 ;; arithmetic shift right
1243 (define_insn "ashrqi3"
1244 [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r,r")
1245 (ashiftrt:QI (match_operand:QI 1 "register_operand" "0,0,0,0,0,0")
1246 (match_operand:QI 2 "general_operand" "r,L,P,K,n,Qm")))]
1248 "* return ashrqi3_out (insn, operands, NULL);"
1249 [(set_attr "length" "5,0,1,2,5,9")
1250 (set_attr "cc" "clobber,none,clobber,clobber,clobber,clobber")])
1252 (define_insn "ashrhi3"
1253 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r,r")
1254 (ashiftrt:HI (match_operand:HI 1 "register_operand" "0,0,0,r,0,0,0")
1255 (match_operand:QI 2 "general_operand" "r,L,P,O,K,n,Qm")))]
1257 "* return ashrhi3_out (insn, operands, NULL);"
1258 [(set_attr "length" "6,0,2,4,4,10,10")
1259 (set_attr "cc" "clobber,none,clobber,set_n,clobber,clobber,clobber")])
1261 (define_insn "ashrsi3"
1262 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,r")
1263 (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0,0,r,0,0,0")
1264 (match_operand:QI 2 "general_operand" "r,L,P,O,K,n,Qm")))]
1266 "* return ashrsi3_out (insn, operands, NULL);"
1267 [(set_attr "length" "8,0,4,6,8,10,12")
1268 (set_attr "cc" "clobber,none,clobber,set_n,clobber,clobber,clobber")])
1270 ;; Optimize if a scratch register from LD_REGS happens to be available.
1273 [(match_scratch:QI 3 "d")
1274 (set (match_operand:HI 0 "register_operand" "")
1275 (ashiftrt:HI (match_operand:HI 1 "register_operand" "")
1276 (match_operand:QI 2 "const_int_operand" "")))]
1278 [(parallel [(set (match_dup 0) (ashiftrt:HI (match_dup 1) (match_dup 2)))
1279 (clobber (match_dup 3))])]
1280 "if (!avr_peep2_scratch_safe (operands[3]))
1283 (define_insn "*ashrhi3_const"
1284 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1285 (ashiftrt:HI (match_operand:HI 1 "register_operand" "0,0,r,0,0")
1286 (match_operand:QI 2 "const_int_operand" "L,P,O,K,n")))
1287 (clobber (match_scratch:QI 3 "=X,X,X,X,&d"))]
1289 "* return ashrhi3_out (insn, operands, NULL);"
1290 [(set_attr "length" "0,2,4,4,10")
1291 (set_attr "cc" "none,clobber,set_n,clobber,clobber")])
1294 [(match_scratch:QI 3 "d")
1295 (set (match_operand:SI 0 "register_operand" "")
1296 (ashiftrt:SI (match_operand:SI 1 "register_operand" "")
1297 (match_operand:QI 2 "const_int_operand" "")))]
1299 [(parallel [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (match_dup 2)))
1300 (clobber (match_dup 3))])]
1301 "if (!avr_peep2_scratch_safe (operands[3]))
1304 (define_insn "*ashrsi3_const"
1305 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1306 (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r,0")
1307 (match_operand:QI 2 "const_int_operand" "L,P,O,n")))
1308 (clobber (match_scratch:QI 3 "=X,X,X,&d"))]
1310 "* return ashrsi3_out (insn, operands, NULL);"
1311 [(set_attr "length" "0,4,4,10")
1312 (set_attr "cc" "none,clobber,set_n,clobber")])
1314 ;; >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
1315 ;; logical shift right
1317 (define_insn "lshrqi3"
1318 [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,!d,r,r")
1319 (lshiftrt:QI (match_operand:QI 1 "register_operand" "0,0,0,0,0,0,0")
1320 (match_operand:QI 2 "general_operand" "r,L,P,K,n,n,Qm")))]
1322 "* return lshrqi3_out (insn, operands, NULL);"
1323 [(set_attr "length" "5,0,1,2,4,6,9")
1324 (set_attr "cc" "clobber,none,set_czn,set_czn,set_czn,set_czn,clobber")])
1326 (define_insn "lshrhi3"
1327 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r,r,r")
1328 (lshiftrt:HI (match_operand:HI 1 "register_operand" "0,0,0,r,0,0,0")
1329 (match_operand:QI 2 "general_operand" "r,L,P,O,K,n,Qm")))]
1331 "* return lshrhi3_out (insn, operands, NULL);"
1332 [(set_attr "length" "6,0,2,2,4,10,10")
1333 (set_attr "cc" "clobber,none,clobber,clobber,clobber,clobber,clobber")])
1335 (define_insn "lshrsi3"
1336 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r,r,r,r")
1337 (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,0,0,r,0,0,0")
1338 (match_operand:QI 2 "general_operand" "r,L,P,O,K,n,Qm")))]
1340 "* return lshrsi3_out (insn, operands, NULL);"
1341 [(set_attr "length" "8,0,4,4,8,10,12")
1342 (set_attr "cc" "clobber,none,clobber,clobber,clobber,clobber,clobber")])
1344 ;; Optimize if a scratch register from LD_REGS happens to be available.
1347 [(match_scratch:QI 3 "d")
1348 (set (match_operand:HI 0 "register_operand" "")
1349 (lshiftrt:HI (match_operand:HI 1 "register_operand" "")
1350 (match_operand:QI 2 "const_int_operand" "")))]
1352 [(parallel [(set (match_dup 0) (lshiftrt:HI (match_dup 1) (match_dup 2)))
1353 (clobber (match_dup 3))])]
1354 "if (!avr_peep2_scratch_safe (operands[3]))
1357 (define_insn "*lshrhi3_const"
1358 [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r")
1359 (lshiftrt:HI (match_operand:HI 1 "register_operand" "0,0,r,0,0")
1360 (match_operand:QI 2 "const_int_operand" "L,P,O,K,n")))
1361 (clobber (match_scratch:QI 3 "=X,X,X,X,&d"))]
1363 "* return lshrhi3_out (insn, operands, NULL);"
1364 [(set_attr "length" "0,2,2,4,10")
1365 (set_attr "cc" "none,clobber,clobber,clobber,clobber")])
1368 [(match_scratch:QI 3 "d")
1369 (set (match_operand:SI 0 "register_operand" "")
1370 (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
1371 (match_operand:QI 2 "const_int_operand" "")))]
1373 [(parallel [(set (match_dup 0) (lshiftrt:SI (match_dup 1) (match_dup 2)))
1374 (clobber (match_dup 3))])]
1375 "if (!avr_peep2_scratch_safe (operands[3]))
1378 (define_insn "*lshrsi3_const"
1379 [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1380 (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r,0")
1381 (match_operand:QI 2 "const_int_operand" "L,P,O,n")))
1382 (clobber (match_scratch:QI 3 "=X,X,X,&d"))]
1384 "* return lshrsi3_out (insn, operands, NULL);"
1385 [(set_attr "length" "0,4,4,10")
1386 (set_attr "cc" "none,clobber,clobber,clobber")])
1388 ;; abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x)
1391 (define_insn "absqi2"
1392 [(set (match_operand:QI 0 "register_operand" "=r")
1393 (abs:QI (match_operand:QI 1 "register_operand" "0")))]
1397 [(set_attr "length" "2")
1398 (set_attr "cc" "clobber")])
1401 (define_insn "abssf2"
1402 [(set (match_operand:SF 0 "register_operand" "=d,r")
1403 (abs:SF (match_operand:SF 1 "register_operand" "0,0")))]
1408 [(set_attr "length" "1,2")
1409 (set_attr "cc" "set_n,clobber")])
1411 ;; 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x 0 - x
1414 (define_insn "negqi2"
1415 [(set (match_operand:QI 0 "register_operand" "=r")
1416 (neg:QI (match_operand:QI 1 "register_operand" "0")))]
1419 [(set_attr "length" "1")
1420 (set_attr "cc" "set_zn")])
1422 (define_insn "neghi2"
1423 [(set (match_operand:HI 0 "register_operand" "=!d,r,&r")
1424 (neg:HI (match_operand:HI 1 "register_operand" "0,0,r")))]
1427 com %B0\;neg %A0\;sbci %B0,lo8(-1)
1428 com %B0\;neg %A0\;sbc %B0,__zero_reg__\;inc %B0
1429 clr %A0\;clr %B0\;sub %A0,%A1\;sbc %B0,%B1"
1430 [(set_attr "length" "3,4,4")
1431 (set_attr "cc" "set_czn,set_n,set_czn")])
1433 (define_insn "negsi2"
1434 [(set (match_operand:SI 0 "register_operand" "=!d,r,&r")
1435 (neg:SI (match_operand:SI 1 "register_operand" "0,0,r")))]
1438 com %D0\;com %C0\;com %B0\;neg %A0\;sbci %B0,lo8(-1)\;sbci %C0,lo8(-1)\;sbci %D0,lo8(-1)
1439 com %D0\;com %C0\;com %B0\;com %A0\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__\;adc %C0,__zero_reg__\;adc %D0,__zero_reg__
1440 clr %A0\;clr %B0\;{clr %C0\;clr %D0|movw %C0,%A0}\;sub %A0,%A1\;sbc %B0,%B1\;sbc %C0,%C1\;sbc %D0,%D1"
1441 [(set_attr_alternative "length"
1444 (if_then_else (eq_attr "mcu_enhanced" "yes")
1447 (set_attr "cc" "set_czn,set_n,set_czn")])
1449 (define_insn "negsf2"
1450 [(set (match_operand:SF 0 "register_operand" "=d,r")
1451 (neg:SF (match_operand:SF 1 "register_operand" "0,0")))]
1455 bst %D0,7\;com %D0\;bld %D0,7\;com %D0"
1456 [(set_attr "length" "1,4")
1457 (set_attr "cc" "set_n,set_n")])
1459 ;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1462 (define_insn "one_cmplqi2"
1463 [(set (match_operand:QI 0 "register_operand" "=r")
1464 (not:QI (match_operand:QI 1 "register_operand" "0")))]
1467 [(set_attr "length" "1")
1468 (set_attr "cc" "set_czn")])
1470 (define_insn "one_cmplhi2"
1471 [(set (match_operand:HI 0 "register_operand" "=r")
1472 (not:HI (match_operand:HI 1 "register_operand" "0")))]
1476 [(set_attr "length" "2")
1477 (set_attr "cc" "set_n")])
1479 (define_insn "one_cmplsi2"
1480 [(set (match_operand:SI 0 "register_operand" "=r")
1481 (not:SI (match_operand:SI 1 "register_operand" "0")))]
1487 [(set_attr "length" "4")
1488 (set_attr "cc" "set_n")])
1490 ;; xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x
1493 (define_insn "extendqihi2"
1494 [(set (match_operand:HI 0 "register_operand" "=r,r")
1495 (sign_extend:HI (match_operand:QI 1 "register_operand" "0,*r")))]
1498 clr %B0\;sbrc %0,7\;com %B0
1499 mov %A0,%A1\;clr %B0\;sbrc %A0,7\;com %B0"
1500 [(set_attr "length" "3,4")
1501 (set_attr "cc" "set_n,set_n")])
1503 (define_insn "extendqisi2"
1504 [(set (match_operand:SI 0 "register_operand" "=r,r")
1505 (sign_extend:SI (match_operand:QI 1 "register_operand" "0,*r")))]
1508 clr %B0\;sbrc %A0,7\;com %B0\;mov %C0,%B0\;mov %D0,%B0
1509 mov %A0,%A1\;clr %B0\;sbrc %A0,7\;com %B0\;mov %C0,%B0\;mov %D0,%B0"
1510 [(set_attr "length" "5,6")
1511 (set_attr "cc" "set_n,set_n")])
1513 (define_insn "extendhisi2"
1514 [(set (match_operand:SI 0 "register_operand" "=r,&r")
1515 (sign_extend:SI (match_operand:HI 1 "register_operand" "0,*r")))]
1518 clr %C0\;sbrc %B0,7\;com %C0\;mov %D0,%C0
1519 {mov %A0,%A1\;mov %B0,%B1|movw %A0,%A1}\;clr %C0\;sbrc %B0,7\;com %C0\;mov %D0,%C0"
1520 [(set_attr_alternative "length"
1522 (if_then_else (eq_attr "mcu_enhanced" "yes")
1525 (set_attr "cc" "set_n,set_n")])
1527 ;; xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x
1530 (define_insn "zero_extendqihi2"
1531 [(set (match_operand:HI 0 "register_operand" "=r,r")
1532 (zero_extend:HI (match_operand:QI 1 "register_operand" "0,*r")))]
1536 mov %A0,%A1\;clr %B0"
1537 [(set_attr "length" "1,2")
1538 (set_attr "cc" "set_n,set_n")])
1540 (define_insn "zero_extendqisi2"
1541 [(set (match_operand:SI 0 "register_operand" "=r,r")
1542 (zero_extend:SI (match_operand:QI 1 "register_operand" "0,*r")))]
1545 clr %B0\;clr %C0\;clr %D0
1546 mov %A0,%A1\;clr %B0\;clr %C0\;clr %D0"
1547 [(set_attr "length" "3,4")
1548 (set_attr "cc" "set_n,set_n")])
1550 (define_insn "zero_extendhisi2"
1551 [(set (match_operand:SI 0 "register_operand" "=r,&r")
1552 (zero_extend:SI (match_operand:HI 1 "register_operand" "0,*r")))]
1556 {mov %A0,%A1\;mov %B0,%B1|movw %A0,%A1}\;clr %C0\;clr %D0"
1557 [(set_attr_alternative "length"
1559 (if_then_else (eq_attr "mcu_enhanced" "yes")
1562 (set_attr "cc" "set_n,set_n")])
1564 ;;<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>
1567 (define_insn "tstqi"
1569 (match_operand:QI 0 "register_operand" "r"))]
1572 [(set_attr "cc" "compare")
1573 (set_attr "length" "1")])
1575 (define_insn "*negated_tstqi"
1577 (neg:QI (match_operand:QI 0 "register_operand" "r")))]
1579 "cp __zero_reg__,%0"
1580 [(set_attr "cc" "compare")
1581 (set_attr "length" "1")])
1583 (define_insn "tsthi"
1585 (match_operand:HI 0 "register_operand" "!w,r"))]
1587 "* return out_tsthi (insn,NULL);"
1588 [(set_attr "cc" "compare,compare")
1589 (set_attr "length" "1,2")])
1591 (define_insn "*negated_tsthi"
1593 (neg:HI (match_operand:HI 0 "register_operand" "r")))]
1595 "cp __zero_reg__,%A0
1596 cpc __zero_reg__,%B0"
1597 [(set_attr "cc" "compare")
1598 (set_attr "length" "2")])
1600 (define_insn "tstsi"
1602 (match_operand:SI 0 "register_operand" "r"))]
1604 "* return out_tstsi (insn,NULL);"
1605 [(set_attr "cc" "compare")
1606 (set_attr "length" "4")])
1608 (define_insn "*negated_tstsi"
1610 (neg:SI (match_operand:SI 0 "register_operand" "r")))]
1612 "cp __zero_reg__,%A0
1613 cpc __zero_reg__,%B0
1614 cpc __zero_reg__,%C0
1615 cpc __zero_reg__,%D0"
1616 [(set_attr "cc" "compare")
1617 (set_attr "length" "4")])
1620 (define_insn "cmpqi"
1622 (compare (match_operand:QI 0 "register_operand" "r,d")
1623 (match_operand:QI 1 "nonmemory_operand" "r,i")))]
1628 [(set_attr "cc" "compare,compare")
1629 (set_attr "length" "1,1")])
1631 (define_insn "*cmpqi_sign_extend"
1633 (compare (sign_extend:HI
1634 (match_operand:QI 0 "register_operand" "d"))
1635 (match_operand:HI 1 "const_int_operand" "n")))]
1636 "INTVAL (operands[1]) >= -128 && INTVAL (operands[1]) <= 127"
1638 [(set_attr "cc" "compare")
1639 (set_attr "length" "1")])
1641 (define_insn "cmphi"
1643 (compare (match_operand:HI 0 "register_operand" "r,d,d,r,r")
1644 (match_operand:HI 1 "nonmemory_operand" "r,M,i,M,i")))
1645 (clobber (match_scratch:QI 2 "=X,X,&d,&d,&d"))]
1648 switch (which_alternative)
1651 return (AS2 (cp,%A0,%A1) CR_TAB
1654 if (reg_unused_after (insn, operands[0])
1655 && INTVAL (operands[1]) >= 0 && INTVAL (operands[1]) <= 63
1656 && test_hard_reg_class (ADDW_REGS, operands[0]))
1657 return AS2 (sbiw,%0,%1);
1659 return (AS2 (cpi,%0,%1) CR_TAB
1660 AS2 (cpc,%B0,__zero_reg__));
1662 if (reg_unused_after (insn, operands[0]))
1663 return (AS2 (subi,%0,lo8(%1)) CR_TAB
1664 AS2 (sbci,%B0,hi8(%1)));
1666 return (AS2 (ldi, %2,hi8(%1)) CR_TAB
1667 AS2 (cpi, %A0,lo8(%1)) CR_TAB
1670 return (AS2 (ldi, %2,lo8(%1)) CR_TAB
1671 AS2 (cp, %A0,%2) CR_TAB
1672 AS2 (cpc, %B0,__zero_reg__));
1675 return (AS2 (ldi, %2,lo8(%1)) CR_TAB
1676 AS2 (cp, %A0,%2) CR_TAB
1677 AS2 (ldi, %2,hi8(%1)) CR_TAB
1682 [(set_attr "cc" "compare,compare,compare,compare,compare")
1683 (set_attr "length" "2,2,3,3,4")])
1686 (define_insn "cmpsi"
1688 (compare (match_operand:SI 0 "register_operand" "r,d,d,r,r")
1689 (match_operand:SI 1 "nonmemory_operand" "r,M,i,M,i")))
1690 (clobber (match_scratch:QI 2 "=X,X,&d,&d,&d"))]
1693 switch (which_alternative)
1696 return (AS2 (cp,%A0,%A1) CR_TAB
1697 AS2 (cpc,%B0,%B1) CR_TAB
1698 AS2 (cpc,%C0,%C1) CR_TAB
1701 if (reg_unused_after (insn, operands[0])
1702 && INTVAL (operands[1]) >= 0 && INTVAL (operands[1]) <= 63
1703 && test_hard_reg_class (ADDW_REGS, operands[0]))
1704 return (AS2 (sbiw,%0,%1) CR_TAB
1705 AS2 (cpc,%C0,__zero_reg__) CR_TAB
1706 AS2 (cpc,%D0,__zero_reg__));
1708 return (AS2 (cpi,%A0,lo8(%1)) CR_TAB
1709 AS2 (cpc,%B0,__zero_reg__) CR_TAB
1710 AS2 (cpc,%C0,__zero_reg__) CR_TAB
1711 AS2 (cpc,%D0,__zero_reg__));
1713 if (reg_unused_after (insn, operands[0]))
1714 return (AS2 (subi,%A0,lo8(%1)) CR_TAB
1715 AS2 (sbci,%B0,hi8(%1)) CR_TAB
1716 AS2 (sbci,%C0,hlo8(%1)) CR_TAB
1717 AS2 (sbci,%D0,hhi8(%1)));
1719 return (AS2 (cpi, %A0,lo8(%1)) CR_TAB
1720 AS2 (ldi, %2,hi8(%1)) CR_TAB
1721 AS2 (cpc, %B0,%2) CR_TAB
1722 AS2 (ldi, %2,hlo8(%1)) CR_TAB
1723 AS2 (cpc, %C0,%2) CR_TAB
1724 AS2 (ldi, %2,hhi8(%1)) CR_TAB
1727 return (AS2 (ldi,%2,lo8(%1)) CR_TAB
1728 AS2 (cp,%A0,%2) CR_TAB
1729 AS2 (cpc,%B0,__zero_reg__) CR_TAB
1730 AS2 (cpc,%C0,__zero_reg__) CR_TAB
1731 AS2 (cpc,%D0,__zero_reg__));
1733 return (AS2 (ldi, %2,lo8(%1)) CR_TAB
1734 AS2 (cp, %A0,%2) CR_TAB
1735 AS2 (ldi, %2,hi8(%1)) CR_TAB
1736 AS2 (cpc, %B0,%2) CR_TAB
1737 AS2 (ldi, %2,hlo8(%1)) CR_TAB
1738 AS2 (cpc, %C0,%2) CR_TAB
1739 AS2 (ldi, %2,hhi8(%1)) CR_TAB
1744 [(set_attr "cc" "compare,compare,compare,compare,compare")
1745 (set_attr "length" "4,4,7,5,8")])
1747 ;; ----------------------------------------------------------------------
1748 ;; JUMP INSTRUCTIONS
1749 ;; ----------------------------------------------------------------------
1750 ;; Conditional jump instructions
1752 (define_expand "beq"
1754 (if_then_else (eq (cc0) (const_int 0))
1755 (label_ref (match_operand 0 "" ""))
1760 (define_expand "bne"
1762 (if_then_else (ne (cc0) (const_int 0))
1763 (label_ref (match_operand 0 "" ""))
1768 (define_expand "bge"
1770 (if_then_else (ge (cc0) (const_int 0))
1771 (label_ref (match_operand 0 "" ""))
1776 (define_expand "bgeu"
1778 (if_then_else (geu (cc0) (const_int 0))
1779 (label_ref (match_operand 0 "" ""))
1784 (define_expand "blt"
1786 (if_then_else (lt (cc0) (const_int 0))
1787 (label_ref (match_operand 0 "" ""))
1792 (define_expand "bltu"
1794 (if_then_else (ltu (cc0) (const_int 0))
1795 (label_ref (match_operand 0 "" ""))
1802 /****************************************************************
1803 AVR not have following conditional jumps: LE,LEU,GT,GTU.
1804 Convert them all to proper jumps.
1805 *****************************************************************/
1807 (define_expand "ble"
1809 (if_then_else (le (cc0) (const_int 0))
1810 (label_ref (match_operand 0 "" ""))
1815 (define_expand "bleu"
1817 (if_then_else (leu (cc0) (const_int 0))
1818 (label_ref (match_operand 0 "" ""))
1823 (define_expand "bgt"
1825 (if_then_else (gt (cc0) (const_int 0))
1826 (label_ref (match_operand 0 "" ""))
1831 (define_expand "bgtu"
1833 (if_then_else (gtu (cc0) (const_int 0))
1834 (label_ref (match_operand 0 "" ""))
1839 ;; Test a single bit in a QI/HI/SImode register.
1840 (define_insn "*sbrx_branch"
1843 (match_operator 0 "comparison_operator"
1845 (match_operand:QI 1 "register_operand" "r")
1847 (match_operand 2 "const_int_operand" "n"))
1849 (label_ref (match_operand 3 "" ""))
1851 "GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE"
1852 "* return avr_out_sbxx_branch (insn, operands);"
1853 [(set (attr "length")
1854 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
1855 (le (minus (pc) (match_dup 3)) (const_int 2046)))
1857 (if_then_else (eq_attr "mcu_mega" "no")
1860 (set_attr "cc" "clobber")])
1862 (define_insn "*sbrx_and_branchhi"
1865 (match_operator 0 "comparison_operator"
1867 (match_operand:HI 1 "register_operand" "r")
1868 (match_operand:HI 2 "const_int_operand" "n"))
1870 (label_ref (match_operand 3 "" ""))
1872 "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
1873 && exact_log2 (INTVAL (operands[2]) & 0xffff) >= 0"
1874 "* return avr_out_sbxx_branch (insn, operands);"
1875 [(set (attr "length")
1876 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
1877 (le (minus (pc) (match_dup 3)) (const_int 2046)))
1879 (if_then_else (eq_attr "mcu_mega" "no")
1882 (set_attr "cc" "clobber")])
1884 (define_insn "*sbrx_and_branchsi"
1887 (match_operator 0 "comparison_operator"
1889 (match_operand:SI 1 "register_operand" "r")
1890 (match_operand:SI 2 "const_int_operand" "n"))
1892 (label_ref (match_operand 3 "" ""))
1894 "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
1895 && exact_log2 (INTVAL (operands[2]) & 0xffffffff) >= 0"
1896 "* return avr_out_sbxx_branch (insn, operands);"
1897 [(set (attr "length")
1898 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
1899 (le (minus (pc) (match_dup 3)) (const_int 2046)))
1901 (if_then_else (eq_attr "mcu_mega" "no")
1904 (set_attr "cc" "clobber")])
1906 ;; Convert sign tests to bit 7/15/31 tests that match the above insns.
1908 [(set (cc0) (match_operand:QI 0 "register_operand" ""))
1909 (set (pc) (if_then_else (ge (cc0) (const_int 0))
1910 (label_ref (match_operand 1 "" ""))
1913 [(set (pc) (if_then_else (eq (zero_extract (match_dup 0)
1917 (label_ref (match_dup 1))
1922 [(set (cc0) (match_operand:QI 0 "register_operand" ""))
1923 (set (pc) (if_then_else (lt (cc0) (const_int 0))
1924 (label_ref (match_operand 1 "" ""))
1927 [(set (pc) (if_then_else (ne (zero_extract (match_dup 0)
1931 (label_ref (match_dup 1))
1936 [(set (cc0) (match_operand:HI 0 "register_operand" ""))
1937 (set (pc) (if_then_else (ge (cc0) (const_int 0))
1938 (label_ref (match_operand 1 "" ""))
1941 [(set (pc) (if_then_else (eq (and:HI (match_dup 0) (const_int -32768))
1943 (label_ref (match_dup 1))
1948 [(set (cc0) (match_operand:HI 0 "register_operand" ""))
1949 (set (pc) (if_then_else (lt (cc0) (const_int 0))
1950 (label_ref (match_operand 1 "" ""))
1953 [(set (pc) (if_then_else (ne (and:HI (match_dup 0) (const_int -32768))
1955 (label_ref (match_dup 1))
1960 [(set (cc0) (match_operand:SI 0 "register_operand" ""))
1961 (set (pc) (if_then_else (ge (cc0) (const_int 0))
1962 (label_ref (match_operand 1 "" ""))
1965 [(set (pc) (if_then_else (eq (and:SI (match_dup 0) (match_dup 2))
1967 (label_ref (match_dup 1))
1969 "operands[2] = GEN_INT (-2147483647 - 1);")
1972 [(set (cc0) (match_operand:SI 0 "register_operand" ""))
1973 (set (pc) (if_then_else (lt (cc0) (const_int 0))
1974 (label_ref (match_operand 1 "" ""))
1977 [(set (pc) (if_then_else (ne (and:SI (match_dup 0) (match_dup 2))
1979 (label_ref (match_dup 1))
1981 "operands[2] = GEN_INT (-2147483647 - 1);")
1983 ;; ************************************************************************
1984 ;; Implementation of conditional jumps here.
1985 ;; Compare with 0 (test) jumps
1986 ;; ************************************************************************
1988 (define_insn "branch"
1990 (if_then_else (match_operator 1 "comparison_operator"
1993 (label_ref (match_operand 0 "" ""))
1995 "! (GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
1996 || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
1998 return ret_cond_branch (operands[1], avr_jump_mode (operands[0],insn), 0);"
1999 [(set_attr "type" "branch")
2000 (set_attr "cc" "clobber")])
2002 (define_insn "difficult_branch"
2004 (if_then_else (match_operator 1 "comparison_operator"
2007 (label_ref (match_operand 0 "" ""))
2009 "(GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
2010 || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
2012 return ret_cond_branch (operands[1], avr_jump_mode (operands[0],insn), 0);"
2013 [(set_attr "type" "branch1")
2014 (set_attr "cc" "clobber")])
2018 (define_insn "rvbranch"
2020 (if_then_else (match_operator 1 "comparison_operator" [(cc0)
2023 (label_ref (match_operand 0 "" ""))))]
2024 "! (GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
2025 || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
2027 return ret_cond_branch (operands[1], avr_jump_mode (operands[0], insn), 1);"
2028 [(set_attr "type" "branch1")
2029 (set_attr "cc" "clobber")])
2031 (define_insn "difficult_rvbranch"
2033 (if_then_else (match_operator 1 "comparison_operator" [(cc0)
2036 (label_ref (match_operand 0 "" ""))))]
2037 "(GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
2038 || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
2040 return ret_cond_branch (operands[1], avr_jump_mode (operands[0], insn), 1);"
2041 [(set_attr "type" "branch")
2042 (set_attr "cc" "clobber")])
2044 ;; **************************************************************************
2045 ;; Unconditional and other jump instructions.
2049 (label_ref (match_operand 0 "" "")))]
2052 if (AVR_MEGA && get_attr_length (insn) != 1)
2053 return AS1 (jmp,%0);
2054 return AS1 (rjmp,%0);
2056 [(set (attr "length")
2057 (if_then_else (and (ge (minus (pc) (match_dup 0)) (const_int -2047))
2058 (le (minus (pc) (match_dup 0)) (const_int 2047)))
2061 (set_attr "cc" "none")])
2065 (define_expand "call"
2066 [(call (match_operand:HI 0 "call_insn_operand" "")
2067 (match_operand:HI 1 "general_operand" ""))]
2068 ;; Operand 1 not used on the AVR.
2074 (define_expand "call_value"
2075 [(set (match_operand 0 "register_operand" "")
2076 (call (match_operand:HI 1 "call_insn_operand" "")
2077 (match_operand:HI 2 "general_operand" "")))]
2078 ;; Operand 2 not used on the AVR.
2082 (define_insn "call_insn"
2083 [(call (mem:HI (match_operand:HI 0 "nonmemory_operand" "!z,*r,s,n"))
2084 (match_operand:HI 1 "general_operand" "X,X,X,X"))]
2085 ;; We don't need in saving Z register because r30,r31 is a call used registers
2086 ;; Operand 1 not used on the AVR.
2087 "(register_operand (operands[0], HImode) || CONSTANT_P (operands[0]))"
2089 if (which_alternative==0)
2091 else if (which_alternative==1)
2094 return (AS2 (movw, r30, %0) CR_TAB
2097 return (AS2 (mov, r30, %A0) CR_TAB
2098 AS2 (mov, r31, %B0) CR_TAB
2101 else if (which_alternative==2)
2102 return AS1(%~call,%c0);
2103 return (AS2 (ldi,r30,lo8(%0)) CR_TAB
2104 AS2 (ldi,r31,hi8(%0)) CR_TAB
2107 [(set_attr "cc" "clobber,clobber,clobber,clobber")
2108 (set_attr_alternative "length"
2110 (if_then_else (eq_attr "mcu_enhanced" "yes")
2113 (if_then_else (eq_attr "mcu_mega" "yes")
2118 (define_insn "call_value_insn"
2119 [(set (match_operand 0 "register_operand" "=r,r,r,r")
2120 (call (mem:HI (match_operand:HI 1 "nonmemory_operand" "!z,*r,s,n"))
2121 ;; We don't need in saving Z register because r30,r31 is a call used registers
2122 (match_operand:HI 2 "general_operand" "X,X,X,X")))]
2123 ;; Operand 2 not used on the AVR.
2124 "(register_operand (operands[0], VOIDmode) || CONSTANT_P (operands[0]))"
2126 if (which_alternative==0)
2128 else if (which_alternative==1)
2131 return (AS2 (movw, r30, %1) CR_TAB
2134 return (AS2 (mov, r30, %A1) CR_TAB
2135 AS2 (mov, r31, %B1) CR_TAB
2138 else if (which_alternative==2)
2139 return AS1(%~call,%c1);
2140 return (AS2 (ldi, r30, lo8(%1)) CR_TAB
2141 AS2 (ldi, r31, hi8(%1)) CR_TAB
2144 [(set_attr "cc" "clobber,clobber,clobber,clobber")
2145 (set_attr_alternative "length"
2147 (if_then_else (eq_attr "mcu_enhanced" "yes")
2150 (if_then_else (eq_attr "mcu_mega" "yes")
2155 (define_insn "return"
2157 "reload_completed && avr_simple_epilogue ()"
2159 [(set_attr "cc" "none")
2160 (set_attr "length" "1")])
2166 [(set_attr "cc" "none")
2167 (set_attr "length" "1")])
2170 (define_insn "indirect_jump"
2171 [(set (pc) (match_operand:HI 0 "register_operand" "!z,*r"))]
2175 push %A0\;push %B0\;ret"
2176 [(set_attr "length" "1,3")
2177 (set_attr "cc" "none,none")])
2181 ;; Table made from "rjmp" instructions for <=8K devices.
2182 (define_insn "*tablejump_rjmp"
2183 [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "!z,*r")] 1))
2184 (use (label_ref (match_operand 1 "" "")))
2185 (clobber (match_dup 0))]
2189 push %A0\;push %B0\;ret"
2190 [(set_attr "length" "1,3")
2191 (set_attr "cc" "none,none")])
2193 ;; Not a prologue, but similar idea - move the common piece of code to libgcc.
2194 (define_insn "*tablejump_lib"
2195 [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")] 1))
2196 (use (label_ref (match_operand 1 "" "")))
2197 (clobber (match_dup 0))]
2198 "AVR_MEGA && TARGET_CALL_PROLOGUES"
2199 "jmp __tablejump2__"
2200 [(set_attr "length" "2")
2201 (set_attr "cc" "clobber")])
2203 (define_insn "*tablejump_enh"
2204 [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")] 1))
2205 (use (label_ref (match_operand 1 "" "")))
2206 (clobber (match_dup 0))]
2207 "AVR_MEGA && AVR_ENHANCED"
2214 [(set_attr "length" "6")
2215 (set_attr "cc" "clobber")])
2217 (define_insn "*tablejump"
2218 [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")] 1))
2219 (use (label_ref (match_operand 1 "" "")))
2220 (clobber (match_dup 0))]
2230 [(set_attr "length" "8")
2231 (set_attr "cc" "clobber")])
2233 (define_expand "casesi"
2235 (minus:HI (subreg:HI (match_operand:SI 0 "register_operand" "") 0)
2236 (match_operand:HI 1 "register_operand" "")))
2237 (parallel [(set (cc0)
2238 (compare (match_dup 6)
2239 (match_operand:HI 2 "register_operand" "")))
2240 (clobber (match_scratch:QI 9 ""))])
2243 (if_then_else (gtu (cc0)
2245 (label_ref (match_operand 4 "" ""))
2249 (plus:HI (match_dup 6) (label_ref (match_operand:HI 3 "" ""))))
2251 (parallel [(set (pc) (unspec:HI [(match_dup 6)] 1))
2252 (use (label_ref (match_dup 3)))
2253 (clobber (match_dup 6))])]
2257 operands[6] = gen_reg_rtx (HImode);
2261 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2262 ;; This instruction sets Z flag
2265 [(set (cc0) (const_int 0))]
2268 [(set_attr "length" "1")
2269 (set_attr "cc" "compare")])
2271 ;; Clear/set/test a single bit in I/O address space.
2274 [(set (mem:QI (match_operand 0 "const_int_operand" "n"))
2275 (and:QI (mem:QI (match_dup 0))
2276 (match_operand 1 "const_int_operand" "n")))]
2277 "avr_io_address_p (operands[0], 1 + 0x20)
2278 && exact_log2 (~INTVAL (operands[1]) & 0xff) >= 0"
2280 operands[2] = GEN_INT (exact_log2 (~INTVAL (operands[1]) & 0xff));
2281 return AS2 (cbi,%0-0x20,%2);
2283 [(set_attr "length" "1")
2284 (set_attr "cc" "none")])
2287 [(set (mem:QI (match_operand 0 "const_int_operand" "n"))
2288 (ior:QI (mem:QI (match_dup 0))
2289 (match_operand 1 "const_int_operand" "n")))]
2290 "avr_io_address_p (operands[0], 1 + 0x20)
2291 && exact_log2 (INTVAL (operands[1]) & 0xff) >= 0"
2293 operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1]) & 0xff));
2294 return AS2 (sbi,%0-0x20,%2);
2296 [(set_attr "length" "1")
2297 (set_attr "cc" "none")])
2299 ;; Lower half of the I/O space - use sbic/sbis directly.
2300 (define_insn "*sbix_branch"
2303 (match_operator 0 "comparison_operator"
2305 (mem:QI (match_operand 1 "const_int_operand" "n"))
2307 (match_operand 2 "const_int_operand" "n"))
2309 (label_ref (match_operand 3 "" ""))
2311 "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
2312 && avr_io_address_p (operands[1], 1 + 0x20)"
2313 "* return avr_out_sbxx_branch (insn, operands);"
2314 [(set (attr "length")
2315 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
2316 (le (minus (pc) (match_dup 3)) (const_int 2046)))
2318 (if_then_else (eq_attr "mcu_mega" "no")
2321 (set_attr "cc" "clobber")])
2323 ;; Tests of bit 7 are pessimized to sign tests, so we need this too...
2324 (define_insn "*sbix_branch_bit7"
2327 (match_operator 0 "comparison_operator"
2328 [(mem:QI (match_operand 1 "const_int_operand" "n"))
2330 (label_ref (match_operand 2 "" ""))
2332 "(GET_CODE (operands[0]) == GE || GET_CODE (operands[0]) == LT)
2333 && avr_io_address_p (operands[1], 1 + 0x20)"
2335 operands[3] = operands[2];
2336 operands[2] = GEN_INT (7);
2337 return avr_out_sbxx_branch (insn, operands);
2339 [(set (attr "length")
2340 (if_then_else (and (ge (minus (pc) (match_dup 2)) (const_int -2046))
2341 (le (minus (pc) (match_dup 2)) (const_int 2046)))
2343 (if_then_else (eq_attr "mcu_mega" "no")
2346 (set_attr "cc" "clobber")])
2348 ;; Upper half of the I/O space - read port to __tmp_reg__ and use sbrc/sbrs.
2349 (define_insn "*sbix_branch_tmp"
2352 (match_operator 0 "comparison_operator"
2354 (mem:QI (match_operand 1 "const_int_operand" "n"))
2356 (match_operand 2 "const_int_operand" "n"))
2358 (label_ref (match_operand 3 "" ""))
2360 "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
2361 && avr_io_address_p (operands[1], 1) && INTVAL (operands[1]) >= 0x40"
2362 "* return avr_out_sbxx_branch (insn, operands);"
2363 [(set (attr "length")
2364 (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
2365 (le (minus (pc) (match_dup 3)) (const_int 2045)))
2367 (if_then_else (eq_attr "mcu_mega" "no")
2370 (set_attr "cc" "clobber")])
2372 (define_insn "*sbix_branch_tmp_bit7"
2375 (match_operator 0 "comparison_operator"
2376 [(mem:QI (match_operand 1 "const_int_operand" "n"))
2378 (label_ref (match_operand 2 "" ""))
2380 "(GET_CODE (operands[0]) == GE || GET_CODE (operands[0]) == LT)
2381 && avr_io_address_p (operands[1], 1) && INTVAL (operands[1]) >= 0x40"
2383 operands[3] = operands[2];
2384 operands[2] = GEN_INT (7);
2385 return avr_out_sbxx_branch (insn, operands);
2387 [(set (attr "length")
2388 (if_then_else (and (ge (minus (pc) (match_dup 2)) (const_int -2046))
2389 (le (minus (pc) (match_dup 2)) (const_int 2045)))
2391 (if_then_else (eq_attr "mcu_mega" "no")
2394 (set_attr "cc" "clobber")])
2396 ;; ************************* Peepholes ********************************
2399 [(set (match_operand:SI 0 "register_operand" "")
2400 (plus:SI (match_dup 0)
2404 (compare (match_dup 0)
2406 (clobber (match_operand:QI 1 "register_operand" ""))])
2408 (if_then_else (ne (cc0) (const_int 0))
2409 (label_ref (match_operand 2 "" ""))
2411 "(test_hard_reg_class (LD_REGS, operands[0])
2412 && test_hard_reg_class (LD_REGS, operands[1]))"
2416 if (test_hard_reg_class (ADDW_REGS, operands[0]))
2417 output_asm_insn (AS2 (sbiw,%0,1) CR_TAB
2418 AS2 (sbc,%C0,__zero_reg__) CR_TAB
2419 AS2 (sbc,%D0,__zero_reg__) \"\\n\", operands);
2421 output_asm_insn (AS2 (subi,%A0,1) CR_TAB
2422 AS2 (sbc,%B0,__zero_reg__) CR_TAB
2423 AS2 (sbc,%C0,__zero_reg__) CR_TAB
2424 AS2 (sbc,%D0,__zero_reg__) \"\\n\", operands);
2425 switch (avr_jump_mode (operands[2],insn))
2428 return AS1 (brcc,%2);
2430 return (AS1 (brcs,.+2) CR_TAB
2433 return (AS1 (brcs,.+4) CR_TAB
2438 [(set (match_operand:HI 0 "register_operand" "")
2439 (plus:HI (match_dup 0)
2443 (compare (match_dup 0)
2445 (clobber (match_operand:QI 1 "register_operand" ""))])
2447 (if_then_else (ne (cc0) (const_int 0))
2448 (label_ref (match_operand 2 "" ""))
2450 "(test_hard_reg_class (LD_REGS, operands[0])
2451 && test_hard_reg_class (LD_REGS, operands[1]))"
2455 if (test_hard_reg_class (ADDW_REGS, operands[0]))
2456 output_asm_insn (AS2 (sbiw,%0,1), operands);
2458 output_asm_insn (AS2 (subi,%A0,1) CR_TAB
2459 AS2 (sbc,%B0,__zero_reg__) \"\\n\", operands);
2460 switch (avr_jump_mode (operands[2],insn))
2463 return AS1 (brcc,%2);
2465 return (AS1 (brcs,.+2) CR_TAB
2468 return (AS1 (brcs,.+4) CR_TAB
2473 [(set (match_operand:QI 0 "register_operand" "")
2474 (plus:QI (match_dup 0)
2477 (compare (match_dup 0)
2480 (if_then_else (ne (cc0) (const_int 0))
2481 (label_ref (match_operand 1 "" ""))
2483 "test_hard_reg_class (LD_REGS, operands[0])"
2487 cc_status.value1 = operands[0];
2488 cc_status.flags |= CC_OVERFLOW_UNUSABLE;
2489 output_asm_insn (AS2 (subi,%A0,1), operands);
2490 switch (avr_jump_mode (operands[1],insn))
2493 return AS1 (brcc,%1);
2495 return (AS1 (brcs,.+2) CR_TAB
2498 return (AS1 (brcs,.+4) CR_TAB
2503 [(set (cc0) (match_operand:QI 0 "register_operand" ""))
2505 (if_then_else (eq (cc0) (const_int 0))
2506 (label_ref (match_operand 1 "" ""))
2508 "jump_over_one_insn_p (insn, operands[1])"
2509 "cpse %0,__zero_reg__")
2513 (compare (match_operand:QI 0 "register_operand" "")
2514 (match_operand:QI 1 "register_operand" "")))
2516 (if_then_else (eq (cc0) (const_int 0))
2517 (label_ref (match_operand 2 "" ""))
2519 "jump_over_one_insn_p (insn, operands[2])"