Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-11

Question about NOP instructions

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

J. Gareth Moreton

Hi everyone,

During my optimisation travels, I frequently stumble across lone NOP instructions in the compiled assembly language.  Normally I leave these alone, but occasionally I stumble across things like this:

    ...
    movq    $0,24(%rbx)
.Lj1859:
    nop
.Lj1858:
    movq    %rbp,%rcx
    ...

And there are jumps elsewhere that go to one label or the other. Is there any reason why a jump should lead to the NOP, or can they all be redirected to after the NOP instruction?

Gareth aka. Kit

Reply by email

Florian Klaempfl
to J. Gareth Moreton
J. Gareth Moreton wrote 14 lines
Hi everyone, During my optimisation travels, I frequently stumble across lone NOP instructions in the compiled assembly language.  Normally I leave these alone, but occasionally I stumble across things like this:     ...     movq    $0,24(%rbx) .Lj1859:     nop .Lj1858:     movq    %rbp,%rcx     ...

Can you please post the complete code? Without it, it's hard to say

And there are jumps elsewhere that go to one label or the other. Is there any reason why a jump should lead to the NOP, or can they all be redirected to after the NOP instruction?

Some are the result of exception handling on x86_64-win64, see compiler/x86_64/nx64flw.pas

Reply by email

J. Gareth Moreton
to Florian Klaempfl

Here's a larger snippet of the code in question - it's a bit too long to post, but there's a lot of conditional jumps to .Lj1859 earlier on:

.Lj1875:
    testl    $1024,92(%rbx)
    jne    .Lj1878
    leaq    .Ld523(%rip),%rax
    movq    %rax,-56(%rbp)
    movq    $11,-64(%rbp)
    movq    64(%rbx),%rax
    movq    %rax,-40(%rbp)
    movq    $11,-48(%rbp)
    leaq    .Ld524(%rip),%rax
    movq    %rax,-24(%rbp)
    movq    $11,-32(%rbp)
    movq    80(%rbx),%rcx
    leaq    -72(%rbp),%rdx
    call CUSTOMCODETOOL$_$TCUSTOMCODETOOL_$__$$_MAINFILENAME$$ANSISTRING     movq    -72(%rbp),%rax
    movq    %rax,-8(%rbp)
    movq    $11,-16(%rbp)
    leaq    -64(%rbp),%rcx
    movl    $3,%edx
    call    FILEPROCS_$$_DEBUGLN$array_of_const     orl    $1024,92(%rbx)
.Lj1878:
    movq    $0,24(%rbx)
.Lj1859:
    nop
.Lj1858:
    movq    %rbp,%rcx
    call
IDENTCOMPLETIONTOOL$_$TIDENTIFIERLISTITEM_$_GETNODE$$TCODETREENODE_$$_fin$00000239     movq    %rsi,%rax
    movq    -88(%rbp),%rbx
    movq    -80(%rbp),%rsi
    leaq    (%rbp),%rsp
    popq    %rbp
    ret
.seh_handler __FPC_specific_handler,@unwind
.seh_handlerdata
    .long    1
    .long    0
    .rva    .Lj1857
    .rva    .Lj1858
    .rva
IDENTCOMPLETIONTOOL$_$TIDENTIFIERLISTITEM_$_GETNODE$$TCODETREENODE_$$_fin$00000239

The two unwind entries (.rva) are labels that come right after a NOP instruction, and are the only references to these labels - meanwhile, the conditional jumps nearer the top go to the labels that appear before the nop instruction and are otherwise just testing registers and memory locations with no calls to other routines.

In the meantime, I've got my jump code fully tested for i386-win32 and x86_64-win64, but am still documenting everything before I post them in a patch.  I'm not sure how it behaves on non-Intel platforms yet, but I can confirm that it at least compiles.

Gareth aka. Kit

Florian Klaempfl wrote 26 lines
Am 02.11.2019 um 15:08 schrieb J. Gareth Moreton: > Hi everyone, > > During my optimisation travels, I frequently stumble across lone NOP > instructions in the compiled assembly language.  Normally I leave these > alone, but occasionally I stumble across things like this: > >     ... >     movq    $0,24(%rbx) > .Lj1859: >     nop > .Lj1858: >     movq    %rbp,%rcx >     ... > Can you please post the complete code? Without it, it's hard to say > And there are jumps elsewhere that go to one label or the other. Is > there any reason why a jump should lead to the NOP, or can they all be > redirected to after the NOP instruction? Some are the result of exception handling on x86_64-win64, see compiler/x86_64/nx64flw.pas _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Florian Klämpfl
to J. Gareth Moreton
J. Gareth Moreton wrote 55 lines
Here's a larger snippet of the code in question - it's a bit too long to post, but there's a lot of conditional jumps to .Lj1859 earlier on: .Lj1875:     testl    $1024,92(%rbx)     jne    .Lj1878     leaq    .Ld523(%rip),%rax     movq    %rax,-56(%rbp)     movq    $11,-64(%rbp)     movq    64(%rbx),%rax     movq    %rax,-40(%rbp)     movq    $11,-48(%rbp)     leaq    .Ld524(%rip),%rax     movq    %rax,-24(%rbp)     movq    $11,-32(%rbp)     movq    80(%rbx),%rcx     leaq    -72(%rbp),%rdx     call CUSTOMCODETOOL$_$TCUSTOMCODETOOL_$__$$_MAINFILENAME$$ANSISTRING     movq    -72(%rbp),%rax     movq    %rax,-8(%rbp)     movq    $11,-16(%rbp)     leaq    -64(%rbp),%rcx     movl    $3,%edx     call    FILEPROCS_$$_DEBUGLN$array_of_const     orl    $1024,92(%rbx) .Lj1878:     movq    $0,24(%rbx) .Lj1859:     nop .Lj1858:     movq    %rbp,%rcx     call IDENTCOMPLETIONTOOL$_$TIDENTIFIERLISTITEM_$_GETNODE$$TCODETREENODE_$$_fin$00000239     movq    %rsi,%rax     movq    -88(%rbp),%rbx     movq    -80(%rbp),%rsi     leaq    (%rbp),%rsp     popq    %rbp     ret .seh_handler __FPC_specific_handler,@unwind .seh_handlerdata     .long    1     .long    0     .rva    .Lj1857     .rva    .Lj1858     .rva IDENTCOMPLETIONTOOL$_$TIDENTIFIERLISTITEM_$_GETNODE$$TCODETREENODE_$$_fin$00000239 The two unwind entries (.rva) are labels that come right after a NOP instruction, and are the only references to these labels - meanwhile, the conditional jumps nearer the top go to the labels that appear before the nop instruction and are otherwise just testing registers and memory locations with no calls to other routines.

Yes, this is exception handling code, have a look at compiler/x86_64/nx64flw.pas for details.

Reply by email

J. Gareth Moreton
to Florian Klämpfl

I figured that was the case.  I don't intend to touch NOP instructions because of their uses in exception handling, but is there any harm in moving the local jumps to branch to after the NOP instructions, for example?

Gareth aka. Kit

Florian Klämpfl wrote 64 lines
Am 03.11.19 um 18:10 schrieb J. Gareth Moreton: > Here's a larger snippet of the code in question - it's a bit too long > to post, but there's a lot of conditional jumps to .Lj1859 earlier on: > > .Lj1875: >      testl    $1024,92(%rbx) >      jne    .Lj1878 >      leaq    .Ld523(%rip),%rax >      movq    %rax,-56(%rbp) >      movq    $11,-64(%rbp) >      movq    64(%rbx),%rax >      movq    %rax,-40(%rbp) >      movq    $11,-48(%rbp) >      leaq    .Ld524(%rip),%rax >      movq    %rax,-24(%rbp) >      movq    $11,-32(%rbp) >      movq    80(%rbx),%rcx >      leaq    -72(%rbp),%rdx >      call > CUSTOMCODETOOL$_$TCUSTOMCODETOOL_$__$$_MAINFILENAME$$ANSISTRING >      movq    -72(%rbp),%rax >      movq    %rax,-8(%rbp) >      movq    $11,-16(%rbp) >      leaq    -64(%rbp),%rcx >      movl    $3,%edx >      call    FILEPROCS_$$_DEBUGLN$array_of_const >      orl    $1024,92(%rbx) > .Lj1878: >      movq    $0,24(%rbx) > .Lj1859: >      nop > .Lj1858: >      movq    %rbp,%rcx >      call > IDENTCOMPLETIONTOOL$_$TIDENTIFIERLISTITEM_$_GETNODE$$TCODETREENODE_$$_fin$00000239 > >      movq    %rsi,%rax >      movq    -88(%rbp),%rbx >      movq    -80(%rbp),%rsi >      leaq    (%rbp),%rsp >      popq    %rbp >      ret > .seh_handler __FPC_specific_handler,@unwind > .seh_handlerdata >      .long    1 >      .long    0 >      .rva    .Lj1857 >      .rva    .Lj1858 >      .rva > IDENTCOMPLETIONTOOL$_$TIDENTIFIERLISTITEM_$_GETNODE$$TCODETREENODE_$$_fin$00000239 > > > The two unwind entries (.rva) are labels that come right after a NOP > instruction, and are the only references to these labels - meanwhile, > the conditional jumps nearer the top go to the labels that appear > before the nop instruction and are otherwise just testing registers > and memory locations with no calls to other routines. Yes, this is exception handling code, have a look at compiler/x86_64/nx64flw.pas for details. _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email