An issue that was raised recently in this forum was the "need" for an old
Microsoft standard calling convention called FASTCALL. Here is the viable
alternative that can be written directly in PowerBASIC when an external
DLL is being called, for lack of another name, this is DIRTYCALL calling
convention.
It works by making a standard DLL function call to retrieve the address
of a label in the DLL function, then it directly calls that address with
a value in the EAX register which is used in the DLL internal function
to perform a simple calculation.
On a large DLL with many function, this would be done first so that you
have the addresses in an array or a global variable and then call the
internal function in the normal DLL function as the program requires.
This method benchmarks on my PIII 600 at about 1100 milliseconds for
100 million iterations of the direct call to the address in the DLL
including the simple calculation in the DLL.
Depending on how familiar you are with PowerBASIC's inline assembler, you
can pass 6 DWORD size parameters in the available integer registers and 8
floating point values in the FP registers. If you have the need to pass
more parameters, you can pass the address of an array or structure in one
integer register.
FASTCALL, ho hum
Regards,
[email protected]
[This message has been edited by Steve Hutchesson (edited January 27, 2001).]
Microsoft standard calling convention called FASTCALL. Here is the viable
alternative that can be written directly in PowerBASIC when an external
DLL is being called, for lack of another name, this is DIRTYCALL calling
convention.
It works by making a standard DLL function call to retrieve the address
of a label in the DLL function, then it directly calls that address with
a value in the EAX register which is used in the DLL internal function
to perform a simple calculation.
On a large DLL with many function, this would be done first so that you
have the addresses in an array or a global variable and then call the
internal function in the normal DLL function as the program requires.
This method benchmarks on my PIII 600 at about 1100 milliseconds for
100 million iterations of the direct call to the address in the DLL
including the simple calculation in the DLL.
Depending on how familiar you are with PowerBASIC's inline assembler, you
can pass 6 DWORD size parameters in the available integer registers and 8
floating point values in the FP registers. If you have the need to pass
more parameters, you can pass the address of an array or structure in one
integer register.
FASTCALL, ho hum

Regards,
[email protected]
Code:
Test code in calling EXE file. TheAddress& = TestFunction tc& = GetTickCount() ! mov ecx, 100000000 ' 100 million tst: ! mov eax, ecx ' pass directly in EAX ! call TheAddress& ! dec ecx ! jnz tst tc2& = GetTickCount() - tc& MessageBox hWin,ByCopy str$(tc2&),"Test", _ %MB_OK or %MB_ICONINFORMATION Test DLL code '########################################################################## #COMPILE DLL '########################################################################## FUNCTION TestFunction ALIAS "TestFunction" () EXPORT as LONG ! jmp past_It ' -------------------------- ' The REAL function is here ' -------------------------- LabelAddress: ! shl eax, 1 ! ret ' -------------------------- past_It: FUNCTION = CodePtr(LabelAddress) END FUNCTION '##########################################################################
Comment