public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86: suppress emission of zero displacements in memory operands
@ 2005-05-06 12:04 Jan Beulich
  2005-05-06 14:00 ` [PATCH] x86: suppress emission of zero displacements in memoryoperands Dave Korn
  0 siblings, 1 reply; 18+ messages in thread
From: Jan Beulich @ 2005-05-06 12:04 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 4329 bytes --]

When explicitly specified, gas encoded a pointless zero displacement in
memory addressing forms. Since this is not normally desired and was most
likely just an oversight, this patch adds an adjustment to eliminate the
displacement in that case.

Built and tested on i686-pc-linux-gnu and x86_64-unknown-linux-gnu.

Jan

gas/
2005-05-06  Jan Beulich  <jbeulich@novell.com>

	* config/tc-i386.c (optimize_disp): Discard displacement entirely when zero and
	not required by encoding constraints.

gas/testsuite/
2005-05-06  Jan Beulich  <jbeulich@novell.com>

	* gas/i386/tlsd.[sd]: Adjust to not assume zero displacement will
	actually be present in memory addressing.
	* gas/i386/tlspic.[sd]: Likewise.

--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/config/tc-i386.c	2005-05-06 08:24:28.000000000 +0200
+++ 2005-05-06/gas/config/tc-i386.c	2005-05-06 11:45:55.861726528 +0200
@@ -2069,7 +2082,13 @@ optimize_disp ()
 	    disp &= (((offsetT) 2 << 31) - 1);
 	    disp = (disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31);
 	  }
-	if (flag_code == CODE_64BIT)
+	if (!disp && (i.types[op] & BaseIndex))
+	  {
+	    i.types[op] &= ~Disp;
+	    i.op[op].disps = 0;
+	    i.disp_operands--;
+	  }
+	else if (flag_code == CODE_64BIT)
 	  {
 	    if (fits_in_signed_long (disp))
 	      i.types[op] |= Disp32S;
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlsd.d	2002-05-23 15:12:50.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlsd.d	2005-05-06 11:01:48.000000000 +0200
@@ -22,10 +22,10 @@ Disassembly of section .text:
 [ 	]+1f: R_386_TLS_LDM	bar
   23:	e8 fc ff ff ff [ 	]*call   24 <fn\+0x24>
 [ 	]+24: R_386_PLT32	___tls_get_addr
-  28:	8d 7f 00 [ 	]*lea    0x0\(%edi\),%edi
+  28:	83 c7 00 [ 	]*add    \$0x0,%edi
   2b:	8d 90 00 00 00 00 [ 	]*lea    0x0\(%eax\),%edx
 [ 	]+2d: R_386_TLS_LDO_32	bar
-  31:	8d 76 00 [ 	]*lea    0x0\(%esi\),%esi
+  31:	83 c6 00 [ 	]*add    \$0x0,%esi
   34:	8d 88 00 00 00 00 [ 	]*lea    0x0\(%eax\),%ecx
 [ 	]+36: R_386_TLS_LDO_32	baz
   3a:	8b 5d fc [ 	]*mov    0xfffffffc\(%ebp\),%ebx
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlsd.s	2002-05-23 15:12:50.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlsd.s	2005-05-06 11:03:36.000000000 +0200
@@ -26,13 +26,13 @@ fn:
 	call	___tls_get_addr@PLT
 
 	/* Just show that there can be arbitrary instructions here  */
-	leal	0(%edi, 1), %edi
+	addl	$0, %edi
 
 	leal	bar@DTPOFF(%eax), %edx
 	/* %edx now contains &bar  */
 
 	/* Again, arbitrary instructions  */
-	leal	0(%esi, 1), %esi
+	addl	$0, %esi
 
 	leal	baz@DTPOFF(%eax), %ecx
 	/* %ecx now contains &baz  */
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlspic.d	2002-09-19 21:01:13.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlspic.d	2005-05-06 11:04:11.000000000 +0200
@@ -1,5 +1,5 @@
 #objdump: -dr
-#name: i386 non-pic tls
+#name: i386 pic tls
 
 .*: +file format .*
 
@@ -15,12 +15,12 @@ Disassembly of section .text:
    b:	81 c3 03 00 00 00 [ 	]*add    \$0x3,%ebx
 [ 	]+d: R_386_GOTPC	_GLOBAL_OFFSET_TABLE_
   11:	65 a1 00 00 00 00 [ 	]*mov    %gs:0x0,%eax
-  17:	8d 76 00 [ 	]*lea    0x0\(%esi\),%esi
+  17:	83 c6 00 [ 	]*add    \$0x0,%esi
   1a:	2b 83 00 00 00 00 [ 	]*sub    0x0\(%ebx\),%eax
 [ 	]+1c: R_386_TLS_IE_32	foo
   20:	8b 83 00 00 00 00 [ 	]*mov    0x0\(%ebx\),%eax
 [ 	]+22: R_386_TLS_GOTIE	foo
-  26:	8d 76 00 [ 	]*lea    0x0\(%esi\),%esi
+  26:	83 c6 00 [ 	]*add    \$0x0,%esi
   29:	65 8b 00 [ 	]*mov    %gs:\(%eax\),%eax
   2c:	65 8b 0d 00 00 00 00 [ 	]*mov    %gs:0x0,%ecx
   33:	03 8b 00 00 00 00 [ 	]*add    0x0\(%ebx\),%ecx
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlspic.s	2002-09-19 21:01:13.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlspic.s	2005-05-06 11:03:48.000000000 +0200
@@ -17,7 +17,7 @@ fn:
 	movl	%gs:0, %eax
 
 	/* Arbitrary instructions in between.  */
-	leal	0(%esi, 1), %esi
+	addl	$0, %esi
 
 	subl	foo@GOTTPOFF(%ebx), %eax
 	/* %eax now contains &foo  */
@@ -26,7 +26,7 @@ fn:
 	movl	foo@GOTNTPOFF(%ebx), %eax
 
 	/* Arbitrary instructions in between.  */
-	leal	0(%esi, 1), %esi
+	addl	$0, %esi
 
 	movl	%gs:(%eax), %eax
 	/* %eax now contains foo  */


[-- Attachment #2: binutils-mainline-x86-zero-mem-disp.patch --]
[-- Type: text/plain, Size: 4211 bytes --]

When explicitly specified, gas encoded a pointless zero displacement in
memory addressing forms. Since this is not normally desired and was most
likely just an oversight, this patch adds an adjustment to eliminate the
displacement in that case.

Built and tested on i686-pc-linux-gnu and x86_64-unknown-linux-gnu.

Jan

gas/
2005-05-06  Jan Beulich  <jbeulich@novell.com>

	* config/tc-i386.c (optimize_disp): Discard displacement entirely when zero and
	not required by encoding constraints.

gas/testsuite/
2005-05-06  Jan Beulich  <jbeulich@novell.com>

	* gas/i386/tlsd.[sd]: Adjust to not assume zero displacement will
	actually be present in memory addressing.
	* gas/i386/tlspic.[sd]: Likewise.

--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/config/tc-i386.c	2005-05-06 08:24:28.000000000 +0200
+++ 2005-05-06/gas/config/tc-i386.c	2005-05-06 11:45:55.861726528 +0200
@@ -2069,7 +2082,13 @@ optimize_disp ()
 	    disp &= (((offsetT) 2 << 31) - 1);
 	    disp = (disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31);
 	  }
-	if (flag_code == CODE_64BIT)
+	if (!disp && (i.types[op] & BaseIndex))
+	  {
+	    i.types[op] &= ~Disp;
+	    i.op[op].disps = 0;
+	    i.disp_operands--;
+	  }
+	else if (flag_code == CODE_64BIT)
 	  {
 	    if (fits_in_signed_long (disp))
 	      i.types[op] |= Disp32S;
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlsd.d	2002-05-23 15:12:50.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlsd.d	2005-05-06 11:01:48.000000000 +0200
@@ -22,10 +22,10 @@ Disassembly of section .text:
 [ 	]+1f: R_386_TLS_LDM	bar
   23:	e8 fc ff ff ff [ 	]*call   24 <fn\+0x24>
 [ 	]+24: R_386_PLT32	___tls_get_addr
-  28:	8d 7f 00 [ 	]*lea    0x0\(%edi\),%edi
+  28:	83 c7 00 [ 	]*add    \$0x0,%edi
   2b:	8d 90 00 00 00 00 [ 	]*lea    0x0\(%eax\),%edx
 [ 	]+2d: R_386_TLS_LDO_32	bar
-  31:	8d 76 00 [ 	]*lea    0x0\(%esi\),%esi
+  31:	83 c6 00 [ 	]*add    \$0x0,%esi
   34:	8d 88 00 00 00 00 [ 	]*lea    0x0\(%eax\),%ecx
 [ 	]+36: R_386_TLS_LDO_32	baz
   3a:	8b 5d fc [ 	]*mov    0xfffffffc\(%ebp\),%ebx
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlsd.s	2002-05-23 15:12:50.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlsd.s	2005-05-06 11:03:36.000000000 +0200
@@ -26,13 +26,13 @@ fn:
 	call	___tls_get_addr@PLT
 
 	/* Just show that there can be arbitrary instructions here  */
-	leal	0(%edi, 1), %edi
+	addl	$0, %edi
 
 	leal	bar@DTPOFF(%eax), %edx
 	/* %edx now contains &bar  */
 
 	/* Again, arbitrary instructions  */
-	leal	0(%esi, 1), %esi
+	addl	$0, %esi
 
 	leal	baz@DTPOFF(%eax), %ecx
 	/* %ecx now contains &baz  */
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlspic.d	2002-09-19 21:01:13.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlspic.d	2005-05-06 11:04:11.000000000 +0200
@@ -1,5 +1,5 @@
 #objdump: -dr
-#name: i386 non-pic tls
+#name: i386 pic tls
 
 .*: +file format .*
 
@@ -15,12 +15,12 @@ Disassembly of section .text:
    b:	81 c3 03 00 00 00 [ 	]*add    \$0x3,%ebx
 [ 	]+d: R_386_GOTPC	_GLOBAL_OFFSET_TABLE_
   11:	65 a1 00 00 00 00 [ 	]*mov    %gs:0x0,%eax
-  17:	8d 76 00 [ 	]*lea    0x0\(%esi\),%esi
+  17:	83 c6 00 [ 	]*add    \$0x0,%esi
   1a:	2b 83 00 00 00 00 [ 	]*sub    0x0\(%ebx\),%eax
 [ 	]+1c: R_386_TLS_IE_32	foo
   20:	8b 83 00 00 00 00 [ 	]*mov    0x0\(%ebx\),%eax
 [ 	]+22: R_386_TLS_GOTIE	foo
-  26:	8d 76 00 [ 	]*lea    0x0\(%esi\),%esi
+  26:	83 c6 00 [ 	]*add    \$0x0,%esi
   29:	65 8b 00 [ 	]*mov    %gs:\(%eax\),%eax
   2c:	65 8b 0d 00 00 00 00 [ 	]*mov    %gs:0x0,%ecx
   33:	03 8b 00 00 00 00 [ 	]*add    0x0\(%ebx\),%ecx
--- /home/jbeulich/src/binutils/mainline/2005-05-06/gas/testsuite/gas/i386/tlspic.s	2002-09-19 21:01:13.000000000 +0200
+++ 2005-05-06/gas/testsuite/gas/i386/tlspic.s	2005-05-06 11:03:48.000000000 +0200
@@ -17,7 +17,7 @@ fn:
 	movl	%gs:0, %eax
 
 	/* Arbitrary instructions in between.  */
-	leal	0(%esi, 1), %esi
+	addl	$0, %esi
 
 	subl	foo@GOTTPOFF(%ebx), %eax
 	/* %eax now contains &foo  */
@@ -26,7 +26,7 @@ fn:
 	movl	foo@GOTNTPOFF(%ebx), %eax
 
 	/* Arbitrary instructions in between.  */
-	leal	0(%esi, 1), %esi
+	addl	$0, %esi
 
 	movl	%gs:(%eax), %eax
 	/* %eax now contains foo  */

^ permalink raw reply	[flat|nested] 18+ messages in thread
* RE: [PATCH] x86: suppress emission of zero displacements in memoryoperands
@ 2005-05-06 16:40 Jan Beulich
  2005-05-06 16:44 ` DJ Delorie
  2005-05-06 16:50 ` H. J. Lu
  0 siblings, 2 replies; 18+ messages in thread
From: Jan Beulich @ 2005-05-06 16:40 UTC (permalink / raw)
  To: dave.korn, binutils

This stripping is intentional; I'm running into this in many cases where structure offsets are generated (i.e. through a C translation), and the zero offset gets needlessly retained. The point is that you anyway can't force the assembler to everything, like use a 32-bit displacement when an 8-bit one (or even none) suffices. If that's already impossible, then adding this additional thing is no issue at all in my opinion. Jan

>>> "Dave Korn" <dave.korn@artimi.com> 06.05.05 15:56:52 >>>
----Original Message----
>From: Jan Beulich
>Sent: 06 May 2005 13:04

> When explicitly specified, gas encoded a pointless zero displacement in
> memory addressing forms. Since this is not normally desired and was most
> likely just an oversight, this patch adds an adjustment to eliminate the
> displacement in that case.

  I'm not sure if I've fully understood the intent of this patch, but I
think you're saying that if someone writes

        mov %eax,0(%edi)

the assembler will emit

   4 0003 8907          mov %eax,(%edi)

and not

   2 0000 894700        mov %eax,0(%edi)

yes?  Nothing the user _explicitly_ specifies should ever be discarded IMO.
What if someone wants to write self-modifying code that stores varying
offsets into that field?


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [PATCH] x86: suppress emission of zero displacements in memoryoperands
@ 2005-05-06 17:01 Jan Beulich
  0 siblings, 0 replies; 18+ messages in thread
From: Jan Beulich @ 2005-05-06 17:01 UTC (permalink / raw)
  To: hjl; +Cc: dave.korn, binutils

>>> "H. J. Lu" <hjl@lucon.org> 06.05.05 18:50:33 >>>
>On Fri, May 06, 2005 at 06:33:00PM +0200, Jan Beulich wrote:
>> This stripping is intentional; I'm running into this in many cases where structure offsets are generated (i.e. through a C translation), and the
>> zero offset gets needlessly retained. The point is that you anyway can't force the assembler to everything, like use a 32-bit displacement
>> when an 8-bit one (or even none) suffices. If that's already impossible, then adding this additional thing is no issue at all in my opinion. Jan
>> 
>
>Please check out
>
>http://people.redhat.com/drepper/tls.pdf 
>
>elf_i386_relocate_section and elf64_x86_64_relocate_section to make
>sure that TLS optimization, which depends on the exact length of
>the instruction, won't get affected. 

I will.

>I still prefer to fix compiler instead of assembler.

I'm not sure what compiler fix you're referring to here. I'm referring to e.g. Linux' asm-offsets logic, which can easily create zero offsets, and which the compiler has no way to deal with.

Jan

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [PATCH] x86: suppress emission of zero displacements in memoryoperands
@ 2005-05-09 10:29 Jan Beulich
  2005-05-09 14:02 ` H. J. Lu
  0 siblings, 1 reply; 18+ messages in thread
From: Jan Beulich @ 2005-05-09 10:29 UTC (permalink / raw)
  To: hjl; +Cc: dave.korn, binutils

>Please check out
>
>http://people.redhat.com/drepper/tls.pdf 
>
>elf_i386_relocate_section and elf64_x86_64_relocate_section to make
>sure that TLS optimization, which depends on the exact length of
>the instruction, won't get affected. 

This can't be affected due to the O_constant check surrounding the whole construct:

    if ((i.types[op] & Disp) && i.op[op].disps->X_op == O_constant)

Jan

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

end of thread, other threads:[~2006-07-14 17:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-06 12:04 [PATCH] x86: suppress emission of zero displacements in memory operands Jan Beulich
2005-05-06 14:00 ` [PATCH] x86: suppress emission of zero displacements in memoryoperands Dave Korn
2005-05-06 14:21   ` Andreas Schwab
2005-05-06 14:26     ` Dave Korn
2005-05-06 14:36       ` H. J. Lu
2005-05-06 14:39       ` Andreas Schwab
2005-05-06 14:56         ` Dave Korn
2005-05-06 15:04           ` Andreas Schwab
2005-05-06 19:35   ` Richard Henderson
2006-07-14 17:03     ` Clifford T. Matthews
2006-07-14 17:30       ` H. J. Lu
2006-07-14 17:34         ` Dave Korn
2005-05-06 16:40 Jan Beulich
2005-05-06 16:44 ` DJ Delorie
2005-05-06 16:50 ` H. J. Lu
2005-05-06 17:01 Jan Beulich
2005-05-09 10:29 Jan Beulich
2005-05-09 14:02 ` H. J. Lu

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).