OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / config / avr / avr.md
index c6da08a..d0b96e1 100644 (file)
@@ -1,7 +1,7 @@
 ;; -*- Mode: Scheme -*-
 ;;   Machine description for GNU compiler,
 ;;   for ATMEL AVR micro controllers.
-;;   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005
+;;   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007
 ;;   Free Software Foundation, Inc.
 ;;   Contributed by Denis Chertykov (denisc@overta.ru)
 
@@ -19,8 +19,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GCC; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;; Special characters after '%':
 ;;  A  No effect (add 0).
 ;;  j  Branch condition.
 ;;  k  Reverse branch condition.
 ;;  o  Displacement for (mem (plus (reg) (const_int))) operands.
+;;  p  POST_INC or PRE_DEC address as a pointer (X, Y, Z)
+;;  r  POST_INC or PRE_DEC address as a register (r26, r28, r30)
 ;;  ~  Output 'r' if not AVR_MEGA.
 
 ;; UNSPEC usage:
 ;;  0  Length of a string, see "strlenhi".
-;;  1  Read from a word address in program memory, see "casesi".
-
+;;  1  Jump by register pair Z or by table addressed by Z, see "casesi".
+
+(define_constants
+  [(REG_X      26)
+   (REG_Y      28)
+   (REG_Z      30)
+   (REG_W      24)
+   (REG_SP     32)
+   (TMP_REGNO  0)      ; temporary register r0
+   (ZERO_REGNO 1)      ; zero register r1
+   (UNSPEC_STRLEN      0)
+   (UNSPEC_INDEX_JMP   1)])
+
+(include "predicates.md")
+(include "constraints.md")
+  
 ;; Condition code settings.
 (define_attr "cc" "none,set_czn,set_zn,set_n,compare,clobber"
   (const_string "none"))
@@ -43,8 +59,8 @@
 (define_attr "type" "branch,branch1,arith,xcall"
   (const_string "arith"))
 
-(define_attr "mcu_enhanced" "yes,no"
-  (const (if_then_else (symbol_ref "AVR_ENHANCED")
+(define_attr "mcu_have_movw" "yes,no"
+  (const (if_then_else (symbol_ref "AVR_HAVE_MOVW")
                       (const_string "yes")
                       (const_string "no"))))
 
   [(set_attr "length" "5")])
 
 (define_insn "*pushqi"
-  [(set (mem:QI (post_dec (reg:HI 32)))
-        (match_operand:QI 0 "nonmemory_operand" "r,L"))]
-  "(operands[0] == const0_rtx || register_operand (operands[0], QImode))"
+  [(set (mem:QI (post_dec (reg:HI REG_SP)))
+        (match_operand:QI 0 "reg_or_0_operand" "r,L"))]
+  ""
   "@
        push %0
        push __zero_reg__"
 
 
 (define_insn "*pushhi"
-  [(set (mem:HI (post_dec (reg:HI 32)))
-        (match_operand:HI 0 "nonmemory_operand" "r,L"))]
-  "(operands[0] == const0_rtx || register_operand (operands[0], HImode))"
+  [(set (mem:HI (post_dec (reg:HI REG_SP)))
+        (match_operand:HI 0 "reg_or_0_operand" "r,L"))]
+  ""
   "@
        push %B0\;push %A0
        push __zero_reg__\;push __zero_reg__"
   [(set_attr "length" "2,2")])
 
 (define_insn "*pushsi"
-  [(set (mem:SI (post_dec (reg:HI 32)))
-        (match_operand:SI 0 "nonmemory_operand" "r,L"))]
-  "(operands[0] == const0_rtx || register_operand (operands[0], SImode))"
+  [(set (mem:SI (post_dec (reg:HI REG_SP)))
+        (match_operand:SI 0 "reg_or_0_operand" "r,L"))]
+  ""
   "@
        push %D0\;push %C0\;push %B0\;push %A0
        push __zero_reg__\;push __zero_reg__\;push __zero_reg__\;push __zero_reg__"
   [(set_attr "length" "4,4")])
 
 (define_insn "*pushsf"
-  [(set (mem:SF (post_dec (reg:HI 32)))
+  [(set (mem:SF (post_dec (reg:HI REG_SP)))
         (match_operand:SF 0 "register_operand" "r"))]
   ""
   "push %D0
 
 (define_peephole2
   [(match_scratch:QI 2 "d")
-   (set (match_operand:QI 0 "register_operand" "")
+   (set (match_operand:QI 0 "l_register_operand" "")
        (match_operand:QI 1 "immediate_operand" ""))]
   "(operands[1] != const0_rtx
-    && test_hard_reg_class (NO_LD_REGS, operands[0]))"
+    && operands[1] != const1_rtx
+    && operands[1] != constm1_rtx)"
   [(parallel [(set (match_dup 0) (match_dup 1))
              (clobber (match_dup 2))])]
   "if (!avr_peep2_scratch_safe (operands[2]))
 
 (define_peephole2
   [(match_scratch:QI 2 "d")
-   (set (match_operand:HI 0 "register_operand" "")
-       (match_operand:HI 1 "immediate_operand" ""))]
-  "(operands[1] != const0_rtx
-    && test_hard_reg_class (NO_LD_REGS, operands[0]))"
+   (set (match_operand:HI 0 "l_register_operand" "")
+        (match_operand:HI 1 "immediate_operand" ""))]
+  "(operands[1] != const0_rtx 
+    && operands[1] != constm1_rtx)"
   [(parallel [(set (match_dup 0) (match_dup 1))
              (clobber (match_dup 2))])]
   "if (!avr_peep2_scratch_safe (operands[2]))
 
 (define_peephole2
   [(match_scratch:QI 2 "d")
-   (set (match_operand:SI 0 "register_operand" "")
-       (match_operand:SI 1 "immediate_operand" ""))]
+   (set (match_operand:SI 0 "l_register_operand" "")
+        (match_operand:SI 1 "immediate_operand" ""))]
   "(operands[1] != const0_rtx
-    && test_hard_reg_class (NO_LD_REGS, operands[0]))"
+    && operands[1] != constm1_rtx)"
   [(parallel [(set (match_dup 0) (match_dup 1))
              (clobber (match_dup 2))])]
   "if (!avr_peep2_scratch_safe (operands[2]))
 
 ;;=========================================================================
 ;; move string (like memcpy)
+;; implement as RTL loop
 
 (define_expand "movmemhi"
   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
-                  (match_operand:BLK 1 "memory_operand" ""))
-             (use (match_operand:HI 2 "const_int_operand" ""))
-             (use (match_operand:HI 3 "const_int_operand" ""))
-             (clobber (match_scratch:HI 4 ""))
-             (clobber (match_scratch:HI 5 ""))
-             (clobber (match_dup 6))])]
+          (match_operand:BLK 1 "memory_operand" ""))
+          (use (match_operand:HI 2 "const_int_operand" ""))
+          (use (match_operand:HI 3 "const_int_operand" ""))])]
   ""
   "{
-  rtx addr0, addr1;
-  int cnt8;
+  int prob;
+  HOST_WIDE_INT count;
   enum machine_mode mode;
+  rtx label = gen_label_rtx ();
+  rtx loop_reg;
+  rtx jump;
+
+  /* Copy pointers into new psuedos - they will be changed.  */
+  rtx addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
+  rtx addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
+
+  /* Create rtx for tmp register - we use this as scratch.  */
+  rtx tmp_reg_rtx  = gen_rtx_REG (QImode, TMP_REGNO);
 
   if (GET_CODE (operands[2]) != CONST_INT)
     FAIL;
-  cnt8 = byte_immediate_operand (operands[2], GET_MODE (operands[2]));
-  mode = cnt8 ? QImode : HImode;
-  operands[6] = gen_rtx_SCRATCH (mode);
-  operands[2] = copy_to_mode_reg (mode,
-                                  gen_int_mode (INTVAL (operands[2]), mode));
-  addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
-  addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0));
-
-  operands[0] = gen_rtx_MEM (BLKmode, addr0);
-  operands[1] = gen_rtx_MEM (BLKmode, addr1);
-}")
 
-(define_insn "*movmemqi_insn"
-  [(set (mem:BLK (match_operand:HI 0 "register_operand" "e"))
-       (mem:BLK (match_operand:HI 1 "register_operand" "e")))
-   (use (match_operand:QI 2 "register_operand" "r"))
-   (use (match_operand:QI 3 "const_int_operand" "i"))
-   (clobber (match_scratch:HI 4 "=0"))
-   (clobber (match_scratch:HI 5 "=1"))
-   (clobber (match_scratch:QI 6 "=2"))]
-  ""
-  "ld __tmp_reg__,%a1+
-       st %a0+,__tmp_reg__
-       dec %2
-       brne .-8"
-  [(set_attr "length" "4")
-   (set_attr "cc" "clobber")])
+  count = INTVAL (operands[2]);
+  if (count <= 0)
+    FAIL;
 
-(define_insn "*movmemhi"
-  [(set (mem:BLK (match_operand:HI 0 "register_operand" "e,e"))
-       (mem:BLK (match_operand:HI 1 "register_operand" "e,e")))
-   (use (match_operand:HI 2 "register_operand" "!w,d"))
-   (use (match_operand:HI 3 "const_int_operand" ""))
-   (clobber (match_scratch:HI 4 "=0,0"))
-   (clobber (match_scratch:HI 5 "=1,1"))
-   (clobber (match_scratch:HI 6 "=2,2"))]
-  ""
-  "*{
-     if (which_alternative==0)
-       return (AS2 (ld,__tmp_reg__,%a1+) CR_TAB
-              AS2 (st,%a0+,__tmp_reg__)  CR_TAB
-              AS2 (sbiw,%A2,1) CR_TAB
-              AS1 (brne,.-8));
-     else
-       return (AS2 (ld,__tmp_reg__,%a1+) CR_TAB
-              AS2 (st,%a0+,__tmp_reg__)  CR_TAB
-              AS2 (subi,%A2,1) CR_TAB
-              AS2 (sbci,%B2,0) CR_TAB
-              AS1 (brne,.-10));
-}"
-  [(set_attr "length" "4,5")
-   (set_attr "cc" "clobber,clobber")])
+  /* Work out branch probability for latter use.  */
+  prob = REG_BR_PROB_BASE - REG_BR_PROB_BASE / count;
+
+  /* See if constant fit 8 bits.  */
+  mode = (count < 0x100) ? QImode : HImode;
+  /* Create loop counter register.  */
+  loop_reg = copy_to_mode_reg (mode, gen_int_mode (count, mode));
+
+  /* Now create RTL code for move loop.  */
+  /* Label at top of loop.  */
+  emit_label (label);
+
+  /* Move one byte into scratch and inc pointer.  */
+  emit_move_insn (tmp_reg_rtx, gen_rtx_MEM (QImode, addr1));
+  emit_move_insn (addr1, gen_rtx_PLUS (Pmode, addr1, const1_rtx));
+
+  /* Move to mem and inc pointer.  */
+  emit_move_insn (gen_rtx_MEM (QImode, addr0), tmp_reg_rtx);
+  emit_move_insn (addr0, gen_rtx_PLUS (Pmode, addr0, const1_rtx));
+
+  /* Decrement count.  */
+  emit_move_insn (loop_reg, gen_rtx_PLUS (mode, loop_reg, constm1_rtx));
+
+  /* Compare with zero and jump if not equal. */
+  emit_cmp_and_jump_insns (loop_reg, const0_rtx, NE, NULL_RTX, mode, 1,
+                           label);
+  /* Set jump probability based on loop count.  */
+  jump = get_last_insn ();
+  REG_NOTES (jump) = gen_rtx_EXPR_LIST (REG_BR_PROB,
+                    GEN_INT (prob),
+                    REG_NOTES (jump));
+  DONE;
+}")
 
-;; =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0 =0
-;; memset (%0, 0, %1)
+;; =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2 =%2
+;; memset (%0, %2, %1)
 
-(define_expand "clrmemhi"
+(define_expand "setmemhi"
   [(parallel [(set (match_operand:BLK 0 "memory_operand" "")
-                  (const_int 0))
+                  (match_operand 2 "const_int_operand" ""))
              (use (match_operand:HI 1 "const_int_operand" ""))
-             (use (match_operand:HI 2 "const_int_operand" "n"))
-             (clobber (match_scratch:HI 3 ""))
-             (clobber (match_dup 4))])]
+             (use (match_operand:HI 3 "const_int_operand" "n"))
+             (clobber (match_scratch:HI 4 ""))
+             (clobber (match_dup 5))])]
   ""
   "{
   rtx addr0;
   int cnt8;
   enum machine_mode mode;
 
+  /* If value to set is not zero, use the library routine.  */
+  if (operands[2] != const0_rtx)
+    FAIL;
+
   if (GET_CODE (operands[1]) != CONST_INT)
     FAIL;
 
   cnt8 = byte_immediate_operand (operands[1], GET_MODE (operands[1]));
   mode = cnt8 ? QImode : HImode;
-  operands[4] = gen_rtx_SCRATCH (mode);
+  operands[5] = gen_rtx_SCRATCH (mode);
   operands[1] = copy_to_mode_reg (mode,
                                   gen_int_mode (INTVAL (operands[1]), mode));
   addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0));
     [(set (match_dup 4)
          (unspec:HI [(match_operand:BLK 1 "memory_operand" "")
                      (match_operand:QI 2 "const_int_operand" "")
-                     (match_operand:HI 3 "immediate_operand" "")] 0))
+                     (match_operand:HI 3 "immediate_operand" "")]
+                    UNSPEC_STRLEN))
      (set (match_dup 4) (plus:HI (match_dup 4)
                                 (const_int -1)))
      (set (match_operand:HI 0 "register_operand" "")
   [(set (match_operand:HI 0 "register_operand" "=e")
        (unspec:HI [(mem:BLK (match_operand:HI 1 "register_operand" "%0"))
                    (const_int 0)
-                   (match_operand:HI 2 "immediate_operand" "i")] 0))]
+                   (match_operand:HI 2 "immediate_operand" "i")]
+                  UNSPEC_STRLEN))]
   ""
   "ld __tmp_reg__,%a0+
        tst __tmp_reg__
                 (match_operand:QI 2 "register_operand" "")))]
   ""
   "{
-  if (!AVR_ENHANCED)
+  if (!AVR_HAVE_MUL)
     {
       emit_insn (gen_mulqi3_call (operands[0], operands[1], operands[2]));
       DONE;
   [(set (match_operand:QI 0 "register_operand" "=r")
        (mult:QI (match_operand:QI 1 "register_operand" "r")
                 (match_operand:QI 2 "register_operand" "r")))]
-  "AVR_ENHANCED"
+  "AVR_HAVE_MUL"
   "mul %1,%2
        mov %0,r0
        clr r1"
 (define_insn "*mulqi3_call"
   [(set (reg:QI 24) (mult:QI (reg:QI 24) (reg:QI 22)))
    (clobber (reg:QI 22))]
-  "!AVR_ENHANCED"
+  "!AVR_HAVE_MUL"
   "%~call __mulqi3"
   [(set_attr "type" "xcall")
    (set_attr "cc" "clobber")])
   [(set (match_operand:HI 0 "register_operand" "=r")
        (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "d"))
                 (sign_extend:HI (match_operand:QI 2 "register_operand" "d"))))]
-  "AVR_ENHANCED"
+  "AVR_HAVE_MUL"
   "muls %1,%2
        movw %0,r0
        clr r1"
   [(set (match_operand:HI 0 "register_operand" "=r")
        (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand" "r"))
                 (zero_extend:HI (match_operand:QI 2 "register_operand" "r"))))]
-  "AVR_ENHANCED"
+  "AVR_HAVE_MUL"
   "mul %1,%2
        movw %0,r0
        clr r1"
   ""
   "
 {
-  if (!AVR_ENHANCED)
+  if (!AVR_HAVE_MUL)
     {
       emit_insn (gen_mulhi3_call (operands[0], operands[1], operands[2]));
       DONE;
   [(set (match_operand:HI 0 "register_operand" "=&r")
        (mult:HI (match_operand:HI 1 "register_operand" "r")
                 (match_operand:HI 2 "register_operand" "r")))]
-  "AVR_ENHANCED"
+  "AVR_HAVE_MUL"
   "mul %A1,%A2
        movw %0,r0
        mul %A1,%B2
   [(set (reg:HI 24) (mult:HI (reg:HI 24) (reg:HI 22)))
    (clobber (reg:HI 22))
    (clobber (reg:QI 21))]
-  "!AVR_ENHANCED"
+  "!AVR_HAVE_MUL"
   "%~call __mulhi3"
   [(set_attr "type" "xcall")
    (set_attr "cc" "clobber")])
              (clobber (reg:HI 26))
              (clobber (reg:HI 30))])
    (set (match_operand:SI 0 "register_operand" "") (reg:SI 22))]
-  "AVR_ENHANCED"
+  "AVR_HAVE_MUL"
   "")
 
 (define_insn "*mulsi3_call"
   [(set (reg:SI 22) (mult:SI (reg:SI 22) (reg:SI 18)))
    (clobber (reg:HI 26))
    (clobber (reg:HI 30))]
-  "AVR_ENHANCED"
+  "AVR_HAVE_MUL"
   "%~call __mulsi3"
   [(set_attr "type" "xcall")
    (set_attr "cc" "clobber")])
   [(set_attr_alternative "length"
                         [(const_int 7)
                          (const_int 8)
-                         (if_then_else (eq_attr "mcu_enhanced" "yes")
+                         (if_then_else (eq_attr "mcu_have_movw" "yes")
                                        (const_int 7)
                                        (const_int 8))])
    (set_attr "cc" "set_czn,set_n,set_czn")])
        {mov %A0,%A1\;mov %B0,%B1|movw %A0,%A1}\;clr %C0\;sbrc %B0,7\;com %C0\;mov %D0,%C0"
   [(set_attr_alternative "length"
                         [(const_int 4)
-                         (if_then_else (eq_attr "mcu_enhanced" "yes")
+                         (if_then_else (eq_attr "mcu_have_movw" "yes")
                                        (const_int 5)
                                        (const_int 6))])
    (set_attr "cc" "set_n,set_n")])
        {mov %A0,%A1\;mov %B0,%B1|movw %A0,%A1}\;clr %C0\;clr %D0"
   [(set_attr_alternative "length"
                         [(const_int 2)
-                         (if_then_else (eq_attr "mcu_enhanced" "yes")
+                         (if_then_else (eq_attr "mcu_have_movw" "yes")
                                        (const_int 3)
                                        (const_int 4))])
    (set_attr "cc" "set_n,set_n")])
 (define_insn "*sbrx_branch"
   [(set (pc)
         (if_then_else
-        (match_operator 0 "comparison_operator"
+        (match_operator 0 "eqne_operator"
                         [(zero_extract
                           (match_operand:QI 1 "register_operand" "r")
                           (const_int 1)
                          (const_int 0)])
         (label_ref (match_operand 3 "" ""))
         (pc)))]
-  "GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE"
+  ""
   "* return avr_out_sbxx_branch (insn, operands);"
   [(set (attr "length")
        (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
 (define_insn "*sbrx_and_branchhi"
   [(set (pc)
         (if_then_else
-        (match_operator 0 "comparison_operator"
+        (match_operator 0 "eqne_operator"
                         [(and:HI
                           (match_operand:HI 1 "register_operand" "r")
-                          (match_operand:HI 2 "const_int_operand" "n"))
+                          (match_operand:HI 2 "single_one_operand" "n"))
                          (const_int 0)])
         (label_ref (match_operand 3 "" ""))
         (pc)))]
-  "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
-   && exact_log2 (INTVAL (operands[2]) & 0xffff) >= 0"
+  ""
   "* return avr_out_sbxx_branch (insn, operands);"
   [(set (attr "length")
        (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
 (define_insn "*sbrx_and_branchsi"
   [(set (pc)
         (if_then_else
-        (match_operator 0 "comparison_operator"
+        (match_operator 0 "eqne_operator"
                         [(and:SI
                           (match_operand:SI 1 "register_operand" "r")
-                          (match_operand:SI 2 "const_int_operand" "n"))
+                          (match_operand:SI 2 "single_one_operand" "n"))
                          (const_int 0)])
         (label_ref (match_operand 3 "" ""))
         (pc)))]
-  "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
-   && exact_log2 (INTVAL (operands[2]) & 0xffffffff) >= 0"
+  ""
   "* return avr_out_sbxx_branch (insn, operands);"
   [(set (attr "length")
        (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
 
 (define_insn "branch"
   [(set (pc)
-        (if_then_else (match_operator 1 "comparison_operator"
+        (if_then_else (match_operator 1 "simple_comparison_operator"
                         [(cc0)
                          (const_int 0)])
                       (label_ref (match_operand 0 "" ""))
                       (pc)))]
-  "! (GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
-      || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
+  ""
   "*
    return ret_cond_branch (operands[1], avr_jump_mode (operands[0],insn), 0);"
   [(set_attr "type" "branch")
 
 (define_insn "difficult_branch"
   [(set (pc)
-        (if_then_else (match_operator 1 "comparison_operator"
+        (if_then_else (match_operator 1 "difficult_comparison_operator"
                         [(cc0)
                          (const_int 0)])
                       (label_ref (match_operand 0 "" ""))
                       (pc)))]
-  "(GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
-    || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
+  ""
   "*
    return ret_cond_branch (operands[1], avr_jump_mode (operands[0],insn), 0);"
   [(set_attr "type" "branch1")
 
 (define_insn "rvbranch"
   [(set (pc)
-        (if_then_else (match_operator 1 "comparison_operator" [(cc0)
-                                                               (const_int 0)])
+        (if_then_else (match_operator 1 "simple_comparison_operator" 
+                       [(cc0)
+                         (const_int 0)])
                       (pc)
                       (label_ref (match_operand 0 "" ""))))]
-  "! (GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
-      || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
+  ""
   "*
    return ret_cond_branch (operands[1], avr_jump_mode (operands[0], insn), 1);"
   [(set_attr "type" "branch1")
 
 (define_insn "difficult_rvbranch"
   [(set (pc)
-        (if_then_else (match_operator 1 "comparison_operator" [(cc0)
-                                                               (const_int 0)])
+        (if_then_else (match_operator 1 "difficult_comparison_operator" 
+                       [(cc0)
+                         (const_int 0)])
                       (pc)
                       (label_ref (match_operand 0 "" ""))))]
-  "(GET_CODE (operands[1]) == GT || GET_CODE (operands[1]) == GTU
-    || GET_CODE (operands[1]) == LE || GET_CODE (operands[1]) == LEU)"
+  ""
   "*
    return ret_cond_branch (operands[1], avr_jump_mode (operands[0], insn), 1);"
   [(set_attr "type" "branch")
      return \"icall\";
   else if (which_alternative==1)
     {
-      if (AVR_ENHANCED)
+      if (AVR_HAVE_MOVW)
        return (AS2 (movw, r30, %0) CR_TAB
                \"icall\");
       else
   [(set_attr "cc" "clobber,clobber,clobber,clobber")
    (set_attr_alternative "length"
                         [(const_int 1)
-                         (if_then_else (eq_attr "mcu_enhanced" "yes")
+                         (if_then_else (eq_attr "mcu_have_movw" "yes")
                                        (const_int 2)
                                        (const_int 3))
                          (if_then_else (eq_attr "mcu_mega" "yes")
      return \"icall\";
   else if (which_alternative==1)
     {
-      if (AVR_ENHANCED)
+      if (AVR_HAVE_MOVW)
        return (AS2 (movw, r30, %1) CR_TAB
                \"icall\");
       else
   [(set_attr "cc" "clobber,clobber,clobber,clobber")
    (set_attr_alternative "length"
                         [(const_int 1)
-                         (if_then_else (eq_attr "mcu_enhanced" "yes")
+                         (if_then_else (eq_attr "mcu_have_movw" "yes")
                                        (const_int 2)
                                        (const_int 3))
                          (if_then_else (eq_attr "mcu_mega" "yes")
 
 ;; Table made from "rjmp" instructions for <=8K devices.
 (define_insn "*tablejump_rjmp"
-  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "!z,*r")] 1))
+  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "!z,*r")]
+                       UNSPEC_INDEX_JMP))
    (use (label_ref (match_operand 1 "" "")))
    (clobber (match_dup 0))]
   "!AVR_MEGA"
 
 ;; Not a prologue, but similar idea - move the common piece of code to libgcc.
 (define_insn "*tablejump_lib"
-  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")] 1))
+  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")]
+                       UNSPEC_INDEX_JMP))
    (use (label_ref (match_operand 1 "" "")))
    (clobber (match_dup 0))]
   "AVR_MEGA && TARGET_CALL_PROLOGUES"
    (set_attr "cc" "clobber")])
 
 (define_insn "*tablejump_enh"
-  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")] 1))
+  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")]
+                       UNSPEC_INDEX_JMP))
    (use (label_ref (match_operand 1 "" "")))
    (clobber (match_dup 0))]
-  "AVR_MEGA && AVR_ENHANCED"
+  "AVR_MEGA && AVR_HAVE_LPMX"
   "lsl r30
        rol r31
        lpm __tmp_reg__,Z+
    (set_attr "cc" "clobber")])
 
 (define_insn "*tablejump"
-  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")] 1))
+  [(set (pc) (unspec:HI [(match_operand:HI 0 "register_operand" "z")]
+                       UNSPEC_INDEX_JMP))
    (use (label_ref (match_operand 1 "" "")))
    (clobber (match_dup 0))]
   "AVR_MEGA"
    (set (match_dup 6)
        (plus:HI (match_dup 6) (label_ref (match_operand:HI 3 "" ""))))
 
-   (parallel [(set (pc) (unspec:HI [(match_dup 6)] 1))
+   (parallel [(set (pc) (unspec:HI [(match_dup 6)] UNSPEC_INDEX_JMP))
              (use (label_ref (match_dup 3)))
              (clobber (match_dup 6))])]
   ""
 ;; Clear/set/test a single bit in I/O address space.
 
 (define_insn "*cbi"
-  [(set (mem:QI (match_operand 0 "const_int_operand" "n"))
+  [(set (mem:QI (match_operand 0 "low_io_address_operand" "n"))
        (and:QI (mem:QI (match_dup 0))
-               (match_operand 1 "const_int_operand" "n")))]
-  "avr_io_address_p (operands[0], 1 + 0x20)
-   && exact_log2 (~INTVAL (operands[1]) & 0xff) >= 0"
+               (match_operand:QI 1 "single_zero_operand" "n")))]
+  "(optimize > 0)"
 {
   operands[2] = GEN_INT (exact_log2 (~INTVAL (operands[1]) & 0xff));
   return AS2 (cbi,%0-0x20,%2);
    (set_attr "cc" "none")])
 
 (define_insn "*sbi"
-  [(set (mem:QI (match_operand 0 "const_int_operand" "n"))
+  [(set (mem:QI (match_operand 0 "low_io_address_operand" "n"))
        (ior:QI (mem:QI (match_dup 0))
-               (match_operand 1 "const_int_operand" "n")))]
-  "avr_io_address_p (operands[0], 1 + 0x20)
-   && exact_log2 (INTVAL (operands[1]) & 0xff) >= 0"
+               (match_operand:QI 1 "single_one_operand" "n")))]
+  "(optimize > 0)"
 {
   operands[2] = GEN_INT (exact_log2 (INTVAL (operands[1]) & 0xff));
   return AS2 (sbi,%0-0x20,%2);
 (define_insn "*sbix_branch"
   [(set (pc)
        (if_then_else
-        (match_operator 0 "comparison_operator"
+        (match_operator 0 "eqne_operator"
                         [(zero_extract
-                          (mem:QI (match_operand 1 "const_int_operand" "n"))
+                          (mem:QI (match_operand 1 "low_io_address_operand" "n"))
                           (const_int 1)
                           (match_operand 2 "const_int_operand" "n"))
                          (const_int 0)])
         (label_ref (match_operand 3 "" ""))
         (pc)))]
-  "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
-   && avr_io_address_p (operands[1], 1 + 0x20)"
+  "(optimize > 0)"
   "* return avr_out_sbxx_branch (insn, operands);"
   [(set (attr "length")
        (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
 (define_insn "*sbix_branch_bit7"
   [(set (pc)
        (if_then_else
-        (match_operator 0 "comparison_operator"
-                        [(mem:QI (match_operand 1 "const_int_operand" "n"))
+        (match_operator 0 "gelt_operator"
+                        [(mem:QI (match_operand 1 "low_io_address_operand" "n"))
                          (const_int 0)])
         (label_ref (match_operand 2 "" ""))
         (pc)))]
-  "(GET_CODE (operands[0]) == GE || GET_CODE (operands[0]) == LT)
-   && avr_io_address_p (operands[1], 1 + 0x20)"
+  "(optimize > 0)"
 {
   operands[3] = operands[2];
   operands[2] = GEN_INT (7);
 (define_insn "*sbix_branch_tmp"
   [(set (pc)
        (if_then_else
-        (match_operator 0 "comparison_operator"
+        (match_operator 0 "eqne_operator"
                         [(zero_extract
-                          (mem:QI (match_operand 1 "const_int_operand" "n"))
+                          (mem:QI (match_operand 1 "higth_io_address_operand" "n"))
                           (const_int 1)
                           (match_operand 2 "const_int_operand" "n"))
                          (const_int 0)])
         (label_ref (match_operand 3 "" ""))
         (pc)))]
-  "(GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
-   && avr_io_address_p (operands[1], 1) && INTVAL (operands[1]) >= 0x40"
+  "(optimize > 0)"
   "* return avr_out_sbxx_branch (insn, operands);"
   [(set (attr "length")
        (if_then_else (and (ge (minus (pc) (match_dup 3)) (const_int -2046))
 (define_insn "*sbix_branch_tmp_bit7"
   [(set (pc)
        (if_then_else
-        (match_operator 0 "comparison_operator"
-                        [(mem:QI (match_operand 1 "const_int_operand" "n"))
+        (match_operator 0 "gelt_operator"
+                        [(mem:QI (match_operand 1 "higth_io_address_operand" "n"))
                          (const_int 0)])
         (label_ref (match_operand 2 "" ""))
         (pc)))]
-  "(GET_CODE (operands[0]) == GE || GET_CODE (operands[0]) == LT)
-   && avr_io_address_p (operands[1], 1) && INTVAL (operands[1]) >= 0x40"
+  "(optimize > 0)"
 {
   operands[3] = operands[2];
   operands[2] = GEN_INT (7);
 ;; ************************* Peepholes ********************************
 
 (define_peephole
-  [(set (match_operand:SI 0 "register_operand" "")
+  [(set (match_operand:SI 0 "d_register_operand" "")
         (plus:SI (match_dup 0)
                  (const_int -1)))
    (parallel
     [(set (cc0)
           (compare (match_dup 0)
                   (const_int -1)))
-     (clobber (match_operand:QI 1 "register_operand" ""))])
+     (clobber (match_operand:QI 1 "d_register_operand" ""))])
    (set (pc)
        (if_then_else (ne (cc0) (const_int 0))
                      (label_ref (match_operand 2 "" ""))
                      (pc)))]
-  "(test_hard_reg_class (LD_REGS, operands[0])
-    && test_hard_reg_class (LD_REGS, operands[1]))"
+  ""
   "*
 {
   CC_STATUS_INIT;
 }")
 
 (define_peephole
-  [(set (match_operand:HI 0 "register_operand" "")
+  [(set (match_operand:HI 0 "d_register_operand" "")
         (plus:HI (match_dup 0)
                  (const_int -1)))
    (parallel
     [(set (cc0)
           (compare (match_dup 0)
                   (const_int 65535)))
-     (clobber (match_operand:QI 1 "register_operand" ""))])
+     (clobber (match_operand:QI 1 "d_register_operand" ""))])
    (set (pc)
        (if_then_else (ne (cc0) (const_int 0))
                      (label_ref (match_operand 2 "" ""))
                      (pc)))]
-  "(test_hard_reg_class (LD_REGS, operands[0])
-    && test_hard_reg_class (LD_REGS, operands[1]))"
+  ""
   "*
 {
   CC_STATUS_INIT;
 }")
 
 (define_peephole
-  [(set (match_operand:QI 0 "register_operand" "")
+  [(set (match_operand:QI 0 "d_register_operand" "")
         (plus:QI (match_dup 0)
                  (const_int -1)))
    (set (cc0)
        (if_then_else (ne (cc0) (const_int 0))
                      (label_ref (match_operand 1 "" ""))
                      (pc)))]
-  "test_hard_reg_class (LD_REGS, operands[0])"
+  ""
   "*
 {
   CC_STATUS_INIT;