diff mbox

PATCH [5/n] X32: Fix x32 trampoline

Message ID 20110709214139.GA3711@intel.com
State New
Headers show

Commit Message

H.J. Lu July 9, 2011, 9:41 p.m. UTC
Hi,

X32 uses movl instead of movabs for trampoline.  OK for trunk?

Thanks.

H.J.
---
2011-07-09  H.J. Lu  <hongjiu.lu@intel.com>

	* config/i386/i386.c (ix86_trampoline_init): Use movl instead
	of movabs for x32.

Comments

Richard Henderson July 9, 2011, 10:46 p.m. UTC | #1
On 07/09/2011 02:41 PM, H.J. Lu wrote:
> Hi,
> 
> X32 uses movl instead of movabs for trampoline.  OK for trunk?
> 
> Thanks.
> 
> H.J.
> ---
> 2011-07-09  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* config/i386/i386.c (ix86_trampoline_init): Use movl instead
> 	of movabs for x32.
> 
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 04cb07d..c852719 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -22721,13 +23030,14 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
>      }
>    else
>      {
> -      int offset = 0;
> +      int offset = 0, size;
>  
>        /* Load the function address to r11.  Try to load address using
>  	 the shorter movl instead of movabs.  We may want to support
>  	 movq for kernel mode, but kernel does not use trampolines at
>  	 the moment.  */
> -      if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
> +      if (TARGET_X32
> +	  || x86_64_zext_immediate_operand (fnaddr, VOIDmode))

Is this change actually necessary?  I would think that the 
predicate has already been adjusted...

> -      emit_move_insn (mem, gen_int_mode (0xba49, HImode));
> +      /* Use the shorter movl instead of movabs for x32.  */
> +      if (TARGET_X32)
> +	{
> +	  size = 6;
> +	  emit_move_insn (mem, gen_int_mode (0xba41, HImode));

Have I forgotten x86 encoding?  I thought movl imm,reg was 5 bytes...


r~
H.J. Lu July 9, 2011, 11:01 p.m. UTC | #2
On Sat, Jul 9, 2011 at 3:46 PM, Richard Henderson <rth@redhat.com> wrote:
> On 07/09/2011 02:41 PM, H.J. Lu wrote:
>> Hi,
>>
>> X32 uses movl instead of movabs for trampoline.  OK for trunk?
>>
>> Thanks.
>>
>> H.J.
>> ---
>> 2011-07-09  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       * config/i386/i386.c (ix86_trampoline_init): Use movl instead
>>       of movabs for x32.
>>
>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
>> index 04cb07d..c852719 100644
>> --- a/gcc/config/i386/i386.c
>> +++ b/gcc/config/i386/i386.c
>> @@ -22721,13 +23030,14 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
>>      }
>>    else
>>      {
>> -      int offset = 0;
>> +      int offset = 0, size;
>>
>>        /* Load the function address to r11.  Try to load address using
>>        the shorter movl instead of movabs.  We may want to support
>>        movq for kernel mode, but kernel does not use trampolines at
>>        the moment.  */
>> -      if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
>> +      if (TARGET_X32
>> +       || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
>
> Is this change actually necessary?  I would think that the
> predicate has already been adjusted...
>
>> -      emit_move_insn (mem, gen_int_mode (0xba49, HImode));
>> +      /* Use the shorter movl instead of movabs for x32.  */
>> +      if (TARGET_X32)
>> +     {
>> +       size = 6;
>> +       emit_move_insn (mem, gen_int_mode (0xba41, HImode));
>
> Have I forgotten x86 encoding?  I thought movl imm,reg was 5 bytes...
>
>

You forgot the REX prefix:

[hjl@gnu-6 tmp]$ cat x.s
	mov $0x12340000, %r11d
[hjl@gnu-6 tmp]$ gcc -c x.s
[hjl@gnu-6 tmp]$ objdump -dw x.o

x.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <.text>:
   0:	41 bb 00 00 34 12    	mov    $0x12340000,%r11d
[hjl@gnu-6 tmp]$
H.J. Lu July 9, 2011, 11:05 p.m. UTC | #3
On Sat, Jul 9, 2011 at 3:46 PM, Richard Henderson <rth@redhat.com> wrote:
> On 07/09/2011 02:41 PM, H.J. Lu wrote:
>> Hi,
>>
>> X32 uses movl instead of movabs for trampoline.  OK for trunk?
>>
>> Thanks.
>>
>> H.J.
>> ---
>> 2011-07-09  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       * config/i386/i386.c (ix86_trampoline_init): Use movl instead
>>       of movabs for x32.
>>
>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
>> index 04cb07d..c852719 100644
>> --- a/gcc/config/i386/i386.c
>> +++ b/gcc/config/i386/i386.c
>> @@ -22721,13 +23030,14 @@ ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
>>      }
>>    else
>>      {
>> -      int offset = 0;
>> +      int offset = 0, size;
>>
>>        /* Load the function address to r11.  Try to load address using
>>        the shorter movl instead of movabs.  We may want to support
>>        movq for kernel mode, but kernel does not use trampolines at
>>        the moment.  */
>> -      if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
>> +      if (TARGET_X32
>> +       || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
>
> Is this change actually necessary?  I would think that the
> predicate has already been adjusted...
>

Since we always use short version for x32, there is no need to call.
x86_64_zext_immediate_operand.
Richard Henderson July 9, 2011, 11:12 p.m. UTC | #4
On 07/09/2011 04:05 PM, H.J. Lu wrote:
>> Is this change actually necessary?  I would think that the
>> predicate has already been adjusted...
>>
> 
> Since we always use short version for x32, there is no need to call.
> x86_64_zext_immediate_operand.

Yes, but using the shorter condition, i.e. always calling
x86_64_zext_immediate_operand and letting it return true for
all x32 symbols, is easier to maintain.

>> > Have I forgotten x86 encoding?  I thought movl imm,reg was 5 bytes...
>> >
>> >
> You forgot the REX prefix:

Ah, right.  I forgot what the chain register was.


r~
H.J. Lu July 10, 2011, 1:20 a.m. UTC | #5
On Sat, Jul 9, 2011 at 4:12 PM, Richard Henderson <rth@redhat.com> wrote:
> On 07/09/2011 04:05 PM, H.J. Lu wrote:
>>> Is this change actually necessary?  I would think that the
>>> predicate has already been adjusted...
>>>
>>
>> Since we always use short version for x32, there is no need to call.
>> x86_64_zext_immediate_operand.
>
> Yes, but using the shorter condition, i.e. always calling
> x86_64_zext_immediate_operand and letting it return true for
> all x32 symbols, is easier to maintain.

I always updated x86_64_zext_immediate_operand for x32.
I will remove TARGET_X32.

Thanks.
diff mbox

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 04cb07d..c852719 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -22721,13 +23030,14 @@  ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
     }
   else
     {
-      int offset = 0;
+      int offset = 0, size;
 
       /* Load the function address to r11.  Try to load address using
 	 the shorter movl instead of movabs.  We may want to support
 	 movq for kernel mode, but kernel does not use trampolines at
 	 the moment.  */
-      if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
+      if (TARGET_X32
+	  || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
 	{
 	  fnaddr = copy_to_mode_reg (DImode, fnaddr);
 
@@ -22750,11 +23060,21 @@  ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
 
       /* Load static chain using movabs to r10.  */
       mem = adjust_address (m_tramp, HImode, offset);
-      emit_move_insn (mem, gen_int_mode (0xba49, HImode));
+      /* Use the shorter movl instead of movabs for x32.  */
+      if (TARGET_X32)
+	{
+	  size = 6;
+	  emit_move_insn (mem, gen_int_mode (0xba41, HImode));
+	}
+      else
+	{
+	  size = 10;
+	  emit_move_insn (mem, gen_int_mode (0xba49, HImode));
+	}
 
-      mem = adjust_address (m_tramp, DImode, offset + 2);
+      mem = adjust_address (m_tramp, ptr_mode, offset + 2);
       emit_move_insn (mem, chain_value);
-      offset += 10;
+      offset += size;
 
       /* Jump to r11; the last (unused) byte is a nop, only there to
 	 pad the write out to a single 32-bit store.  */