[PATCH][AVR] Add 'avr25' architecture for new ATtiny devices.

Anatoll Sokolov aesok@dol.ru
Thu Jun 8 06:30:00 GMT 2006


Hello.

New ATtiny devices have 'MOVW' and 'LPM Rx, Z' instruction but GCC don't use
them. This patch add 'avr25' architecture for AVR target, and move ATtiny13,
ATtiny2313, ATtinyX4, ATtinyX5, ATtinyX61 and AT86RF401 devices from 'avr2' to
in 'avr25' architecture.


2006-06-08  Anatoly Sokolov <aesok@post.ru>

ChangeLog:
	* config/avr/avr.h (avr_have_movw_lpmx_p): Declare.
	(TARGET_CPU_CPP_BUILTINS): Add __AVR_HAVE_MOVW__ and 
	__AVR_HAVE_LPMX__.
	(AVR_HAVE_MOVW) Define.
	(ASSEMBLER_DIALECT): Use AVR_HAVE_MOVW.
	(ASM_SPEC): Add avr25.
	(LINK_SPEC): Add avr25.
	* config/avr/avr.c (avr_have_movw_lpmx_p): Add.
	(base_arch_s): Add new member 'have_movw_lpmx'.
	(avr_arch_types): Init 'have_movw_lpmx'.
	(avr_mcu_types): Add 'avr25'. Move attiny13, attiny2313, attiny24,
	attiny44, attiny84, attiny25, attiny45, attiny85, attiny261,
	attiny461, attiny861 and at86rf401 in 'avr25' arhitecture.
	(avr_override_options): Init 'avr_have_movw_lpmx_p'.
	(output_movhi, output_movsisf, ashlsi3_out, avr_rtx_costs): Use 
	AVR_HAVE_MOVW.
	(avr_file_start): Do not output '.arh' derective.
	* config/avr/libgcc.S (mov_l): Use __AVR_HAVE_MOVW__.
	(__do_copy_data): Use __AVR_HAVE_LPMX__.
	* config/avr/avr.md (mcu_enhanced): Delete.
	(mcu_have_movw): Define.
	(negsi2, extendhisi2, zero_extendhisi2): Use 'mcu_have_movw'.
	(call_insn, call_value_insn): Use 'call_insn' and __AVR_HAVE_MOVW__.
	* config/avr/t-avr(MULTILIB_OPTIONS, MULTILIB_DIRNAMES): Add avr25.
	(MULTILIB_MATCHES): Add attiny13, attiny2313, attiny24, attiny44,
	attiny84, attiny25, attiny45, attiny85, attiny261, attiny461, 
	attiny861 and at86rf401 devices.

Index: gcc/config/avr/libgcc.S
===================================================================
--- gcc/config/avr/libgcc.S	(revision 114480)
+++ gcc/config/avr/libgcc.S	(working copy)
@@ -40,7 +40,7 @@
 	.section .text.libgcc, "ax", @progbits
 
 	.macro	mov_l  r_dest, r_src
-#if defined (__AVR_ENHANCED__)
+#if defined (__AVR_HAVE_MOVW__)
 	movw	\r_dest, \r_src
 #else
 	mov	\r_dest, \r_src
@@ -48,7 +48,7 @@
 	.endm
 
 	.macro	mov_h  r_dest, r_src
-#if defined (__AVR_ENHANCED__)
+#if defined (__AVR_HAVE_MOVW__)
 	; empty
 #else
 	mov	\r_dest, \r_src
@@ -276,10 +276,10 @@
 	cpc	r_arg1H,r_arg1L
 	brne	__mulsi3_loop		; exit if multiplier = 0
 __mulsi3_exit:
-	mov	r_arg1HH,r_resHH	; result to return register
-	mov	r_arg1HL,r_resHL
-	mov	r_arg1H,r_resH
-	mov	r_arg1L,r_resL
+	mov_h	r_arg1HH,r_resHH	; result to return register
+	mov_l	r_arg1HL,r_resHL
+	mov_h	r_arg1H,r_resH
+	mov_l	r_arg1L,r_resL
 	ret
 #endif /* !defined (__AVR_ENHANCED__) */
 #undef r_arg1L 
@@ -698,7 +698,7 @@
 	ldi	r31, hi8(__data_load_start)
 	rjmp	.do_copy_data_start
 .do_copy_data_loop:
-#if defined (__AVR_ENHANCED__)
+#if defined (__AVR_HAVE_LPMX__)
 	lpm	r0, Z+
 #else
 	lpm
Index: gcc/config/avr/avr.md
===================================================================
--- gcc/config/avr/avr.md	(revision 114480)
+++ gcc/config/avr/avr.md	(working copy)
@@ -57,8 +57,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"))))
 
@@ -1455,7 +1455,7 @@
   [(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")])
@@ -1533,7 +1533,7 @@
 	{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")])
@@ -1570,7 +1570,7 @@
 	{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")])
@@ -2104,7 +2104,7 @@
      return \"icall\";
   else if (which_alternative==1)
     {
-      if (AVR_ENHANCED)
+      if (AVR_HAVE_MOVW)
 	return (AS2 (movw, r30, %0) CR_TAB
 		\"icall\");
       else
@@ -2121,7 +2121,7 @@
   [(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")
@@ -2141,7 +2141,7 @@
      return \"icall\";
   else if (which_alternative==1)
     {
-      if (AVR_ENHANCED)
+      if (AVR_HAVE_MOVW)
 	return (AS2 (movw, r30, %1) CR_TAB
 		\"icall\");
       else
@@ -2158,7 +2158,7 @@
   [(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")
Index: gcc/config/avr/avr.c
===================================================================
--- gcc/config/avr/avr.c	(revision 114480)
+++ gcc/config/avr/avr.c	(working copy)
@@ -126,20 +126,25 @@
 /* Assembler only.  */
 int avr_asm_only_p = 0;
 
+/* Core have 'MOVW' and 'LPM Rx,Z' instructions.  */
+int avr_have_movw_lpmx_p = 0;
+
 struct base_arch_s {
   int asm_only;
   int enhanced;
   int mega;
+  int have_movw_lpmx;
   const char *const macro;
 };
 
 static const struct base_arch_s avr_arch_types[] = {
-  { 1, 0, 0, NULL },  /* unknown device specified */
-  { 1, 0, 0, "__AVR_ARCH__=1" },
-  { 0, 0, 0, "__AVR_ARCH__=2" },
-  { 0, 0, 1, "__AVR_ARCH__=3" },
-  { 0, 1, 0, "__AVR_ARCH__=4" },
-  { 0, 1, 1, "__AVR_ARCH__=5" }
+  { 1, 0, 0, 0,  NULL },  /* unknown device specified */
+  { 1, 0, 0, 0, "__AVR_ARCH__=1" },
+  { 0, 0, 0, 0, "__AVR_ARCH__=2" },
+  { 0, 0, 1, 0, "__AVR_ARCH__=3" },
+  { 0, 1, 0, 1, "__AVR_ARCH__=4" },
+  { 0, 1, 1, 1, "__AVR_ARCH__=5" },
+  { 0, 0, 0, 1, "__AVR_ARCH__=25"}
 };
 
 struct mcu_type_s {
@@ -173,18 +178,19 @@
   { "at90c8534", 2, "__AVR_AT90C8534__" },
   { "at90s8535", 2, "__AVR_AT90S8535__" },
     /* Classic + MOVW, <= 8K.  */
-  { "attiny13",   2, "__AVR_ATtiny13__" },
-  { "attiny2313", 2, "__AVR_ATtiny2313__" },
-  { "attiny24", 2, "__AVR_ATtiny24__" },
-  { "attiny44", 2, "__AVR_ATtiny44__" },
-  { "attiny84", 2, "__AVR_ATtiny84__" },
-  { "attiny25", 2, "__AVR_ATtiny25__" },
-  { "attiny45", 2, "__AVR_ATtiny45__" },
-  { "attiny85", 2, "__AVR_ATtiny85__" },
-  { "attiny261", 2, "__AVR_ATtiny261__" },
-  { "attiny461", 2, "__AVR_ATtiny461__" },
-  { "attiny861", 2, "__AVR_ATtiny861__" },
-  { "at86rf401", 2, "__AVR_AT86RF401__" },
+  { "avr25",      6, NULL },
+  { "attiny13",   6, "__AVR_ATtiny13__" },
+  { "attiny2313", 6, "__AVR_ATtiny2313__" },
+  { "attiny24",   6, "__AVR_ATtiny24__" },
+  { "attiny44",   6, "__AVR_ATtiny44__" },
+  { "attiny84",   6, "__AVR_ATtiny84__" },
+  { "attiny25",   6, "__AVR_ATtiny25__" },
+  { "attiny45",   6, "__AVR_ATtiny45__" },
+  { "attiny85",   6, "__AVR_ATtiny85__" },
+  { "attiny261",  6, "__AVR_ATtiny261__" },
+  { "attiny461",  6, "__AVR_ATtiny461__" },
+  { "attiny861",  6, "__AVR_ATtiny861__" },
+  { "at86rf401",  6, "__AVR_AT86RF401__" },
     /* Classic, > 8K.  */
   { "avr3",      3, NULL },
   { "atmega103", 3, "__AVR_ATmega103__" },
@@ -319,6 +325,7 @@
   avr_asm_only_p = base->asm_only;
   avr_enhanced_p = base->enhanced;
   avr_mega_p = base->mega;
+  avr_have_movw_lpmx_p = base->have_movw_lpmx;
   avr_base_arch_macro = base->macro;
   avr_extra_arch_macro = t->macro;
 
@@ -1656,7 +1663,7 @@
 		      AS2 (in,%B0,__SP_H__));
 	    }
 
-	  if (AVR_ENHANCED)
+	  if (AVR_HAVE_MOVW)
 	    {
 	      *l = 1;
 	      return (AS2 (movw,%0,%1));
@@ -2325,7 +2332,7 @@
 	{
 	  if (true_regnum (dest) > true_regnum (src))
 	    {
-	      if (AVR_ENHANCED)
+	      if (AVR_HAVE_MOVW)
 		{
 		  *l = 2;
 		  return (AS2 (movw,%C0,%C1) CR_TAB
@@ -2339,7 +2346,7 @@
 	    }
 	  else
 	    {
-	      if (AVR_ENHANCED)
+	      if (AVR_HAVE_MOVW)
 		{
 		  *l = 2;
 		  return (AS2 (movw,%A0,%A1) CR_TAB
@@ -2366,7 +2373,7 @@
 	  if (GET_CODE (src) == CONST_INT)
 	    {
 	      const char *const clr_op0 =
-		AVR_ENHANCED ? (AS1 (clr,%A0) CR_TAB
+		AVR_HAVE_MOVW ? (AS1 (clr,%A0) CR_TAB
 				AS1 (clr,%B0) CR_TAB
 				AS2 (movw,%C0,%A0))
 			     : (AS1 (clr,%A0) CR_TAB
@@ -2376,20 +2383,20 @@
 
 	      if (src == const0_rtx) /* mov r,L */
 		{
-		  *l = AVR_ENHANCED ? 3 : 4;
+		  *l = AVR_HAVE_MOVW ? 3 : 4;
 		  return clr_op0;
 		}
 	      else if (src == const1_rtx)
 		{
 		  if (!real_l)
 		    output_asm_insn (clr_op0, operands);
-		  *l = AVR_ENHANCED ? 4 : 5;
+		  *l = AVR_HAVE_MOVW ? 4 : 5;
 		  return AS1 (inc,%A0);
 		}
 	      else if (src == constm1_rtx)
 		{
 		  /* Immediate constants -1 to any register */
-		  if (AVR_ENHANCED)
+		  if (AVR_HAVE_MOVW)
 		    {
 		      *l = 4;
 		      return (AS1 (clr,%A0)     CR_TAB
@@ -2410,7 +2417,7 @@
 
 		  if (bit_nr >= 0)
 		    {
-		      *l = AVR_ENHANCED ? 5 : 6;
+		      *l = AVR_HAVE_MOVW ? 5 : 6;
 		      if (!real_l)
 			{
 			  output_asm_insn (clr_op0, operands);
@@ -3301,7 +3308,7 @@
 	  if (INTVAL (operands[2]) < 32)
 	    break;
 
-	  if (AVR_ENHANCED)
+	  if (AVR_HAVE_MOVW)
 	    return *len = 3, (AS1 (clr,%D0) CR_TAB
 			      AS1 (clr,%C0) CR_TAB
 			      AS2 (movw,%A0,%C0));
@@ -3338,7 +3345,7 @@
 	    int reg0 = true_regnum (operands[0]);
 	    int reg1 = true_regnum (operands[1]);
 	    *len = 4;
-	    if (AVR_ENHANCED && (reg0 + 2 != reg1))
+	    if (AVR_HAVE_MOVW && (reg0 + 2 != reg1))
 	      {
 		*len = 3;
 		return (AS2 (movw,%C0,%A1) CR_TAB
@@ -3685,7 +3692,7 @@
 	    int reg0 = true_regnum (operands[0]);
 	    int reg1 = true_regnum (operands[1]);
 	    *len=6;
-	    if (AVR_ENHANCED && (reg0 != reg1 + 2))
+	    if (AVR_HAVE_MOVW && (reg0 != reg1 + 2))
 	      {
 		*len = 5;
 		return (AS2 (movw,%A0,%C1) CR_TAB
@@ -3737,7 +3744,7 @@
 	  /* fall through */
 
 	case 31:
-	  if (AVR_ENHANCED)
+	  if (AVR_HAVE_MOVW)
 	    return *len = 4, (AS1 (lsl,%D0)     CR_TAB
 			      AS2 (sbc,%A0,%A0) CR_TAB
 			      AS2 (mov,%B0,%A0) CR_TAB
@@ -4133,7 +4140,7 @@
 	  if (INTVAL (operands[2]) < 32)
 	    break;
 
-	  if (AVR_ENHANCED)
+	  if (AVR_HAVE_MOVW)
 	    return *len = 3, (AS1 (clr,%D0) CR_TAB
 			      AS1 (clr,%C0) CR_TAB
 			      AS2 (movw,%A0,%C0));
@@ -4167,7 +4174,7 @@
 	    int reg0 = true_regnum (operands[0]);
 	    int reg1 = true_regnum (operands[1]);
 	    *len = 4;
-	    if (AVR_ENHANCED && (reg0 != reg1 + 2))
+	    if (AVR_HAVE_MOVW && (reg0 != reg1 + 2))
 	      {
 		*len = 3;
 		return (AS2 (movw,%A0,%C1) CR_TAB
@@ -4813,7 +4820,7 @@
 
   default_file_start ();
 
-  fprintf (asm_out_file, "\t.arch %s\n", avr_mcu_name);
+/*  fprintf (asm_out_file, "\t.arch %s\n", avr_mcu_name);*/
   fputs ("__SREG__ = 0x3f\n"
 	 "__SP_H__ = 0x3e\n"
 	 "__SP_L__ = 0x3d\n", asm_out_file);
@@ -5301,7 +5308,7 @@
 		*total = COSTS_N_INSNS (optimize_size ? 7 : 8);
 		break;
 	      case 31:
-		*total = COSTS_N_INSNS (AVR_ENHANCED ? 4 : 5);
+		*total = COSTS_N_INSNS (AVR_HAVE_MOVW ? 4 : 5);
 		break;
 	      default:
 		*total = COSTS_N_INSNS (optimize_size ? 7 : 113);
Index: gcc/config/avr/t-avr
===================================================================
--- gcc/config/avr/t-avr	(revision 114480)
+++ gcc/config/avr/t-avr	(working copy)
@@ -37,11 +37,23 @@
 
 FPBIT = fp-bit.c
 
-MULTILIB_OPTIONS = mmcu=avr2/mmcu=avr3/mmcu=avr4/mmcu=avr5
-MULTILIB_DIRNAMES = avr2 avr3 avr4 avr5
+MULTILIB_OPTIONS = mmcu=avr2/mmcu=avr25/mmcu=avr3/mmcu=avr4/mmcu=avr5
+MULTILIB_DIRNAMES = avr2 avr25 avr3 avr4 avr5
 
 # The many avr2 matches are not listed here - this is the default.
 MULTILIB_MATCHES = \
+	mmcu?avr25=mmcu?attiny13 \
+	mmcu?avr25=mmcu?attiny2313 \
+	mmcu?avr25=mmcu?attiny24 \
+	mmcu?avr25=mmcu?attiny44 \
+	mmcu?avr25=mmcu?attiny84 \
+	mmcu?avr25=mmcu?attiny25 \
+	mmcu?avr25=mmcu?attiny45 \
+	mmcu?avr25=mmcu?attiny85 \
+	mmcu?avr25=mmcu?attiny261 \
+	mmcu?avr25=mmcu?attiny461 \
+	mmcu?avr25=mmcu?attiny861 \
+	mmcu?avr25=mmcu?at86rf401 \
 	mmcu?avr3=mmcu?atmega103 \
 	mmcu?avr3=mmcu?atmega603 \
 	mmcu?avr3=mmcu?at43usb320 \
Index: gcc/config/avr/avr.h
===================================================================
--- gcc/config/avr/avr.h	(revision 114480)
+++ gcc/config/avr/avr.h	(working copy)
@@ -31,6 +31,10 @@
 	builtin_define (avr_base_arch_macro);	\
       if (avr_extra_arch_macro)			\
 	builtin_define (avr_extra_arch_macro);	\
+      if (avr_have_movw_lpmx_p)			\
+	builtin_define ("__AVR_HAVE_MOVW__");	\
+      if (avr_have_movw_lpmx_p)			\
+	builtin_define ("__AVR_HAVE_LPMX__");	\
       if (avr_asm_only_p)			\
 	builtin_define ("__AVR_ASM_ONLY__");	\
       if (avr_enhanced_p)			\
@@ -47,12 +51,14 @@
 extern int avr_mega_p;
 extern int avr_enhanced_p;
 extern int avr_asm_only_p;
+extern int avr_have_movw_lpmx_p;
 #ifndef IN_LIBGCC2
 extern GTY(()) section *progmem_section;
 #endif
 
 #define AVR_MEGA (avr_mega_p && !TARGET_SHORT_CALLS)
 #define AVR_ENHANCED (avr_enhanced_p)
+#define AVR_HAVE_MOVW (avr_have_movw_lpmx_p)
 
 #define TARGET_VERSION fprintf (stderr, " (GNU assembler syntax)");
 
@@ -626,7 +632,7 @@
 
 #define USER_LABEL_PREFIX ""
 
-#define ASSEMBLER_DIALECT AVR_ENHANCED
+#define ASSEMBLER_DIALECT AVR_HAVE_MOVW
 
 #define ASM_OUTPUT_REG_PUSH(STREAM, REGNO)	\
 {						\
@@ -718,7 +724,8 @@
 /* A C string constant that tells the GCC drvier program options to
    pass to `cc1plus'.  */
 
-#define ASM_SPEC "%{mmcu=*:-mmcu=%*}"
+#define ASM_SPEC "%{mmcu=avr25:-mmcu=avr2;\
+mmcu=*:-mmcu=%*}"
 
 #define LINK_SPEC " %{!mmcu*:-m avr2}\
 %{mmcu=at90s1200|\
@@ -816,7 +823,7 @@
 %{mmcu=at90s8535:crts8535.o%s} \
 %{mmcu=at86rf401:crt86401.o%s} \
 %{mmcu=attiny13:crttn13.o%s} \
-%{mmcu=attiny2313:crttn2313.o%s} \
+%{mmcu=attiny2313|mmcu=avr25:crttn2313.o%s} \
 %{mmcu=attiny24:crttn24.o%s} \
 %{mmcu=attiny44:crttn44.o%s} \
 %{mmcu=attiny84:crttn84.o%s} \


Anatoly.



More information about the Gcc-patches mailing list