I was wondering what it would take to speed up Spin?
Maybe a new compiler that generates a "Large Memory Model" program or maybe use multiple cogs to speed up interpretation of the current byte codes.
I have created a spin to c++ converter which, combined with propgcc, can produce LMM PASM (or COG PASM for a small enough program) from Spin (see http://forums.parallax.com/showthread.php?137134-spin2cpp-version-0.2).It's still very incomplete and buggy, but it's able to successfully convert a few of the objects from the obex.
Of course doing this amounts to trading speed for space. For example on a simple Fibonacci program I get the following results:
Spin interpreter:
size =908 bytes,
fibo(20) time taken: 44,832,912 cycles
So the LMM PASM is roughly 5 times bigger and 5 times faster, on this sample. Usually I would expect the speed advantage of LMM PASM to be a bit smaller (2x-3x); the Fibonacci code just happens to be small enough to fit in gcc's fast cache, so it mostly runs in the Cog. Similarly the size advantage of Spin bytecodes will be less for larger programs, since much of the 5508 bytes in the compiled code is fixed overhead imposed by the run time library.
Actually I have to say I'm quite impressed with the performance of the Spin interpreter -- Chip did an incredible job of optimizing it, especially given the constraint that it had to fit in 1 cog!
Eric
CON
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
OBJ
fds : "FullDuplexSerial.spin"
PUB run | i,x,now,elapsed
'' start up the serial port
fds.start(31, 30, 0, 115200)
'' and say hello
repeat i from 10 to 20
now := cnt
x := fibo(i)
elapsed := cnt - now
fds.str(string("fibo("))
fds.dec(i)
fds.str(string(") = "))
fds.dec(x)
fds.str(string(" time taken: "))
fds.dec(elapsed)
fds.str(string(" cycles", 13, 10))
PUB fibo(x)
if (x < 2)
return x
return fibo(x-1) + fibo(x-2)
Comments
(see http://forums.parallax.com/showthread.php?137134-spin2cpp-version-0.2). It's still very incomplete and buggy, but it's able to successfully convert a few of the objects from the obex.
Of course doing this amounts to trading speed for space. For example on a simple Fibonacci program I get the following results:
Spin interpreter:
size =908 bytes,
fibo(20) time taken: 44,832,912 cycles
spin2cpp + gcc -O -mfcache:
size = 5508 bytes,
fibo(20) time taken: 9,107,344 cycles
So the LMM PASM is roughly 5 times bigger and 5 times faster, on this sample. Usually I would expect the speed advantage of LMM PASM to be a bit smaller (2x-3x); the Fibonacci code just happens to be small enough to fit in gcc's fast cache, so it mostly runs in the Cog. Similarly the size advantage of Spin bytecodes will be less for larger programs, since much of the 5508 bytes in the compiled code is fixed overhead imposed by the run time library.
Actually I have to say I'm quite impressed with the performance of the Spin interpreter -- Chip did an incredible job of optimizing it, especially given the constraint that it had to fit in 1 cog!
Eric