News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Dynamic vs static linking

Started by jj2007, April 08, 2017, 06:56:56 PM

Previous topic - Next topic

zedd151

:smiley:  No FreeLibrary call?
That should be considered too, if calculating the extra time spent using this method, imo.
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

TimoVJL

No need, as if someone know how things goes.
FreeLibrary() is only needed, if want to free some resources, if that a dll doesn't used anymore.
May the source be with you

zedd151

Quote from: TimoVJL on April 05, 2025, 12:17:00 AMNo need, as if someone know how things goes.
FreeLibrary() is only needed, if want to free some resources, if that a dll doesn't used anymore.

I thought it was worth a mention, in any case.  :smiley:
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

jj2007

Quote from: TimoVJL on April 04, 2025, 11:11:02 PMadditional time to get function addresses from dll, LoadLibrary / GetProcAddress

I timed that for my Windows GUI template: about 0.6 milliseconds, once at program start :cool:

Re FreeLibrary: only necessary if you need to free resources but keep the program running - a rather exotic requirement. A simple ExitProcess takes care of libraries.

zedd151

Quote from: jj2007 on April 05, 2025, 02:58:40 AMRe FreeLibrary: only necessary if you need to free resources but keep the program running - a rather exotic requirement. A simple ExitProcess takes care of libraries.
Oh. That, I did not know. I thought that any libraries opened with LoadLibrary needed to be freed with FreeLibrary explicitly, before exiting.  :toothy:  It was only in special cases that I had ever used it. I.e., temporarily loading a plugin for one of my editors for example.
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:


daydreamer

When I coded java,I tried java native interface and loaded. Dll and called c code, speed improvement was worth it,much faster than same java code
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

TimoVJL

Pelles C 13 project
results are now after changing test order
May the source be with you

zedd151

TestDynStatic1:
1328 ticks dynamic
1328 ticks implib

TestDynStatic164:
672 ticks dynamic
657 ticks implib
for TestDynStatic1_workspace.zip
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

But then you changed the zip file....

TestDynStatic1.exe
1203 ticks dynamic
1328 ticks implib

1188 ticks dynamic
1328 ticks implib

1187 ticks dynamic
1313 ticks implib

1203 ticks dynamic
1313 ticks implib

1203 ticks dynamic
1312 ticks implib
TestDynStatic164.exe
672 ticks dynamic
609 ticks implib

610 ticks dynamic
625 ticks implib

625 ticks dynamic
640 ticks implib

625 ticks dynamic
594 ticks implib

625 ticks dynamic
625 ticks implib
for TestDynStatic1_workspace1.zip

'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

NoCforMe

So basically 6 of one, half a dozen of the other.
Meh ...
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on April 06, 2025, 08:09:55 AMSo basically 6 of one, half a dozen of the other.
Meh ...
But 12 for 64 bit version  :tongue: (almost twice as fast)
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

NoCforMe

I was referring to the difference between "dynamic" and "implib".
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on April 06, 2025, 08:19:17 AMI was referring to the difference between "dynamic" and "implib".
:biggrin:  I know.   :joking:
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn:

InfiniteLoop

I thought native calls were supposed to be faster?
I ran my own tests.
NTGetTickCount doesn't exist so we must use NTQueryPerformanceCounter.

Cycles normal 35
Cycles dynamic 425
Cycles syscall 933

35 cycles is too fast to be a system call. Something is wrong.

EXTRN GetProcAddress:PROC
EXTRN GetModuleHandleA:PROC
EXTRN QueryPerformanceCounter:PROC
.data
ModuleName BYTE "Kernel32.dll",0
NTModuleName BYTE "Ntdll.dll",0
ProcName BYTE "QueryPerformanceCounter",0
NTProcName BYTE "NtQueryPerformanceCounter",0
ALIGN 16
Counter QWORD 1337
.code

TestNT proc
push rbx
push rdi
push rsi
sub rsp,32
lea rcx,NTModuleName
call GetModuleHandleA
mov rcx,rax
lea rdx,NTProcName
call GetProcAddress
mov esi,[rax+4]
lfence
mfence
rdtsc ;edx:eax
lfence
shl rdx,32
lea rdi,[rax+rdx]
mov ebx,16384
Start_NT:
mov eax,esi
lea r10,Counter
xor edx,edx
syscall ;(rax),r10,rdx,r8,r9
dec ebx
jnz Start_NT
lfence
mfence
rdtsc
lfence
shl rdx,32
or rax,rdx
sub rax,rdi
shr eax,14
add rsp,32
pop rsi
pop rdi
pop rbx
ret
TestNT endp


TestNative proc
push rsi
push rbx
push rdi
sub rsp,32
lea rcx,ModuleName
call GetModuleHandleA
test rax,rax
jz Error_End
mov rcx,rax
lea rdx,ProcName
call GetProcAddress
test rax,rax
jz Error_End
mov rsi,rax
lfence
mfence
rdtsc ;edx:eax
lfence
shl rdx,32
lea rdi,[rax+rdx]
mov ebx,16384
Start_NA:
lea rcx,Counter
call rsi ;->RAX
dec ebx
jnz Start_NA
lfence
mfence
rdtsc
lfence
shl rdx,32
or rax,rdx
sub rax,rdi
shr eax,14
Error_End:
add rsp,32
pop rdi
pop rbx
pop rsi
ret
TestNative endp

TestNormal proc
push rbx
push rdi
sub rsp,40
lfence
mfence
rdtsc ;edx:eax
lfence
shl rdx,32
lea rdi,[rax+rdx]
mov ebx,16384
Start_N:
lea rcx,Counter
call QueryPerformanceCounter ;->RAX
dec ebx
jnz Start_N
lfence
mfence
rdtsc
lfence
shl rdx,32
or rax,rdx
sub rax,rdi
shr eax,14
add rsp,40
pop rdi
pop rbx
ret
TestNormal endp


zedd151

Quote from: InfiniteLoop on Today at 12:22:28 PM35 cycles is too fast to be a system call. Something is wrong.

For results much lower than the others, maybe an issue with your testing methods?
Also, why not attach the executable for your tests, so others can use it. That is sort of standard practice here in the Laboratory for timing/cycle counting tests, afaics.

Just curious, why NTanything?
'As we don't do "requests", show us your code first.'  -  hutch—

¯\_(ツ)_/¯   :azn: