Re: [PATCH] MIPS r5900, --with-llsc=?

2013-06-16 Thread Richard Sandiford
Jürgen Urban juergenur...@gmx.de writes:
 Hello Richard,

   How much other changes will be currently accepted here? There is other
   stuff which I want to prepare and submit here, e.g.:

   3. fix use of ll/sc in libgomp, either increase mips ISA level or use
   syscall (which is broken in Linux 2.6.35.4).

 The attached patch fixes problem 3. libgomp was not the cause of the
 problem. When linux is detected in gcc/config.gcc, the variable
 with_llsc is set to yes. This happens before the CPU is checked. I
 fixed this by storing the original parameter. I think this is better
 than moving the code up.

I think this shows that the current mips*-linux* targets are setting
with_llsc in the wrong place.  They should be doing it further down,
where other with_foo defaults are set.

Also, I only just noticed that VxWorks and R5900 were setting with_arch
in the with_cpu block.  --with-cpu isn't supported/meaningful for MIPS.

Is the second patch below OK for your target?  (Not yet applied.)

 The patch for gcc/config/mips/mips.h fixes that .set mips2 wasn't used
 when with_llsc=yes was configured.

 The patch for gcc/config/mips/mips.c gets lld and scd working. These
 instructions are normally not emulated by the Linux kernel and the
 syscall only supports 32 bit. So I changed my kernel to support lld and
 scd.

Looks good, thanks.  I tweaked the mips.c change to follow coding
conventions and kept !TARGET_MIPS16 last.  Applied as follows.

Thanks,
Richard

[Applied patch]

gcc/
2013-06-16  Jürgen Urban  juergenur...@gmx.de

* config/mips/mips.h (ISA_HAS_LL_SC): Exclude TARGET_MIPS5900.
* config/mips/mips.c (mips_start_ll_sc_sync_block): Output
.set mips3 for 64-bit targets.

Index: gcc/config/mips/mips.h
===
--- gcc/config/mips/mips.h  2013-06-16 10:04:33.151622456 +0100
+++ gcc/config/mips/mips.h  2013-06-16 10:12:52.265346985 +0100
@@ -1063,7 +1063,7 @@ #define GENERATE_SYNC \
 /* ISA includes ll and sc.  Note that this implies ISA_HAS_SYNC
because the expanders use both ISA_HAS_SYNC and ISA_HAS_LL_SC
instructions.  */
-#define ISA_HAS_LL_SC (mips_isa = 2  !TARGET_MIPS16)
+#define ISA_HAS_LL_SC (mips_isa = 2  !TARGET_MIPS5900  !TARGET_MIPS16)
 #define GENERATE_LL_SC \
   (target_flags_explicit  MASK_LLSC   \
? TARGET_LLSC  !TARGET_MIPS16 \
Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c  2013-06-16 10:04:33.151622456 +0100
+++ gcc/config/mips/mips.c  2013-06-16 10:12:57.717387243 +0100
@@ -12463,7 +12463,10 @@ mips_start_ll_sc_sync_block (void)
   if (!ISA_HAS_LL_SC)
 {
   output_asm_insn (.set\tpush, 0);
-  output_asm_insn (.set\tmips2, 0);
+  if (TARGET_64BIT)
+   output_asm_insn (.set\tmips3, 0);
+  else
+   output_asm_insn (.set\tmips2, 0);
 }
 }
 
[Suggested config.gcc patch]

gcc/
* config.gcc (mips*-mti-linux*, mips64*-*-linux*, mipsisa64*-*-linux*)
(mips*-*-linux*): Move default with_llsc setting to where other
defaults are set.
(mips*-*-vxworks*): Move with_arch default from with_cpu block to
with_arch block.
(mips64r5900-*-*, mips64r5900el-*-*, mipsr5900-*-*, mipsr5900el-*-*):
Likewise.  Remove default with_tune setting.  Move default float
setting to its own block.  Handle with_llsc in the same block as above.

Index: gcc/config.gcc
===
--- gcc/config.gcc	2013-06-16 09:41:57.518019616 +0100
+++ gcc/config.gcc	2013-06-16 09:59:57.660470388 +0100
@@ -1813,7 +1813,6 @@ mips*-mti-linux*)
 	tm_defines=${tm_defines} MIPS_ISA_DEFAULT=33 MIPS_ABI_DEFAULT=ABI_32
 	gnu_ld=yes
 	gas=yes
-	test x$with_llsc != x || with_llsc=yes
 	;;
 mips64*-*-linux* | mipsisa64*-*-linux*)
 	tm_file=dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/gnu-user64.h mips/linux64.h mips/linux-common.h
@@ -1834,7 +1833,6 @@ mips64*-*-linux* | mipsisa64*-*-linux*)
 	esac
 	gnu_ld=yes
 	gas=yes
-	test x$with_llsc != x || with_llsc=yes
 	;;
 mips*-*-linux*)# Linux MIPS, either endian.
 tm_file=dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/linux.h
@@ -1850,7 +1848,6 @@ mips*-*-linux*)# Linux MIPS, either
 mipsisa32*)
 		tm_defines=${tm_defines} MIPS_ISA_DEFAULT=32
 esac
-	test x$with_llsc != x || with_llsc=yes
 	;;
 mips*-mti-elf*)
 	tm_file=elfos.h newlib-stdint.h ${tm_file} mips/elf.h mips/sde.h mips/mti-elf.h
@@ -2982,22 +2979,6 @@ if test x$with_cpu = x ; then
 	  ;;
   esac
   ;;
-mips64r5900-*-* | mips64r5900el-*-* | mipsr5900-*-* | mipsr5900el-*-*)
-  with_arch=r5900
-  with_tune=r5900
-  if test x$with_llsc = x; then
-	# r5900 doesn't support ll, sc, lld and scd instructions:
-	with_llsc=no
-  fi
-  if test 

Re: [PATCH] MIPS r5900, --with-llsc=?

2013-06-16 Thread Jürgen Urban
Hello Richard,

 
How much other changes will be currently accepted here? There is other
stuff which I want to prepare and submit here, e.g.:
 
3. fix use of ll/sc in libgomp, either increase mips ISA level or use
syscall (which is broken in Linux 2.6.35.4).
 
  The attached patch fixes problem 3. libgomp was not the cause of the
  problem. When linux is detected in gcc/config.gcc, the variable
  with_llsc is set to yes. This happens before the CPU is checked. I
  fixed this by storing the original parameter. I think this is better
  than moving the code up.

 I think this shows that the current mips*-linux* targets are setting
 with_llsc in the wrong place.  They should be doing it further down,
 where other with_foo defaults are set.

 Also, I only just noticed that VxWorks and R5900 were setting with_arch
 in the with_cpu block.  --with-cpu isn't supported/meaningful for MIPS.

 Is the second patch below OK for your target?  (Not yet applied.)

  The patch for gcc/config/mips/mips.h fixes that .set mips2 wasn't used
  when with_llsc=yes was configured.
 
  The patch for gcc/config/mips/mips.c gets lld and scd working. These
  instructions are normally not emulated by the Linux kernel and the
  syscall only supports 32 bit. So I changed my kernel to support lld and
  scd.

 Looks good, thanks.  I tweaked the mips.c change to follow coding
 conventions and kept !TARGET_MIPS16 last.

Yes, the patch is OK. Checked, tested and working.

Best regards
Jürgen


[PATCH] MIPS r5900, --with-llsc=?

2013-06-15 Thread Jürgen Urban
Hello Richard,

   How much other changes will be currently accepted here? There is other
   stuff which I want to prepare and submit here, e.g.:

   3. fix use of ll/sc in libgomp, either increase mips ISA level or use
   syscall (which is broken in Linux 2.6.35.4).

The attached patch fixes problem 3. libgomp was not the cause of the problem. 
When linux is detected in gcc/config.gcc, the variable with_llsc is set to 
yes. This happens before the CPU is checked. I fixed this by storing the 
original parameter. I think this is better than moving the code up.

The patch for gcc/config/mips/mips.h fixes that .set mips2 wasn't used when 
with_llsc=yes was configured.

The patch for gcc/config/mips/mips.c gets lld and scd working. These 
instructions are normally not emulated by the Linux kernel and the syscall only 
supports 32 bit. So I changed my kernel to support lld and scd. On the long 
term I plan to use registers k0 or k1 as address registers for the instructions 
lb, lw, ld, lq, sb, sw, sd and sq which was suggested for the PS2 in an old 
paper, because the registers are changed by the kernel on interrupts. There 
were measurements which showed much performance improvement on the PS2 when no 
illegal instructions are used.

Best regards
JürgenIndex: gcc/config.gcc
===
--- gcc/config.gcc	(Revision 199708)
+++ gcc/config.gcc	(Arbeitskopie)
@@ -297,6 +297,9 @@
 	;;
 esac
 
+# Save parameter --with-llsc for later check.
+param_llsc=$with_llsc
+
 # Set default cpu_type, tm_file, tm_p_file and xm_file so it can be
 # updated in each machine entry.  Also set default extra_headers for some
 # machines.
@@ -2985,7 +2988,7 @@
 mips64r5900-*-* | mips64r5900el-*-* | mipsr5900-*-* | mipsr5900el-*-*)
   with_arch=r5900
   with_tune=r5900
-  if test x$with_llsc = x; then
+  if test x$param_llsc = x; then
 	# r5900 doesn't support ll, sc, lld and scd instructions:
 	with_llsc=no
   fi
Index: gcc/config/mips/mips.c
===
--- gcc/config/mips/mips.c	(Revision 199708)
+++ gcc/config/mips/mips.c	(Arbeitskopie)
@@ -12463,7 +12463,11 @@
   if (!ISA_HAS_LL_SC)
 {
   output_asm_insn (.set\tpush, 0);
-  output_asm_insn (.set\tmips2, 0);
+  if (TARGET_64BIT) {
+output_asm_insn (.set\tmips3, 0);
+  } else {
+output_asm_insn (.set\tmips2, 0);
+  }
 }
 }
 
Index: gcc/config/mips/mips.h
===
--- gcc/config/mips/mips.h	(Revision 199708)
+++ gcc/config/mips/mips.h	(Arbeitskopie)
@@ -1063,7 +1081,7 @@
 /* ISA includes ll and sc.  Note that this implies ISA_HAS_SYNC
because the expanders use both ISA_HAS_SYNC and ISA_HAS_LL_SC
instructions.  */
-#define ISA_HAS_LL_SC (mips_isa = 2  !TARGET_MIPS16)
+#define ISA_HAS_LL_SC (mips_isa = 2  !TARGET_MIPS16  !TARGET_MIPS5900)
 #define GENERATE_LL_SC			\
   (target_flags_explicit  MASK_LLSC	\
? TARGET_LLSC  !TARGET_MIPS16	\