Patchwork Adding Leon processor to the SPARC list of processors

login
register
mail settings
Submitter Konrad Eisele
Date Nov. 22, 2010, 3:38 p.m.
Message ID <4CEA8E83.6000408@gaisler.com>
Download mbox | patch
Permalink /patch/72564/
State New
Headers show

Comments

Konrad Eisele - Nov. 22, 2010, 3:38 p.m.
Hi,
Appended is a new patch, this time against svn://gcc.gnu.org/svn/gcc/trunk.

Following the recent comments by Eric, the patch now sketches the
following setup:

If multi-lib is wanted:
 configure --with-cpu=leon ... :         creates multilib-dir soft|v8 combinations using [-msoft-float|-mcpu=sparcleonv8]
                                         (MULTILIB_OPTIONS = msoft-float mcpu=sparcleonv8)

If Single-lib is wanted:
 configure --with-cpu=sparcleonv7 --with-float=soft --disable-multilib ...  : (v7 | soft | no-multilib)
 configure --with-cpu=sparcleonv8 --with-float=soft --disable-multilib ...  : (v8 | soft | no-multilib)
 configure --with-cpu=sparcleonv7 --with-float=hard --disable-multilib ...  : (v7 | hard | no-multilib)
 configure --with-cpu=sparcleonv8 --with-float=hard --disable-multilib ...  : (v8 | hard | no-multilib)

Using --with-cpu=leon|sparcleonv7|sparcleonv8 the the sparc_cpu is switched to PROCESSOR_LEON.

If this sheme is ok, i'll test it more thoroughly to check that the various version
create the right output...
Please comment.

-- Greetings Konrad



Konrad Eisele wrote:
> Hello,
> Jiri Gaisler has now signed the FSF copyleft (it took quite long to get
> through the procedure) and I was said that I could post the patches
> now.
> 
> The patches are straightforward I think.
> 1. Adds machine description gcc-4.4.2/gcc/config/sparc/leon.md
> 2. gcc-4.4.2.ori/gcc/config/sparc/sparc.c:
>    + adds leon_costs struct.
>    + 4 target CPUs are added:
>      sparchfleon  : hard float v7
>      sparchfleonv8: hard float v8
>      sparcsfleon  : soft float v7
>      sparcsfleonv8: soft float v8
>    + 1 cpu type: PROCESSOR_LEON
>      that is called "leon" in sparc.md
> 3. gcc-4.4.2.ori/gcc/config/sparc/sparc.h:
>    add the 4 target cpu defines
> 4. gcc-4.4.2.ori/gcc/config/sparc/sparc.md:
>    define cpu "leon" and include "leon.md"
> 5. gcc-4.4.2/gcc/config/sparc/t-leon:
>    makefile template for leon
> 6. gcc-4.4.2/gcc/config.gcc:
>    include t-leon for sparc[sf|hf]leon[v8].
> 
> They dont interfere with current code. If I should change something,
> please let me know or maybe here is something I didnt think of...
> 
>> Leon is a conforming implementation of the SPARC V7/V8 architecture so it
>> should be possible to support it alongside the other SPARC implementations in
>> the SPARC back-end of the mainline compiler.  I'd be happy to review patches
>> to this effect (and I presume the other SPARC maintainers are OK with this).
>>
>> So I'd suggest that Luís Vitório and/or Konrad do the required paperwork, and
>> then start to post their patches on the gcc-patches@ list.  I'll sponsor them
>> for write access at that point.
>>
>> -- Eric Botcazou
> 
> I come back to the offer of Eric: if the patches are approved I'd be
> greatfull if you could check them in.
> 
> -- Thanks Konrad
> 
> 
> 
> To verify (if someone is interested):
> I have created a crosstool-ng based install script that will build the 4
> sparc-leon cross-compilers:
> 
> $wget ftp://gaisler.com/gaisler.com/linux/linuxbuild/linuxbuild-0.0.3.tar.bz2
> $tar xvf linuxbuild-0.0.3.tar.bz2
> $cd linuxbuild-0.0.3
> $make help
> $make cts
> 
> This will create /opt/sparc-linux-toolchains/{hfleon,hfleonv8,sfleon,sfleonv8}
> (Write premissions needed for /opt/sparc-linux-toolchains/).
> 
> The crosstool-ng script uses --with-cpu=sparc[sf|hf]leon[v8] to select
> the desired proc type.
> 
> 
> 
> 
>

Patch

Index: gcc/gcc/config.gcc
===================================================================
--- gcc/gcc/config.gcc	(revision 167027)
+++ gcc/gcc/config.gcc	(working copy)
@@ -3437,6 +3437,9 @@ 
 			| v9 | ultrasparc | ultrasparc3 | niagara | niagara2)
 				# OK
 				;;
+			sparcleonv7 | sparcleonv8 | leon)
+				tmake_file="${tmake_file} sparc/t-leon"
+				;;
 			*)
 				echo "Unknown cpu used in --with-$which=$val" 1>&2
 				exit 1
Index: gcc/gcc/config/sparc/sparc.md
===================================================================
--- gcc/gcc/config/sparc/sparc.md	(revision 167027)
+++ gcc/gcc/config/sparc/sparc.md	(working copy)
@@ -103,6 +103,7 @@ 
   "v7,
    cypress,
    v8,
+   leon,
    supersparc,
    sparclite,f930,f934,
    hypersparc,sparclite86x,
@@ -344,6 +345,7 @@ 
 (include "ultra3.md")
 (include "niagara.md")
 (include "niagara2.md")
+(include "leon.md")
 
 
 ;; Operand and operator predicates and constraints
Index: gcc/gcc/config/sparc/sparc.c
===================================================================
--- gcc/gcc/config/sparc/sparc.c	(revision 167027)
+++ gcc/gcc/config/sparc/sparc.c	(working copy)
@@ -249,6 +249,30 @@ 
   0, /* shift penalty */
 };
 
+static const
+struct processor_costs leon_costs = {
+  COSTS_N_INSNS (1), /* int load */
+  COSTS_N_INSNS (1), /* int signed load */
+  COSTS_N_INSNS (1), /* int zeroed load */
+  COSTS_N_INSNS (1), /* float load */
+  COSTS_N_INSNS (1), /* fmov, fneg, fabs */
+  COSTS_N_INSNS (1), /* fadd, fsub */
+  COSTS_N_INSNS (1), /* fcmp */
+  COSTS_N_INSNS (1), /* fmov, fmovr */
+  COSTS_N_INSNS (1), /* fmul */
+  COSTS_N_INSNS (15), /* fdivs */
+  COSTS_N_INSNS (15), /* fdivd */
+  COSTS_N_INSNS (23), /* fsqrts */
+  COSTS_N_INSNS (23), /* fsqrtd */
+  COSTS_N_INSNS (5), /* imul */
+  COSTS_N_INSNS (5), /* imulX */
+  0, /* imul bit factor */
+  COSTS_N_INSNS (5), /* idiv */
+  COSTS_N_INSNS (5), /* idivX */
+  COSTS_N_INSNS (1), /* movcc/movr */
+  0, /* shift penalty */
+};
+
 const struct processor_costs *sparc_costs = &cypress_costs;
 
 #ifdef HAVE_AS_RELAX_OPTION
@@ -717,6 +741,8 @@ 
     { TARGET_CPU_ultrasparc3, "ultrasparc3" },
     { TARGET_CPU_niagara, "niagara" },
     { TARGET_CPU_niagara2, "niagara2" },
+    { TARGET_CPU_sparcleonv7, "sparcleonv7" },
+    { TARGET_CPU_sparcleonv8, "sparcleonv8" },
     { 0, 0 }
   };
   const struct cpu_default *def;
@@ -755,6 +781,9 @@ 
     /* UltraSPARC T1 */
     { "niagara", PROCESSOR_NIAGARA, MASK_ISA, MASK_V9|MASK_DEPRECATED_V8_INSNS},
     { "niagara2", PROCESSOR_NIAGARA, MASK_ISA, MASK_V9},
+    /* SPARC-LEON */
+    { "sparcleonv7",   PROCESSOR_LEON, MASK_ISA, MASK_FPU },
+    { "sparcleonv8",   PROCESSOR_LEON, MASK_ISA & ~(MASK_V8), MASK_V8|MASK_FPU },
     { 0, (enum processor_type) 0, 0, 0 }
   };
   const struct cpu_table *cpu;
@@ -925,6 +954,9 @@ 
     case PROCESSOR_NIAGARA2:
       sparc_costs = &niagara2_costs;
       break;
+    case PROCESSOR_LEON:
+      sparc_costs = &leon_costs;
+      break;
     };
 
 #ifdef TARGET_DEFAULT_LONG_DOUBLE_128
Index: gcc/gcc/config/sparc/leon.md
===================================================================
--- gcc/gcc/config/sparc/leon.md	(revision 0)
+++ gcc/gcc/config/sparc/leon.md	(revision 0)
@@ -0,0 +1,56 @@ 
+;; Scheduling description for Leon.
+;;   Copyright (C) 2010 Free Software Foundation, Inc.
+;;
+;; This file is part of GCC.
+;;
+;; GCC is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+;;
+;; GCC is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GCC; see the file COPYING3.  If not see
+;; <http://www.gnu.org/licenses/>.
+
+
+(define_automaton "leon")
+
+(define_cpu_unit "leon_memory, leon_fpalu" "leon")
+(define_cpu_unit "leon_fpmds" "leon")
+(define_cpu_unit "write_buf" "leon")
+
+(define_insn_reservation "leon_load" 1
+  (and (eq_attr "cpu" "leon")
+    (eq_attr "type" "load,sload,fpload"))
+  "leon_memory")
+
+(define_insn_reservation "leon_store" 1
+  (and (eq_attr "cpu" "leon")
+    (eq_attr "type" "store,fpstore"))
+  "leon_memory+write_buf")
+  
+(define_insn_reservation "leon_fp_alu" 1
+  (and (eq_attr "cpu" "leon")
+    (eq_attr "type" "fp,fpmove"))
+  "leon_fpalu, nothing")
+
+(define_insn_reservation "leon_fp_mult" 1
+  (and (eq_attr "cpu" "leon")
+    (eq_attr "type" "fpmul"))
+  "leon_fpmds, nothing")
+
+(define_insn_reservation "leon_fp_div" 16
+  (and (eq_attr "cpu" "leon")
+    (eq_attr "type" "fpdivs,fpdivd"))
+  "leon_fpmds, nothing*15")
+
+(define_insn_reservation "leon_fp_sqrt" 23
+  (and (eq_attr "cpu" "leon")
+    (eq_attr "type" "fpsqrts,fpsqrtd"))
+  "leon_fpmds, nothing*21")
+
Index: gcc/gcc/config/sparc/sparc.h
===================================================================
--- gcc/gcc/config/sparc/sparc.h	(revision 167027)
+++ gcc/gcc/config/sparc/sparc.h	(working copy)
@@ -243,6 +243,9 @@ 
 #define TARGET_CPU_ultrasparc3	9
 #define TARGET_CPU_niagara	10
 #define TARGET_CPU_niagara2	11
+#define TARGET_CPU_sparcleonv7  12
+#define TARGET_CPU_sparcleonv8  13
+#define TARGET_CPU_leon TARGET_CPU_sparcleonv7
 
 #if TARGET_CPU_DEFAULT == TARGET_CPU_v9 \
  || TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc \
@@ -299,6 +302,16 @@ 
 #define ASM_CPU32_DEFAULT_SPEC "-Asparclite"
 #endif
 
+#if TARGET_CPU_DEFAULT == TARGET_CPU_sparcleonv7
+#define CPP_CPU32_DEFAULT_SPEC "-Dsparcleon"
+#define ASM_CPU32_DEFAULT_SPEC ""
+#endif
+
+#if TARGET_CPU_DEFAULT == TARGET_CPU_sparcleonv8
+#define CPP_CPU32_DEFAULT_SPEC "-Dsparcleon -D__sparc_v8__ "
+#define ASM_CPU32_DEFAULT_SPEC ""
+#endif
+
 #if TARGET_CPU_DEFAULT == TARGET_CPU_supersparc
 #define CPP_CPU32_DEFAULT_SPEC "-D__supersparc__ -D__sparc_v8__"
 #define ASM_CPU32_DEFAULT_SPEC ""
@@ -369,6 +382,9 @@ 
 %{mcpu=ultrasparc3:-D__sparc_v9__} \
 %{mcpu=niagara:-D__sparc_v9__} \
 %{mcpu=niagara2:-D__sparc_v9__} \
+%{mcpu=leon:-Dsparcleon} \
+%{mcpu=sparcleonv7:-Dsparcleon} \
+%{mcpu=sparcleonv8:-Dsparcleon -D__sparc_v8__} \
 %{!mcpu*:%{!mcypress:%{!msparclite:%{!mf930:%{!mf934:%{!mv8:%{!msupersparc:%(cpp_cpu_default)}}}}}}} \
 "
 #define CPP_ARCH32_SPEC ""
@@ -527,6 +543,7 @@ 
   PROCESSOR_V7,
   PROCESSOR_CYPRESS,
   PROCESSOR_V8,
+  PROCESSOR_LEON,
   PROCESSOR_SUPERSPARC,
   PROCESSOR_SPARCLITE,
   PROCESSOR_F930,
Index: gcc/gcc/config/sparc/t-leon
===================================================================
--- gcc/gcc/config/sparc/t-leon	(revision 0)
+++ gcc/gcc/config/sparc/t-leon	(revision 0)
@@ -0,0 +1,24 @@ 
+# configuration file for LEON cpu
+
+LIB1ASMSRC = sparc/lb1spc.asm
+LIB1ASMFUNCS = _mulsi3 _divsi3 _modsi3
+
+# We want fine grained libraries, so use the new code to build the
+# floating point emulation libraries.
+FPBIT = fp-bit.c
+DPBIT = dp-bit.c
+
+dp-bit.c: $(srcdir)/config/fp-bit.c
+	cat $(srcdir)/config/fp-bit.c > dp-bit.c
+
+fp-bit.c: $(srcdir)/config/fp-bit.c
+	echo '#define FLOAT' > fp-bit.c
+	cat $(srcdir)/config/fp-bit.c >> fp-bit.c
+
+MULTILIB_OPTIONS = msoft-float mcpu=sparcleonv8 
+MULTILIB_DIRNAMES = soft v8 
+MULTILIB_MATCHES = msoft-float=mno-fpu
+MULTILIB_MATCHES = msoft-float=mno-fpu mcpu?sparcleonv8=mcpu?v8 
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib