News:

Function Finder  Find all the functions within source code files

Main Menu

PlayBASIC To DLL (Development Blog)

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

Previous topic - Next topic

kevin

#45
  PlayBASIC To Dll - Testing - 1,000,000 Point Rotation Example (real time)

    Here's something for those die hard skeptics out there, is rotating / clipping and drawing a 1,000,000 points to the screen possible in PlayBASIC ?  - Well, not running through the VM's, but it is if you translate your code to machine code via PB2DLL then it's easily within your grasp.  

    I remember back in the mid 90's counting clock cycles to try and get a few hundred points, let alone a 1000 points rotated in a couple of frames from hand optimized assembly.   You can do that easily in PB today (even running on the slowest VM ten years ago),  but it's mind boggling how far this has all scaled up.    Where we are at a point where you don't need to a low level understanding of machine language, just some a background in how images buffers work and you can unlock even more performance.   

    See -> Common Point Rotation / Dot Cube (PB2DLL Example)  - This example includes 3 version of original routine.  The first version is the naive solution, it's a direct port of the original PB code, where the second and third solutions use some lower level direct memory access to unlock further performance. The 2 and 3 routines run slower in the VM, but much faster in machine code.
 

    The best news about this, is the current PB2DLL's translator  has only a few redundancy tweaks in it, as yet I haven't added any arithmetic optimizations.  :)


kevin

 PlayBASIC To Dll -   Tweaking Looping Constructs

      The past day or so I've been wrestling with FOR/NEXT/STEP implementation in the translator of all things.   Those reading the PB1.64P upgrade blog lately would no doubt be aware that the compiler/VM side has recently changed,  the changes were explicitly made to facilitate an easier more accurate translation to machine code from the byte code origin.   When porting the changes across to PB2DLL I noticed that it only supported Integer FOR/NEXT looping structures, where as the VM supports integer and floating point look structures

      Floating point loops present a bit of a problem due to the FPU's rather awful implementation,  but really that's everything floating point in these things.   Writing the translator code isn't difficult, it's just that it needs extra steps when dealing with floats which feels rather awkward.    Knowing this,  invested some time into the PB compiler to make sure the compiler side cleans out any unnecessary steps when setting up the loop and gives enough information to easily work out how to set the loop and what kind of set up is needed.    The decoder is able to pick up short cut situations where you used literals in your For Next Statement and cut down amount of screen code needed, in some cases on screening is need.  Since the loops duration can be validated at compile time.   It's those little things that help fine tune the performance of the final machine code. 

       The big question is when do we release ?   - Well since both sides need to be in alignment for the resulting DLL's work, the original plan was to release them both together, but I think we might release PB2DLL first..  This will help further test the translation in real world situations.  Of course that'll most likely mean that  there will be a few updates made prior to the release,  but there's not that can be  done about it.   It now just needs people other than me testing it. 


kevin

PlayBASIC To Dll -   Exporting LinkDLL binding code

       Had a few short programming (testing mainly) sessions over the weekend. Up until now, I've been testing the translator from the PB IDE.    So in order to run it, i've got to compile and run as normal (F5),  but as release time nears, we need to be able to build it into a final  EXE, but it's here we ran into a new problem,  where the exported internal structures could stop the exe from running.    I though this might happen, given how much of the PB VM internals have changed over the last 6 months.  Tracking down the issue took a while, but was fairly easy to solve which is a good thing.    So now I can build & run PB2DLL in exe form and it works as normal. 

       Once the build problem was sorted, i've been getting back to the GUI and internal exporter functions.   For the first version(s) I'm not going to bother with adding switching over the assembly code generation/optimization, it'll just do it silently.    There are times when that wouldn't be wanted, but  can't foresee anybody running into such problems.   Which means for the time being some of the GUI toggles have been ripped.   The only option that is useful is the Export LINKDLL code option.     This option gets the translator to build a chunk of the PlayBASIC source code that handles the function binding to the newly created DLL.   

      Linking to DLL's is something of a mystery for most people, basically all that happens is the PB compiler/VM create interfaces to external machine code that look and act like normal PB functions in your program.    There's some limitations in current versions of PB as to what data type/structures you can pass into and out of them, but those will be tweaked out in time.    In order to use our newly converted DLL's in our PlayBASIC programs, it stands to reason that we'd need to know how to write the LinkDLL binding code for the functions we wish to use.  Which was true yesterday, but now the translator can build a template of the exported functions for you in PlayBASIC code.   Obviously there's some limits in terms of data types that it currently supports, which stem from the PB compiler side not supporting passing PB internal structures through to external code.  Why? - because nothing other than PB understands PB internal structures, making supporting that originally point less.   

   To test the LinkDLL exporting, added a function bogus functions to  the common point rotation demo and here's what we get.   

PlayBASIC Code: [Select]
; ---------------------------------------------------------------------
; ---------------------------------------------------------------------
; ---- [cube.dll ]---------------------------------------
; ---- [ Created:28 Apr 2014 ]---------------------------------------
; ---------------------------------------------------------------------
; ---------------------------------------------------------------------


linkDll "cube.dll"

dll_addintegers(a,b) alias "dll_addintegers" as Integer
dll_addfloats(a#,b#) alias "dll_addfloats" as Float
dll_addstrings(a$,b$) alias "dll_addstrings" as String
dll_rotate_vertex_cube_9mult_common_point(sections,spacing,scale#) alias "dll_rotate_vertex_cube_9mult_common_point"
dll_rotate_vertex_cube_9mult_common_point_opt1(sections,spacing,scale#) alias "dll_rotate_vertex_cube_9mult_common_point_opt1"
dll_rotate_vertex_cube_9mult_common_point_opt2(sections,spacing,scale#) alias "dll_rotate_vertex_cube_9mult_common_point_opt2"


EndlinkDll





   This code can either get cut'n'pasted in your project or #included.  Either way once it's in and assuming PB can find your DLL (it's in the project folder) then your away in the machine code era!   


   What might be a good is to get PB2DLL to mangle the export names in the DLL.  So if you have a function called "AddIntegers", the external name can be mangled into some random hash, such as  'ABHDGSNFSSF'  - This would mean that exported linkDLL codes must match the build of dll exactly, as if the alias names don't match, windows can't local the machine code function and it won't run !   It'd only be helpful to prevent snoops from look at your function  names and potentially working out the parameters. 


kevin

#48
  PlayBASIC To Dll -   Doc's

      Haven't had a lot of time for this all week really, so I'm only just getting around to setting up the PB2HTML syntax highlighter library.  The lib is based on the PB documentation builder version, but with updated logic.   The updated version can handle block comments and is much more accurate when laying the code out in the output.  So tabbed code fragments line up where they need.   Ran into a couple of odd issues in the updated version where HTML special characters could leak through and break the output in the browser, which seem to be ironed out now.  

      Tonight I've been putting the PB2HTML library into the documentation builder.  The builder parses the source documents looking for PBCODE blocks in the html pages.  When it finds a pair, it grabs the text between them and passes it to syntax highlighter code.  It's a bit messier than say a forum post, since I'm using HTML editing rather than pure TEXT with all custom tags.   Using html just means I can use any old html editor to make pages as long as I place my info between the custom tags on the page.   The parser just grabs info sections form the html page, then wedges them into the output template.     The idea being to speed up editing of actual text, since it doesn't have to be rendered to see it.

      Bellow is another mock up of the doc's with the syntax highlighting stuff and menu stuff wedged into it.


kevin

#49
PlayBASIC To Dll -   Doc's Continued:

   After a busy weekend which included  Mothers day, an 80th birthday,  a 50th birthday and an 18th birthday, the weekend wasn't really a code mine.    I think the sugar rush is only now  starting to ware off now.   But on the up side, we do  have some documentation now.    

   Late last week started pulling the components together for the doc's.  I had 90% of the code laying around and various pre existing templates previously set up, so it wasn't that hard to get it working.   The problem as always is coming up with useful content.   How you define useful is anybodies guess.  

   Thankfully the tool is simple enough though, it doesn't really need a lot of usage explanation, provided the user is familiar with PlayBASIC to begin with. If you're not, then really there's little point in paraphrasing what's already in the manual..   Anyway, a lot of the special case stuff will be presented in the form of FAQ's.  The major of that stuff is covered in this very blog or the initial blog,  but Been trying to distill the important bits up front.  I'd say it'll take a few rounds to get everything included..

     Bellow a live (AS IS) version of the docs.   Some of the pages are just left overs from the previous template, so they really don't need to be there..  

      (old doc's link removed)


kevin

#50
  
PlayBASIC2DLL V0.99 Commercial Edition released


      Yes it's here... Finally...after more than few marathon nights the first fully fledged version of PlayBASIC2DLL is available to the community.  PlayBASIC2DLL brings the power of native code to the PlayBASIC developer,  all we can say is welcome back to the machine code age.  

      This initial release has been discounted for the community down to $27.50 (US) from it's regular $49.99 US


 
Order


      You can order the product through shareit who provide all major payment processing methods from bank card, paypal, cheque, money order and more.    

      Purchase PlayBASIC2DLL (login required)


ATLUS



ATLUS

me too, but how about future updates...

monkeybot


kevin

Quote from: ATLUS on June 03, 2014, 11:13:48 AM
All future updates free?

   Updates are indeed free for the life of the product.   

ATLUS


ATLUS

Did anyone receive a serial key. I still waiting a key.

kevin


Haven't received any confirmations from shareit as yet.  How many hours ago did you order ?

ATLUS