before I ask for compiler optimizations I would like to understand why the compiler currently does things like the following examples. Maybe the PureBasic team can elaborate a little bit about the reasons?
Let's assume the following PureBasic code:
Code: Select all
Procedure Test()
Protected A, B
A = Random(100)
B = A
ProcedureReturn B
EndProcedure
Code: Select all
; Procedure Test()
macro MP0{
_Procedure0:
PS0=64
XOR rax,rax
PUSH rax
PUSH rax
SUB rsp,40
; Protected A, B
; A = Random(100)
PUSH qword 100
POP rcx
CALL PB_Random_THREAD
MOV qword [rsp+40],rax
; B = A
PUSH qword [rsp+40]
POP rax
MOV qword [rsp+48],rax
; ProcedureReturn B
MOV rax,qword [rsp+48]
JMP _EndProcedure1
; EndProcedure
XOR rax,rax
_EndProcedure1:
ADD rsp,56
RET
}
Code: Select all
; A = Random(100)
PUSH qword 100
POP rcx
CALL PB_Random_THREAD
MOV qword [rsp+40],rax
Code: Select all
; A = Random(100)
MOV rcx,qword 100
CALL PB_Random_THREAD
MOV qword [rsp+40],rax
Code: Select all
; B = A
PUSH qword [rsp+40]
POP rax
MOV qword [rsp+48],rax
Code: Select all
; B = A
MOV rax,qword [rsp+40]
MOV qword [rsp+48],rax
Code: Select all
; B = A
PUSH qword [rsp+40]
POP qword [rsp+48]
Thanks in advance!
[compiled using PB 5.11 x64 on Windows]
[Edit 1: updated to clarify code examples]