Performance boost from spin to asm?
__red__
Posts: 470
Admittedly I'm three days into actually using my propeller so please forgive the greenness of my question:
Thanks,
Red
Given the simplicity of the above code, would re-writing it in asm gain me any significant performance increase? It's currently taking 3.1ms to execute the outer loop. Given that my application requires me to read 260 keys instead of just 32 I need to be able to poll a fair amount on one cog before deploying to more.repeat
outa[SHLD]~ 'Load 'em up!
outa[CLK]~~ 'Get clock in correct position for...
outa[SHLD]~~'Clock transitions now shift data.
v1 := v1 << 1 + ina[SER] 'First bit is already in position.
repeat (32)
outa[CLK]~~ 'Transit up and shift
v1 := v1 << 1 + ina[SER] 'Read bit
outa[CLK]~ 'Drop the clock in preparation for next cycle
v2 := v1
Thanks,
Red
Comments
Yes, you'll get a tremendous speed increase by redoing this in assembly language. There are some very fast techniques for doing this using a cog counter to generate the clock, but a straightforward inner loop will take about 5 instructions to shift in a bit from the 74HC165, then another few instructions to handle each long that results and gets stored in main (hub) memory as well as managing the memory addresses and counts. You're talking about roughly 10us per long (32 bits).
Thank you for the reply and yes, you're right - I am reading from a chain of 74HC165s.
I've seen code to do the clock like you said but I'm fearful that my reading may lose sync with the counter so I've avoided that method.
Looks like I have some reading to do wrt asm. 3.1ms to 10us would be well worth the time invested in learning asm.
Thanks,
Red
So, I've written the following which appears to work very well in Gear. Looking forward to testing it on real hardware when I get home tonight:
Probably not the perfect code (like I should be using a counter instead of bit-banging myself) but I'm happy with the start that I've made :-)
Thanks again,
Red
Done!
Of course, now through my browsing I'm reading the "Tricks and Traps" pdf and it looks like
may be invalid, even with the NR flag.
edit:
That Traps and Tricks document saved my life again it seems:
"This is because, no matter
how many positions are shifted, the carry (if written) always gets the initial
value of bit 0 for right shifts/rotates or bit 31 for left shifts/rotates"
Given that your 3.1ms loop becomes 10us, or 310x faster, that seems about right.