Re: Copy & Paste Funtcion
Posted: Thu Nov 08, 2012 12:23 am
Drnkhobo wrote:Ive just noticed (yes,only now) when you connect a text primitive to the dsp module, it shows the conversion to asm right?
- Also why not then just use the output and have a asm instead of dsp module???
Yes, it is the assembly output of the compiler. - and yes, you can copy and paste it into an assembly primitive.
If you just do that, there is no radvantage, as the instructions used by the CPU will remain exactly the same, as DSP code is compiled rather than interpreted. However, once you have your code nice and tight, the assembly listing gives you a starting point for optimising it further.
The code compiler is really quite basic, and often puts extra opcodes in there that aren't really needed - for example writing a register value (the xmm's) to memory, and then immediately reading it back out again - like this...
Code: Select all
//Some code here
//that puts a value into xmm0
movaps xmm0, MyVariable; //copies cmm0 to memory
movaps MyVariable, xmm0; //and read it straight back out again
//Code continues
//doing stuff
//with xmm0...and then there a million and one other things that you can do to eat away at the CPU cycles. It really is a huge subject to learn (and very addictive!) - I have seen some code designs reduced to less than 20% of the CPU load using hand written assembly, though the savings are only very rarely that big.
However, the best advice is to get to know the DSP code really well first - unless the code program is already very well optimised, there is little point in saving just a few CPU cycles with assembly. It is also very tricky to do, as assembly is very hard to read, there are no de-bugging tools, and it's very easy to make crashes!
However, if you do want to start learning a little assembly,, making little codes and then peeking at the compiler output is a damn good way to start.
You can also learn to write better code by looking at the assembly - you can find ways to write your code statements that make the assembly listing shorter. From the RMS code, a good example would be the min/max part. It will come out with less memory read/writes if you write it all on one line, i.e....
Code: Select all
average = min(1,max(0,sum/samples));