#! /bin/sh -e

# DP: ARM patch for default tuning

src=gcc
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    src=$3/gcc
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p1 --fuzz 10 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p1 --fuzz 10 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- src/gcc/config/arm/arm.c	2001/05/24 21:09:05	1.146
+++ src/gcc/config/arm/arm.c	2001/06/17 19:10:22
@@ -430,6 +430,32 @@ arm_override_options ()
 	abort ();
 
       insn_flags = sel->flags;
+
+#ifdef TARGET_TUNE_DEFAULT
+      /* If the user didn't specify tuning either, use the target's
+	 preferred flags.  */
+      if (tune_flags == 0)
+	{
+	  struct processors * tunesel;
+	  struct cpu_default * tunedef;
+
+	  for (tunedef = cpu_defaults; tunedef->name; tunedef++)
+	    if (tunedef->cpu == TARGET_TUNE_DEFAULT)
+	      break;
+
+	  if (tunedef->name == NULL)
+	    abort ();
+
+	  for (tunesel = all_cores; tunesel->name != NULL; tunesel++)
+	    if (streq (tunedef->name, tunesel->name))
+	      break;
+
+	  if (tunesel->name == NULL)
+	    abort ();
+
+	  tune_flags = tunesel->flags;
+	}
+#endif
       
       /* Now check to see if the user has specified some command line
 	 switch that require certain abilities from the cpu.  */
--- src/gcc/config/arm/linux-elf.h~	13 Dec 2001 00:27:30 -0000	1.30
+++ src/gcc/config/arm/linux-elf.h	Thu May 23 07:59:25 2002
@@ -122,6 +122,9 @@
 #undef  CC1_SPEC
 #define CC1_SPEC "%{profile:-p}"
 
+/* Tune for XScale.  */
+#define TARGET_TUNE_DEFAULT TARGET_CPU_xscale
+
 /* Copied from config/linux.h, needed for libstdc++v3.  */
 #undef CPLUSPLUS_CPP_SPEC
 #define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
