Better code generation with PureBasic Windows x64

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Better code generation with PureBasic Windows x64

Post by Danilo »

PB 4.61 x64 generated code:

Code: Select all

; MoveWindow_(WindowID(0),x,y,WindowWidth(0),WindowHeight(0),#True)
  PUSH   qword 1
  SUB    rsp,8
  PUSH   qword 0
  POP    rcx
  SUB    rsp,32
  CALL   PB_WindowHeight
  ADD    rsp,40
  MOV    rax,rax            ; MOV rax,rax - after function call
  PUSH   rax
  PUSH   qword 0
  POP    rcx
  SUB    rsp,32
  CALL   PB_WindowWidth
  ADD    rsp,32
  MOV    rax,rax            ; MOV rax,rax - after function call
  PUSH   rax
  MOVSX  rax,byte [v_y]
  MOV    rax,rax            ; MOV rax,rax - after variable loading
  PUSH   rax
  MOVSX  rax,byte [v_x]
  MOV    rax,rax            ; MOV rax,rax - after variable loading
  PUSH   rax
  SUB    rsp,8
  PUSH   qword 0
  POP    rcx
  SUB    rsp,32
  CALL   PB_WindowID
  ADD    rsp,40
  MOV    rax,rax            ; MOV rax,rax - after function call
  PUSH   rax
  POP    rcx
  POP    rdx
  POP    r8
  POP    r9
  SUB    rsp,32
  CALL   MoveWindow
  ADD    rsp,48
; 
; freq_l.l = 800 : duration_l.l = 200
  MOV    dword [v_freq_l],800
  MOV    dword [v_duration_l],200
; Beep_(freq_l, duration_l)
  MOVSXD rax,dword [v_duration_l]
  MOV    rax,rax            ; MOV rax, rax ??
  PUSH   rax
  MOVSXD rax,dword [v_freq_l]
  MOV    rax,rax            ; MOV rax, rax ??
  PUSH   rax
  POP    rcx
  POP    rdx
  CALL   Beep
; 
; freq_i.i = 800 : duration_i.i = 200
  MOV    qword [v_freq_i],800
  MOV    qword [v_duration_i],200
; Beep_(freq_i, duration_i)
  PUSH   qword [v_duration_i]
  PUSH   qword [v_freq_i]
  POP    rcx
  POP    rdx
  CALL   Beep
PureBasic inserts "MOV rax, rax" after every "load variable" instruction, if the variable is smaller than 64bit...
...and after every function call in expressions. Is this necessary everywhere in the code?

Also, it always pushes ALL parameters onto stack and then it POPs the first 4 arguments into its registers:

Code: Select all

; Beep_(freq_i, duration_i)
  PUSH   qword [v_duration_i]
  PUSH   qword [v_freq_i]
  POP    rcx
  POP    rdx
  CALL   Beep
Couldn't this be changed/improved a little bit, so the first 4 arguments go directly into the registers RCX, RDX, R8 and R9?

Code: Select all

  MOV    qword rdx, [v_duration_i]
  MOV    qword rcx, [v_freq_i]
  CALL   Beep
This is done on every WinAPI call and adds many unnecessary instructions and code bloat.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Better code generation with PureBasic Windows x64

Post by Fred »

It's planned.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Better code generation with PureBasic Windows x64

Post by Danilo »

Fred wrote:It's planned.
Thanks!
Post Reply