PureBasic Forum
https://www.purebasic.fr/english/

ASM Output Question regarding push/pop
https://www.purebasic.fr/english/viewtopic.php?f=35&t=70542
Page 1 of 1

Author:  Crusiatus Black [ Tue Apr 10, 2018 11:11 am ]
Post subject:  ASM Output Question regarding push/pop

Hi All,

I'm working on a simple tool for my own optimization purposes and while I was working on this tool, I noticed something I don't understand. Now, I think this might be some alignment or optimization method I don't know, however I figured I'd ask the question here;

I have a structure named derp within a procedure, and I'm accessing index 100 like so:
Code:
single = derp\chars[100]


The produced assembly code on x64 Linux is:
Code:
; single = derp\chars[100]
  MOV    dword [CLN],60 ; pbcompiler -l option
  LEA    rbp,[rsp+48]
  PUSH   rbp
  POP    rbp
  MOVSX  rax,byte [rbp+100]
  PUSH   rax
  POP    rax
  MOV    byte [v_single],al


However something I don't understand are the push rbp, pop rbp and push rax, pop rax instructions. Can anyone explain to me why those are pushed and popped immediately?

Author:  Fred [ Tue Apr 10, 2018 4:53 pm ]
Post subject:  Re: ASM Output Question regarding push/pop

Is this code in debug mode ? The peephole optimiser should catch these cases and remove them in release. It's useless code, only here because the code generator works step by step and output the asm immediately.

Author:  Crusiatus Black [ Tue Apr 10, 2018 5:08 pm ]
Post subject:  Re: ASM Output Question regarding push/pop

Hi Fred! This was compiled with 'pbcompiler -c -l -e outname'. So I'm assuming the debugger is not enabled then, right? I simply enabled the OnError lines support

Author:  CELTIC88 [ Tue Apr 10, 2018 6:09 pm ]
Post subject:  Re: ASM Output Question regarding push/pop

because "pb" translates your code word by word to asm and is very difficult to generate it without junk code.

if you want optimize your code , learn asm!

Author:  Crusiatus Black [ Tue Apr 10, 2018 6:29 pm ]
Post subject:  Re: ASM Output Question regarding push/pop

CELTIC88 wrote:
because "pb" translates your code word by word to asm and is very difficult to generate it without junk code.

if you want optimize your code , learn asm!


That's a weird response, I know ASM - I merely was asking the reasoning behind this code generation and as you can see from Fred's response, there is a reasoning behind it.

Author:  Fred [ Wed Apr 11, 2018 11:11 am ]
Post subject:  Re: ASM Output Question regarding push/pop

I will take a closer look to see why it's not removed in release mode.

Author:  Crusiatus Black [ Thu Apr 12, 2018 10:10 am ]
Post subject:  Re: ASM Output Question regarding push/pop

Fred wrote:
I will take a closer look to see why it's not removed in release mode.


Thank you, however is this not because I used the commented asm option? Even though I don't consider this to be a debug mode, it still is an intermediate step isn't it?

Author:  Fred [ Thu Apr 12, 2018 10:28 am ]
Post subject:  Re: ASM Output Question regarding push/pop

It should be the final file which is sent to the assembler, so no further pass are done on it (it's done like this so you can tweak the output file without wondering if it will be parsed again by the compiler).

Author:  Crusiatus Black [ Thu Apr 12, 2018 1:47 pm ]
Post subject:  Re: ASM Output Question regarding push/pop

Yes that is what I always used it for, good to know. Would you like me to test multiple PureBasic versions with this same piece of code? This was produced using the latest PB on Linux x64

Author:  Fred [ Thu Apr 12, 2018 1:51 pm ]
Post subject:  Re: ASM Output Question regarding push/pop

I don't bother about it, I will take a look.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/