XCHG is slow ?

Vitaly Davidovich vitalyd at gmail.com
Tue Jul 3 16:43:15 PDT 2012


I thought NOP is the same opcode as xchg eax eax on x86? It shouldn't be
expensive on its own unless a lock prefix is added.

Sent from my phone
On Jul 3, 2012 7:37 PM, "Rémi Forax" <forax at univ-mlv.fr> wrote:

> On 07/04/2012 01:29 AM, John Rose wrote:
>
>> On Jul 3, 2012, at 4:26 PM, John Rose wrote:
>>
>>  Isn't "dec %esi" really a REX prefix? — John
>>>
>>
>> No, not if it's two bytes.
>>
>> Pretty strange.  I don't think our nop-generator produces xchg.
>>
>
> it seems so.
>
>
>> — John
>>
>
> Here is the output of PrintOptoAssembly,
>
> Rémi
>
> #
> #  int ( int )
> #
> #r018 rsi   : parm 0: int
> # -- Old rsp -- Framesize: 48 --
> #r089 rsp+44: in_preserve
> #r088 rsp+40: return address
> #r087 rsp+36: in_preserve
> #r086 rsp+32: saved fp register
> #r085 rsp+28: pad2, stack alignment
> #r084 rsp+24: pad2, stack alignment
> #r083 rsp+20: Fixed slot 1
> #r082 rsp+16: Fixed slot 0
> #r093 rsp+12: spill
> #r092 rsp+ 8: spill
> #r091 rsp+ 4: spill
> #r090 rsp+ 0: spill
> #
> abababab   N1: #    B1 <- B6 B9  Freq: 1
> abababab
> 000   B1: #    B5 B2 <- BLOCK HEAD IS JUNK   Freq: 1
> 000       # stack bang
>     pushq   rbp    # Save rbp
>     subq    rsp, #32    # Create frame
>
> 00c       movl    RBP, RSI    # spill
> 00e       cmpl    RSI, #2
> 011       jl,s   B5  P=0.500597 C=6700.000000
> 011
> 013   B2: #    B7 B3 <- B1  Freq: 0.499403
> 013       decl    RSI    # int
>           nop     # 2 bytes pad for loops and calls
> 017       call,static  ClassicFibo::fibo
>         # ClassicFibo::fibo @ bci:10  L[0]=RBP
>         # OopMap{off=28}
> 01c
> 01c   B3: #    B8 B4 <- B2  Freq: 0.499393
>         # Block is sole successor of call
> 01c       movl    [rsp + #0], RAX    # spill
> 01f       movl    RSI, RBP    # spill
> 021       addl    RSI, #-2    # int
>           nop     # 3 bytes pad for loops and calls
> 027       call,static  ClassicFibo::fibo
>         # ClassicFibo::fibo @ bci:16  L[0]=_ STK[0]=rsp + #0
>         # OopMap{off=44}
> 02c
> 02c   B4: #    B6 <- B3  Freq: 0.499383
>         # Block is sole successor of call
> 02c       addl    RAX, [RSP + #0 (32-bit)]    # int
> 02f       jmp,s   B6
> 02f
> 031   B5: #    B6 <- B1  Freq: 0.500597
> 031       movl    RAX, #1    # int
> 031
> 036   B6: #    N1 <- B5 B4  Freq: 0.99998
> 036       addq    rsp, 32    # Destroy frame
>     popq   rbp
>     testl  rax, [rip + #offset_to_poll_page]    # Safepoint: poll for GC
>
> 041       ret
> 041
> 042   B7: #    B9 <- B2  Freq: 4.99403e-06
> 042       # exception oop is in rax; no code emitted
> 042       movq    RSI, RAX    # spill
> 045       jmp,s   B9
> 045
> 047   B8: #    B9 <- B3  Freq: 4.99393e-06
> 047       # exception oop is in rax; no code emitted
> 047       movq    RSI, RAX    # spill
> 047
> 04a   B9: #    N1 <- B7 B8  Freq: 9.98796e-06
> 04a       addq    rsp, 32    # Destroy frame
>     popq   rbp
>
> 04f       jmp     rethrow_stub
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20120703/124f58c1/attachment-0001.html 


More information about the hotspot-compiler-dev mailing list