Main Menu

PlayBASIC To DLL (Development Blog)

Started by kevin, November 14, 2013, 10:41:59 PM

Previous topic - Next topic

kevin


PlayBASIC To Dll -  1,000,000 Point Rotation Example (Remix)

       You've probably noticed that dot cube examples is a particular favourite of mine when testing 'tweaks' to the Pb2DLL codes generation ability.   It's not that it's a particular beautiful demo, it just boils down to some serious number crunching with a good dose of memory thrashing to boot.   So it stands to reason if the generator can stream line any expressions better or avoid hitting memory unnecessarily, then those tweaks will show up as better performance.

       For the last few sessions of PB2DLL, I've been  focusing upon improving the serialization detection as well as embedded this behavior around more of the common functionality.   For example, if you call function that returned an Integer/float, then it scans ahead looking for any sequences it can clean up for us.     So if we had a bit of code like   AlignedToGridMouseX  = MouseX() /  GridWidth,  then previous versions would have hit memory when pulling the mouseX() function,  now the result lives in a register and would be divided on chip, before finally being written out to memory.   

        Performance wise today's build of PB2DLL gives us around a 4FPS boost, going from running at 11FPS on the test system to 15FPS.   In millisecond terms, that's about a 24 millisecond improvement.  The demo runs in about 66 milliseconds now, where as it was running in approximately 90 milliseconds before.       


kevin

#76
  PlayBASIC To Dll V0.99h  Released and Available For Download (11th,July,2014)

    Here's revision H of PB2DLL V0.99 package.    This revision continues to focus on finding those left over core instructions that weren't supported in the translation,  as well as improving the quality of the code produced.   One of the operations that was missing was reading from a handle from a type structure.  This is important as we can use this to detect what cells within an array are populated are what ones aren't.  

    eg.

PlayBASIC Code: [Select]
     For lp=0 to 100

if Alien(lp) ; here we're reading the handle of type at this position within the array. If the value there is zero, then it's empty, otherwise it exists.

Alien(lp).x+=Alien(lp).SpeedX
Alien(lp).y+=Alien(lp).Speedy

endif

next




 
 Code Generation:

     This version supports better stream lining of expressions of core instructions onto the CPU from both the integer and floating point sides.  The goal of such changes it avoid hitting memory were possible as well as replacing common operations where it makes sense.  One of the recent additions can now trap temp registers that appear following internal command set function calls.  So if you called some internal command function that returned a floating point value, the generator will try and sequentially solve any following instructions.   

       Eg.

       x#  =GetSpriteX(SomeSPRITE) /  GridWidth

      So some code like this now leaves the result of the function call on the fpu and performs the division on the fpu also.    Which gets rid of some temporary memory thrashing that the runtimes have to do, but our machine code dll's don't.    This means that generally if your expression stacks well, you'll get very solid performance from it.


 Download:

     To download use the link that was assigned to you from your registration email.   That link will always return the latest edition of PB2DLL to you.  


 History

 

V0.99h  30th,June,2014  - 10th,July,2014

Added:

- ReadTypeCell byte code was being decoded, but didn't export
 any assembly. Making those programs fail

Code Generation Changes:

- Added COS/SIN single float functions  to the float solver.
- added Let to integer solver.  
- Integer solver now supports the less than, less than equal operators
- Float solver has better support to follow temps or left/right
 side of math operators.
- Integer solver supports RGBA(),RGBR(),RGBG(),RGBB()
- Tweaked internal command set caller to watch for the serialized returns
 from operations that return Integers and Floats
- RANGE() can start a serialized sequence.  Allowing code like
 IF RANGE(a,b,c) to solve on chip.
- Shift & roll functions now support integer sequences after them.
- Integer bit operations can now solve integer sequences after them
- String compares functions now support integer sequences after them

Fixes:

- Both Int & Flt serial solvers could look past the end of sequence when
  the first opcode didn't return a temp register.
- return parameters for 'bound' functions didn't seem export working code
- RANGE() wasn't allowing fields to be anything other than integer
- Integer serial solver didn't check if the return type when it ran into a
assignment statement.  Which would break is the expression was an integer
being written to a float.



V0.99g  23rd,June, 2014  - 30th,June,2014

Fixes:
- The import library list would break when there's more than one
 library that needed to be imported/exported

- Reading from typed fields was exporting UTD pointer.

- DLL entry code now screens for caller actions.  Which seems to fix
 the crash on exit stuff that's been happening.  
 
- Seemed to be passing the wrong 'temp variable' in the integer serialer    

Code Generation:

- Parser better detects when an  AND/ON/XOR opcode is at the start
 possible run of serialized opcodes

- Integer serializer can handle equal and not equal compare
 operations.  
 
- Integer serializer can handle comparewith branch opcodes.

- Testing some single param float functions (Sqrt/ABS) to the float
 solver.  Seems to work well !
 
 
V0.99e/f  13th,June, 2014  -14th,June, 2014

Code Generation:

- Added serialized solver for runs of INTEGER opcodes.  
 The solver currently supports  ADD, SUB, MULT, DIV
 / AND / OR / XOR / shift << and shift >> operators

                   eg.
                         result = 10*A +B - C <<2 >> 8    
                         
- Added serialized solver for runs of FLOAT opcodes.  
 The solver currently supports  ADD, SUB, MULT, DIV

                   eg.
                         result = 10*A# +B# - C#
                         


V0.99e   13th,June, 2014  -14th,June, 2014

Code Generation:

- Added serialized solver for runs of INTEGER opcodes.  
 The solver currently supports  ADD, SUB, MULT, DIV
 / AND/OR/XOR/ shifts << and shift >> operators

                   eg.
                         result = 10*A +B - C <<2 >> 8    
                         
- Added serialized solver for runs of FLOAT opcodes.  
 The solver currently supports  ADD, SUB, MULT, DIV

                   eg.
                         result = 10*A# +B# - C#



V0.99c/d   May,2014  -7th,June, 2014  

Code Generation:
- COSRADIUS & SINRADIUS resolved directly on FPU
- COSNewValue & SinNEwValue resolved directly on FPU

Fixes:

                 - Re-Tweaked the rego field screening :(




V0.99a   May,2014  -6th,June, 2014  

Code Generation:

- RgbAlphaAnd(), RgbAlphaOr() & RgbAlphaXor() functions are now trapped and inlined
 on demand.  

- GetDistance2D(X1,y1,x2,y2) is trapped and placed in line for the FPU.
 The call is about 50% less code when passing floats to the function and probably
 75% less code when passing integers in.  Speed wise it bench marks up to 15 times  faster.  

- Cos/Sin functions are resolved now directly in line on the FPU for you.


Fixes:

- Sqrt() & ABS() decoders didn't move the PC correctly causing the parser to get
out of alignment... Throwing a bunch of bogus errors after those statements

                 - Tweaked the rego field screening to only accept characters between ASCII 32 to 128
                 

 


ATLUS

Kevin, where can i read how to use DLL, any tutorial?

kevin


ATLUS


kevin

#80
PlayBASIC To Dll V099i  -  More Serialization Support

   While working on the G2D (Open GL for PLayBASIC) library  last week ran into a couple of operations that weren't being decoded by PB2DLL, so any programs that used them those would fail.   One situation was when passing UDT pointers between the various internal function types, of which there are a few.  While doing that I noticed some other easy to add serialization opportunities to the code generation.  In other words a few more easy ways to make it even faster in certain situations.

   Serialization in PB2DLL refers to how the code generator solves runs of operations, where the focus is to avoid writing temp data to the memory where possible.  One such situation that i'd noticed was with Peek/Poking fields user defined typed pointers.  Previously if you accessed a Integer/Byte/Word field from a type and depending upon the operation, the compiler would store these in VM registers, which means hitting memory in the VM.   Of course in our machine code DLL's we don't need that, but the translator has to detect when such situations occur.

    Let's have a look at an example.    

PlayBASIC Code: [Select]
   Type TestType
Status
Count
ThisByte as byte
ThisWord as word
x#,y#,z#
IntArray(10)
FltArray#(10)
StrArray$(10)
EndTYpe



Function DLL_TEST()


Dim me as testtype pointer

Me = new TestType
me.count=100
a=45

result=me.count
print result
result=me.count+A
print result
result=me.count+A+me.count
print result



me.count = me.count +a

me.ThisByte = me.ThisByte +a+b
me.ThisWord = me.ThisWord +a+b

Sync
WaitKey


EndFUnction





     Such test code doesn't really do anything interesting, but the various occurrences of the me.ThisByte ,  me.ThisWord & me.Count can now be further solved out, where they'd previously hit a VM register (written to memory).    

     
     This will even help direct writes between UDT pointers, so  a line of PlayBASIC code like this me.count = me.count say, now becomes 4 machine code instructions.  Which could be further simplified to 3 instructions when the two pointers are the same, but it doesn't currently do that.

   




   

kevin

#81
 PlayBASIC To Dll V099i  -  Beta5 download

  This beta includes all the latest code generation features.   Custom need only  download it and copy the EXE into your existing PB2DLL folder.  

   Old beta removed


kevin

#82
  PlayBASIC To Dll V099i  -  More Pointer/Float Serialization

        Floating point support in x86 always feels like a  bit of mess to me really, which seems to stem from the external FPU legacy.   Back in the day, x86 cpu's didn't have floating point built in,  it was an optional extra.   Now even though it's been integrated into your cpu, it still feels like a completely separate device as far as the instruction set is concerned.  In some ways that's handy (2 separate pipelines), but occasionally you just wish you could move between the integer and float registers without hitting memory..  

        With this round of updates I've been focusing on making further improvements to the code generation, mostly focusing on Pointers and peek/poking the various data types.    Solving most integer stuff is fairly easy and side of the optimizer is the most mature, the float side can be a bit award as it only likes to pull floats from memory, rather than a register..  None the less, a number of extra little additions have been added that help sequences of float operations resolver easier and easier.  

        Bogus Example Code:

PlayBASIC Code: [Select]
      type TestType
x#,y#,z#
EndTYpe


Dim Src as testtype pointer
Dim Dest as testtype pointer

Src = new testtype
Dest = new testtype


; write some integer values into these float fields..
; this type of type mismatch is now auto recast at compile time
Src.x = 1111
Src.y = 2222
Src.z = 3333


; copy a field to another within the same type
; The op
Src.x=Src.Y

; copy fieldds between different types
Dest.x=Src.x

; copy a field and add 100 to it
Dest.y=Src.y+100

; copy a field and mult it by 2
Dest.z=Src.z*2

print Dest.x
print Dest.y
print Dest.z


Sync
waitkey





         Since all fields from these typed pointers are floats, PB2DLL can take some liberties with the output code.  Take the a line like Src.x=Src.Y,  where we're copying a float from one structure to a different location in the same structure.   Previous editions of PB2DLL would hit memory pulling the value out of the structure, only to write it in the next opcode.  The parser now has a short cut for this,  turning the output code into 3 instructions and since they're the same type we don't have to hit the FPU.  So it's just copying a pair of integers.  

     The expression Dest.y=Src.y+100 are now supported by the float sequencer.  Previously the result of Src.Y+100 would sit in a VM register (get written to memory) and them be written out into the target structure..  Now it only writes to  memory when the result is computed on the FPU.   

          Which all sounds like mumbo jumbo, but here the latest changes give the G2D particles demo about even more through put on my legacy test machine.   Will have to go test some other demos.

kevin

 PlayBASIC To Dll V0.99i  Released and Available For Download (13th,Jan,2015)

     Here's revision I of PlayBASIC2DLL V0.99 package.    This revision furthers more improvement to the machine code generation as well continuing to iron any hidden instructions that weren't supported by the translation engine.   

     In terms of code generation this version seem focuses mainly on pointer operations, in particular  when reading / writing from a user defined typed pointer is used within an expression, as well as arithmetic and assignment operations on between pointers or between a pointer and integer.   

     Example:
PlayBASIC Code: [Select]
      type TestType
x#,y#,z#
EndTYpe


Dim Src as testtype pointer
Dim Dest as testtype pointer

Src = new testtype
Dest = new testtype


; write some integer values into these float fields..
; this type of type mismatch is now auto recast at compile time
Src.x = 1111
Src.y = 2222
Src.z = 3333


; copy a field to another within the same type
; The op
Src.x=Src.Y

; copy fieldds between different types
Dest.x=Src.x

; copy a field and add 100 to it
Dest.y=Src.y+100

; copy a field and mult it by 2
Dest.z=Src.z*2

print Dest.x
print Dest.y
print Dest.z


Sync
waitkey






    This tool is intended to be used with PlayBASIC V1.64P2 retail update. !


    Reminder: Always read the development BLOG's carefully for information on the in's and outs of any upgrade !


  Download:

      To download, use your unique link that was assigned to you in your registration email.   That link will always return the latest edition of PlayBASIC2DLL to you. 



  History

 
V0.99i  19th,Nov,2014  - 13th,Jan,2015

Fixes:
- Call function was missing support for pointer as parameter fields
- On GOTO would output code with clashing labels in it.

Code Generation Changes:
- Integer solver now supports integer/byte/word typed pointer read
  accesses.    Eg  result = Me.X + SomeInteger
 
- Integer solver supports pointer additions
 
- Integer solver supports INT() function on pointers

- Integer solver supports MoveToPrr in INT() function on pointers

- Integer solver supports Pointer Additions Int/Word & Byte

- Float Solver support runs that write to integer/float pointers.
eg  UserDefinedTypePointer.SomeFloat#  = A#+B#+C
eg  UserDefinedTypePointer.SomeInteger = A#+B#+C   (auto cast when written)

- Solver can trap move pointers/ pointer casts and serialize them

- Float solver support runs from Peeked floats
- Float solver can short cut moves between float fields without loading to FPU
  eg    You.X# = Me.X#   - If ME & YOU are UDT pointer, then this just moves
  the memory, rather than loading to FPU and writing back


V0.99h  30th,June,2014  - 10th,July,2014

Added:

- ReadTypeCell byte code was being decoded, but didn't export
  any assembly. Making those programs fail

Code Generation Changes:

- Added COS/SIN single float functions  to the float solver.
- added Let to integer solver. 
- Integer solver now supports the less than, less than equal operators
- Float solver has better support to follow temps or left/right
  side of math operators.
- Integer solver supports RGBA(),RGBR(),RGBG(),RGBB()
- Tweaked internal command set caller to watch for the serialized returns
  from operations that return Integers and Floats
- RANGE() can start a serialized sequence.  Allowing code like
  IF RANGE(a,b,c) to solve on chip.
- Shift & roll functions now support integer sequences after them.
- Integer bit operations can now solve integer sequences after them
- String compares functions now support integer sequences after them

Fixes:

- Both Int & Flt serial solvers could look past the end of sequence when
   the first opcode didn't return a temp register.
- return parameters for 'bound' functions didn't seem export working code
- RANGE() wasn't allowing fields to be anything other than integer
- Integer serial solver didn't check if the return type when it ran into a
assignment statement.  Which would break if the expression was an integer
being written to a float.
 

V0.99g  23rd,June, 2014  - 30th,June,2014

Fixes:
- The import library list would break when there's more than one
  library that needed to be imported/exported

- Reading from typed fields wasn't exporting UTD pointer.

- DLL entry code now screens for caller actions.  Which seems to fix
  the crash on exit stuff that's been happening. 
 
- Seemed to be passing the wrong 'temp variable' in the integer serialer     

Code Generation:

- Parser better detects when an  AND/ON/XOR opcode is at the start
  possible run of serialized opcodes

- Integer serializer can handle equal and not equal compare
  operations. 
 
- Integer serializer can handle comparewith branch opcodes.

- Testing some single param float functions (Sqrt/ABS) to the float
  solver.  Seems to work well !
 
 
V0.99e/f  13th,June, 2014  -14th,June, 2014

Code Generation:

- Added serialized solver for runs of INTEGER opcodes. 
  The solver currently supports  ADD, SUB, MULT, DIV
  / AND / OR / XOR / shift << and shift >> operators

                    eg.
                          result = 10*A +B - C <<2 >> 8   
                         
- Added serialized solver for runs of FLOAT opcodes. 
  The solver currently supports  ADD, SUB, MULT, DIV

                    eg.
                          result = 10*A# +B# - C#
                         


V0.99c/d   May,2014  -7th,June, 2014 

Code Generation:
- COSRADIUS & SINRADIUS resolved directly on FPU
- COSNewValue & SinNEwValue resolved directly on FPU

Fixes:

                  - Re-Tweaked the rego field screening :(
                 


V0.99a   May,2014  -6th,June, 2014 

Code Generation:

- RgbAlphaAnd(), RgbAlphaOr() & RgbAlphaXor() functions are now trapped and inlined
  on demand. 

- GetDistance2D(X1,y1,x2,y2) is trapped and inlined onto the FPU for.
  The call is about 50% less code when passing floats to the function and probably
  75% less code when passing integers in.  Speed wise it bench marks at 15 times
  faster. 

- COS & SIN resolved directly onto FPU

Fixes:

- Sqrt() & ABS() decoders didn't move the PC correctly causing the parser to get
out of alignment and throw a bunch of bogus errors after those statements

                - Tweaked the rego field screening to only accept characters between ASCII 32 to 128
                 

 

kevin


PlayBASIC To Dll V0.99k  Released and Available For Download (24th,Nov,2015)

     Here's revision K of PlayBASIC2DLL V0.99 package.    This update address a few minor issues with the machine code generation and includes a few new command sets that were overlooked in previous builds.

    This tool is intended to be used with PlayBASIC V1.64P3 retail update. !


    Reminder: Always read the development BLOG's carefully for information on the in's and outs of any upgrade !


  Download:

      To download, use your unique link that was assigned to you in your registration email.   That link will always return the latest edition of PlayBASIC2DLL to you. 



  History

 
V0.99k  29th,Sep,2015   - 8th,Nov,2015

Code Generation Changes:
- Added support for the Date & Time function command set to PB2DLL

- Added some alignment to loop structures.

Fixes:
- Updated the Square Root parser. 



V0.99j  14th,Jan,2015  - 24th,May,2015

Fixes:
- external function calling was missing support for pointer parameters
- integer function calling was missing support for pointer parameters
making command calls like GetSpriteRect() fail in the DLL




V0.99i  19th,Nov,2014  - 13th,Jan,2015

Fixes:
- Call function was missing support for pointer as parameter fields
- On GOTO would output code with clashing labels in it.

Code Generation Changes:
- Integer solver now supports integer/byte/word typed pointer read
  accesses.    Eg  result = Me.X + SomeInteger
 
- Integer solver supports pointer additions
 
- Integer solver supports INT() function on pointers

- Integer solver supports MoveToPrr in INT() function on pointers

- Integer solver supports Pointer Additions Int/Word & Byte

- Float Solver support runs that write to integer/float pointers.
eg  UserDefinedTypePointer.SomeFloat#  = A#+B#+C
eg  UserDefinedTypePointer.SomeInteger = A#+B#+C   (auto cast when written)

- Solver can trap move pointers/ pointer casts and serialize them

- Float solver support runs from Peeked floats
- Float solver can short cut moves between float fields without loading to FPU
  eg    You.X# = Me.X#   - If ME & YOU are UDT pointer, then this just moves
  the memory, rather than loading to FPU and writing back


V0.99h  30th,June,2014  - 10th,July,2014

Added:

- ReadTypeCell byte code was being decoded, but didn't export
  any assembly. Making those programs fail

Code Generation Changes:

- Added COS/SIN single float functions  to the float solver.
- added Let to integer solver. 
- Integer solver now supports the less than, less than equal operators
- Float solver has better support to follow temps or left/right
  side of math operators.
- Integer solver supports RGBA(),RGBR(),RGBG(),RGBB()
- Tweaked internal command set caller to watch for the serialized returns
  from operations that return Integers and Floats
- RANGE() can start a serialized sequence.  Allowing code like
  IF RANGE(a,b,c) to solve on chip.
- Shift & roll functions now support integer sequences after them.
- Integer bit operations can now solve integer sequences after them
- String compares functions now support integer sequences after them

Fixes:

- Both Int & Flt serial solvers could look past the end of sequence when
   the first opcode didn't return a temp register.
- return parameters for 'bound' functions didn't seem export working code
- RANGE() wasn't allowing fields to be anything other than integer
- Integer serial solver didn't check if the return type when it ran into a
assignment statement.  Which would break if the expression was an integer
being written to a float.
 

V0.99g  23rd,June, 2014  - 30th,June,2014

Fixes:
- The import library list would break when there's more than one
  library that needed to be imported/exported

- Reading from typed fields wasn't exporting UTD pointer.

- DLL entry code now screens for caller actions.  Which seems to fix
  the crash on exit stuff that's been happening. 
 
- Seemed to be passing the wrong 'temp variable' in the integer serialer     

Code Generation:

- Parser better detects when an  AND/ON/XOR opcode is at the start
  possible run of serialized opcodes

- Integer serializer can handle equal and not equal compare
  operations. 
 
- Integer serializer can handle comparewith branch opcodes.

- Testing some single param float functions (Sqrt/ABS) to the float
  solver.  Seems to work well !
 
 
V0.99e/f  13th,June, 2014  -14th,June, 2014

Code Generation:

- Added serialized solver for runs of INTEGER opcodes. 
  The solver currently supports  ADD, SUB, MULT, DIV
  / AND / OR / XOR / shift << and shift >> operators

                    eg.
                          result = 10*A +B - C <<2 >> 8   
                         
- Added serialized solver for runs of FLOAT opcodes. 
  The solver currently supports  ADD, SUB, MULT, DIV

                    eg.
                          result = 10*A# +B# - C#
                         


V0.99c/d   May,2014  -7th,June, 2014 

Code Generation:
- COSRADIUS & SINRADIUS resolved directly on FPU
- COSNewValue & SinNEwValue resolved directly on FPU

Fixes:

                  - Re-Tweaked the rego field screening :(
                 


V0.99a   May,2014  -6th,June, 2014 

Code Generation:

- RgbAlphaAnd(), RgbAlphaOr() & RgbAlphaXor() functions are now trapped and inlined
  on demand. 

- GetDistance2D(X1,y1,x2,y2) is trapped and inlined onto the FPU for.
  The call is about 50% less code when passing floats to the function and probably
  75% less code when passing integers in.  Speed wise it bench marks at 15 times
  faster. 

- COS & SIN resolved directly onto FPU

Fixes:

- Sqrt() & ABS() decoders didn't move the PC correctly causing the parser to get
out of alignment and throw a bunch of bogus errors after those statements

                - Tweaked the rego field screening to only accept characters between ASCII 32 to 128
                 

 

baggey

Hi,

It's been a while since i used playbasic but im interested in the pb 2 dll program.
i can't order it as the site isn't working for me in france?

How can i get it so i can experiment!?

Keep up the good work Baggey!
Jesus was only famous because of his dad

kevin

#86
Quotei can't order it as the site isn't working for me in france?

  It's not currently available and I'm not too sure when it will be, as there are a few more pressing things on the to do list.      

kevin


  PlayBASIC To Dll -  GOES FREE in MAY 2019

       Yes, you read that correctly, PB2DLL will be released FREE in the coming days.   





stevmjon

free should get more people to use this.

out of interest kev, what made you decide to release this free?
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

Quote from: stevmjon on May 19, 2019, 08:07:11 PM
free should get more people to use this.

   Perhaps, but it's a  little to difficult for most people.   


Quote
out of interest kev, what made you decide to release this free?

   Lack of  Time and it's 4 or 5 years old and now almost a complete generation behind..