Speed of ASM Instructions ...(comparison of different implementations)
Posted: Wed Dec 14, 2022 12:48 pm
Hi folks,
I am doing some memory analysing stuff and was wondering about the best implementation.
This is what the ASM output shows: (I have prepared the part which is in my opinion the most important)
I would be interested in your opinion as ASM experts on this?
TIA.
Happy coding and stay healthy.
I am doing some memory analysing stuff and was wondering about the best implementation.
Code: Select all
; === Test Program -- Compare implementations ===
Structure TByteArray ; Memory Access by *Memory\Byte[Index]
Byte.a[0]
EndStructure
Procedure Test_1(*M, Index)
Protected r
r = PeekA(*M + Index)
Debug "1:" + r + " | " + Index
EndProcedure
Procedure Test_2(*Mem.TByteArray, Index)
Protected r
r = *Mem\Byte[Index]
Debug "2:" + r + " | " + Index
EndProcedure
*MemoryID = AllocateMemory(500)
If *MemoryID
Debug "Starting address of the 500 Byte memory area:"
PokeS(*MemoryID, "ABC Store this string in the memory area", -1, #PB_Ascii)
Test_1(*MemoryID, 1)
Test_2(*MemoryID, 1)
FreeMemory(*MemoryID) ; will also be done automatically at the end of program
Else
Debug "Couldn't allocate the requested memory!"
EndIf
Code: Select all
; === Test 2 =========================================== Test 1 ===============================
;
; Structure TByteArray
; Byte.a[0]
; EndStructure
;
; Procedure Test_2(*Mem.TByteArray, Index) ; Procedure Test_1(*M, Index)
_Procedure2: _Procedure0:
MOV qword [rsp+8],rcx MOV qword [rsp+8],rcx
MOV qword [rsp+16],rdx MOV qword [rsp+16],rdx
PUSH rbp PUSH r15
PS2=64 PS0=64
XOR rax,rax XOR rax,rax
PUSH rax PUSH rax
SUB rsp,40 SUB rsp,40
; Protected r ; Protected r
; r = *Mem\Byte[Index] ; r = PeekA(*M + Index)
MOV rbp,qword [rsp+PS2+0] MOV r15,qword [rsp+PS0+0]
PUSH rbp ADD r15,qword [rsp+PS0+8]
MOV rax,qword [rsp+PS2+16] MOV rax,r15
POP rbp PUSH rax
ADD rbp,rax POP rcx
MOVZX rax,byte [rbp] CALL PB_PeekA
PUSH rax
POP rax
MOV qword [rsp+40],rax MOV qword [rsp+40],rax
; ;
; Debug "2:" + r + " | " + Index ; Debug "1:" + r + " | " + Index
; EndProcedure ; EndProcedure
I would be interested in your opinion as ASM experts on this?
TIA.
Happy coding and stay healthy.