This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] Support new PC-relative branch instructions for Moxie port.


I recently added PC-relative branch instructions to the Moxie ISA.  This
reduces code size between 7 and 15% on the benchmarks I've run.  I've
already committed support for these new instructions into binutils and
the GDB simulator, and now here is the GCC patch.  It simply defines
length attributes for all instructions so GCC can select the right
branch instruction sequence depending on the range of the branch.

I'm checking this in.

Thanks,

AG



2009-06-11  Anthony Green  <green@moxielogic.com>

	* config/moxie/moxie.md: Define length attribute for all
	instructions.
	(rCC): Define.
	(*b<cond:code>): Support limited branch ranges for new PC-relative
	branch instructions.
	* config/moxie/moxie.h (HAS_LONG_UNCOND_BRANCH): Define.


Index: gcc/config/moxie/moxie.md
===================================================================
--- gcc/config/moxie/moxie.md	(revision 148387)
+++ gcc/config/moxie/moxie.md	(working copy)
@@ -19,12 +19,15 @@
 ;; <http://www.gnu.org/licenses/>.
 
 ;; -------------------------------------------------------------------------
-;; Moxie specific constraints
+;; Moxie specific constraints, predicates and attributes
 ;; -------------------------------------------------------------------------
 
 (include "constraints.md")
 (include "predicates.md")
 
+; Most instructions are two bytes long.
+(define_attr "length" "" (const_int 2))
+
 ;; -------------------------------------------------------------------------
 ;; nop instruction
 ;; -------------------------------------------------------------------------
@@ -232,7 +235,8 @@
    ld.l   %0, %1
    lda.l  %0, %1
    sto.l  %0, %1
-   ldo.l  %0, %1")
+   ldo.l  %0, %1"
+  [(set_attr "length"	"2,6,2,6,2,6,6,6")])
 
 (define_expand "movqi"
   [(set (match_operand:QI 0 "general_operand" "")
@@ -258,7 +262,8 @@
    ld.b   %0, %1
    lda.b  %0, %1
    sto.b  %0, %1
-   ldo.b  %0, %1")
+   ldo.b  %0, %1"
+  [(set_attr "length"	"2,6,2,6,2,6,6,6")])
 
 (define_expand "movhi"
   [(set (match_operand:HI 0 "general_operand" "")
@@ -284,7 +289,8 @@
    ld.s   %0, %1
    lda.s  %0, %1
    sto.s  %0, %1
-   ldo.s  %0, %1")
+   ldo.s  %0, %1"
+  [(set_attr "length"	"2,6,2,6,2,6,6,6")])
 
 ;; -------------------------------------------------------------------------
 ;; Compare instructions
@@ -329,6 +335,9 @@
 (define_code_attr CC [(ne "ne") (eq "eq") (lt "lt") (ltu "ltu") 
 		      (gt "gt") (gtu "gtu") (ge "ge") (le "le") 
 		      (geu "geu") (leu "leu") ])
+(define_code_attr rCC [(ne "eq") (eq "ne") (lt "ge") (ltu "geu") 
+		       (gt "le") (gtu "leu") (ge "lt") (le "gt") 
+		       (geu "ltu") (leu "gtu") ])
 
 (define_insn "*b<cond:code>"
   [(set (pc)
@@ -337,7 +346,15 @@
 		      (label_ref (match_operand 0 "" ""))
 		      (pc)))]
   ""
-  "b<CC>   %l0")
+{
+  if (get_attr_length (insn) == 2)
+    return "b<CC>   %l0";
+  else
+    return "b<rCC>   .+6\n\tjmpa   %l0";
+}
+  [(set (attr "length")
+        (if_then_else (lt (abs (minus (pc) (match_dup 0))) (const_int 1022))
+                      (const_int 2) (const_int 8)))])
 
 ;; -------------------------------------------------------------------------
 ;; Call and Jump instructions
@@ -358,7 +375,8 @@
   ""
   "@
    jsra   %0
-   jsr    %0")
+   jsr    %0"
+  [(set_attr "length"	"6,2")])
 
 (define_expand "call_value"
   [(set (match_operand 0 "" "")
@@ -375,7 +393,8 @@
 		       1 "immediate_operand" "i"))
 	      (match_operand 2 "" "")))]
   ""
-  "jsra   %1")
+  "jsra   %1"
+  [(set_attr "length"	"6")])
 
 (define_insn "*call_value_indirect"
   [(set (match_operand 0 "register_operand" "=r")
@@ -394,7 +413,8 @@
   [(set (pc)
 	(label_ref (match_operand 0 "" "")))]
   ""
-  "jmpa   %l0")
+  "jmpa   %l0"
+  [(set_attr "length"	"6")])
 
 
 ;; -------------------------------------------------------------------------
Index: gcc/config/moxie/moxie.h
===================================================================
--- gcc/config/moxie/moxie.h	(revision 148387)
+++ gcc/config/moxie/moxie.h	(working copy)
@@ -571,4 +571,6 @@
     builtin_define_std ("MOXIE");		\
   }
 
+#define HAS_LONG_UNCOND_BRANCH true
+
 #endif /* GCC_MOXIE_H */



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]