Merge cond-optab branch.
[official-gcc.git] / gcc / config / avr / avr.md
blob86a217dc23c99bc4845e700905912a0b0db73fc0
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, 2006, 2007, 2008
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 3, or (at your option)
13 ;; any later version.
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 COPYING3.  If not see
22 ;; <http://www.gnu.org/licenses/>.
24 ;; Special characters after '%':
25 ;;  A  No effect (add 0).
26 ;;  B  Add 1 to REG number, MEM address or CONST_INT.
27 ;;  C  Add 2.
28 ;;  D  Add 3.
29 ;;  j  Branch condition.
30 ;;  k  Reverse branch condition.
31 ;;  o  Displacement for (mem (plus (reg) (const_int))) operands.
32 ;;  p  POST_INC or PRE_DEC address as a pointer (X, Y, Z)
33 ;;  r  POST_INC or PRE_DEC address as a register (r26, r28, r30)
34 ;;  ~  Output 'r' if not AVR_HAVE_JMP_CALL.
35 ;;  !  Output 'e' if AVR_HAVE_EIJMP_EICALL.
37 ;; UNSPEC usage:
38 ;;  0  Length of a string, see "strlenhi".
39 ;;  1  Jump by register pair Z or by table addressed by Z, see "casesi".
41 (define_constants
42   [(REG_X       26)
43    (REG_Y       28)
44    (REG_Z       30)
45    (REG_W       24)
46    (REG_SP      32)
47    (TMP_REGNO   0)      ; temporary register r0
48    (ZERO_REGNO  1)      ; zero register r1
49    
50    (SREG_ADDR   0x5F)
51    (RAMPZ_ADDR  0x5B)
52    
53    (UNSPEC_STRLEN       0)
54    (UNSPEC_INDEX_JMP    1)
55    (UNSPEC_SEI          2)
56    (UNSPEC_CLI          3)
58    (UNSPECV_PROLOGUE_SAVES      0)
59    (UNSPECV_EPILOGUE_RESTORES   1)
60    (UNSPECV_WRITE_SP_IRQ_ON     2)
61    (UNSPECV_WRITE_SP_IRQ_OFF    3)
62    (UNSPECV_GOTO_RECEIVER       4)])
64 (include "predicates.md")
65 (include "constraints.md")
66   
67 ;; Condition code settings.
68 (define_attr "cc" "none,set_czn,set_zn,set_n,compare,clobber"
69   (const_string "none"))
71 (define_attr "type" "branch,branch1,arith,xcall"
72   (const_string "arith"))
74 (define_attr "mcu_have_movw" "yes,no"
75   (const (if_then_else (symbol_ref "AVR_HAVE_MOVW")
76                        (const_string "yes")
77                        (const_string "no"))))
79 (define_attr "mcu_mega" "yes,no"
80   (const (if_then_else (symbol_ref "AVR_HAVE_JMP_CALL")
81                        (const_string "yes")
82                        (const_string "no"))))
83   
85 ;; The size of instructions in bytes.
86 ;; XXX may depend from "cc"
88 (define_attr "length" ""
89   (cond [(eq_attr "type" "branch")
90          (if_then_else (and (ge (minus (pc) (match_dup 0))
91                                 (const_int -63))
92                             (le (minus (pc) (match_dup 0))
93                                 (const_int 62)))
94                        (const_int 1)
95                        (if_then_else (and (ge (minus (pc) (match_dup 0))
96                                               (const_int -2045))
97                                           (le (minus (pc) (match_dup 0))
98                                               (const_int 2045)))
99                                      (const_int 2)
100                                      (const_int 3)))
101          (eq_attr "type" "branch1")
102          (if_then_else (and (ge (minus (pc) (match_dup 0))
103                                 (const_int -62))
104                             (le (minus (pc) (match_dup 0))
105                                 (const_int 61)))
106                        (const_int 2)
107                        (if_then_else (and (ge (minus (pc) (match_dup 0))
108                                               (const_int -2044))
109                                           (le (minus (pc) (match_dup 0))
110                                               (const_int 2043)))
111                                      (const_int 3)
112                                      (const_int 4)))
113          (eq_attr "type" "xcall")
114          (if_then_else (eq_attr "mcu_mega" "no")
115                        (const_int 1)
116                        (const_int 2))]
117         (const_int 2)))
119 ;; Define mode iterator
120 (define_mode_iterator QISI [(QI "") (HI "") (SI "")])
122 ;;========================================================================
123 ;; The following is used by nonlocal_goto and setjmp.
124 ;; The receiver pattern will create no instructions since internally
125 ;; virtual_stack_vars = hard_frame_pointer + 1 so the RTL become R28=R28
126 ;; This avoids creating add/sub offsets in frame_pointer save/resore.
127 ;; The 'null' receiver also avoids  problems with optimisation
128 ;; not recognising incoming jmp and removing code that resets frame_pointer.
129 ;; The code derived from builtins.c.
131 (define_expand "nonlocal_goto_receiver"
132   [(set (reg:HI REG_Y) 
133         (unspec_volatile:HI [(const_int 0)] UNSPECV_GOTO_RECEIVER))]
134   ""
135   {
136     emit_move_insn (virtual_stack_vars_rtx, 
137                     gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, 
138                                   gen_int_mode (STARTING_FRAME_OFFSET,
139                                                 Pmode)));
140   /* This might change the hard frame pointer in ways that aren't
141     apparent to early optimization passes, so force a clobber.  */
142     emit_clobber (hard_frame_pointer_rtx);
143     DONE;
144   })
145   
147 ;; Defining nonlocal_goto_receiver means we must also define this.
148 ;; even though its function is identical to that in builtins.c
150 (define_expand "nonlocal_goto"
151   [
152   (use (match_operand 0 "general_operand"))
153   (use (match_operand 1 "general_operand"))
154   (use (match_operand 2 "general_operand"))
155   (use (match_operand 3 "general_operand"))
156   ]
157   ""
159   rtx r_label = copy_to_reg (operands[1]);
160   rtx r_fp = operands[3];
161   rtx r_sp = operands[2];
163   emit_clobber (gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode)));
165   emit_clobber (gen_rtx_MEM (BLKmode, hard_frame_pointer_rtx));
167   emit_move_insn (hard_frame_pointer_rtx, r_fp);
168   emit_stack_restore (SAVE_NONLOCAL, r_sp, NULL_RTX);
170   emit_use (hard_frame_pointer_rtx);
171   emit_use (stack_pointer_rtx);
173   emit_indirect_jump (r_label);
175   DONE;
179 (define_insn "*pushqi"
180   [(set (mem:QI (post_dec (reg:HI REG_SP)))
181         (match_operand:QI 0 "reg_or_0_operand" "r,L"))]
182   ""
183   "@
184         push %0
185         push __zero_reg__"
186   [(set_attr "length" "1,1")])
189 (define_insn "*pushhi"
190   [(set (mem:HI (post_dec (reg:HI REG_SP)))
191         (match_operand:HI 0 "reg_or_0_operand" "r,L"))]
192   ""
193   "@
194         push %B0\;push %A0
195         push __zero_reg__\;push __zero_reg__"
196   [(set_attr "length" "2,2")])
198 (define_insn "*pushsi"
199   [(set (mem:SI (post_dec (reg:HI REG_SP)))
200         (match_operand:SI 0 "reg_or_0_operand" "r,L"))]
201   ""
202   "@
203         push %D0\;push %C0\;push %B0\;push %A0
204         push __zero_reg__\;push __zero_reg__\;push __zero_reg__\;push __zero_reg__"
205   [(set_attr "length" "4,4")])
207 (define_insn "*pushsf"
208   [(set (mem:SF (post_dec (reg:HI REG_SP)))
209         (match_operand:SF 0 "register_operand" "r"))]
210   ""
211   "push %D0
212         push %C0
213         push %B0
214         push %A0"
215   [(set_attr "length" "4")])
217 ;;========================================================================
218 ;; move byte
219 ;; The last alternative (any immediate constant to any register) is
220 ;; very expensive.  It should be optimized by peephole2 if a scratch
221 ;; register is available, but then that register could just as well be
222 ;; allocated for the variable we are loading.  But, most of NO_LD_REGS
223 ;; are call-saved registers, and most of LD_REGS are call-used registers,
224 ;; so this may still be a win for registers live across function calls.
226 (define_expand "movqi"
227   [(set (match_operand:QI 0 "nonimmediate_operand" "")
228         (match_operand:QI 1 "general_operand" ""))]
229   ""
230   "/* One of the ops has to be in a register.  */
231    if (!register_operand(operand0, QImode)
232        && ! (register_operand(operand1, QImode) || const0_rtx == operand1))
233        operands[1] = copy_to_mode_reg(QImode, operand1);
234   ")
236 (define_insn "*movqi"
237   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,d,Qm,r,q,r,*r")
238         (match_operand:QI 1 "general_operand"       "r,i,rL,Qm,r,q,i"))]
239   "(register_operand (operands[0],QImode)
240     || register_operand (operands[1], QImode) || const0_rtx == operands[1])"
241   "* return output_movqi (insn, operands, NULL);"
242   [(set_attr "length" "1,1,5,5,1,1,4")
243    (set_attr "cc" "none,none,clobber,clobber,none,none,clobber")])
245 ;; This is used in peephole2 to optimize loading immediate constants
246 ;; if a scratch register from LD_REGS happens to be available.
248 (define_insn "*reload_inqi"
249   [(set (match_operand:QI 0 "register_operand" "=l")
250         (match_operand:QI 1 "immediate_operand" "i"))
251    (clobber (match_operand:QI 2 "register_operand" "=&d"))]
252   "reload_completed"
253   "ldi %2,lo8(%1)
254         mov %0,%2"
255   [(set_attr "length" "2")
256    (set_attr "cc" "none")])
258 (define_peephole2
259   [(match_scratch:QI 2 "d")
260    (set (match_operand:QI 0 "l_register_operand" "")
261         (match_operand:QI 1 "immediate_operand" ""))]
262   "(operands[1] != const0_rtx
263     && operands[1] != const1_rtx
264     && operands[1] != constm1_rtx)"
265   [(parallel [(set (match_dup 0) (match_dup 1))
266               (clobber (match_dup 2))])]
267   "")
269 ;;============================================================================
270 ;; move word (16 bit)
272 (define_expand "movhi"
273   [(set (match_operand:HI 0 "nonimmediate_operand" "")
274         (match_operand:HI 1 "general_operand"       ""))]
275   ""
276   "
278    /* One of the ops has to be in a register.  */
279   if (!register_operand(operand0, HImode)
280       && !(register_operand(operand1, HImode) || const0_rtx == operands[1]))
281     {
282       operands[1] = copy_to_mode_reg(HImode, operand1);
283     }
286 (define_insn "*movhi_sp"
287   [(set (match_operand:HI 0 "register_operand" "=q,r")
288         (match_operand:HI 1 "register_operand"  "r,q"))]
289   "((stack_register_operand(operands[0], HImode) && register_operand (operands[1], HImode))
290     || (register_operand (operands[0], HImode) && stack_register_operand(operands[1], HImode)))"
291   "* return output_movhi (insn, operands, NULL);"
292   [(set_attr "length" "5,2")
293    (set_attr "cc" "none,none")])
295 (define_insn "movhi_sp_r_irq_off"
296   [(set (match_operand:HI 0 "stack_register_operand" "=q")
297         (unspec_volatile:HI [(match_operand:HI 1 "register_operand"  "r")] 
298                             UNSPECV_WRITE_SP_IRQ_OFF))]
299   ""
300   "out __SP_H__, %B1
301         out __SP_L__, %A1"
302   [(set_attr "length" "2")
303    (set_attr "cc" "none")])
305 (define_insn "movhi_sp_r_irq_on"
306   [(set (match_operand:HI 0 "stack_register_operand" "=q")
307         (unspec_volatile:HI [(match_operand:HI 1 "register_operand"  "r")] 
308                             UNSPECV_WRITE_SP_IRQ_ON))]
309   ""
310   "cli
311         out __SP_H__, %B1
312         sei
313         out __SP_L__, %A1"
314   [(set_attr "length" "4")
315    (set_attr "cc" "none")])
317 (define_peephole2
318   [(match_scratch:QI 2 "d")
319    (set (match_operand:HI 0 "l_register_operand" "")
320         (match_operand:HI 1 "immediate_operand" ""))]
321   "(operands[1] != const0_rtx 
322     && operands[1] != constm1_rtx)"
323   [(parallel [(set (match_dup 0) (match_dup 1))
324               (clobber (match_dup 2))])]
325   "")
327 ;; '*' because it is not used in rtl generation, only in above peephole
328 (define_insn "*reload_inhi"
329   [(set (match_operand:HI 0 "register_operand" "=r")
330         (match_operand:HI 1 "immediate_operand" "i"))
331    (clobber (match_operand:QI 2 "register_operand" "=&d"))]
332   "reload_completed"
333   "* return output_reload_inhi (insn, operands, NULL);"
334   [(set_attr "length" "4")
335    (set_attr "cc" "none")])
337 (define_insn "*movhi"
338   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,d,*r,q,r")
339         (match_operand:HI 1 "general_operand"       "r,m,rL,i,i,r,q"))]
340   "(register_operand (operands[0],HImode)
341     || register_operand (operands[1],HImode) || const0_rtx == operands[1])"
342   "* return output_movhi (insn, operands, NULL);"
343   [(set_attr "length" "2,6,7,2,6,5,2")
344    (set_attr "cc" "none,clobber,clobber,none,clobber,none,none")])
346 (define_peephole2 ; movw
347   [(set (match_operand:QI 0 "even_register_operand" "")
348         (match_operand:QI 1 "even_register_operand" ""))
349    (set (match_operand:QI 2 "odd_register_operand" "")
350         (match_operand:QI 3 "odd_register_operand" ""))]
351   "(AVR_HAVE_MOVW
352     && REGNO (operands[0]) == REGNO (operands[2]) - 1
353     && REGNO (operands[1]) == REGNO (operands[3]) - 1)"
354   [(set (match_dup 4) (match_dup 5))]
355   {
356     operands[4] = gen_rtx_REG (HImode, REGNO (operands[0]));
357     operands[5] = gen_rtx_REG (HImode, REGNO (operands[1]));
358   })
360 (define_peephole2 ; movw_r
361   [(set (match_operand:QI 0 "odd_register_operand" "")
362         (match_operand:QI 1 "odd_register_operand" ""))
363    (set (match_operand:QI 2 "even_register_operand" "")
364         (match_operand:QI 3 "even_register_operand" ""))]
365   "(AVR_HAVE_MOVW
366     && REGNO (operands[2]) == REGNO (operands[0]) - 1
367     && REGNO (operands[3]) == REGNO (operands[1]) - 1)"
368   [(set (match_dup 4) (match_dup 5))]
369   {
370     operands[4] = gen_rtx_REG (HImode, REGNO (operands[2]));
371     operands[5] = gen_rtx_REG (HImode, REGNO (operands[3]));
372   })
374 ;;==========================================================================
375 ;; move double word (32 bit)
377 (define_expand "movsi"
378   [(set (match_operand:SI 0 "nonimmediate_operand" "")
379         (match_operand:SI 1 "general_operand"  ""))]
380   ""
381   "
383   /* One of the ops has to be in a register.  */
384   if (!register_operand (operand0, SImode)
385       && !(register_operand (operand1, SImode) || const0_rtx == operand1))
386     {
387       operands[1] = copy_to_mode_reg (SImode, operand1);
388     }
393 (define_peephole2 ; movsi_lreg_const
394   [(match_scratch:QI 2 "d")
395    (set (match_operand:SI 0 "l_register_operand" "")
396         (match_operand:SI 1 "immediate_operand" ""))
397    (match_dup 2)]
398   "(operands[1] != const0_rtx
399     && operands[1] != constm1_rtx)"
400   [(parallel [(set (match_dup 0) (match_dup 1))
401               (clobber (match_dup 2))])]
402   "")
404 ;; '*' because it is not used in rtl generation.
405 (define_insn "*reload_insi"
406   [(set (match_operand:SI 0 "register_operand" "=r")
407         (match_operand:SI 1 "immediate_operand" "i"))
408    (clobber (match_operand:QI 2 "register_operand" "=&d"))]
409   "reload_completed"
410   "* return output_reload_insisf (insn, operands, NULL);"
411   [(set_attr "length" "8")
412    (set_attr "cc" "none")])
415 (define_insn "*movsi"
416   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,Qm,!d,r")
417         (match_operand:SI 1 "general_operand"       "r,L,Qm,rL,i,i"))]
418   "(register_operand (operands[0],SImode)
419     || register_operand (operands[1],SImode) || const0_rtx == operands[1])"
420   "* return output_movsisf (insn, operands, NULL);"
421   [(set_attr "length" "4,4,8,9,4,10")
422    (set_attr "cc" "none,set_zn,clobber,clobber,none,clobber")])
424 ;; fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
425 ;; move floating point numbers (32 bit)
427 (define_expand "movsf"
428   [(set (match_operand:SF 0 "nonimmediate_operand" "")
429         (match_operand:SF 1 "general_operand"  ""))]
430   ""
431   "
433   /* One of the ops has to be in a register.  */
434   if (!register_operand (operand1, SFmode)
435       && !register_operand (operand0, SFmode))
436     {
437       operands[1] = copy_to_mode_reg (SFmode, operand1);
438     }
441 (define_insn "*movsf"
442   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,r,Qm,!d,r")
443         (match_operand:SF 1 "general_operand"       "r,G,Qm,r,F,F"))]
444   "register_operand (operands[0], SFmode)
445    || register_operand (operands[1], SFmode)"
446   "* return output_movsisf (insn, operands, NULL);"
447   [(set_attr "length" "4,4,8,9,4,10")
448    (set_attr "cc" "none,set_zn,clobber,clobber,none,clobber")])
450 ;;=========================================================================
451 ;; move string (like memcpy)
452 ;; implement as RTL loop
454 (define_expand "movmemhi"
455   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
456           (match_operand:BLK 1 "memory_operand" ""))
457           (use (match_operand:HI 2 "const_int_operand" ""))
458           (use (match_operand:HI 3 "const_int_operand" ""))])]
459   ""
460   "{
461   int prob;
462   HOST_WIDE_INT count;
463   enum machine_mode mode;
464   rtx label = gen_label_rtx ();
465   rtx loop_reg;
466   rtx jump;
468   /* Copy pointers into new psuedos - they will be changed.  */
469   rtx addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
470   rtx addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
472   /* Create rtx for tmp register - we use this as scratch.  */
473   rtx tmp_reg_rtx  = gen_rtx_REG (QImode, TMP_REGNO);
475   if (GET_CODE (operands[2]) != CONST_INT)
476     FAIL;
478   count = INTVAL (operands[2]);
479   if (count <= 0)
480     FAIL;
482   /* Work out branch probability for latter use.  */
483   prob = REG_BR_PROB_BASE - REG_BR_PROB_BASE / count;
485   /* See if constant fit 8 bits.  */
486   mode = (count < 0x100) ? QImode : HImode;
487   /* Create loop counter register.  */
488   loop_reg = copy_to_mode_reg (mode, gen_int_mode (count, mode));
490   /* Now create RTL code for move loop.  */
491   /* Label at top of loop.  */
492   emit_label (label);
494   /* Move one byte into scratch and inc pointer.  */
495   emit_move_insn (tmp_reg_rtx, gen_rtx_MEM (QImode, addr1));
496   emit_move_insn (addr1, gen_rtx_PLUS (Pmode, addr1, const1_rtx));
498   /* Move to mem and inc pointer.  */
499   emit_move_insn (gen_rtx_MEM (QImode, addr0), tmp_reg_rtx);
500   emit_move_insn (addr0, gen_rtx_PLUS (Pmode, addr0, const1_rtx));
502   /* Decrement count.  */
503   emit_move_insn (loop_reg, gen_rtx_PLUS (mode, loop_reg, constm1_rtx));
505   /* Compare with zero and jump if not equal. */
506   emit_cmp_and_jump_insns (loop_reg, const0_rtx, NE, NULL_RTX, mode, 1,
507                            label);
508   /* Set jump probability based on loop count.  */
509   jump = get_last_insn ();
510   REG_NOTES (jump) = gen_rtx_EXPR_LIST (REG_BR_PROB,
511                     GEN_INT (prob),
512                     REG_NOTES (jump));
513   DONE;
516 ;; =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2
517 ;; memset (%0, %2, %1)
519 (define_expand "setmemhi"
520   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
521                    (match_operand 2 "const_int_operand" ""))
522               (use (match_operand:HI 1 "const_int_operand" ""))
523               (use (match_operand:HI 3 "const_int_operand" "n"))
524               (clobber (match_scratch:HI 4 ""))
525               (clobber (match_dup 5))])]
526   ""
527   "{
528   rtx addr0;
529   int cnt8;
530   enum machine_mode mode;
532   /* If value to set is not zero, use the library routine.  */
533   if (operands[2] != const0_rtx)
534     FAIL;
536   if (GET_CODE (operands[1]) != CONST_INT)
537     FAIL;
539   cnt8 = byte_immediate_operand (operands[1], GET_MODE (operands[1]));
540   mode = cnt8 ? QImode : HImode;
541   operands[5] = gen_rtx_SCRATCH (mode);
542   operands[1] = copy_to_mode_reg (mode,
543                                   gen_int_mode (INTVAL (operands[1]), mode));
544   addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
545   operands[0] = gen_rtx_MEM (BLKmode, addr0);
548 (define_insn "*clrmemqi"
549   [(set (mem:BLK (match_operand:HI 0 "register_operand" "e"))
550         (const_int 0))
551    (use (match_operand:QI 1 "register_operand" "r"))
552    (use (match_operand:QI 2 "const_int_operand" "n"))
553    (clobber (match_scratch:HI 3 "=0"))
554    (clobber (match_scratch:QI 4 "=&1"))]
555   ""
556   "st %a0+,__zero_reg__
557         dec %1
558         brne .-6"
559   [(set_attr "length" "3")
560    (set_attr "cc" "clobber")])
562 (define_insn "*clrmemhi"
563   [(set (mem:BLK (match_operand:HI 0 "register_operand" "e,e"))
564         (const_int 0))
565    (use (match_operand:HI 1 "register_operand" "!w,d"))
566    (use (match_operand:HI 2 "const_int_operand" "n,n"))
567    (clobber (match_scratch:HI 3 "=0,0"))
568    (clobber (match_scratch:HI 4 "=&1,&1"))]
569   ""
570   "*{
571      if (which_alternative==0)
572        return (AS2 (st,%a0+,__zero_reg__) CR_TAB
573                AS2 (sbiw,%A1,1) CR_TAB
574                AS1 (brne,.-6));
575      else
576        return (AS2 (st,%a0+,__zero_reg__) CR_TAB
577                AS2 (subi,%A1,1) CR_TAB
578                AS2 (sbci,%B1,0) CR_TAB
579                AS1 (brne,.-8));
581   [(set_attr "length" "3,4")
582    (set_attr "cc" "clobber,clobber")])
584 (define_expand "strlenhi"
585     [(set (match_dup 4)
586           (unspec:HI [(match_operand:BLK 1 "memory_operand" "")
587                       (match_operand:QI 2 "const_int_operand" "")
588                       (match_operand:HI 3 "immediate_operand" "")]
589                      UNSPEC_STRLEN))
590      (set (match_dup 4) (plus:HI (match_dup 4)
591                                  (const_int -1)))
592      (set (match_operand:HI 0 "register_operand" "")
593           (minus:HI (match_dup 4)
594                     (match_dup 5)))]
595    ""
596    "{
597   rtx addr;
598   if (! (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 0))
599     FAIL;
600   addr = copy_to_mode_reg (Pmode, XEXP (operands[1],0));
601   operands[1] = gen_rtx_MEM (BLKmode, addr); 
602   operands[5] = addr;
603   operands[4] = gen_reg_rtx (HImode);
606 (define_insn "*strlenhi"
607   [(set (match_operand:HI 0 "register_operand" "=e")
608         (unspec:HI [(mem:BLK (match_operand:HI 1 "register_operand" "%0"))
609                     (const_int 0)
610                     (match_operand:HI 2 "immediate_operand" "i")]
611                    UNSPEC_STRLEN))]
612   ""
613   "ld __tmp_reg__,%a0+
614         tst __tmp_reg__
615         brne .-6"
616   [(set_attr "length" "3")
617    (set_attr "cc" "clobber")])
619 ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
620 ; add bytes
622 (define_insn "addqi3"
623   [(set (match_operand:QI 0 "register_operand" "=r,d,r,r")
624         (plus:QI (match_operand:QI 1 "register_operand" "%0,0,0,0")
625                  (match_operand:QI 2 "nonmemory_operand" "r,i,P,N")))]
626   ""
627   "@
628         add %0,%2
629         subi %0,lo8(-(%2))
630         inc %0
631         dec %0"
632   [(set_attr "length" "1,1,1,1")
633    (set_attr "cc" "set_czn,set_czn,set_zn,set_zn")])
636 (define_expand "addhi3"
637   [(set (match_operand:HI 0 "register_operand" "")
638         (plus:HI (match_operand:HI 1 "register_operand" "")
639                  (match_operand:HI 2 "nonmemory_operand" "")))]
640   ""
641   "
643   if (GET_CODE (operands[2]) == CONST_INT)
644     {
645       short tmp = INTVAL (operands[2]);
646       operands[2] = GEN_INT(tmp);
647     }
651 (define_insn "*addhi3_zero_extend"
652   [(set (match_operand:HI 0 "register_operand" "=r")
653         (plus:HI (zero_extend:HI
654                   (match_operand:QI 1 "register_operand" "r"))
655                  (match_operand:HI 2 "register_operand" "0")))]
656   ""
657   "add %A0,%1
658         adc %B0,__zero_reg__"
659   [(set_attr "length" "2")
660    (set_attr "cc" "set_n")])
662 (define_insn "*addhi3_zero_extend1"
663   [(set (match_operand:HI 0 "register_operand" "=r")
664         (plus:HI (match_operand:HI 1 "register_operand" "%0")
665                  (zero_extend:HI
666                   (match_operand:QI 2 "register_operand" "r"))))]
667   ""
668   "add %A0,%2
669         adc %B0,__zero_reg__"
670   [(set_attr "length" "2")
671    (set_attr "cc" "set_n")])
673 (define_insn "*addhi3_sp_R_pc2"
674   [(set (match_operand:HI 1 "stack_register_operand" "=q")
675         (plus:HI (match_operand:HI 2 "stack_register_operand" "q")
676                  (match_operand:HI 0 "avr_sp_immediate_operand" "R")))]
677   "AVR_2_BYTE_PC"
678   "*{
679       if (CONST_INT_P (operands[0]))
680         {
681           switch(INTVAL (operands[0]))
682             {
683             case -6: 
684               return \"rcall .\" CR_TAB 
685                      \"rcall .\" CR_TAB 
686                      \"rcall .\";
687             case -5: 
688               return \"rcall .\" CR_TAB 
689                      \"rcall .\" CR_TAB 
690                      \"push __tmp_reg__\";
691             case -4: 
692               return \"rcall .\" CR_TAB 
693                      \"rcall .\";
694             case -3: 
695               return \"rcall .\" CR_TAB 
696                      \"push __tmp_reg__\";
697             case -2: 
698               return \"rcall .\";
699             case -1: 
700               return \"push __tmp_reg__\";
701             case 0: 
702               return \"\";
703             case 1: 
704               return \"pop __tmp_reg__\";
705             case 2: 
706               return \"pop __tmp_reg__\" CR_TAB 
707                      \"pop __tmp_reg__\";
708             case 3: 
709               return \"pop __tmp_reg__\" CR_TAB 
710                      \"pop __tmp_reg__\" CR_TAB 
711                      \"pop __tmp_reg__\";
712             case 4: 
713               return \"pop __tmp_reg__\" CR_TAB 
714                      \"pop __tmp_reg__\" CR_TAB 
715                      \"pop __tmp_reg__\" CR_TAB 
716                      \"pop __tmp_reg__\";
717             case 5: 
718               return \"pop __tmp_reg__\" CR_TAB 
719                      \"pop __tmp_reg__\" CR_TAB 
720                      \"pop __tmp_reg__\" CR_TAB 
721                      \"pop __tmp_reg__\" CR_TAB 
722                      \"pop __tmp_reg__\";
723             }
724         }
725       return \"bug\";
726     }"
727   [(set (attr "length") 
728         (cond [(eq (const_int -6) (symbol_ref "INTVAL (operands[0])")) (const_int 3)
729                (eq (const_int -5) (symbol_ref "INTVAL (operands[0])")) (const_int 3)
730                (eq (const_int -4) (symbol_ref "INTVAL (operands[0])")) (const_int 2)
731                (eq (const_int -3) (symbol_ref "INTVAL (operands[0])")) (const_int 2)
732                (eq (const_int -2) (symbol_ref "INTVAL (operands[0])")) (const_int 1)
733                (eq (const_int -1) (symbol_ref "INTVAL (operands[0])")) (const_int 1)
734                (eq (const_int  0) (symbol_ref "INTVAL (operands[0])")) (const_int 0)
735                (eq (const_int  1) (symbol_ref "INTVAL (operands[0])")) (const_int 1)
736                (eq (const_int  2) (symbol_ref "INTVAL (operands[0])")) (const_int 2)
737                (eq (const_int  3) (symbol_ref "INTVAL (operands[0])")) (const_int 3)
738                (eq (const_int  4) (symbol_ref "INTVAL (operands[0])")) (const_int 4)
739                (eq (const_int  5) (symbol_ref "INTVAL (operands[0])")) (const_int 5)]
740                (const_int 0)))])
742 (define_insn "*addhi3_sp_R_pc3"
743   [(set (match_operand:HI 1 "stack_register_operand" "=q")
744         (plus:HI (match_operand:HI 2 "stack_register_operand" "q")
745                  (match_operand:QI 0 "avr_sp_immediate_operand" "R")))]
746   "AVR_3_BYTE_PC"
747   "*{
748       if (CONST_INT_P (operands[0]))
749         {
750           switch(INTVAL (operands[0]))
751             {
752             case -6: 
753               return \"rcall .\" CR_TAB 
754                      \"rcall .\";
755             case -5: 
756               return \"rcall .\" CR_TAB 
757                      \"push __tmp_reg__\" CR_TAB 
758                      \"push __tmp_reg__\";
759             case -4: 
760               return \"rcall .\" CR_TAB 
761                      \"push __tmp_reg__\";
762             case -3: 
763               return \"rcall .\";
764             case -2: 
765               return \"push __tmp_reg__\" CR_TAB 
766                      \"push __tmp_reg__\";
767             case -1: 
768               return \"push __tmp_reg__\";
769             case 0: 
770               return \"\";
771             case 1: 
772               return \"pop __tmp_reg__\";
773             case 2: 
774               return \"pop __tmp_reg__\" CR_TAB 
775                      \"pop __tmp_reg__\";
776             case 3: 
777               return \"pop __tmp_reg__\" CR_TAB 
778                      \"pop __tmp_reg__\" CR_TAB 
779                      \"pop __tmp_reg__\";
780             case 4: 
781               return \"pop __tmp_reg__\" CR_TAB 
782                      \"pop __tmp_reg__\" CR_TAB 
783                      \"pop __tmp_reg__\" CR_TAB 
784                      \"pop __tmp_reg__\";
785             case 5: 
786               return \"pop __tmp_reg__\" CR_TAB 
787                      \"pop __tmp_reg__\" CR_TAB 
788                      \"pop __tmp_reg__\" CR_TAB 
789                      \"pop __tmp_reg__\" CR_TAB 
790                      \"pop __tmp_reg__\";
791             }
792         }
793       return \"bug\";
794     }"
795   [(set (attr "length") 
796         (cond [(eq (const_int -6) (symbol_ref "INTVAL (operands[0])")) (const_int 2)
797                (eq (const_int -5) (symbol_ref "INTVAL (operands[0])")) (const_int 3)
798                (eq (const_int -4) (symbol_ref "INTVAL (operands[0])")) (const_int 2)
799                (eq (const_int -3) (symbol_ref "INTVAL (operands[0])")) (const_int 1)
800                (eq (const_int -2) (symbol_ref "INTVAL (operands[0])")) (const_int 2)
801                (eq (const_int -1) (symbol_ref "INTVAL (operands[0])")) (const_int 1)
802                (eq (const_int  0) (symbol_ref "INTVAL (operands[0])")) (const_int 0)
803                (eq (const_int  1) (symbol_ref "INTVAL (operands[0])")) (const_int 1)
804                (eq (const_int  2) (symbol_ref "INTVAL (operands[0])")) (const_int 2)
805                (eq (const_int  3) (symbol_ref "INTVAL (operands[0])")) (const_int 3)
806                (eq (const_int  4) (symbol_ref "INTVAL (operands[0])")) (const_int 4)
807                (eq (const_int  5) (symbol_ref "INTVAL (operands[0])")) (const_int 5)]
808                (const_int 0)))])
810 (define_insn "*addhi3"
811   [(set (match_operand:HI 0 "register_operand" "=r,!w,!w,d,r,r")
812         (plus:HI
813          (match_operand:HI 1 "register_operand" "%0,0,0,0,0,0")
814          (match_operand:HI 2 "nonmemory_operand" "r,I,J,i,P,N")))]
815   ""
816   "@
817         add %A0,%A2\;adc %B0,%B2
818         adiw %A0,%2
819         sbiw %A0,%n2
820         subi %A0,lo8(-(%2))\;sbci %B0,hi8(-(%2))
821         sec\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__
822         sec\;sbc %A0,__zero_reg__\;sbc %B0,__zero_reg__"
823   [(set_attr "length" "2,1,1,2,3,3")
824    (set_attr "cc" "set_n,set_czn,set_czn,set_czn,set_n,set_n")])
826 (define_insn "addsi3"
827   [(set (match_operand:SI 0 "register_operand" "=r,!w,!w,d,r,r")
828           (plus:SI
829            (match_operand:SI 1 "register_operand" "%0,0,0,0,0,0")
830            (match_operand:SI 2 "nonmemory_operand" "r,I,J,i,P,N")))]
831   ""
832   "@
833         add %A0,%A2\;adc %B0,%B2\;adc %C0,%C2\;adc %D0,%D2
834         adiw %0,%2\;adc %C0,__zero_reg__\;adc %D0,__zero_reg__
835         sbiw %0,%n2\;sbc %C0,__zero_reg__\;sbc %D0,__zero_reg__
836         subi %0,lo8(-(%2))\;sbci %B0,hi8(-(%2))\;sbci %C0,hlo8(-(%2))\;sbci %D0,hhi8(-(%2))
837         sec\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__\;adc %C0,__zero_reg__\;adc %D0,__zero_reg__
838         sec\;sbc %A0,__zero_reg__\;sbc %B0,__zero_reg__\;sbc %C0,__zero_reg__\;sbc %D0,__zero_reg__"
839   [(set_attr "length" "4,3,3,4,5,5")
840    (set_attr "cc" "set_n,set_n,set_czn,set_czn,set_n,set_n")])
842 (define_insn "*addsi3_zero_extend"
843   [(set (match_operand:SI 0 "register_operand" "=r")
844         (plus:SI (zero_extend:SI
845                   (match_operand:QI 1 "register_operand" "r"))
846                  (match_operand:SI 2 "register_operand" "0")))]
847   ""
848   "add %A0,%1
849         adc %B0,__zero_reg__
850         adc %C0,__zero_reg__
851         adc %D0,__zero_reg__"
852   [(set_attr "length" "4")
853    (set_attr "cc" "set_n")])
855 ;-----------------------------------------------------------------------------
856 ; sub bytes
857 (define_insn "subqi3"
858   [(set (match_operand:QI 0 "register_operand" "=r,d")
859         (minus:QI (match_operand:QI 1 "register_operand" "0,0")
860                   (match_operand:QI 2 "nonmemory_operand" "r,i")))]
861   ""
862   "@
863         sub %0,%2
864         subi %0,lo8(%2)"
865   [(set_attr "length" "1,1")
866    (set_attr "cc" "set_czn,set_czn")])
868 (define_insn "subhi3"
869   [(set (match_operand:HI 0 "register_operand" "=r,d")
870         (minus:HI (match_operand:HI 1 "register_operand" "0,0")
871                   (match_operand:HI 2 "nonmemory_operand" "r,i")))]
872   ""
873   "@
874         sub %A0,%A2\;sbc %B0,%B2
875         subi %A0,lo8(%2)\;sbci %B0,hi8(%2)"
876   [(set_attr "length" "2,2")
877    (set_attr "cc" "set_czn,set_czn")])
879 (define_insn "*subhi3_zero_extend1"
880   [(set (match_operand:HI 0 "register_operand" "=r")
881         (minus:HI (match_operand:HI 1 "register_operand" "0")
882                   (zero_extend:HI
883                    (match_operand:QI 2 "register_operand" "r"))))]
884   ""
885   "sub %A0,%2
886         sbc %B0,__zero_reg__"
887   [(set_attr "length" "2")
888    (set_attr "cc" "set_n")])
890 (define_insn "subsi3"
891   [(set (match_operand:SI 0 "register_operand" "=r,d")
892         (minus:SI (match_operand:SI 1 "register_operand" "0,0")
893                  (match_operand:SI 2 "nonmemory_operand" "r,i")))]
894   ""
895   "@
896         sub %0,%2\;sbc %B0,%B2\;sbc %C0,%C2\;sbc %D0,%D2
897         subi %A0,lo8(%2)\;sbci %B0,hi8(%2)\;sbci %C0,hlo8(%2)\;sbci %D0,hhi8(%2)"
898   [(set_attr "length" "4,4")
899    (set_attr "cc" "set_czn,set_czn")])
901 (define_insn "*subsi3_zero_extend"
902   [(set (match_operand:SI 0 "register_operand" "=r")
903         (minus:SI (match_operand:SI 1 "register_operand" "0")
904                   (zero_extend:SI
905                    (match_operand:QI 2 "register_operand" "r"))))]
906   ""
907   "sub %A0,%2
908         sbc %B0,__zero_reg__
909         sbc %C0,__zero_reg__
910         sbc %D0,__zero_reg__"
911   [(set_attr "length" "4")
912    (set_attr "cc" "set_n")])
914 ;******************************************************************************
915 ; mul
917 (define_expand "mulqi3"
918   [(set (match_operand:QI 0 "register_operand" "")
919         (mult:QI (match_operand:QI 1 "register_operand" "")
920                  (match_operand:QI 2 "register_operand" "")))]
921   ""
922   "{
923   if (!AVR_HAVE_MUL)
924     {
925       emit_insn (gen_mulqi3_call (operands[0], operands[1], operands[2]));
926       DONE;
927     }
930 (define_insn "*mulqi3_enh"
931   [(set (match_operand:QI 0 "register_operand" "=r")
932         (mult:QI (match_operand:QI 1 "register_operand" "r")
933                  (match_operand:QI 2 "register_operand" "r")))]
934   "AVR_HAVE_MUL"
935   "mul %1,%2
936         mov %0,r0
937         clr r1"
938   [(set_attr "length" "3")
939    (set_attr "cc" "clobber")])
941 (define_expand "mulqi3_call"
942   [(set (reg:QI 24) (match_operand:QI 1 "register_operand" ""))
943    (set (reg:QI 22) (match_operand:QI 2 "register_operand" ""))
944    (parallel [(set (reg:QI 24) (mult:QI (reg:QI 24) (reg:QI 22)))
945               (clobber (reg:QI 22))])
946    (set (match_operand:QI 0 "register_operand" "") (reg:QI 24))]
947   ""
948   "")
950 (define_insn "*mulqi3_call"
951   [(set (reg:QI 24) (mult:QI (reg:QI 24) (reg:QI 22)))
952    (clobber (reg:QI 22))]
953   "!AVR_HAVE_MUL"
954   "%~call __mulqi3"
955   [(set_attr "type" "xcall")
956    (set_attr "cc" "clobber")])
958 (define_insn "mulqihi3"
959   [(set (match_operand:HI 0 "register_operand" "=r")
960         (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "d"))
961                  (sign_extend:HI (match_operand:QI 2 "register_operand" "d"))))]
962   "AVR_HAVE_MUL"
963   "muls %1,%2
964         movw %0,r0
965         clr r1"
966   [(set_attr "length" "3")
967    (set_attr "cc" "clobber")])
969 (define_insn "umulqihi3"
970   [(set (match_operand:HI 0 "register_operand" "=r")
971         (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
972                  (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
973   "AVR_HAVE_MUL"
974   "mul %1,%2
975         movw %0,r0
976         clr r1"
977   [(set_attr "length" "3")
978    (set_attr "cc" "clobber")])
980 (define_expand "mulhi3"
981   [(set (match_operand:HI 0 "register_operand" "")
982         (mult:HI (match_operand:HI 1 "register_operand" "")
983                  (match_operand:HI 2 "register_operand" "")))]
984   ""
985   "
987   if (!AVR_HAVE_MUL)
988     {
989       emit_insn (gen_mulhi3_call (operands[0], operands[1], operands[2]));
990       DONE;
991     }
994 (define_insn "*mulhi3_enh"
995   [(set (match_operand:HI 0 "register_operand" "=&r")
996         (mult:HI (match_operand:HI 1 "register_operand" "r")
997                  (match_operand:HI 2 "register_operand" "r")))]
998   "AVR_HAVE_MUL"
999   "mul %A1,%A2
1000         movw %0,r0
1001         mul %A1,%B2
1002         add %B0,r0
1003         mul %B1,%A2
1004         add %B0,r0
1005         clr r1"
1006   [(set_attr "length" "7")
1007    (set_attr "cc" "clobber")])
1009 (define_expand "mulhi3_call"
1010   [(set (reg:HI 24) (match_operand:HI 1 "register_operand" ""))
1011    (set (reg:HI 22) (match_operand:HI 2 "register_operand" ""))
1012    (parallel [(set (reg:HI 24) (mult:HI (reg:HI 24) (reg:HI 22)))
1013               (clobber (reg:HI 22))
1014               (clobber (reg:QI 21))])
1015    (set (match_operand:HI 0 "register_operand" "") (reg:HI 24))]
1016   ""
1017   "")
1019 (define_insn "*mulhi3_call"
1020   [(set (reg:HI 24) (mult:HI (reg:HI 24) (reg:HI 22)))
1021    (clobber (reg:HI 22))
1022    (clobber (reg:QI 21))]
1023   "!AVR_HAVE_MUL"
1024   "%~call __mulhi3"
1025   [(set_attr "type" "xcall")
1026    (set_attr "cc" "clobber")])
1028 ;; Operand 2 (reg:SI 18) not clobbered on the enhanced core.
1029 ;; All call-used registers clobbered otherwise - normal library call.
1030 (define_expand "mulsi3"
1031   [(set (reg:SI 22) (match_operand:SI 1 "register_operand" ""))
1032    (set (reg:SI 18) (match_operand:SI 2 "register_operand" ""))
1033    (parallel [(set (reg:SI 22) (mult:SI (reg:SI 22) (reg:SI 18)))
1034               (clobber (reg:HI 26))
1035               (clobber (reg:HI 30))])
1036    (set (match_operand:SI 0 "register_operand" "") (reg:SI 22))]
1037   "AVR_HAVE_MUL"
1038   "")
1040 (define_insn "*mulsi3_call"
1041   [(set (reg:SI 22) (mult:SI (reg:SI 22) (reg:SI 18)))
1042    (clobber (reg:HI 26))
1043    (clobber (reg:HI 30))]
1044   "AVR_HAVE_MUL"
1045   "%~call __mulsi3"
1046   [(set_attr "type" "xcall")
1047    (set_attr "cc" "clobber")])
1049 ; / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / % / %
1050 ; divmod
1052 ;; Generate libgcc.S calls ourselves, because:
1053 ;;  - we know exactly which registers are clobbered (for QI and HI
1054 ;;    modes, some of the call-used registers are preserved)
1055 ;;  - we get both the quotient and the remainder at no extra cost
1057 (define_expand "divmodqi4"
1058   [(set (reg:QI 24) (match_operand:QI 1 "register_operand" ""))
1059    (set (reg:QI 22) (match_operand:QI 2 "register_operand" ""))
1060    (parallel [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
1061               (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
1062               (clobber (reg:QI 22))
1063               (clobber (reg:QI 23))])
1064    (set (match_operand:QI 0 "register_operand" "") (reg:QI 24))
1065    (set (match_operand:QI 3 "register_operand" "") (reg:QI 25))]
1066   ""
1067   "")
1069 (define_insn "*divmodqi4_call"
1070   [(set (reg:QI 24) (div:QI (reg:QI 24) (reg:QI 22)))
1071    (set (reg:QI 25) (mod:QI (reg:QI 24) (reg:QI 22)))
1072    (clobber (reg:QI 22))
1073    (clobber (reg:QI 23))]
1074   ""
1075   "%~call __divmodqi4"
1076   [(set_attr "type" "xcall")
1077    (set_attr "cc" "clobber")])
1079 (define_expand "udivmodqi4"
1080   [(set (reg:QI 24) (match_operand:QI 1 "register_operand" ""))
1081    (set (reg:QI 22) (match_operand:QI 2 "register_operand" ""))
1082    (parallel [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
1083               (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
1084               (clobber (reg:QI 23))])
1085    (set (match_operand:QI 0 "register_operand" "") (reg:QI 24))
1086    (set (match_operand:QI 3 "register_operand" "") (reg:QI 25))]
1087   ""
1088   "")
1090 (define_insn "*udivmodqi4_call"
1091   [(set (reg:QI 24) (udiv:QI (reg:QI 24) (reg:QI 22)))
1092    (set (reg:QI 25) (umod:QI (reg:QI 24) (reg:QI 22)))
1093    (clobber (reg:QI 23))]
1094   ""
1095   "%~call __udivmodqi4"
1096   [(set_attr "type" "xcall")
1097    (set_attr "cc" "clobber")])
1099 (define_expand "divmodhi4"
1100   [(set (reg:HI 24) (match_operand:HI 1 "register_operand" ""))
1101    (set (reg:HI 22) (match_operand:HI 2 "register_operand" ""))
1102    (parallel [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
1103               (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
1104               (clobber (reg:HI 26))
1105               (clobber (reg:QI 21))])
1106    (set (match_operand:HI 0 "register_operand" "") (reg:HI 22))
1107    (set (match_operand:HI 3 "register_operand" "") (reg:HI 24))]
1108   ""
1109   "")
1111 (define_insn "*divmodhi4_call"
1112   [(set (reg:HI 22) (div:HI (reg:HI 24) (reg:HI 22)))
1113    (set (reg:HI 24) (mod:HI (reg:HI 24) (reg:HI 22)))
1114    (clobber (reg:HI 26))
1115    (clobber (reg:QI 21))]
1116   ""
1117   "%~call __divmodhi4"
1118   [(set_attr "type" "xcall")
1119    (set_attr "cc" "clobber")])
1121 (define_expand "udivmodhi4"
1122   [(set (reg:HI 24) (match_operand:HI 1 "register_operand" ""))
1123    (set (reg:HI 22) (match_operand:HI 2 "register_operand" ""))
1124    (parallel [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
1125               (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
1126               (clobber (reg:HI 26))
1127               (clobber (reg:QI 21))])
1128    (set (match_operand:HI 0 "register_operand" "") (reg:HI 22))
1129    (set (match_operand:HI 3 "register_operand" "") (reg:HI 24))]
1130   ""
1131   "")
1133 (define_insn "*udivmodhi4_call"
1134   [(set (reg:HI 22) (udiv:HI (reg:HI 24) (reg:HI 22)))
1135    (set (reg:HI 24) (umod:HI (reg:HI 24) (reg:HI 22)))
1136    (clobber (reg:HI 26))
1137    (clobber (reg:QI 21))]
1138   ""
1139   "%~call __udivmodhi4"
1140   [(set_attr "type" "xcall")
1141    (set_attr "cc" "clobber")])
1143 (define_expand "divmodsi4"
1144   [(set (reg:SI 22) (match_operand:SI 1 "register_operand" ""))
1145    (set (reg:SI 18) (match_operand:SI 2 "register_operand" ""))
1146    (parallel [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
1147               (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
1148               (clobber (reg:HI 26))
1149               (clobber (reg:HI 30))])
1150    (set (match_operand:SI 0 "register_operand" "") (reg:SI 18))
1151    (set (match_operand:SI 3 "register_operand" "") (reg:SI 22))]
1152   ""
1153   "")
1155 (define_insn "*divmodsi4_call"
1156   [(set (reg:SI 18) (div:SI (reg:SI 22) (reg:SI 18)))
1157    (set (reg:SI 22) (mod:SI (reg:SI 22) (reg:SI 18)))
1158    (clobber (reg:HI 26))
1159    (clobber (reg:HI 30))]
1160   ""
1161   "%~call __divmodsi4"
1162   [(set_attr "type" "xcall")
1163    (set_attr "cc" "clobber")])
1165 (define_expand "udivmodsi4"
1166   [(set (reg:SI 22) (match_operand:SI 1 "register_operand" ""))
1167    (set (reg:SI 18) (match_operand:SI 2 "register_operand" ""))
1168    (parallel [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
1169               (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
1170               (clobber (reg:HI 26))
1171               (clobber (reg:HI 30))])
1172    (set (match_operand:SI 0 "register_operand" "") (reg:SI 18))
1173    (set (match_operand:SI 3 "register_operand" "") (reg:SI 22))]
1174   ""
1175   "")
1177 (define_insn "*udivmodsi4_call"
1178   [(set (reg:SI 18) (udiv:SI (reg:SI 22) (reg:SI 18)))
1179    (set (reg:SI 22) (umod:SI (reg:SI 22) (reg:SI 18)))
1180    (clobber (reg:HI 26))
1181    (clobber (reg:HI 30))]
1182   ""
1183   "%~call __udivmodsi4"
1184   [(set_attr "type" "xcall")
1185    (set_attr "cc" "clobber")])
1187 ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
1188 ; and
1190 (define_insn "andqi3"
1191   [(set (match_operand:QI 0 "register_operand" "=r,d")
1192         (and:QI (match_operand:QI 1 "register_operand" "%0,0")
1193                 (match_operand:QI 2 "nonmemory_operand" "r,i")))]
1194   ""
1195   "@
1196         and %0,%2
1197         andi %0,lo8(%2)"
1198   [(set_attr "length" "1,1")
1199    (set_attr "cc" "set_zn,set_zn")])
1201 (define_insn "andhi3"
1202   [(set (match_operand:HI 0 "register_operand" "=r,d,r")
1203           (and:HI (match_operand:HI 1 "register_operand" "%0,0,0")
1204                   (match_operand:HI 2 "nonmemory_operand" "r,i,M")))
1205    (clobber (match_scratch:QI 3 "=X,X,&d"))]
1206   ""
1207   "*{
1208   if (which_alternative==0)
1209     return (AS2 (and,%A0,%A2) CR_TAB
1210             AS2 (and,%B0,%B2));
1211   else if (which_alternative==1)
1212     {
1213       if (GET_CODE (operands[2]) == CONST_INT)
1214         {
1215           int mask = INTVAL (operands[2]);
1216           if ((mask & 0xff) != 0xff)
1217             output_asm_insn (AS2 (andi,%A0,lo8(%2)), operands);
1218           if ((mask & 0xff00) != 0xff00)
1219             output_asm_insn (AS2 (andi,%B0,hi8(%2)), operands);
1220           return \"\";
1221         }
1222         return (AS2 (andi,%A0,lo8(%2)) CR_TAB
1223                 AS2 (andi,%B0,hi8(%2)));
1224      }
1225   return (AS2 (ldi,%3,lo8(%2)) CR_TAB
1226           AS2 (and,%A0,%3)     CR_TAB
1227           AS1 (clr,%B0));
1229   [(set_attr "length" "2,2,3")
1230    (set_attr "cc" "set_n,clobber,set_n")])
1232 (define_insn "andsi3"
1233   [(set (match_operand:SI 0 "register_operand" "=r,d")
1234         (and:SI (match_operand:SI 1 "register_operand" "%0,0")
1235                 (match_operand:SI 2 "nonmemory_operand" "r,i")))]
1236   ""
1237   "*{
1238   if (which_alternative==0)
1239     return (AS2 (and, %0,%2)   CR_TAB
1240             AS2 (and, %B0,%B2) CR_TAB
1241             AS2 (and, %C0,%C2) CR_TAB
1242             AS2 (and, %D0,%D2));
1243   else if (which_alternative==1)
1244     {
1245       if (GET_CODE (operands[2]) == CONST_INT)
1246         {
1247           HOST_WIDE_INT mask = INTVAL (operands[2]);
1248           if ((mask & 0xff) != 0xff)
1249             output_asm_insn (AS2 (andi,%A0,lo8(%2)), operands);
1250           if ((mask & 0xff00) != 0xff00)
1251             output_asm_insn (AS2 (andi,%B0,hi8(%2)), operands);
1252           if ((mask & 0xff0000L) != 0xff0000L)
1253             output_asm_insn (AS2 (andi,%C0,hlo8(%2)), operands);
1254           if ((mask & 0xff000000L) != 0xff000000L)
1255             output_asm_insn (AS2 (andi,%D0,hhi8(%2)), operands);
1256           return \"\";
1257         }
1258       return (AS2 (andi, %A0,lo8(%2))  CR_TAB
1259               AS2 (andi, %B0,hi8(%2)) CR_TAB
1260               AS2 (andi, %C0,hlo8(%2)) CR_TAB
1261               AS2 (andi, %D0,hhi8(%2)));
1262     }
1263   return \"bug\";
1265   [(set_attr "length" "4,4")
1266    (set_attr "cc" "set_n,clobber")])
1268 (define_peephole2 ; andi
1269   [(set (match_operand:QI 0 "d_register_operand" "")
1270         (and:QI (match_dup 0)
1271                 (match_operand:QI 1 "const_int_operand" "")))
1272    (set (match_dup 0)
1273         (and:QI (match_dup 0)
1274                 (match_operand:QI 2 "const_int_operand" "")))]
1275   ""
1276   [(set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))]
1277   {
1278     operands[1] = GEN_INT (INTVAL (operands[1]) & INTVAL (operands[2]));
1279   })
1281 ;;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1282 ;; ior
1284 (define_insn "iorqi3"
1285   [(set (match_operand:QI 0 "register_operand" "=r,d")
1286         (ior:QI (match_operand:QI 1 "register_operand" "%0,0")
1287                 (match_operand:QI 2 "nonmemory_operand" "r,i")))]
1288   ""
1289   "@
1290         or %0,%2
1291         ori %0,lo8(%2)"
1292   [(set_attr "length" "1,1")
1293    (set_attr "cc" "set_zn,set_zn")])
1295 (define_insn "iorhi3"
1296   [(set (match_operand:HI 0 "register_operand" "=r,d")
1297         (ior:HI (match_operand:HI 1 "register_operand" "%0,0")
1298                 (match_operand:HI 2 "nonmemory_operand" "r,i")))]
1299   ""
1300   "*{
1301   if (which_alternative==0)
1302     return (AS2 (or,%A0,%A2) CR_TAB
1303             AS2 (or,%B0,%B2));
1304   if (GET_CODE (operands[2]) == CONST_INT)
1305      {
1306         int mask = INTVAL (operands[2]);
1307         if (mask & 0xff)
1308           output_asm_insn (AS2 (ori,%A0,lo8(%2)), operands);
1309         if (mask & 0xff00)
1310           output_asm_insn (AS2 (ori,%B0,hi8(%2)), operands);
1311         return \"\";
1312       }
1313    return (AS2 (ori,%0,lo8(%2)) CR_TAB
1314            AS2 (ori,%B0,hi8(%2)));
1315 }"  
1316   [(set_attr "length" "2,2")
1317    (set_attr "cc" "set_n,clobber")])
1319 (define_insn "*iorhi3_clobber"
1320   [(set (match_operand:HI 0 "register_operand" "=r,r")
1321         (ior:HI (match_operand:HI 1 "register_operand" "%0,0")
1322                 (match_operand:HI 2 "immediate_operand" "M,i")))
1323    (clobber (match_scratch:QI 3 "=&d,&d"))]
1324   ""
1325   "@
1326         ldi %3,lo8(%2)\;or %A0,%3
1327         ldi %3,lo8(%2)\;or %A0,%3\;ldi %3,hi8(%2)\;or %B0,%3"
1328   [(set_attr "length" "2,4")
1329    (set_attr "cc" "clobber,set_n")])
1331 (define_insn "iorsi3"
1332   [(set (match_operand:SI 0 "register_operand"        "=r,d")
1333         (ior:SI (match_operand:SI 1 "register_operand" "%0,0")
1334                 (match_operand:SI 2 "nonmemory_operand" "r,i")))]
1335   ""
1336   "*{
1337   if (which_alternative==0)
1338     return (AS2 (or, %0,%2)   CR_TAB
1339             AS2 (or, %B0,%B2) CR_TAB
1340             AS2 (or, %C0,%C2) CR_TAB
1341             AS2 (or, %D0,%D2));
1342   if (GET_CODE (operands[2]) == CONST_INT)
1343      {
1344         HOST_WIDE_INT mask = INTVAL (operands[2]);
1345         if (mask & 0xff)
1346           output_asm_insn (AS2 (ori,%A0,lo8(%2)), operands);
1347         if (mask & 0xff00)
1348           output_asm_insn (AS2 (ori,%B0,hi8(%2)), operands);
1349         if (mask & 0xff0000L)
1350           output_asm_insn (AS2 (ori,%C0,hlo8(%2)), operands);
1351         if (mask & 0xff000000L)
1352           output_asm_insn (AS2 (ori,%D0,hhi8(%2)), operands);
1353         return \"\";
1354       }
1355   return (AS2 (ori, %A0,lo8(%2))  CR_TAB
1356           AS2 (ori, %B0,hi8(%2)) CR_TAB
1357           AS2 (ori, %C0,hlo8(%2)) CR_TAB
1358           AS2 (ori, %D0,hhi8(%2)));
1360   [(set_attr "length" "4,4")
1361    (set_attr "cc" "set_n,clobber")])
1363 (define_insn "*iorsi3_clobber"
1364   [(set (match_operand:SI 0 "register_operand"        "=r,r")
1365         (ior:SI (match_operand:SI 1 "register_operand" "%0,0")
1366                 (match_operand:SI 2 "immediate_operand" "M,i")))
1367    (clobber (match_scratch:QI 3 "=&d,&d"))]
1368   ""
1369   "@
1370         ldi %3,lo8(%2)\;or %A0,%3
1371         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"
1372   [(set_attr "length" "2,8")
1373    (set_attr "cc" "clobber,set_n")])
1375 ;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1376 ;; xor
1378 (define_insn "xorqi3"
1379   [(set (match_operand:QI 0 "register_operand" "=r")
1380         (xor:QI (match_operand:QI 1 "register_operand" "%0")
1381                 (match_operand:QI 2 "register_operand" "r")))]
1382   ""
1383   "eor %0,%2"
1384   [(set_attr "length" "1")
1385    (set_attr "cc" "set_zn")])
1387 (define_insn "xorhi3"
1388   [(set (match_operand:HI 0 "register_operand" "=r")
1389         (xor:HI (match_operand:HI 1 "register_operand" "%0")
1390                 (match_operand:HI 2 "register_operand" "r")))]
1391   ""
1392   "eor %0,%2
1393         eor %B0,%B2"
1394   [(set_attr "length" "2")
1395    (set_attr "cc" "set_n")])
1397 (define_insn "xorsi3"
1398   [(set (match_operand:SI 0 "register_operand" "=r")
1399         (xor:SI (match_operand:SI 1 "register_operand" "%0")
1400                 (match_operand:SI 2 "register_operand" "r")))]
1401   ""
1402   "eor %0,%2
1403         eor %B0,%B2
1404         eor %C0,%C2
1405         eor %D0,%D2"
1406   [(set_attr "length" "4")
1407    (set_attr "cc" "set_n")])
1409 ;; swap swap swap swap swap swap swap swap swap swap swap swap swap swap swap
1410 ;; swap
1412 (define_expand "rotlqi3"
1413   [(set (match_operand:QI 0 "register_operand" "")
1414         (rotate:QI (match_operand:QI 1 "register_operand" "")
1415                    (match_operand:QI 2 "const_int_operand" "")))]
1416   ""
1417   "
1419   if (INTVAL (operands[2]) != 4)
1420     FAIL;
1423 (define_insn "*rotlqi3_4"
1424   [(set (match_operand:QI 0 "register_operand" "=r")
1425         (rotate:QI (match_operand:QI 1 "register_operand" "0")
1426                    (const_int 4)))]
1427   ""
1428   "swap %0"
1429   [(set_attr "length" "1")
1430    (set_attr "cc" "none")])
1432 (define_expand "rotlhi3"
1433   [(set (match_operand:HI 0 "register_operand" "")
1434         (rotate:HI (match_operand:HI 1 "register_operand" "")
1435                    (match_operand:HI 2 "const_int_operand" "")))]
1436   ""
1437   "
1439   if (INTVAL (operands[2]) != 8)
1440     FAIL;
1443 (define_insn_and_split "*rotlhi3_8"
1444   [(set (match_operand:HI 0 "register_operand" "=r")
1445         (rotate:HI (match_operand:HI 1 "register_operand" "r")
1446                    (const_int 8)))]
1447   ""
1448   "mov __tmp_reg__,%A0
1449         mov %A0,%B0
1450         mov %B0, __tmp_reg__"
1451   "reload_completed
1452    && REGNO (operands[0]) != REGNO (operands[1])"
1453   [(set (match_dup 2) (match_dup 5))
1454    (set (match_dup 3) (match_dup 4))]
1455   "operands[2] = gen_lowpart (QImode, operands[0]);
1456    operands[3] = gen_highpart (QImode, operands[0]);
1458    operands[4] = gen_lowpart (QImode, operands[1]);
1459    operands[5] = gen_highpart (QImode, operands[1]);"
1460    [(set_attr "length" "3")
1461    (set_attr "cc" "none")])
1463 (define_expand "rotlsi3"
1464   [(set (match_operand:SI 0 "register_operand" "")
1465         (rotate:SI (match_operand:SI 1 "register_operand" "")
1466                    (match_operand:SI 2 "const_int_operand" "")))]
1467   ""
1468   "
1470   if (INTVAL (operands[2]) != 8
1471       || INTVAL (operands[2]) != 16
1472       || INTVAL (operands[2]) != 24)
1473     FAIL;
1476 (define_insn_and_split "*rotlsi3_16"
1477   [(set (match_operand:SI 0 "register_operand" "=r")
1478         (rotate:SI (match_operand:SI 1 "register_operand" "r")
1479                    (const_int 16)))]
1480   ""
1481   "{mov __tmp_reg__,%A1\;mov %A0,%C1\;mov %C0, __tmp_reg__\;mov __tmp_reg__,%B1\;mov %B0,%D1\;mov %D0, __tmp_reg__|movw __tmp_reg__,%A1\;movw %A0,%C1\;movw %C0, __tmp_reg__\;clr __zero_reg__}"
1482   "reload_completed
1483    && REGNO (operands[0]) != REGNO (operands[1])"
1484   [(set (match_dup 2) (match_dup 5))
1485    (set (match_dup 3) (match_dup 4))]
1486   "unsigned int si_lo_off = subreg_lowpart_offset (HImode, SImode);
1487    unsigned int si_hi_off = subreg_highpart_offset (HImode, SImode);
1489    operands[2] = simplify_gen_subreg (HImode, operands[0], SImode, si_lo_off);
1490    operands[3] = simplify_gen_subreg (HImode, operands[0], SImode, si_hi_off);
1492    operands[4] = simplify_gen_subreg (HImode, operands[1], SImode, si_lo_off);
1493    operands[5] = simplify_gen_subreg (HImode, operands[1], SImode, si_hi_off);
1495    if (REGNO (operands[0]) == REGNO(operands[1]) + 2)
1496      {
1497        emit_move_insn (operands[3], operands[4]);
1498        DONE;
1499      }
1500    else if (REGNO (operands[0]) == REGNO(operands[1]) - 2)
1501      {
1502        emit_move_insn (operands[2], operands[5]);
1503        DONE;
1504      }"
1505   [(set (attr "length") (if_then_else (eq_attr "mcu_have_movw" "yes")
1506                                       (const_int 4)
1507                                       (const_int 6)))
1508    (set (attr "cc") (if_then_else (eq_attr "mcu_have_movw" "yes")
1509                                   (const_string "clobber")
1510                                   (const_string "none")))])
1512 (define_insn_and_split "*rotlsi3_8"
1513   [(set (match_operand:SI 0 "register_operand" "=r")
1514         (rotate:SI (match_operand:SI 1 "register_operand" "r")
1515                    (const_int 8)))]
1516   ""
1517   "mov __tmp_reg__,%D1
1518         mov %D0,%C1
1519         mov %C0,%B1
1520         mov %B0,%A1
1521         mov %A0, __tmp_reg__"
1522   "reload_completed
1523    && REGNO (operands[0]) != REGNO (operands[1])"
1524   [(const_int 0)]
1525   "unsigned int si_lo_off = subreg_lowpart_offset (HImode, SImode);
1526    unsigned int si_hi_off = subreg_highpart_offset (HImode, SImode);
1527    unsigned int hi_lo_off = subreg_lowpart_offset (QImode, HImode);
1528    unsigned int hi_hi_off = subreg_highpart_offset (QImode, HImode);
1530    operands[2] = simplify_gen_subreg (HImode, operands[0], SImode, si_lo_off);
1531    operands[4] = simplify_gen_subreg (HImode, operands[0], SImode, si_hi_off);
1532    operands[3] = simplify_gen_subreg (QImode, operands[2], HImode, hi_hi_off);
1533    operands[2] = simplify_gen_subreg (QImode, operands[2], HImode, hi_lo_off);
1534    operands[5] = simplify_gen_subreg (QImode, operands[4], HImode, hi_hi_off);
1535    operands[4] = simplify_gen_subreg (QImode, operands[4], HImode, hi_lo_off);
1537    operands[6] = simplify_gen_subreg (HImode, operands[1], SImode, si_lo_off);
1538    operands[8] = simplify_gen_subreg (HImode, operands[1], SImode, si_hi_off);
1539    operands[7] = simplify_gen_subreg (QImode, operands[6], HImode, hi_hi_off);
1540    operands[6] = simplify_gen_subreg (QImode, operands[6], HImode, hi_lo_off);
1541    operands[9] = simplify_gen_subreg (QImode, operands[8], HImode, hi_hi_off);
1542    operands[8] = simplify_gen_subreg (QImode, operands[8], HImode, hi_lo_off);
1544    if (REGNO (operands[0]) < REGNO(operands[1]))
1545      {
1546        emit_move_insn (operands[2], operands[9]);
1547        emit_move_insn (operands[3], operands[6]);
1548        emit_move_insn (operands[4], operands[7]);
1549        emit_move_insn (operands[5], operands[8]);
1550      }
1551    else
1552      {
1553        emit_move_insn (operands[5], operands[8]);
1554        emit_move_insn (operands[2], operands[9]);
1555        emit_move_insn (operands[4], operands[7]);
1556        emit_move_insn (operands[3], operands[6]);
1557      }
1558    DONE;"
1559    [(set_attr "length" "5")
1560    (set_attr "cc" "none")])
1562 (define_insn_and_split "*rotlsi3_24"
1563   [(set (match_operand:SI 0 "register_operand" "=r")
1564         (rotate:SI (match_operand:SI 1 "register_operand" "r")
1565                    (const_int 24)))]
1566   ""
1567   "mov __tmp_reg__,%A1
1568         mov %A0,%B1
1569         mov %B0,%C1
1570         mov %C0,%D1
1571         mov %D0, __tmp_reg__"
1572   "reload_completed
1573    && REGNO (operands[0]) != REGNO (operands[1])"
1574   [(const_int 0)]
1575   "unsigned int si_lo_off = subreg_lowpart_offset (HImode, SImode);
1576    unsigned int si_hi_off = subreg_highpart_offset (HImode, SImode);
1577    unsigned int hi_lo_off = subreg_lowpart_offset (QImode, HImode);
1578    unsigned int hi_hi_off = subreg_highpart_offset (QImode, HImode);
1580    operands[2] = simplify_gen_subreg (HImode, operands[0], SImode, si_lo_off);
1581    operands[4] = simplify_gen_subreg (HImode, operands[0], SImode, si_hi_off);
1582    operands[3] = simplify_gen_subreg (QImode, operands[2], HImode, hi_hi_off);
1583    operands[2] = simplify_gen_subreg (QImode, operands[2], HImode, hi_lo_off);
1584    operands[5] = simplify_gen_subreg (QImode, operands[4], HImode, hi_hi_off);
1585    operands[4] = simplify_gen_subreg (QImode, operands[4], HImode, hi_lo_off);
1587    operands[6] = simplify_gen_subreg (HImode, operands[1], SImode, si_lo_off);
1588    operands[8] = simplify_gen_subreg (HImode, operands[1], SImode, si_hi_off);
1589    operands[7] = simplify_gen_subreg (QImode, operands[6], HImode, hi_hi_off);
1590    operands[6] = simplify_gen_subreg (QImode, operands[6], HImode, hi_lo_off);
1591    operands[9] = simplify_gen_subreg (QImode, operands[8], HImode, hi_hi_off);
1592    operands[8] = simplify_gen_subreg (QImode, operands[8], HImode, hi_lo_off);
1594    if (REGNO (operands[0]) < REGNO(operands[1]))
1595      {
1596        emit_move_insn (operands[2], operands[7]);
1597        emit_move_insn (operands[5], operands[6]);
1598        emit_move_insn (operands[3], operands[8]);
1599        emit_move_insn (operands[4], operands[9]);
1600      }
1601    else
1602      {
1603        emit_move_insn (operands[5], operands[6]);
1604        emit_move_insn (operands[4], operands[9]);
1605        emit_move_insn (operands[3], operands[8]);
1606        emit_move_insn (operands[2], operands[7]);
1607      }
1608    DONE;"
1609    [(set_attr "length" "5")
1610    (set_attr "cc" "none")])
1612 ;;<< << << << << << << << << << << << << << << << << << << << << << << << << <<
1613 ;; arithmetic shift left
1615 (define_expand "ashlqi3"
1616   [(set (match_operand:QI 0 "register_operand"            "")
1617         (ashift:QI (match_operand:QI 1 "register_operand" "")
1618                    (match_operand:QI 2 "general_operand"  "")))]
1619   ""
1620   "")
1622 (define_split ; ashlqi3_const4
1623   [(set (match_operand:QI 0 "d_register_operand" "")
1624         (ashift:QI (match_dup 0)
1625                    (const_int 4)))]
1626   ""
1627   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1628    (set (match_dup 0) (and:QI (match_dup 0) (const_int -16)))]
1629   "")
1631 (define_split ; ashlqi3_const5
1632   [(set (match_operand:QI 0 "d_register_operand" "")
1633         (ashift:QI (match_dup 0)
1634                    (const_int 5)))]
1635   ""
1636   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1637    (set (match_dup 0) (ashift:QI (match_dup 0) (const_int 1)))
1638    (set (match_dup 0) (and:QI (match_dup 0) (const_int -32)))]
1639   "")
1641 (define_split ; ashlqi3_const6
1642   [(set (match_operand:QI 0 "d_register_operand" "")
1643         (ashift:QI (match_dup 0)
1644                    (const_int 6)))]
1645   ""
1646   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1647    (set (match_dup 0) (ashift:QI (match_dup 0) (const_int 2)))
1648    (set (match_dup 0) (and:QI (match_dup 0) (const_int -64)))]
1649   "")
1651 (define_insn "*ashlqi3"
1652   [(set (match_operand:QI 0 "register_operand"           "=r,r,r,r,!d,r,r")
1653         (ashift:QI (match_operand:QI 1 "register_operand" "0,0,0,0,0,0,0")
1654                    (match_operand:QI 2 "general_operand"  "r,L,P,K,n,n,Qm")))]
1655   ""
1656   "* return ashlqi3_out (insn, operands, NULL);"
1657   [(set_attr "length" "5,0,1,2,4,6,9")
1658    (set_attr "cc" "clobber,none,set_czn,set_czn,set_czn,set_czn,clobber")])
1660 (define_insn "ashlhi3"
1661   [(set (match_operand:HI 0 "register_operand"           "=r,r,r,r,r,r,r")
1662         (ashift:HI (match_operand:HI 1 "register_operand" "0,0,0,r,0,0,0")
1663                    (match_operand:QI 2 "general_operand"  "r,L,P,O,K,n,Qm")))]
1664   ""
1665   "* return ashlhi3_out (insn, operands, NULL);"
1666   [(set_attr "length" "6,0,2,2,4,10,10")
1667    (set_attr "cc" "clobber,none,set_n,clobber,set_n,clobber,clobber")])
1669 (define_insn "ashlsi3"
1670   [(set (match_operand:SI 0 "register_operand"           "=r,r,r,r,r,r,r")
1671         (ashift:SI (match_operand:SI 1 "register_operand" "0,0,0,r,0,0,0")
1672                    (match_operand:QI 2 "general_operand"  "r,L,P,O,K,n,Qm")))]
1673   ""
1674   "* return ashlsi3_out (insn, operands, NULL);"
1675   [(set_attr "length" "8,0,4,4,8,10,12")
1676    (set_attr "cc" "clobber,none,set_n,clobber,set_n,clobber,clobber")])
1678 ;; Optimize if a scratch register from LD_REGS happens to be available.
1680 (define_peephole2 ; ashlqi3_l_const4
1681   [(set (match_operand:QI 0 "l_register_operand" "")
1682         (ashift:QI (match_dup 0)
1683                    (const_int 4)))
1684    (match_scratch:QI 1 "d")]
1685   ""
1686   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1687    (set (match_dup 1) (const_int -16))
1688    (set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))]
1689   "")
1691 (define_peephole2 ; ashlqi3_l_const5
1692   [(set (match_operand:QI 0 "l_register_operand" "")
1693         (ashift:QI (match_dup 0)
1694                    (const_int 5)))
1695    (match_scratch:QI 1 "d")]
1696   ""
1697   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1698    (set (match_dup 0) (ashift:QI (match_dup 0) (const_int 1)))
1699    (set (match_dup 1) (const_int -32))
1700    (set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))]
1701   "")
1703 (define_peephole2 ; ashlqi3_l_const6
1704   [(set (match_operand:QI 0 "l_register_operand" "")
1705         (ashift:QI (match_dup 0)
1706                    (const_int 6)))
1707    (match_scratch:QI 1 "d")]
1708   ""
1709   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1710    (set (match_dup 0) (ashift:QI (match_dup 0) (const_int 2)))
1711    (set (match_dup 1) (const_int -64))
1712    (set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))]
1713   "")
1715 (define_peephole2
1716   [(match_scratch:QI 3 "d")
1717    (set (match_operand:HI 0 "register_operand" "")
1718         (ashift:HI (match_operand:HI 1 "register_operand" "")
1719                    (match_operand:QI 2 "const_int_operand" "")))]
1720   ""
1721   [(parallel [(set (match_dup 0) (ashift:HI (match_dup 1) (match_dup 2)))
1722               (clobber (match_dup 3))])]
1723   "")
1725 (define_insn "*ashlhi3_const"
1726   [(set (match_operand:HI 0 "register_operand"            "=r,r,r,r,r")
1727         (ashift:HI (match_operand:HI 1 "register_operand"  "0,0,r,0,0")
1728                    (match_operand:QI 2 "const_int_operand" "L,P,O,K,n")))
1729    (clobber (match_scratch:QI 3 "=X,X,X,X,&d"))]
1730   "reload_completed"
1731   "* return ashlhi3_out (insn, operands, NULL);"
1732   [(set_attr "length" "0,2,2,4,10")
1733    (set_attr "cc" "none,set_n,clobber,set_n,clobber")])
1735 (define_peephole2
1736   [(match_scratch:QI 3 "d")
1737    (set (match_operand:SI 0 "register_operand" "")
1738         (ashift:SI (match_operand:SI 1 "register_operand" "")
1739                    (match_operand:QI 2 "const_int_operand" "")))]
1740   ""
1741   [(parallel [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
1742               (clobber (match_dup 3))])]
1743   "")
1745 (define_insn "*ashlsi3_const"
1746   [(set (match_operand:SI 0 "register_operand"            "=r,r,r,r")
1747         (ashift:SI (match_operand:SI 1 "register_operand"  "0,0,r,0")
1748                    (match_operand:QI 2 "const_int_operand" "L,P,O,n")))
1749    (clobber (match_scratch:QI 3 "=X,X,X,&d"))]
1750   "reload_completed"
1751   "* return ashlsi3_out (insn, operands, NULL);"
1752   [(set_attr "length" "0,4,4,10")
1753    (set_attr "cc" "none,set_n,clobber,clobber")])
1755 ;; >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
1756 ;; arithmetic shift right
1758 (define_insn "ashrqi3"
1759   [(set (match_operand:QI 0 "register_operand" "=r,r,r,r,r,r")
1760         (ashiftrt:QI (match_operand:QI 1 "register_operand" "0,0,0,0,0,0")
1761                      (match_operand:QI 2 "general_operand"  "r,L,P,K,n,Qm")))]
1762   ""
1763   "* return ashrqi3_out (insn, operands, NULL);"
1764   [(set_attr "length" "5,0,1,2,5,9")
1765    (set_attr "cc" "clobber,none,clobber,clobber,clobber,clobber")])
1767 (define_insn "ashrhi3"
1768   [(set (match_operand:HI 0 "register_operand"             "=r,r,r,r,r,r,r")
1769         (ashiftrt:HI (match_operand:HI 1 "register_operand" "0,0,0,r,0,0,0")
1770                      (match_operand:QI 2 "general_operand"  "r,L,P,O,K,n,Qm")))]
1771   ""
1772   "* return ashrhi3_out (insn, operands, NULL);"
1773   [(set_attr "length" "6,0,2,4,4,10,10")
1774    (set_attr "cc" "clobber,none,clobber,set_n,clobber,clobber,clobber")])
1776 (define_insn "ashrsi3"
1777   [(set (match_operand:SI 0 "register_operand"             "=r,r,r,r,r,r,r")
1778         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0,0,r,0,0,0")
1779                      (match_operand:QI 2 "general_operand"  "r,L,P,O,K,n,Qm")))]
1780   ""
1781   "* return ashrsi3_out (insn, operands, NULL);"
1782   [(set_attr "length" "8,0,4,6,8,10,12")
1783    (set_attr "cc" "clobber,none,clobber,set_n,clobber,clobber,clobber")])
1785 ;; Optimize if a scratch register from LD_REGS happens to be available.
1787 (define_peephole2
1788   [(match_scratch:QI 3 "d")
1789    (set (match_operand:HI 0 "register_operand" "")
1790         (ashiftrt:HI (match_operand:HI 1 "register_operand" "")
1791                      (match_operand:QI 2 "const_int_operand" "")))]
1792   ""
1793   [(parallel [(set (match_dup 0) (ashiftrt:HI (match_dup 1) (match_dup 2)))
1794               (clobber (match_dup 3))])]
1795   "")
1797 (define_insn "*ashrhi3_const"
1798   [(set (match_operand:HI 0 "register_operand"              "=r,r,r,r,r")
1799         (ashiftrt:HI (match_operand:HI 1 "register_operand"  "0,0,r,0,0")
1800                      (match_operand:QI 2 "const_int_operand" "L,P,O,K,n")))
1801    (clobber (match_scratch:QI 3 "=X,X,X,X,&d"))]
1802   "reload_completed"
1803   "* return ashrhi3_out (insn, operands, NULL);"
1804   [(set_attr "length" "0,2,4,4,10")
1805    (set_attr "cc" "none,clobber,set_n,clobber,clobber")])
1807 (define_peephole2
1808   [(match_scratch:QI 3 "d")
1809    (set (match_operand:SI 0 "register_operand" "")
1810         (ashiftrt:SI (match_operand:SI 1 "register_operand" "")
1811                      (match_operand:QI 2 "const_int_operand" "")))]
1812   ""
1813   [(parallel [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (match_dup 2)))
1814               (clobber (match_dup 3))])]
1815   "")
1817 (define_insn "*ashrsi3_const"
1818   [(set (match_operand:SI 0 "register_operand"              "=r,r,r,r")
1819         (ashiftrt:SI (match_operand:SI 1 "register_operand"  "0,0,r,0")
1820                      (match_operand:QI 2 "const_int_operand" "L,P,O,n")))
1821    (clobber (match_scratch:QI 3 "=X,X,X,&d"))]
1822   "reload_completed"
1823   "* return ashrsi3_out (insn, operands, NULL);"
1824   [(set_attr "length" "0,4,4,10")
1825    (set_attr "cc" "none,clobber,set_n,clobber")])
1827 ;; >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
1828 ;; logical shift right
1830 (define_expand "lshrqi3"
1831   [(set (match_operand:QI 0 "register_operand"              "")
1832         (lshiftrt:QI (match_operand:QI 1 "register_operand" "")
1833                      (match_operand:QI 2 "general_operand"  "")))]
1834   ""
1835   "")
1837 (define_split   ; lshrqi3_const4
1838   [(set (match_operand:QI 0 "d_register_operand" "")
1839         (lshiftrt:QI (match_dup 0)
1840                      (const_int 4)))]
1841   ""
1842   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1843    (set (match_dup 0) (and:QI (match_dup 0) (const_int 15)))]
1844   "")
1846 (define_split   ; lshrqi3_const5
1847   [(set (match_operand:QI 0 "d_register_operand" "")
1848         (lshiftrt:QI (match_dup 0)
1849                      (const_int 5)))]
1850   ""
1851   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1852    (set (match_dup 0) (lshiftrt:QI (match_dup 0) (const_int 1)))
1853    (set (match_dup 0) (and:QI (match_dup 0) (const_int 7)))]
1854   "")
1856 (define_split   ; lshrqi3_const6
1857   [(set (match_operand:QI 0 "d_register_operand" "")
1858         (lshiftrt:QI (match_dup 0)
1859                      (const_int 6)))]
1860   ""
1861   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1862    (set (match_dup 0) (lshiftrt:QI (match_dup 0) (const_int 2)))
1863    (set (match_dup 0) (and:QI (match_dup 0) (const_int 3)))]
1864   "")
1866 (define_insn "*lshrqi3"
1867   [(set (match_operand:QI 0 "register_operand"             "=r,r,r,r,!d,r,r")
1868         (lshiftrt:QI (match_operand:QI 1 "register_operand" "0,0,0,0,0,0,0")
1869                      (match_operand:QI 2 "general_operand"  "r,L,P,K,n,n,Qm")))]
1870   ""
1871   "* return lshrqi3_out (insn, operands, NULL);"
1872   [(set_attr "length" "5,0,1,2,4,6,9")
1873    (set_attr "cc" "clobber,none,set_czn,set_czn,set_czn,set_czn,clobber")])
1875 (define_insn "lshrhi3"
1876   [(set (match_operand:HI 0 "register_operand"             "=r,r,r,r,r,r,r")
1877         (lshiftrt:HI (match_operand:HI 1 "register_operand" "0,0,0,r,0,0,0")
1878                      (match_operand:QI 2 "general_operand"  "r,L,P,O,K,n,Qm")))]
1879   ""
1880   "* return lshrhi3_out (insn, operands, NULL);"
1881   [(set_attr "length" "6,0,2,2,4,10,10")
1882    (set_attr "cc" "clobber,none,clobber,clobber,clobber,clobber,clobber")])
1884 (define_insn "lshrsi3"
1885   [(set (match_operand:SI 0 "register_operand"             "=r,r,r,r,r,r,r")
1886         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,0,0,r,0,0,0")
1887                      (match_operand:QI 2 "general_operand"  "r,L,P,O,K,n,Qm")))]
1888   ""
1889   "* return lshrsi3_out (insn, operands, NULL);"
1890   [(set_attr "length" "8,0,4,4,8,10,12")
1891    (set_attr "cc" "clobber,none,clobber,clobber,clobber,clobber,clobber")])
1893 ;; Optimize if a scratch register from LD_REGS happens to be available.
1895 (define_peephole2 ; lshrqi3_l_const4
1896   [(set (match_operand:QI 0 "l_register_operand" "")
1897         (lshiftrt:QI (match_dup 0)
1898                      (const_int 4)))
1899    (match_scratch:QI 1 "d")]
1900   ""
1901   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1902    (set (match_dup 1) (const_int 15))
1903    (set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))]
1904   "")
1906 (define_peephole2 ; lshrqi3_l_const5
1907   [(set (match_operand:QI 0 "l_register_operand" "")
1908         (lshiftrt:QI (match_dup 0)
1909                      (const_int 5)))
1910    (match_scratch:QI 1 "d")]
1911   ""
1912   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1913    (set (match_dup 0) (lshiftrt:QI (match_dup 0) (const_int 1)))
1914    (set (match_dup 1) (const_int 7))
1915    (set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))]
1916   "")
1918 (define_peephole2 ; lshrqi3_l_const6
1919   [(set (match_operand:QI 0 "l_register_operand" "")
1920         (lshiftrt:QI (match_dup 0)
1921                      (const_int 6)))
1922    (match_scratch:QI 1 "d")]
1923   ""
1924   [(set (match_dup 0) (rotate:QI (match_dup 0) (const_int 4)))
1925    (set (match_dup 0) (lshiftrt:QI (match_dup 0) (const_int 2)))
1926    (set (match_dup 1) (const_int 3))
1927    (set (match_dup 0) (and:QI (match_dup 0) (match_dup 1)))]
1928   "")
1930 (define_peephole2
1931   [(match_scratch:QI 3 "d")
1932    (set (match_operand:HI 0 "register_operand" "")
1933         (lshiftrt:HI (match_operand:HI 1 "register_operand" "")
1934                      (match_operand:QI 2 "const_int_operand" "")))]
1935   ""
1936   [(parallel [(set (match_dup 0) (lshiftrt:HI (match_dup 1) (match_dup 2)))
1937               (clobber (match_dup 3))])]
1938   "")
1940 (define_insn "*lshrhi3_const"
1941   [(set (match_operand:HI 0 "register_operand"              "=r,r,r,r,r")
1942         (lshiftrt:HI (match_operand:HI 1 "register_operand"  "0,0,r,0,0")
1943                      (match_operand:QI 2 "const_int_operand" "L,P,O,K,n")))
1944    (clobber (match_scratch:QI 3 "=X,X,X,X,&d"))]
1945   "reload_completed"
1946   "* return lshrhi3_out (insn, operands, NULL);"
1947   [(set_attr "length" "0,2,2,4,10")
1948    (set_attr "cc" "none,clobber,clobber,clobber,clobber")])
1950 (define_peephole2
1951   [(match_scratch:QI 3 "d")
1952    (set (match_operand:SI 0 "register_operand" "")
1953         (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
1954                      (match_operand:QI 2 "const_int_operand" "")))]
1955   ""
1956   [(parallel [(set (match_dup 0) (lshiftrt:SI (match_dup 1) (match_dup 2)))
1957               (clobber (match_dup 3))])]
1958   "")
1960 (define_insn "*lshrsi3_const"
1961   [(set (match_operand:SI 0 "register_operand"              "=r,r,r,r")
1962         (lshiftrt:SI (match_operand:SI 1 "register_operand"  "0,0,r,0")
1963                      (match_operand:QI 2 "const_int_operand" "L,P,O,n")))
1964    (clobber (match_scratch:QI 3 "=X,X,X,&d"))]
1965   "reload_completed"
1966   "* return lshrsi3_out (insn, operands, NULL);"
1967   [(set_attr "length" "0,4,4,10")
1968    (set_attr "cc" "none,clobber,clobber,clobber")])
1970 ;; abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x) abs(x)
1971 ;; abs
1973 (define_insn "absqi2"
1974   [(set (match_operand:QI 0 "register_operand" "=r")
1975         (abs:QI (match_operand:QI 1 "register_operand" "0")))]
1976   ""
1977   "sbrc %0,7
1978         neg %0"
1979   [(set_attr "length" "2")
1980    (set_attr "cc" "clobber")])
1983 (define_insn "abssf2"
1984   [(set (match_operand:SF 0 "register_operand" "=d,r")
1985         (abs:SF (match_operand:SF 1 "register_operand" "0,0")))]
1986   ""
1987   "@
1988         andi %D0,0x7f
1989         clt\;bld %D0,7"
1990   [(set_attr "length" "1,2")
1991    (set_attr "cc" "set_n,clobber")])
1993 ;; 0 - x  0 - x  0 - x  0 - x  0 - x  0 - x  0 - x  0 - x  0 - x  0 - x  0 - x
1994 ;; neg
1996 (define_insn "negqi2"
1997   [(set (match_operand:QI 0 "register_operand" "=r")
1998         (neg:QI (match_operand:QI 1 "register_operand" "0")))]
1999   ""
2000   "neg %0"
2001   [(set_attr "length" "1")
2002    (set_attr "cc" "set_zn")])
2004 (define_insn "neghi2"
2005   [(set (match_operand:HI 0 "register_operand"       "=!d,r,&r")
2006         (neg:HI (match_operand:HI 1 "register_operand" "0,0,r")))]
2007   ""
2008   "@
2009         com %B0\;neg %A0\;sbci %B0,lo8(-1)
2010         com %B0\;neg %A0\;sbc %B0,__zero_reg__\;inc %B0
2011         clr %A0\;clr %B0\;sub %A0,%A1\;sbc %B0,%B1"
2012   [(set_attr "length" "3,4,4")
2013    (set_attr "cc" "set_czn,set_n,set_czn")])
2015 (define_insn "negsi2"
2016   [(set (match_operand:SI 0 "register_operand"       "=!d,r,&r")
2017         (neg:SI (match_operand:SI 1 "register_operand" "0,0,r")))]
2018   ""
2019   "@
2020         com %D0\;com %C0\;com %B0\;neg %A0\;sbci %B0,lo8(-1)\;sbci %C0,lo8(-1)\;sbci %D0,lo8(-1)
2021         com %D0\;com %C0\;com %B0\;com %A0\;adc %A0,__zero_reg__\;adc %B0,__zero_reg__\;adc %C0,__zero_reg__\;adc %D0,__zero_reg__
2022         clr %A0\;clr %B0\;{clr %C0\;clr %D0|movw %C0,%A0}\;sub %A0,%A1\;sbc %B0,%B1\;sbc %C0,%C1\;sbc %D0,%D1"
2023   [(set_attr_alternative "length"
2024                          [(const_int 7)
2025                           (const_int 8)
2026                           (if_then_else (eq_attr "mcu_have_movw" "yes")
2027                                         (const_int 7)
2028                                         (const_int 8))])
2029    (set_attr "cc" "set_czn,set_n,set_czn")])
2031 (define_insn "negsf2"
2032   [(set (match_operand:SF 0 "register_operand" "=d,r")
2033         (neg:SF (match_operand:SF 1 "register_operand" "0,0")))]
2034   ""
2035   "@
2036         subi %D0,0x80
2037         bst %D0,7\;com %D0\;bld %D0,7\;com %D0"
2038   [(set_attr "length" "1,4")
2039    (set_attr "cc" "set_n,set_n")])
2041 ;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2042 ;; not
2044 (define_insn "one_cmplqi2"
2045   [(set (match_operand:QI 0 "register_operand" "=r")
2046         (not:QI (match_operand:QI 1 "register_operand" "0")))]
2047   ""
2048   "com %0"
2049   [(set_attr "length" "1")
2050    (set_attr "cc" "set_czn")])
2052 (define_insn "one_cmplhi2"
2053   [(set (match_operand:HI 0 "register_operand" "=r")
2054         (not:HI (match_operand:HI 1 "register_operand" "0")))]
2055   ""
2056   "com %0
2057         com %B0"
2058   [(set_attr "length" "2")
2059    (set_attr "cc" "set_n")])
2061 (define_insn "one_cmplsi2"
2062   [(set (match_operand:SI 0 "register_operand" "=r")
2063         (not:SI (match_operand:SI 1 "register_operand" "0")))]
2064   ""
2065   "com %0
2066         com %B0
2067         com %C0
2068         com %D0"
2069   [(set_attr "length" "4")
2070    (set_attr "cc" "set_n")])
2072 ;; xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x
2073 ;; sign extend
2075 (define_insn "extendqihi2"
2076   [(set (match_operand:HI 0 "register_operand" "=r,r")
2077         (sign_extend:HI (match_operand:QI 1 "register_operand" "0,*r")))]
2078   ""
2079   "@
2080         clr %B0\;sbrc %0,7\;com %B0
2081         mov %A0,%A1\;clr %B0\;sbrc %A0,7\;com %B0"
2082   [(set_attr "length" "3,4")
2083    (set_attr "cc" "set_n,set_n")])
2085 (define_insn "extendqisi2"
2086   [(set (match_operand:SI 0 "register_operand" "=r,r")
2087         (sign_extend:SI (match_operand:QI 1 "register_operand" "0,*r")))]
2088   ""
2089   "@
2090         clr %B0\;sbrc %A0,7\;com %B0\;mov %C0,%B0\;mov %D0,%B0
2091         mov %A0,%A1\;clr %B0\;sbrc %A0,7\;com %B0\;mov %C0,%B0\;mov %D0,%B0"
2092   [(set_attr "length" "5,6")
2093    (set_attr "cc" "set_n,set_n")])
2095 (define_insn "extendhisi2"
2096   [(set (match_operand:SI 0 "register_operand"               "=r,&r")
2097         (sign_extend:SI (match_operand:HI 1 "register_operand" "0,*r")))]
2098   ""
2099   "@
2100         clr %C0\;sbrc %B0,7\;com %C0\;mov %D0,%C0
2101         {mov %A0,%A1\;mov %B0,%B1|movw %A0,%A1}\;clr %C0\;sbrc %B0,7\;com %C0\;mov %D0,%C0"
2102   [(set_attr_alternative "length"
2103                          [(const_int 4)
2104                           (if_then_else (eq_attr "mcu_have_movw" "yes")
2105                                         (const_int 5)
2106                                         (const_int 6))])
2107    (set_attr "cc" "set_n,set_n")])
2109 ;; xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x xx<---x
2110 ;; zero extend
2112 (define_insn_and_split "zero_extendqihi2"
2113   [(set (match_operand:HI 0 "register_operand" "=r")
2114         (zero_extend:HI (match_operand:QI 1 "register_operand" "r")))]
2115   ""
2116   "#"
2117   "reload_completed"
2118   [(set (match_dup 2) (match_dup 1))
2119    (set (match_dup 3) (const_int 0))]
2120   "unsigned int low_off = subreg_lowpart_offset (QImode, HImode);
2121    unsigned int high_off = subreg_highpart_offset (QImode, HImode);
2122    
2123    operands[2] = simplify_gen_subreg (QImode, operands[0], HImode, low_off);
2124    operands[3] = simplify_gen_subreg (QImode, operands[0], HImode, high_off);
2125   ")
2127 (define_insn_and_split "zero_extendqisi2"
2128   [(set (match_operand:SI 0 "register_operand" "=r")
2129         (zero_extend:SI (match_operand:QI 1 "register_operand" "r")))]
2130   ""
2131   "#"
2132   "reload_completed"
2133   [(set (match_dup 2) (zero_extend:HI (match_dup 1)))
2134    (set (match_dup 3) (const_int 0))]
2135   "unsigned int low_off = subreg_lowpart_offset (HImode, SImode);
2136    unsigned int high_off = subreg_highpart_offset (HImode, SImode);
2137    
2138    operands[2] = simplify_gen_subreg (HImode, operands[0], SImode, low_off);
2139    operands[3] = simplify_gen_subreg (HImode, operands[0], SImode, high_off);
2140   ")
2142 (define_insn_and_split "zero_extendhisi2"
2143   [(set (match_operand:SI 0 "register_operand" "=r")
2144         (zero_extend:SI (match_operand:HI 1 "register_operand" "r")))]
2145   ""
2146   "#"
2147   "reload_completed"
2148   [(set (match_dup 2) (match_dup 1))
2149    (set (match_dup 3) (const_int 0))]
2150   "unsigned int low_off = subreg_lowpart_offset (HImode, SImode);
2151    unsigned int high_off = subreg_highpart_offset (HImode, SImode);
2152    
2153    operands[2] = simplify_gen_subreg (HImode, operands[0], SImode, low_off);
2154    operands[3] = simplify_gen_subreg (HImode, operands[0], SImode, high_off);
2155   ")
2157 (define_insn_and_split "zero_extendqidi2"
2158   [(set (match_operand:DI 0 "register_operand" "=r")
2159         (zero_extend:DI (match_operand:QI 1 "register_operand" "r")))]
2160   ""
2161   "#"
2162   "reload_completed"
2163   [(set (match_dup 2) (zero_extend:SI (match_dup 1)))
2164    (set (match_dup 3) (const_int 0))]
2165   "unsigned int low_off = subreg_lowpart_offset (SImode, DImode);
2166    unsigned int high_off = subreg_highpart_offset (SImode, DImode);
2167    
2168    operands[2] = simplify_gen_subreg (SImode, operands[0], DImode, low_off);
2169    operands[3] = simplify_gen_subreg (SImode, operands[0], DImode, high_off);
2170   ")
2172 (define_insn_and_split "zero_extendhidi2"
2173   [(set (match_operand:DI 0 "register_operand" "=r")
2174         (zero_extend:DI (match_operand:HI 1 "register_operand" "r")))]
2175   ""
2176   "#"
2177   "reload_completed"
2178   [(set (match_dup 2) (zero_extend:SI (match_dup 1)))
2179    (set (match_dup 3) (const_int 0))]
2180   "unsigned int low_off = subreg_lowpart_offset (SImode, DImode);
2181    unsigned int high_off = subreg_highpart_offset (SImode, DImode);
2182    
2183    operands[2] = simplify_gen_subreg (SImode, operands[0], DImode, low_off);
2184    operands[3] = simplify_gen_subreg (SImode, operands[0], DImode, high_off);
2185   ")
2187 (define_insn_and_split "zero_extendsidi2"
2188   [(set (match_operand:DI 0 "register_operand" "=r")
2189         (zero_extend:DI (match_operand:SI 1 "register_operand" "r")))]
2190   ""
2191   "#"
2192   "reload_completed"
2193   [(set (match_dup 2) (match_dup 1))
2194    (set (match_dup 3) (const_int 0))]
2195   "unsigned int low_off = subreg_lowpart_offset (SImode, DImode);
2196    unsigned int high_off = subreg_highpart_offset (SImode, DImode);
2197    
2198    operands[2] = simplify_gen_subreg (SImode, operands[0], DImode, low_off);
2199    operands[3] = simplify_gen_subreg (SImode, operands[0], DImode, high_off);
2200   ")
2202 ;;<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>
2203 ;; compare
2205 ; Optimize negated tests into reverse compare if overflow is undefined.
2206 (define_insn "*negated_tstqi"
2207   [(set (cc0)
2208         (compare (neg:QI (match_operand:QI 0 "register_operand" "r"))
2209                  (const_int 0)))]
2210   "(!flag_wrapv && !flag_trapv && flag_strict_overflow)"
2211   "cp __zero_reg__,%0"
2212   [(set_attr "cc" "compare")
2213    (set_attr "length" "1")])
2215 (define_insn "*reversed_tstqi"
2216   [(set (cc0)
2217         (compare (const_int 0)
2218                  (match_operand:QI 0 "register_operand" "r")))]
2219   ""
2220   "cp __zero_reg__,%0"
2221 [(set_attr "cc" "compare")
2222  (set_attr "length" "2")])
2224 (define_insn "*negated_tsthi"
2225   [(set (cc0)
2226         (compare (neg:HI (match_operand:HI 0 "register_operand" "r"))
2227                  (const_int 0)))]
2228   "(!flag_wrapv && !flag_trapv && flag_strict_overflow)"
2229   "cp __zero_reg__,%A0
2230         cpc __zero_reg__,%B0"
2231 [(set_attr "cc" "compare")
2232  (set_attr "length" "2")])
2234 ;; Leave here the clobber used by the cmphi pattern for simplicity, even
2235 ;; though it is unused, because this pattern is synthesized by avr_reorg.
2236 (define_insn "*reversed_tsthi"
2237   [(set (cc0)
2238         (compare (const_int 0)
2239                  (match_operand:HI 0 "register_operand" "r")))
2240    (clobber (match_scratch:QI 1 "=X"))]
2241   ""
2242   "cp __zero_reg__,%A0
2243         cpc __zero_reg__,%B0"
2244 [(set_attr "cc" "compare")
2245  (set_attr "length" "2")])
2247 (define_insn "*negated_tstsi"
2248   [(set (cc0)
2249         (compare (neg:SI (match_operand:SI 0 "register_operand" "r"))
2250                  (const_int 0)))]
2251   "(!flag_wrapv && !flag_trapv && flag_strict_overflow)"
2252   "cp __zero_reg__,%A0
2253         cpc __zero_reg__,%B0
2254         cpc __zero_reg__,%C0
2255         cpc __zero_reg__,%D0"
2256   [(set_attr "cc" "compare")
2257    (set_attr "length" "4")])
2259 (define_insn "*reversed_tstsi"
2260   [(set (cc0)
2261         (compare (const_int 0)
2262                  (match_operand:SI 0 "register_operand" "r")))
2263    (clobber (match_scratch:QI 1 "=X"))]
2264   ""
2265   "cp __zero_reg__,%A0
2266         cpc __zero_reg__,%B0
2267         cpc __zero_reg__,%C0
2268         cpc __zero_reg__,%D0"
2269   [(set_attr "cc" "compare")
2270    (set_attr "length" "4")])
2273 (define_insn "*cmpqi"
2274   [(set (cc0)
2275         (compare (match_operand:QI 0 "register_operand"  "r,r,d")
2276                  (match_operand:QI 1 "nonmemory_operand" "L,r,i")))]
2277   ""
2278   "@
2279         tst %0
2280         cp %0,%1
2281         cpi %0,lo8(%1)"
2282   [(set_attr "cc" "compare,compare,compare")
2283    (set_attr "length" "1,1,1")])
2285 (define_insn "*cmpqi_sign_extend"
2286   [(set (cc0)
2287         (compare (sign_extend:HI
2288                   (match_operand:QI 0 "register_operand"  "d"))
2289                  (match_operand:HI 1 "const_int_operand" "n")))]
2290   "INTVAL (operands[1]) >= -128 && INTVAL (operands[1]) <= 127"
2291   "cpi %0,lo8(%1)"
2292   [(set_attr "cc" "compare")
2293    (set_attr "length" "1")])
2295 (define_insn "*cmphi"
2296   [(set (cc0)
2297         (compare (match_operand:HI 0 "register_operand"  "!w,r,r,d,d,r,r")
2298                  (match_operand:HI 1 "nonmemory_operand" "L,L,r,M,i,M,i")))
2299    (clobber (match_scratch:QI 2 "=X,X,X,X,&d,&d,&d"))]
2300   ""
2301   "*{
2302   switch (which_alternative)
2303     {
2304     case 0: case 1:
2305       return out_tsthi (insn, operands[0], NULL);
2307     case 2:
2308       return (AS2 (cp,%A0,%A1) CR_TAB
2309               AS2 (cpc,%B0,%B1));
2310     case 3:
2311       if (reg_unused_after (insn, operands[0])
2312           && INTVAL (operands[1]) >= 0 && INTVAL (operands[1]) <= 63
2313           && test_hard_reg_class (ADDW_REGS, operands[0]))
2314         return AS2 (sbiw,%0,%1);
2315        else
2316         return (AS2 (cpi,%0,%1) CR_TAB
2317                 AS2 (cpc,%B0,__zero_reg__));
2318     case 4:
2319       if (reg_unused_after (insn, operands[0]))
2320         return (AS2 (subi,%0,lo8(%1))  CR_TAB
2321                 AS2 (sbci,%B0,hi8(%1)));
2322       else
2323         return (AS2 (ldi, %2,hi8(%1))  CR_TAB
2324                 AS2 (cpi, %A0,lo8(%1)) CR_TAB
2325                 AS2 (cpc, %B0,%2));
2326    case 5:
2327       return (AS2 (ldi, %2,lo8(%1))  CR_TAB
2328               AS2 (cp, %A0,%2) CR_TAB
2329               AS2 (cpc, %B0,__zero_reg__));
2331    case 6:
2332       return (AS2 (ldi, %2,lo8(%1))  CR_TAB
2333               AS2 (cp, %A0,%2)       CR_TAB
2334               AS2 (ldi, %2,hi8(%1)) CR_TAB
2335               AS2 (cpc, %B0,%2));
2336     }
2337   return \"bug\";
2338 }" 
2339   [(set_attr "cc" "compare,compare,compare,compare,compare,compare,compare")
2340    (set_attr "length" "1,2,2,2,3,3,4")])
2343 (define_insn "*cmpsi"
2344   [(set (cc0)
2345         (compare (match_operand:SI 0 "register_operand"  "r,r,d,d,r,r")
2346                  (match_operand:SI 1 "nonmemory_operand" "L,r,M,i,M,i")))
2347    (clobber (match_scratch:QI 2 "=X,X,X,&d,&d,&d"))]
2348   ""
2349   "*{
2350   switch (which_alternative)
2351     {
2352     case 0:
2353       return out_tstsi (insn, operands[0], NULL);
2355     case 1:
2356       return (AS2 (cp,%A0,%A1) CR_TAB
2357               AS2 (cpc,%B0,%B1) CR_TAB
2358               AS2 (cpc,%C0,%C1) CR_TAB
2359               AS2 (cpc,%D0,%D1));
2360     case 2:
2361       if (reg_unused_after (insn, operands[0])
2362           && INTVAL (operands[1]) >= 0 && INTVAL (operands[1]) <= 63
2363           && test_hard_reg_class (ADDW_REGS, operands[0]))
2364         return (AS2 (sbiw,%0,%1) CR_TAB
2365                 AS2 (cpc,%C0,__zero_reg__) CR_TAB
2366                 AS2 (cpc,%D0,__zero_reg__));
2367       else
2368         return (AS2 (cpi,%A0,lo8(%1))  CR_TAB
2369                 AS2 (cpc,%B0,__zero_reg__) CR_TAB
2370                 AS2 (cpc,%C0,__zero_reg__) CR_TAB
2371                 AS2 (cpc,%D0,__zero_reg__));
2372     case 3:
2373       if (reg_unused_after (insn, operands[0]))
2374         return (AS2 (subi,%A0,lo8(%1))  CR_TAB
2375                 AS2 (sbci,%B0,hi8(%1))  CR_TAB
2376                 AS2 (sbci,%C0,hlo8(%1))  CR_TAB
2377                 AS2 (sbci,%D0,hhi8(%1)));
2378       else
2379        return (AS2 (cpi, %A0,lo8(%1))   CR_TAB
2380                AS2 (ldi, %2,hi8(%1))  CR_TAB
2381                AS2 (cpc, %B0,%2)       CR_TAB
2382                AS2 (ldi, %2,hlo8(%1))  CR_TAB
2383                AS2 (cpc, %C0,%2)       CR_TAB
2384                AS2 (ldi, %2,hhi8(%1)) CR_TAB
2385                AS2 (cpc, %D0,%2));
2386     case 4:
2387         return (AS2 (ldi,%2,lo8(%1))        CR_TAB
2388                 AS2 (cp,%A0,%2)            CR_TAB
2389                 AS2 (cpc,%B0,__zero_reg__) CR_TAB
2390                 AS2 (cpc,%C0,__zero_reg__) CR_TAB
2391                 AS2 (cpc,%D0,__zero_reg__));
2392     case 5:
2393        return (AS2 (ldi, %2,lo8(%1))   CR_TAB
2394                AS2 (cp, %A0,%2)        CR_TAB
2395                AS2 (ldi, %2,hi8(%1))  CR_TAB
2396                AS2 (cpc, %B0,%2)       CR_TAB
2397                AS2 (ldi, %2,hlo8(%1))  CR_TAB
2398                AS2 (cpc, %C0,%2)       CR_TAB
2399                AS2 (ldi, %2,hhi8(%1)) CR_TAB
2400                AS2 (cpc, %D0,%2));
2401     }
2402   return \"bug\";
2404   [(set_attr "cc" "compare,compare,compare,compare,compare,compare")
2405    (set_attr "length" "4,4,4,7,5,8")])
2408 ;; ----------------------------------------------------------------------
2409 ;; JUMP INSTRUCTIONS
2410 ;; ----------------------------------------------------------------------
2411 ;; Conditional jump instructions
2413 (define_expand "cbranchsi4"
2414   [(parallel [(set (cc0)
2415                    (compare (match_operand:SI 1 "register_operand" "")
2416                             (match_operand:SI 2 "nonmemory_operand" "")))
2417               (clobber (match_scratch:QI 4 ""))])
2418    (set (pc)
2419         (if_then_else
2420               (match_operator 0 "ordered_comparison_operator" [(cc0)
2421                                                                (const_int 0)])
2422               (label_ref (match_operand 3 "" ""))
2423               (pc)))]
2424  "")
2426 (define_expand "cbranchhi4"
2427   [(parallel [(set (cc0)
2428                    (compare (match_operand:HI 1 "register_operand" "")
2429                             (match_operand:HI 2 "nonmemory_operand" "")))
2430               (clobber (match_scratch:QI 4 ""))])
2431    (set (pc)
2432         (if_then_else
2433               (match_operator 0 "ordered_comparison_operator" [(cc0)
2434                                                                (const_int 0)])
2435               (label_ref (match_operand 3 "" ""))
2436               (pc)))]
2437  "")
2439 (define_expand "cbranchqi4"
2440   [(set (cc0)
2441         (compare (match_operand:QI 1 "register_operand" "")
2442                  (match_operand:QI 2 "nonmemory_operand" "")))
2443    (set (pc)
2444         (if_then_else
2445               (match_operator 0 "ordered_comparison_operator" [(cc0)
2446                                                                (const_int 0)])
2447               (label_ref (match_operand 3 "" ""))
2448               (pc)))]
2449  "")
2452 ;; Test a single bit in a QI/HI/SImode register.
2453 (define_insn "*sbrx_branch"
2454   [(set (pc)
2455         (if_then_else
2456          (match_operator 0 "eqne_operator"
2457                          [(zero_extract:HI
2458                            (match_operand:QI 1 "register_operand" "r")
2459                            (const_int 1)
2460                            (match_operand 2 "const_int_operand" "n"))
2461                           (const_int 0)])
2462          (label_ref (match_operand 3 "" ""))
2463          (pc)))]
2464   ""
2465   "* return avr_out_sbxx_branch (insn, operands);"
2466   [(set (attr "length")
2467         (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
2468                            (le (minus (pc) (match_dup 3)) (const_int 2046)))
2469                       (const_int 2)
2470                       (if_then_else (eq_attr "mcu_mega" "no")
2471                                     (const_int 2)
2472                                     (const_int 4))))
2473    (set_attr "cc" "clobber")])
2475 (define_insn "*sbrx_and_branchhi"
2476   [(set (pc)
2477         (if_then_else
2478          (match_operator 0 "eqne_operator"
2479                          [(and:HI
2480                            (match_operand:HI 1 "register_operand" "r")
2481                            (match_operand:HI 2 "single_one_operand" "n"))
2482                           (const_int 0)])
2483          (label_ref (match_operand 3 "" ""))
2484          (pc)))]
2485   ""
2486   "* return avr_out_sbxx_branch (insn, operands);"
2487   [(set (attr "length")
2488         (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
2489                            (le (minus (pc) (match_dup 3)) (const_int 2046)))
2490                       (const_int 2)
2491                       (if_then_else (eq_attr "mcu_mega" "no")
2492                                     (const_int 2)
2493                                     (const_int 4))))
2494    (set_attr "cc" "clobber")])
2496 (define_insn "*sbrx_and_branchsi"
2497   [(set (pc)
2498         (if_then_else
2499          (match_operator 0 "eqne_operator"
2500                          [(and:SI
2501                            (match_operand:SI 1 "register_operand" "r")
2502                            (match_operand:SI 2 "single_one_operand" "n"))
2503                           (const_int 0)])
2504          (label_ref (match_operand 3 "" ""))
2505          (pc)))]
2506   ""
2507   "* return avr_out_sbxx_branch (insn, operands);"
2508   [(set (attr "length")
2509         (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
2510                            (le (minus (pc) (match_dup 3)) (const_int 2046)))
2511                       (const_int 2)
2512                       (if_then_else (eq_attr "mcu_mega" "no")
2513                                     (const_int 2)
2514                                     (const_int 4))))
2515    (set_attr "cc" "clobber")])
2517 ;; Convert sign tests to bit 7/15/31 tests that match the above insns.
2518 (define_peephole2
2519   [(set (cc0) (compare (match_operand:QI 0 "register_operand" "")
2520                        (const_int 0)))
2521    (set (pc) (if_then_else (ge (cc0) (const_int 0))
2522                            (label_ref (match_operand 1 "" ""))
2523                            (pc)))]
2524   ""
2525   [(set (pc) (if_then_else (eq (zero_extract:HI (match_dup 0)
2526                                                 (const_int 1)
2527                                                 (const_int 7))
2528                                (const_int 0))
2529                            (label_ref (match_dup 1))
2530                            (pc)))]
2531   "")
2533 (define_peephole2
2534   [(set (cc0) (compare (match_operand:QI 0 "register_operand" "")
2535                        (const_int 0)))
2536    (set (pc) (if_then_else (lt (cc0) (const_int 0))
2537                            (label_ref (match_operand 1 "" ""))
2538                            (pc)))]
2539   ""
2540   [(set (pc) (if_then_else (ne (zero_extract:HI (match_dup 0)
2541                                                 (const_int 1)
2542                                                 (const_int 7))
2543                                (const_int 0))
2544                            (label_ref (match_dup 1))
2545                            (pc)))]
2546   "")
2548 (define_peephole2
2549   [(parallel [(set (cc0) (compare (match_operand:HI 0 "register_operand" "")
2550                                   (const_int 0)))
2551               (clobber (match_operand:HI 2 ""))])
2552    (set (pc) (if_then_else (ge (cc0) (const_int 0))
2553                            (label_ref (match_operand 1 "" ""))
2554                            (pc)))]
2555   ""
2556   [(set (pc) (if_then_else (eq (and:HI (match_dup 0) (const_int -32768))
2557                                (const_int 0))
2558                            (label_ref (match_dup 1))
2559                            (pc)))]
2560   "")
2562 (define_peephole2
2563   [(parallel [(set (cc0) (compare (match_operand:HI 0 "register_operand" "")
2564                                   (const_int 0)))
2565               (clobber (match_operand:HI 2 ""))])
2566    (set (pc) (if_then_else (lt (cc0) (const_int 0))
2567                            (label_ref (match_operand 1 "" ""))
2568                            (pc)))]
2569   ""
2570   [(set (pc) (if_then_else (ne (and:HI (match_dup 0) (const_int -32768))
2571                                (const_int 0))
2572                            (label_ref (match_dup 1))
2573                            (pc)))]
2574   "")
2576 (define_peephole2
2577   [(parallel [(set (cc0) (compare (match_operand:SI 0 "register_operand" "")
2578                                   (const_int 0)))
2579               (clobber (match_operand:SI 2 ""))])
2580    (set (pc) (if_then_else (ge (cc0) (const_int 0))
2581                            (label_ref (match_operand 1 "" ""))
2582                            (pc)))]
2583   ""
2584   [(set (pc) (if_then_else (eq (and:SI (match_dup 0) (match_dup 2))
2585                                (const_int 0))
2586                            (label_ref (match_dup 1))
2587                            (pc)))]
2588   "operands[2] = GEN_INT (-2147483647 - 1);")
2590 (define_peephole2
2591   [(parallel [(set (cc0) (compare (match_operand:SI 0 "register_operand" "")
2592                                   (const_int 0)))
2593               (clobber (match_operand:SI 2 ""))])
2594    (set (pc) (if_then_else (lt (cc0) (const_int 0))
2595                            (label_ref (match_operand 1 "" ""))
2596                            (pc)))]
2597   ""
2598   [(set (pc) (if_then_else (ne (and:SI (match_dup 0) (match_dup 2))
2599                                (const_int 0))
2600                            (label_ref (match_dup 1))
2601                            (pc)))]
2602   "operands[2] = GEN_INT (-2147483647 - 1);")
2604 ;; ************************************************************************
2605 ;; Implementation of conditional jumps here.
2606 ;;  Compare with 0 (test) jumps
2607 ;; ************************************************************************
2609 (define_insn "branch"
2610   [(set (pc)
2611         (if_then_else (match_operator 1 "simple_comparison_operator"
2612                         [(cc0)
2613                          (const_int 0)])
2614                       (label_ref (match_operand 0 "" ""))
2615                       (pc)))]
2616   ""
2617   "*
2618    return ret_cond_branch (operands[1], avr_jump_mode (operands[0],insn), 0);"
2619   [(set_attr "type" "branch")
2620    (set_attr "cc" "clobber")])
2622 ;; ****************************************************************
2623 ;; AVR does not have following conditional jumps: LE,LEU,GT,GTU.
2624 ;; Convert them all to proper jumps.
2625 ;; ****************************************************************/
2627 (define_insn "difficult_branch"
2628   [(set (pc)
2629         (if_then_else (match_operator 1 "difficult_comparison_operator"
2630                         [(cc0)
2631                          (const_int 0)])
2632                       (label_ref (match_operand 0 "" ""))
2633                       (pc)))]
2634   ""
2635   "*
2636    return ret_cond_branch (operands[1], avr_jump_mode (operands[0],insn), 0);"
2637   [(set_attr "type" "branch1")
2638    (set_attr "cc" "clobber")])
2640 ;; revers branch
2642 (define_insn "rvbranch"
2643   [(set (pc)
2644         (if_then_else (match_operator 1 "simple_comparison_operator" 
2645                         [(cc0)
2646                          (const_int 0)])
2647                       (pc)
2648                       (label_ref (match_operand 0 "" ""))))]
2649   ""
2650   "*
2651    return ret_cond_branch (operands[1], avr_jump_mode (operands[0], insn), 1);"
2652   [(set_attr "type" "branch1")
2653    (set_attr "cc" "clobber")])
2655 (define_insn "difficult_rvbranch"
2656   [(set (pc)
2657         (if_then_else (match_operator 1 "difficult_comparison_operator" 
2658                         [(cc0)
2659                          (const_int 0)])
2660                       (pc)
2661                       (label_ref (match_operand 0 "" ""))))]
2662   ""
2663   "*
2664    return ret_cond_branch (operands[1], avr_jump_mode (operands[0], insn), 1);"
2665   [(set_attr "type" "branch")
2666    (set_attr "cc" "clobber")])
2668 ;; **************************************************************************
2669 ;; Unconditional and other jump instructions.
2671 (define_insn "jump"
2672   [(set (pc)
2673         (label_ref (match_operand 0 "" "")))]
2674   ""
2675   "*{
2676   if (AVR_HAVE_JMP_CALL && get_attr_length (insn) != 1)
2677     return AS1 (jmp,%0);
2678   return AS1 (rjmp,%0);
2680   [(set (attr "length")
2681         (if_then_else (match_operand 0 "symbol_ref_operand" "") 
2682                 (if_then_else (eq_attr "mcu_mega" "no")
2683                               (const_int 1)
2684                               (const_int 2))
2685                 (if_then_else (and (ge (minus (pc) (match_dup 0)) (const_int -2047))
2686                                    (le (minus (pc) (match_dup 0)) (const_int 2047)))
2687                               (const_int 1)
2688                               (const_int 2))))
2689    (set_attr "cc" "none")])
2691 ;; call
2693 (define_expand "call"
2694   [(call (match_operand:HI 0 "call_insn_operand" "")
2695          (match_operand:HI 1 "general_operand" ""))]
2696   ;; Operand 1 not used on the AVR.
2697   ""
2698   "")
2700 ;; call value
2702 (define_expand "call_value"
2703   [(set (match_operand 0 "register_operand" "")
2704         (call (match_operand:HI 1 "call_insn_operand" "")
2705               (match_operand:HI 2 "general_operand" "")))]
2706   ;; Operand 2 not used on the AVR.
2707   ""
2708   "")
2710 (define_insn "call_insn"
2711   [(call (mem:HI (match_operand:HI 0 "nonmemory_operand" "!z,*r,s,n"))
2712          (match_operand:HI 1 "general_operand" "X,X,X,X"))]
2713 ;; We don't need in saving Z register because r30,r31 is a call used registers
2714   ;; Operand 1 not used on the AVR.
2715   "(register_operand (operands[0], HImode) || CONSTANT_P (operands[0]))"
2716   "*{
2717   if (which_alternative==0)
2718      return \"%!icall\";
2719   else if (which_alternative==1)
2720     {
2721       if (AVR_HAVE_MOVW)
2722         return (AS2 (movw, r30, %0) CR_TAB
2723                \"%!icall\");
2724       else
2725         return (AS2 (mov, r30, %A0) CR_TAB
2726                 AS2 (mov, r31, %B0) CR_TAB
2727                 \"%!icall\");
2728     }
2729   else if (which_alternative==2)
2730     return AS1(%~call,%c0);
2731   return (AS2 (ldi,r30,lo8(%0)) CR_TAB
2732           AS2 (ldi,r31,hi8(%0)) CR_TAB
2733           \"%!icall\");
2735   [(set_attr "cc" "clobber,clobber,clobber,clobber")
2736    (set_attr_alternative "length"
2737                          [(const_int 1)
2738                           (if_then_else (eq_attr "mcu_have_movw" "yes")
2739                                         (const_int 2)
2740                                         (const_int 3))
2741                           (if_then_else (eq_attr "mcu_mega" "yes")
2742                                         (const_int 2)
2743                                         (const_int 1))
2744                           (const_int 3)])])
2746 (define_insn "call_value_insn"
2747   [(set (match_operand 0 "register_operand" "=r,r,r,r")
2748         (call (mem:HI (match_operand:HI 1 "nonmemory_operand" "!z,*r,s,n"))
2749 ;; We don't need in saving Z register because r30,r31 is a call used registers
2750               (match_operand:HI 2 "general_operand" "X,X,X,X")))]
2751   ;; Operand 2 not used on the AVR.
2752   "(register_operand (operands[0], VOIDmode) || CONSTANT_P (operands[0]))"
2753   "*{
2754   if (which_alternative==0)
2755      return \"%!icall\";
2756   else if (which_alternative==1)
2757     {
2758       if (AVR_HAVE_MOVW)
2759         return (AS2 (movw, r30, %1) CR_TAB
2760                 \"%!icall\");
2761       else
2762         return (AS2 (mov, r30, %A1) CR_TAB
2763                 AS2 (mov, r31, %B1) CR_TAB
2764                 \"%!icall\");
2765     }
2766   else if (which_alternative==2)
2767     return AS1(%~call,%c1);
2768   return (AS2 (ldi, r30, lo8(%1)) CR_TAB
2769           AS2 (ldi, r31, hi8(%1)) CR_TAB
2770           \"%!icall\");
2772   [(set_attr "cc" "clobber,clobber,clobber,clobber")
2773    (set_attr_alternative "length"
2774                          [(const_int 1)
2775                           (if_then_else (eq_attr "mcu_have_movw" "yes")
2776                                         (const_int 2)
2777                                         (const_int 3))
2778                           (if_then_else (eq_attr "mcu_mega" "yes")
2779                                         (const_int 2)
2780                                         (const_int 1))
2781                           (const_int 3)])])
2783 (define_insn "nop"
2784   [(const_int 0)]
2785   ""
2786   "nop"
2787   [(set_attr "cc" "none")
2788    (set_attr "length" "1")])
2790 ; indirect jump
2791 (define_insn "indirect_jump"
2792   [(set (pc) (match_operand:HI 0 "register_operand" "!z,*r"))]
2793   "!AVR_HAVE_EIJMP_EICALL"
2794   "@
2795         ijmp
2796         push %A0\;push %B0\;ret"
2797   [(set_attr "length" "1,3")
2798    (set_attr "cc" "none,none")])
2800 (define_insn "*indirect_jump_avr6"
2801   [(set (pc) (match_operand:HI 0 "register_operand" "z"))]
2802   "AVR_HAVE_EIJMP_EICALL"
2803   "eijmp"
2804   [(set_attr "length" "1")
2805    (set_attr "cc" "none")])
2807 ;; table jump
2809 ;; Table made from "rjmp" instructions for <=8K devices.
2810 (define_insn "*tablejump_rjmp"
2811   [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "!z,*r")]
2812                         UNSPEC_INDEX_JMP))
2813    (use (label_ref (match_operand 1 "" "")))
2814    (clobber (match_dup 0))]
2815   "(!AVR_HAVE_JMP_CALL) && (!AVR_HAVE_EIJMP_EICALL)"
2816   "@
2817         ijmp
2818         push %A0\;push %B0\;ret"
2819   [(set_attr "length" "1,3")
2820    (set_attr "cc" "none,none")])
2822 ;; Not a prologue, but similar idea - move the common piece of code to libgcc.
2823 (define_insn "*tablejump_lib"
2824   [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")]
2825                         UNSPEC_INDEX_JMP))
2826    (use (label_ref (match_operand 1 "" "")))
2827    (clobber (match_dup 0))]
2828   "AVR_HAVE_JMP_CALL && TARGET_CALL_PROLOGUES"
2829   "jmp __tablejump2__"
2830   [(set_attr "length" "2")
2831    (set_attr "cc" "clobber")])
2833 (define_insn "*tablejump_enh"
2834   [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")]
2835                         UNSPEC_INDEX_JMP))
2836    (use (label_ref (match_operand 1 "" "")))
2837    (clobber (match_dup 0))]
2838   "AVR_HAVE_JMP_CALL && AVR_HAVE_LPMX"
2839   "lsl r30
2840         rol r31
2841         lpm __tmp_reg__,Z+
2842         lpm r31,Z
2843         mov r30,__tmp_reg__
2844         %!ijmp"
2845   [(set_attr "length" "6")
2846    (set_attr "cc" "clobber")])
2848 (define_insn "*tablejump"
2849   [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")]
2850                         UNSPEC_INDEX_JMP))
2851    (use (label_ref (match_operand 1 "" "")))
2852    (clobber (match_dup 0))]
2853   "AVR_HAVE_JMP_CALL && !AVR_HAVE_EIJMP_EICALL"
2854   "lsl r30
2855         rol r31
2856         lpm
2857         inc r30
2858         push r0
2859         lpm
2860         push r0
2861         ret"
2862   [(set_attr "length" "8")
2863    (set_attr "cc" "clobber")])
2865 (define_expand "casesi"
2866   [(set (match_dup 6)
2867         (minus:HI (subreg:HI (match_operand:SI 0 "register_operand" "") 0)
2868                   (match_operand:HI 1 "register_operand" "")))
2869    (parallel [(set (cc0)
2870                    (compare (match_dup 6)
2871                             (match_operand:HI 2 "register_operand" "")))
2872               (clobber (match_scratch:QI 9 ""))])
2873    
2874    (set (pc)
2875         (if_then_else (gtu (cc0)
2876                            (const_int 0))
2877                       (label_ref (match_operand 4 "" ""))
2878                       (pc)))
2880    (set (match_dup 6)
2881         (plus:HI (match_dup 6) (label_ref (match_operand:HI 3 "" ""))))
2883    (parallel [(set (pc) (unspec:HI [(match_dup 6)] UNSPEC_INDEX_JMP))
2884               (use (label_ref (match_dup 3)))
2885               (clobber (match_dup 6))])]
2886   ""
2887   "
2889   operands[6] = gen_reg_rtx (HImode);
2893 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2894 ;; This instruction sets Z flag
2896 (define_insn "sez"
2897   [(set (cc0) (const_int 0))]
2898   ""
2899   "sez"
2900   [(set_attr "length" "1")
2901    (set_attr "cc" "compare")])
2903 ;; Clear/set/test a single bit in I/O address space.
2905 (define_insn "*cbi"
2906   [(set (mem:QI (match_operand 0 "low_io_address_operand" "n"))
2907         (and:QI (mem:QI (match_dup 0))
2908                 (match_operand:QI 1 "single_zero_operand" "n")))]
2909   "(optimize > 0)"
2911   operands[2] = GEN_INT (exact_log2 (~INTVAL (operands[1]) & 0xff));
2912   return AS2 (cbi,%0-0x20,%2);
2914   [(set_attr "length" "1")
2915    (set_attr "cc" "none")])
2917 (define_insn "*sbi"
2918   [(set (mem:QI (match_operand 0 "low_io_address_operand" "n"))
2919         (ior:QI (mem:QI (match_dup 0))
2920                 (match_operand:QI 1 "single_one_operand" "n")))]
2921   "(optimize > 0)"
2923   operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1]) & 0xff));
2924   return AS2 (sbi,%0-0x20,%2);
2926   [(set_attr "length" "1")
2927    (set_attr "cc" "none")])
2929 ;; Lower half of the I/O space - use sbic/sbis directly.
2930 (define_insn "*sbix_branch"
2931   [(set (pc)
2932         (if_then_else
2933          (match_operator 0 "eqne_operator"
2934                          [(zero_extract:HI
2935                            (mem:QI (match_operand 1 "low_io_address_operand" "n"))
2936                            (const_int 1)
2937                            (match_operand 2 "const_int_operand" "n"))
2938                           (const_int 0)])
2939          (label_ref (match_operand 3 "" ""))
2940          (pc)))]
2941   "(optimize > 0)"
2942   "* return avr_out_sbxx_branch (insn, operands);"
2943   [(set (attr "length")
2944         (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
2945                            (le (minus (pc) (match_dup 3)) (const_int 2046)))
2946                       (const_int 2)
2947                       (if_then_else (eq_attr "mcu_mega" "no")
2948                                     (const_int 2)
2949                                     (const_int 4))))
2950    (set_attr "cc" "clobber")])
2952 ;; Tests of bit 7 are pessimized to sign tests, so we need this too...
2953 (define_insn "*sbix_branch_bit7"
2954   [(set (pc)
2955         (if_then_else
2956          (match_operator 0 "gelt_operator"
2957                          [(mem:QI (match_operand 1 "low_io_address_operand" "n"))
2958                           (const_int 0)])
2959          (label_ref (match_operand 2 "" ""))
2960          (pc)))]
2961   "(optimize > 0)"
2963   operands[3] = operands[2];
2964   operands[2] = GEN_INT (7);
2965   return avr_out_sbxx_branch (insn, operands);
2967   [(set (attr "length")
2968         (if_then_else (and (ge (minus (pc) (match_dup 2)) (const_int -2046))
2969                            (le (minus (pc) (match_dup 2)) (const_int 2046)))
2970                       (const_int 2)
2971                       (if_then_else (eq_attr "mcu_mega" "no")
2972                                     (const_int 2)
2973                                     (const_int 4))))
2974    (set_attr "cc" "clobber")])
2976 ;; Upper half of the I/O space - read port to __tmp_reg__ and use sbrc/sbrs.
2977 (define_insn "*sbix_branch_tmp"
2978   [(set (pc)
2979         (if_then_else
2980          (match_operator 0 "eqne_operator"
2981                          [(zero_extract:HI
2982                            (mem:QI (match_operand 1 "high_io_address_operand" "n"))
2983                            (const_int 1)
2984                            (match_operand 2 "const_int_operand" "n"))
2985                           (const_int 0)])
2986          (label_ref (match_operand 3 "" ""))
2987          (pc)))]
2988   "(optimize > 0)"
2989   "* return avr_out_sbxx_branch (insn, operands);"
2990   [(set (attr "length")
2991         (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
2992                            (le (minus (pc) (match_dup 3)) (const_int 2045)))
2993                       (const_int 3)
2994                       (if_then_else (eq_attr "mcu_mega" "no")
2995                                     (const_int 3)
2996                                     (const_int 5))))
2997    (set_attr "cc" "clobber")])
2999 (define_insn "*sbix_branch_tmp_bit7"
3000   [(set (pc)
3001         (if_then_else
3002          (match_operator 0 "gelt_operator"
3003                          [(mem:QI (match_operand 1 "high_io_address_operand" "n"))
3004                           (const_int 0)])
3005          (label_ref (match_operand 2 "" ""))
3006          (pc)))]
3007   "(optimize > 0)"
3009   operands[3] = operands[2];
3010   operands[2] = GEN_INT (7);
3011   return avr_out_sbxx_branch (insn, operands);
3013   [(set (attr "length")
3014         (if_then_else (and (ge (minus (pc) (match_dup 2)) (const_int -2046))
3015                            (le (minus (pc) (match_dup 2)) (const_int 2045)))
3016                       (const_int 3)
3017                       (if_then_else (eq_attr "mcu_mega" "no")
3018                                     (const_int 3)
3019                                     (const_int 5))))
3020    (set_attr "cc" "clobber")])
3022 ;; ************************* Peepholes ********************************
3024 (define_peephole
3025   [(set (match_operand:SI 0 "d_register_operand" "")
3026         (plus:SI (match_dup 0)
3027                  (const_int -1)))
3028    (parallel
3029     [(set (cc0)
3030           (compare (match_dup 0)
3031                    (const_int -1)))
3032      (clobber (match_operand:QI 1 "d_register_operand" ""))])
3033    (set (pc)
3034         (if_then_else (ne (cc0) (const_int 0))
3035                       (label_ref (match_operand 2 "" ""))
3036                       (pc)))]
3037   ""
3038   "*
3040   CC_STATUS_INIT;
3041   if (test_hard_reg_class (ADDW_REGS, operands[0]))
3042     output_asm_insn (AS2 (sbiw,%0,1) CR_TAB
3043                      AS2 (sbc,%C0,__zero_reg__) CR_TAB
3044                      AS2 (sbc,%D0,__zero_reg__) \"\\n\", operands);
3045   else
3046     output_asm_insn (AS2 (subi,%A0,1) CR_TAB
3047                      AS2 (sbc,%B0,__zero_reg__) CR_TAB
3048                      AS2 (sbc,%C0,__zero_reg__) CR_TAB
3049                      AS2 (sbc,%D0,__zero_reg__) \"\\n\", operands);
3050   switch (avr_jump_mode (operands[2],insn))
3051   {
3052     case 1:
3053       return AS1 (brcc,%2);
3054     case 2:
3055       return (AS1 (brcs,.+2) CR_TAB
3056               AS1 (rjmp,%2));
3057   }
3058   return (AS1 (brcs,.+4) CR_TAB
3059           AS1 (jmp,%2));
3062 (define_peephole
3063   [(set (match_operand:HI 0 "d_register_operand" "")
3064         (plus:HI (match_dup 0)
3065                  (const_int -1)))
3066    (parallel
3067     [(set (cc0)
3068           (compare (match_dup 0)
3069                    (const_int 65535)))
3070      (clobber (match_operand:QI 1 "d_register_operand" ""))])
3071    (set (pc)
3072         (if_then_else (ne (cc0) (const_int 0))
3073                       (label_ref (match_operand 2 "" ""))
3074                       (pc)))]
3075   ""
3076   "*
3078   CC_STATUS_INIT;
3079   if (test_hard_reg_class (ADDW_REGS, operands[0]))
3080     output_asm_insn (AS2 (sbiw,%0,1), operands);
3081   else
3082     output_asm_insn (AS2 (subi,%A0,1) CR_TAB
3083                      AS2 (sbc,%B0,__zero_reg__) \"\\n\", operands);
3084   switch (avr_jump_mode (operands[2],insn))
3085   {
3086     case 1:
3087       return AS1 (brcc,%2);
3088     case 2:
3089       return (AS1 (brcs,.+2) CR_TAB
3090               AS1 (rjmp,%2));
3091   }
3092   return (AS1 (brcs,.+4) CR_TAB
3093           AS1 (jmp,%2));
3096 (define_peephole
3097   [(set (match_operand:QI 0 "d_register_operand" "")
3098         (plus:QI (match_dup 0)
3099                  (const_int -1)))
3100    (set (cc0)
3101         (compare (match_dup 0)
3102                  (const_int -1)))
3103    (set (pc)
3104         (if_then_else (ne (cc0) (const_int 0))
3105                       (label_ref (match_operand 1 "" ""))
3106                       (pc)))]
3107   ""
3108   "*
3110   CC_STATUS_INIT;
3111   cc_status.value1 = operands[0];
3112   cc_status.flags |= CC_OVERFLOW_UNUSABLE;
3113   output_asm_insn (AS2 (subi,%A0,1), operands);
3114   switch (avr_jump_mode (operands[1],insn))
3115   {
3116     case 1:
3117       return AS1 (brcc,%1);
3118     case 2:
3119       return (AS1 (brcs,.+2) CR_TAB
3120               AS1 (rjmp,%1));
3121   }
3122   return (AS1 (brcs,.+4) CR_TAB
3123           AS1 (jmp,%1));
3126 (define_peephole
3127   [(set (cc0)
3128         (compare (match_operand:QI 0 "register_operand" "")
3129                  (const_int 0)))
3130    (set (pc)
3131         (if_then_else (eq (cc0) (const_int 0))
3132                       (label_ref (match_operand 1 "" ""))
3133                       (pc)))]
3134   "jump_over_one_insn_p (insn, operands[1])"
3135   "cpse %0,__zero_reg__")
3137 (define_peephole
3138   [(set (cc0)
3139         (compare (match_operand:QI 0 "register_operand" "")
3140                  (match_operand:QI 1 "register_operand" "")))
3141    (set (pc)
3142         (if_then_else (eq (cc0) (const_int 0))
3143                       (label_ref (match_operand 2 "" ""))
3144                       (pc)))]
3145   "jump_over_one_insn_p (insn, operands[2])"
3146   "cpse %0,%1")
3148 ;;pppppppppppppppppppppppppppppppppppppppppppppppppppp
3149 ;;prologue/epilogue support instructions
3151 (define_insn "popqi"
3152   [(set (match_operand:QI 0 "register_operand" "=r")
3153         (mem:QI (post_inc (reg:HI REG_SP))))]
3154   ""
3155   "pop %0"
3156   [(set_attr "cc" "none")
3157    (set_attr "length" "1")])
3159 (define_insn "pophi"
3160   [(set (match_operand:HI 0 "register_operand" "=r")
3161         (mem:HI (post_inc (reg:HI REG_SP))))]
3162   ""
3163   "pop %A0\;pop %B0"
3164   [(set_attr "cc" "none")
3165    (set_attr "length" "2")])
3167 ;; Enable Interrupts
3168 (define_insn "enable_interrupt"
3169   [(unspec [(const_int 0)] UNSPEC_SEI)]
3170   ""
3171   "sei"
3172   [(set_attr "length" "1")
3173   (set_attr "cc" "none")
3174   ])
3176 ;; Disable Interrupts
3177 (define_insn "disable_interrupt"
3178   [(unspec [(const_int 0)] UNSPEC_CLI)]
3179   ""
3180   "cli"
3181   [(set_attr "length" "1")
3182   (set_attr "cc" "none")
3183   ])
3185 ;;  Library prologue saves
3186 (define_insn "call_prologue_saves"
3187   [(unspec_volatile:HI [(const_int 0)] UNSPECV_PROLOGUE_SAVES)
3188    (match_operand:HI 0 "immediate_operand" "")
3189    (set (reg:HI REG_SP) (minus:HI 
3190                            (reg:HI REG_SP)
3191                            (match_operand:HI 1 "immediate_operand" "")))
3192    (use (reg:HI REG_X))
3193    (clobber (reg:HI REG_Z))]
3194   ""
3195   "ldi r30,lo8(gs(1f))
3196         ldi r31,hi8(gs(1f))
3197         %~jmp __prologue_saves__+((18 - %0) * 2)
3199   [(set_attr_alternative "length"
3200                          [(if_then_else (eq_attr "mcu_mega" "yes")
3201                                         (const_int 6)
3202                                         (const_int 5))])
3203   (set_attr "cc" "clobber")
3204   ])
3205   
3206 ;  epilogue  restores using library
3207 (define_insn "epilogue_restores"
3208   [(unspec_volatile:QI [(const_int 0)] UNSPECV_EPILOGUE_RESTORES)
3209    (set (reg:HI REG_Y ) (plus:HI 
3210                            (reg:HI REG_Y)
3211                            (match_operand:HI 0 "immediate_operand" ""))) 
3212    (set (reg:HI REG_SP) (reg:HI REG_Y))
3213    (clobber  (reg:QI REG_Z))]
3214   ""
3215   "ldi r30, lo8(%0)
3216         %~jmp __epilogue_restores__ + ((18 - %0) * 2)"
3217   [(set_attr_alternative "length"
3218                          [(if_then_else (eq_attr "mcu_mega" "yes")
3219                                         (const_int 3)
3220                                         (const_int 2))])
3221   (set_attr "cc" "clobber")
3222   ])
3223   
3224 ; return
3225 (define_insn "return"
3226   [(return)]
3227   "reload_completed && avr_simple_epilogue ()"
3228   "ret"
3229   [(set_attr "cc" "none")
3230    (set_attr "length" "1")])
3232 (define_insn "return_from_epilogue"
3233   [(return)]
3234   "(reload_completed 
3235     && cfun->machine 
3236     && !(cfun->machine->is_interrupt || cfun->machine->is_signal)
3237     && !cfun->machine->is_naked)"
3238   "ret"
3239   [(set_attr "cc" "none")
3240    (set_attr "length" "1")])
3242 (define_insn "return_from_interrupt_epilogue"
3243   [(return)]
3244   "(reload_completed 
3245     && cfun->machine 
3246     && (cfun->machine->is_interrupt || cfun->machine->is_signal)
3247     && !cfun->machine->is_naked)"
3248   "reti"
3249   [(set_attr "cc" "none")
3250    (set_attr "length" "1")])
3252 (define_insn "return_from_naked_epilogue"
3253   [(return)]
3254   "(reload_completed 
3255     && cfun->machine 
3256     && cfun->machine->is_naked)"
3257   ""
3258   [(set_attr "cc" "none")
3259    (set_attr "length" "0")])
3261 (define_expand "prologue"
3262   [(const_int 0)]
3263   ""
3264   "
3265   {
3266     expand_prologue (); 
3267     DONE;
3268   }")
3270 (define_expand "epilogue"
3271   [(const_int 0)]
3272   ""
3273   "
3274   {
3275     expand_epilogue (); 
3276     DONE;
3277   }")