public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] MIPS/GAS: Fix register use annotation of ALNV.PS
@ 2011-02-25  1:06 Maciej W. Rozycki
  2011-02-26  9:40 ` Richard Sandiford
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej W. Rozycki @ 2011-02-25  1:06 UTC (permalink / raw)
  To: binutils; +Cc: Richard Sandiford

Hi,

 The ALNV.PS instruction lacks register use annotation for its general 
register argument.  As a result it can be reordered into a branch delay 
slot even if it reads a register that the branch writes.  Here's a fix.

 Regression-tested with the mips-sde-elf and mips-gnu-linux targets.  OK 
to apply?

2011-02-25  Maciej W. Rozycki  <macro@codesourcery.com>

	opcodes/
	* mips-opc.c (mips_builtin_opcodes): Correct register use 
	annotation of "alnv.ps".

	gas/testsuite/
	* gas/mips/alnv_ps-swap.d: New test for ALNV.PS instruction
	branch swapping.
	* gas/mips/alnv_ps-swap.s: Source for the new test.
	* gas/mips/mips.exp: Run the new test.

  Maciej

binutils-mips-opcode-alnv.diff
Index: binutils-fsf-trunk-quilt/opcodes/mips-opc.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/opcodes/mips-opc.c	2011-02-24 23:46:08.000000000 +0000
+++ binutils-fsf-trunk-quilt/opcodes/mips-opc.c	2011-02-24 23:46:09.000000000 +0000
@@ -297,7 +297,7 @@ const struct mips_opcode mips_builtin_op
 {"alni.ob", "X,Y,Z,O",	0x78000018, 0xff00003f,	WR_D|RD_S|RD_T|FP_D,	0,		MX|SB1	},
 {"alni.ob", "D,S,T,%",	0x48000018, 0xff00003f,	WR_D|RD_S|RD_T, 	0,		N54	},
 {"alni.qh", "X,Y,Z,O",	0x7800001a, 0xff00003f,	WR_D|RD_S|RD_T|FP_D,	0,		MX	},
-{"alnv.ps", "D,V,T,s",	0x4c00001e, 0xfc00003f,	WR_D|RD_S|RD_T|FP_D,	0,		I5_33	},
+{"alnv.ps", "D,V,T,s",	0x4c00001e, 0xfc00003f,	WR_D|RD_S|RD_T|RD_s|FP_D, 0,		I5_33	},
 {"alnv.ob", "X,Y,Z,s",	0x78000019, 0xfc00003f,	WR_D|RD_S|RD_T|RD_s|FP_D, 0,		MX|SB1	},
 {"alnv.qh", "X,Y,Z,s",	0x7800001b, 0xfc00003f,	WR_D|RD_S|RD_T|RD_s|FP_D, 0,		MX	},
 {"and",     "d,v,t",	0x00000024, 0xfc0007ff,	WR_d|RD_s|RD_t,		0,		I1	},
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/alnv_ps-swap.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/alnv_ps-swap.d	2011-02-24 23:46:09.000000000 +0000
@@ -0,0 +1,39 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS ALNV.PS instruction branch swapping
+#as: -32
+
+# Check that a register dependency between ALNV.PS and the following
+# branch prevents from branch swapping.
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+[0-9a-f]+ <[^>]*> 1000ffff 	b	0+0000 <foo>
+[0-9a-f]+ <[^>]*> 4c60111e 	alnv\.ps	\$f4,\$f2,\$f0,v1
+[0-9a-f]+ <[^>]*> 0411fffd 	bal	0+0000 <foo>
+[0-9a-f]+ <[^>]*> 4c60111e 	alnv\.ps	\$f4,\$f2,\$f0,v1
+[0-9a-f]+ <[^>]*> 0470fffb 	bltzal	v1,0+0000 <foo>
+[0-9a-f]+ <[^>]*> 4c60111e 	alnv\.ps	\$f4,\$f2,\$f0,v1
+[0-9a-f]+ <[^>]*> 0060f809 	jalr	v1
+[0-9a-f]+ <[^>]*> 4c60111e 	alnv\.ps	\$f4,\$f2,\$f0,v1
+[0-9a-f]+ <[^>]*> 00602009 	jalr	a0,v1
+[0-9a-f]+ <[^>]*> 4c60111e 	alnv\.ps	\$f4,\$f2,\$f0,v1
+[0-9a-f]+ <[^>]*> 4c60111e 	alnv\.ps	\$f4,\$f2,\$f0,v1
+[0-9a-f]+ <[^>]*> 03e01809 	jalr	v1,ra
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 1000fff2 	b	0+0000 <foo>
+[0-9a-f]+ <[^>]*> 4fe0111e 	alnv\.ps	\$f4,\$f2,\$f0,ra
+[0-9a-f]+ <[^>]*> 4fe0111e 	alnv\.ps	\$f4,\$f2,\$f0,ra
+[0-9a-f]+ <[^>]*> 0411ffef 	bal	0+0000 <foo>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 4fe0111e 	alnv\.ps	\$f4,\$f2,\$f0,ra
+[0-9a-f]+ <[^>]*> 0470ffec 	bltzal	v1,0+0000 <foo>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 4fe0111e 	alnv\.ps	\$f4,\$f2,\$f0,ra
+[0-9a-f]+ <[^>]*> 0060f809 	jalr	v1
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 00602009 	jalr	a0,v1
+[0-9a-f]+ <[^>]*> 4fe0111e 	alnv\.ps	\$f4,\$f2,\$f0,ra
+[0-9a-f]+ <[^>]*> 03e01809 	jalr	v1,ra
+[0-9a-f]+ <[^>]*> 4fe0111e 	alnv\.ps	\$f4,\$f2,\$f0,ra
+	\.\.\.
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/alnv_ps-swap.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/alnv_ps-swap.s	2011-02-24 23:46:09.000000000 +0000
@@ -0,0 +1,33 @@
+# Source file to test branch swapping with the ALNV.PS instruction.
+
+	.text
+foo:
+	alnv.ps	$f4, $f2, $f0, $3
+	b	foo
+	alnv.ps	$f4, $f2, $f0, $3
+	bal	foo
+	alnv.ps	$f4, $f2, $f0, $3
+	bltzal	$3, foo
+	alnv.ps	$f4, $f2, $f0, $3
+	jalr	$3
+	alnv.ps	$f4, $f2, $f0, $3
+	jalr	$4, $3
+	alnv.ps	$f4, $f2, $f0, $3
+	jalr	$3, $31
+
+	alnv.ps	$f4, $f2, $f0, $31
+	b	foo
+	alnv.ps	$f4, $f2, $f0, $31
+	bal	foo
+	alnv.ps	$f4, $f2, $f0, $31
+	bltzal	$3, foo
+	alnv.ps	$f4, $f2, $f0, $31
+	jalr	$3
+	alnv.ps	$f4, $f2, $f0, $31
+	jalr	$4, $3
+	alnv.ps	$f4, $f2, $f0, $31
+	jalr	$3, $31
+
+# Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	2
+	.space	8
Index: binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/testsuite/gas/mips/mips.exp	2011-02-24 23:46:09.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/testsuite/gas/mips/mips.exp	2011-02-24 23:46:09.000000000 +0000
@@ -983,6 +983,9 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "mips32-sync"
     run_dump_test_arches "mips32r2-sync" \
 					[mips_arch_list_matching mips32r2]
+    run_dump_test_arches "alnv_ps-swap" [lsort -dictionary -unique [concat \
+					[mips_arch_list_matching mips5] \
+					[mips_arch_list_matching mips32r2] ] ]
 
     if $has_newabi { run_dump_test "cfi-n64-1" }
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS/GAS: Fix register use annotation of ALNV.PS
  2011-02-25  1:06 [PATCH] MIPS/GAS: Fix register use annotation of ALNV.PS Maciej W. Rozycki
@ 2011-02-26  9:40 ` Richard Sandiford
  2011-02-28 16:39   ` Maciej W. Rozycki
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Sandiford @ 2011-02-26  9:40 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: binutils

"Maciej W. Rozycki" <macro@codesourcery.com> writes:
>  The ALNV.PS instruction lacks register use annotation for its general 
> register argument.  As a result it can be reordered into a branch delay 
> slot even if it reads a register that the branch writes.  Here's a fix.

Ouch.  So easily done.  Did someone find out the hard way, or was this
just by inspection?

> 2011-02-25  Maciej W. Rozycki  <macro@codesourcery.com>
>
> 	opcodes/
> 	* mips-opc.c (mips_builtin_opcodes): Correct register use 
> 	annotation of "alnv.ps".
>
> 	gas/testsuite/
> 	* gas/mips/alnv_ps-swap.d: New test for ALNV.PS instruction
> 	branch swapping.
> 	* gas/mips/alnv_ps-swap.s: Source for the new test.
> 	* gas/mips/mips.exp: Run the new test.

OK, thanks.

Richard

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS/GAS: Fix register use annotation of ALNV.PS
  2011-02-26  9:40 ` Richard Sandiford
@ 2011-02-28 16:39   ` Maciej W. Rozycki
  0 siblings, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2011-02-28 16:39 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: binutils

On Sat, 26 Feb 2011, Richard Sandiford wrote:

> >  The ALNV.PS instruction lacks register use annotation for its general 
> > register argument.  As a result it can be reordered into a branch delay 
> > slot even if it reads a register that the branch writes.  Here's a fix.
> 
> Ouch.  So easily done.  Did someone find out the hard way, or was this
> just by inspection?

 The microMIPS version of ALNV.PS is enough of an oddball that I couldn't 
resist checking we've got the standard version right either. ;)

> > 2011-02-25  Maciej W. Rozycki  <macro@codesourcery.com>
> >
> > 	opcodes/
> > 	* mips-opc.c (mips_builtin_opcodes): Correct register use 
> > 	annotation of "alnv.ps".
> >
> > 	gas/testsuite/
> > 	* gas/mips/alnv_ps-swap.d: New test for ALNV.PS instruction
> > 	branch swapping.
> > 	* gas/mips/alnv_ps-swap.s: Source for the new test.
> > 	* gas/mips/mips.exp: Run the new test.
> 
> OK, thanks.

 It's now in, thanks.

  Maciej

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-28 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-25  1:06 [PATCH] MIPS/GAS: Fix register use annotation of ALNV.PS Maciej W. Rozycki
2011-02-26  9:40 ` Richard Sandiford
2011-02-28 16:39   ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).