beginner : about Spin interpreter
henrib75
Posts: 9
Hello,
I'm starting in Parallax Propeller and I have a lot of questions on the Spin interpreter ... I've practiced programming microcontroler (Intel) and know some languages (C, x86 ASM, Basic, ActionScript, etc. ...). I understand that the interpreter would sit in a Cog RAM and reads instructions (and interprets) in the Main RAM. But as this is dependent on the Ram Main Hub, a Cog can read the RAM only when it's his turn? The interpreter spends more time waiting than execute an instruction?
or I'm wrong completely in the operation? If I am right, this is not the worst speed reducer for this interpreter ? There is not a "buffer" (in Cog Ram) that avoids reading a single instruction at a time? particularly
in the loops?
THANK YOU !
Henri Blum
site : www.opium-bleu.com
blog : www.HenriBlum.com
ps: I'm French, so excuse my English ...
Comments
The maximum rate of transfer to/from hub ram at 80MHz is thus one long every 200ns, or 20MB/second. The maximum rate of cog instruction execution is 20MIPs - not too mismatched in my opinion.
Don't forget the interpreter has to spend some time decoding and executing the byte code so there is plenty to do whilst waiting for the next hub access slot to come around.
The Spin interpreter is published here somewhere so yo can have a look at it and see how it may be optimized.
I suspect you will have a hard time improving on Chips implementation though.
Didn't Cluso99 make some improvements?
I thought I read (here on the forum) that he was able to increase the interpreters speed a bit.
The interpreter implements a great set of byte-codes, so for every bytecode a number of instructions are executed within the cog. IIRC it was ~50 instructions average, although I got the simple maths bytecodes down to ~25. As Mike said, the stacks are in hub, so this also adds to hub delays. However, from my working with the interpreter, hub is not really the bottleneck. I manages to unravel Chips code because I stole 1KB of hub to do the instruction decoding - this saved both speed and instructions. I also built a zero-footprint (in cog) debugger that can trace all the instructions (either pasm and/or spin bytecodes).
Having said all of this, the interpreter is quite slow compared to pasm. The advantage is small program space. Therefore, a mix of spin (where speed is not an issue) and pasm (where speed is required) is an ideal mix, and makes for easy code writing.
I looked at reading longs rather than bytes, but in fact it takes more instructions to work this out, and of course takes valuable pasm instruction space. Much better results can be achieved in speeding up the interpreter code.