Hi Charles,
pure magic with that PI
Thanks,
Petr
Here is another example. This one uses a loop.
[code=thinbasic]
' Array filled with PI
'----------------------------------------------
dim sgl(16) as single
'----------------------------------------------
sASM = MC_Eval$ "
b8 #sgl ' address to eax
b9 NL16 ' mov ecx,16 16 repeats
' do '
d9 eb ' fldpi load pi
d9 18 ' fstp [eax] store 32bit float and pop
05 NL4 ' add eax,4 next element
49 ' dec ecx
7f f4 ' jg do repeat 12 bytes back
' '
b8 NL2 ' mov eax,2 retval 2 in eax
C3
"
'----------------------------------------------
'---Get the address of the ASM string
psASM = strPTR(sASM) ' address of code
'---Fire the direct call using dynamic asm
CALL DWORD psASM to RetVal ' make the call and get the return value
'---Show return value
MsgBox 0, sgl(1)+" "+sgl(16)
[/code]
Hi Charles,
pure magic with that PI
Thanks,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Pure magic for sure. Try to substitute 16 with 16 millions
[code=thinbasic]
' Array filled with PI
'----------------------------------------------
dim sgl(16000000) as single
'----------------------------------------------
sASM = MC_Eval$ "
b8 #sgl ' address to eax
b9 NL16000000 ' mov ecx,16 16 repeats
' do '
d9 eb ' fldpi load pi
d9 18 ' fstp [eax] store 32bit float and pop
05 NL4 ' add eax,4 next element
49 ' dec ecx
7f f4 ' jg do repeat 12 bytes back
' '
b8 NL2 ' mov eax,2 retval 2 in eax
C3
"
'----------------------------------------------
'---Get the address of the ASM string
psASM = strPTR(sASM) ' address of code
'---Fire the direct call using dynamic asm
CALL DWORD psASM to RetVal ' make the call and get the return value
'---Show return value
MsgBox 0, sgl(1)+" "+sgl(16000000)
[/code]
Speed is ... inconsistent.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Updated thinCore.dll. New DLL is attached to the following post http://community.thinbasic.com/index...11307#msg11307
Just download and substitute thinCore.dll you have into \thinBasic\ directory.
Added MC_Exec(StringMachineCode) function in substitution to CALL DWORD ...
With MC_Exec there is no need to calculate pointer to string to be passed to CALL DWORD ... statement. Just pass the machine code string and you will get back return LONG.
So previous code can be rewritte to:
[code=thinbasic]
' Array filled with PI
'----------------------------------------------
dim sgl(16) as single
'----------------------------------------------
sASM = MC_Eval "
b8 #sgl ' address to eax
b9 NL16 ' mov ecx,16 16 repeats
' do '
d9 eb ' fldpi load pi
d9 18 ' fstp [eax] store 32bit float and pop
05 NL4 ' add eax,4 next element
49 ' dec ecx
7f f4 ' jg do repeat 12 bytes back
' '
b8 NL2 ' mov eax,2 retval 2 in eax
C3
"
'----------------------------------------------
'---Invoke the machine code string
RetVal = MC_Exec(sASM)
'---No need to calculate STRPTR(sASM) to be used into CALL DWORD ...
'----------------------------------------------
'---Show return value
MsgBox 0, RetVal & $crlf & sgl(1)+" "+sgl(16)
[/code]
As usual, update will be present in next preview release.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Yes, Ive just tested out to 160million, it is the operating system, memory management and various other processes that are able to interrupt the procedings. These will inevitably cause irregular timings. But if the script is run several times, it settles to a fairly stable figure. - about 0.625 seconds for 160 million elements on my PC.
When the FPU instructions are removed (not forgetting to adjust the loop jump), the time drops to 0.115 secs. The FPU is thorough but slow as you will see with trig functions. In fact you can do a lot of useful work on the CPU while the FPU is thinking about the next cosine, so even at the single core level timing is not entirely predictable. Even individual CPU registers can compute in parallel.
PS thanks for the Exec function!
A pleasure Charles.
I've updated again thinCore.dll here: http://community.thinbasic.com/index...11307#msg11307
In case of MC_Eval found some parsing error, no runtime errors are generated but &HC3 string will be returned as suggested.
If machine string will be equal to &HC3, MC_Exec will not get back any value but just zero will be returned.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks for improvements Eros,
sadly ( or luckily ? ) I could not get any inconsistent results, just lightning fast execution on high numbers of iterations.
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
I may have missed it but can you modify the string while the script is executing then call it get the value back modify it again and call it....you get the idea is it fixed as soon as the script is executed.
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
Abraxas, is it a question?
Sorry I do not understand if you are asking a confirmation or not.
If it is aquestion, yes. You can change (or create) the string dynamically outside MC_Eval.
Then call MC_Eval to get back a binary form of the string.
Than call MC_Exec
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
yes it was a question, just badly worded
you answer it it anyway and it was the answer I wanted.
thanks
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
Bookmarks