Fast Spin? And how to launch it?
JasonDorie
Posts: 1,930
I remember reading a while back about a faster version of the Spin interpreter. I've poked and prodded and Googled, and found references to the faster interpreter, but I haven't seen any concrete examples on how one might launch a standard Spin function with non-ROM Spin interpreter. Has anyone done this, and if so, do you have an example you could share?
Why I want it: I'm working on the math routines for my DCM-based quad. They're pretty fast, but I'd like to make them faster. I'm using a lot lines that look like this:
Result := (V ** N) << 4
The << 4 part can be eliminated if I just alter the code that handles the ** instruction to do it for me. My code is littered with these shifts, so it would make things quite a bit faster. I can make the changes to the interpreter without any trouble, but I have no idea how to go about actually launching the interpreter and giving it my function to run.
Why I want it: I'm working on the math routines for my DCM-based quad. They're pretty fast, but I'd like to make them faster. I'm using a lot lines that look like this:
Result := (V ** N) << 4
The << 4 part can be eliminated if I just alter the code that handles the ** instruction to do it for me. My code is littered with these shifts, so it would make things quite a bit faster. I can make the changes to the interpreter without any trouble, but I have no idea how to go about actually launching the interpreter and giving it my function to run.
Comments
What are the possible values for N? Perhaps you can use table lookup or some other optimization for (V ** N) << 4.
I know that to launch a ROM-Spin interpreter I use cognew( Function, @stack), and to launch a PASM cog I use cognew( @DatEntry, param). I assume that to run my own interpreter I need to use the PASM form of cognew to run my copy of the interpreter, but I have no idea what to pass it to get it to start executing my compiled Spin code.
You said "...set up the initial stack and parameters to run your Spin program" - Are there examples of how to do that anywhere?
Thanks for the reply.
Do I have that right? That's easier than I was expecting.
The only thing I was going to change is the code for that one opcode. Unfortunately I get the impression from your code that this will only for for the primary cog. I tried it on a cog that I'm launching to run my DCM loop and that didn't work.
Is the $0004 argument the location of the Main function? If so, it looks like I'm going to need to track down the stack-frame setup version after all.
Thanks though - this is helping me understand it a little better.
Could you verify your ** change(s) with a simple primary only test?
It would be possible for me to actually make the main thread be the DCM loop, and just have it spawn the flight loop on another cog. I don't see why that wouldn't work, but it would require me rearranging a bunch of code to try it.
In parallel to this, I'm also writing a bunch of math functions in PASM that can be called with a sequence of instructions (in fact, you helped me fix a bug in it not long ago). Ultimately I may just write the DCM code in PASM, but if I can get the interpreter to run a modded version of my code, I might get the speedup I need without having to do the full translation.
Bedtime for me - I'll have to follow this up later, but your help is much appreciated.
There is also my zero footprint debugger. iirc it launches my interpreter and a soft version of the rom interpreter.
one launch method uses a set of spin patch instructions to modify the interpreter once it is loadedinto cog. thismight also be useful too.
Links are in my signature to the tools list.hippy did alot of theinitial research into patching the rom interpreter once loaded.