368 clock cycles???
Philldapill
Posts: 1,283
I'm working on something that requires very fast code, but since I don't know assembly much at all, I decided to see how long certain bits of code take. I widdled the code down smaller and smaller because it didn't make sense until I ended up with:
PUB TestTime
· count1 := cnt
· count2 := cnt
· TV.dec(count2-count1)
The output is 368. I'm only assuming that this means it took 368 clock cycles between assigning count1, and finishing the assignment of count2. The TV object is just a simple ouput display. Does it really seem like it could take 368 clock cycles to do all this???
PUB TestTime
· count1 := cnt
· count2 := cnt
· TV.dec(count2-count1)
The output is 368. I'm only assuming that this means it took 368 clock cycles between assigning count1, and finishing the assignment of count2. The TV object is just a simple ouput display. Does it really seem like it could take 368 clock cycles to do all this???
Comments
But yes if you need any to run at a high speed then you will need assembeler.
Steven
Take your assigment:
would correspond to the SPIN action; this will take 26 ticks worstcase which is "only" 15 times fster than SPIN.
But no machine code programmer would do this. He would rather reserve a register (a COG cell) for "cnt1" and just code
which will take 4 ticks only and now will be 90 times faster than SPIN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 1/12/2008 2:03:18 AM GMT
The truth is that any program is a combination of simple things that have to be done quickly and repeatedly and much more complex things that are done occasionally and without much regard to time (within reason).· With the Propeller, the fast things are some kinds of I/O (like video and high speed serial) and some kinds of repetitive computations (like DSP type stuff).· Pretty much anything else can be done more slowly and space starts to become important rather than speed.· Spin is a better fit there and the use of appropriately sized structures rather than using longs for everything.
The trick is to place the dividing line properly.· Sometimes you can only find out how to implement something by getting it to work slowly (in Spin here) and measuring how long parts of the process take, then optimizing them one by one to see if that makes a difference.· There have been many case studies where what was believed to be the bottleneck in a program was not that at all ... It was something else.· You want to measure what's actually going on before committing to a difficult optimization process for something that may get thrown away later.
PASM is undoubteldy fast (20MIPS), Spin is slower, but it's all relative. Take a 'normal' single accumulator architecture running at 1MIPS ...
Spin is a closematch for that, so with all that Spin needs to do in the background it is still comparable to that 1 MIPS processor, and you have up to eight of those processors.
So fast or slow, it all depends on what you compare it with. For example, PASM runs like a snail nailed to the ground if you compare it to some things.
In fact machine language is "slow" compared to the doings of hardware. A computer is an interpreter as much as SPIN is - fast, but slow wrt to the "real world" of electronics...
The speed-down is a factor of six with the Propeller machine code, mitigated by the inleaved instruction execution to four...
-Phil