If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
About DSP code module
11 posts
• Page 1 of 2 • 1, 2
About DSP code module
I am having lots of fun with the DSP code module. My results are rarely useful but i'm coming along.
I ripped the code for a simple 6dB LP filter, and i managed to make it into serial stereo LP+HP for my delay build.
I tried to pack L and R, send it through the filter, and then unpack. The manual says that it will make my 2 channels practically use the same amount of processing as a single channel. Ouh, i would love that, but i had no luck with it yet, hehe. I use it to do high and low damping on the echoes, sorta. Anyways, as i was 'doubling' the code into stereo it got me thinking...
1) Does the DSP code module have any CPU % overhead/use on it's own? Like, Would i save resources from cramming all the code into one module?
2) I'm having a hard time converting to the reversed 'if' mask style. Is it possible to include several lines of code in a condition, or only a single line?
3) Again with the masking... 'KG_is_back' posted a DSP coded Multiplexer that i'm very fond of. I am trying to 'revert' it into a Selector, but no luck. No matter what i do, i only get signal through the very last input.
I hoped that only one of the 4 conditions would be true, and the respective value sent to output?
Cheers
I ripped the code for a simple 6dB LP filter, and i managed to make it into serial stereo LP+HP for my delay build.
- Code: Select all
streamin in1;
streamin in2;
streamin cutoff1;
streamin cutoff2;
streamout out1;
streamout out2;
float lp1,hp1,lp2,hp2;
lp1=lp1*(1.0-cutoff1)+in1*cutoff1;
hp1=hp1*(1.0-cutoff2)+lp1*cutoff2;
out1 = lp1-hp1;
lp2=lp2*(1.0-cutoff1)+in2*cutoff1;
hp2=hp2*(1.0-cutoff2)+lp2*cutoff2;
out2 = lp2-hp2;
I tried to pack L and R, send it through the filter, and then unpack. The manual says that it will make my 2 channels practically use the same amount of processing as a single channel. Ouh, i would love that, but i had no luck with it yet, hehe. I use it to do high and low damping on the echoes, sorta. Anyways, as i was 'doubling' the code into stereo it got me thinking...
1) Does the DSP code module have any CPU % overhead/use on it's own? Like, Would i save resources from cramming all the code into one module?
2) I'm having a hard time converting to the reversed 'if' mask style. Is it possible to include several lines of code in a condition, or only a single line?
3) Again with the masking... 'KG_is_back' posted a DSP coded Multiplexer that i'm very fond of. I am trying to 'revert' it into a Selector, but no luck. No matter what i do, i only get signal through the very last input.
- Code: Select all
streamin select;
streamin in0;
streamin in1;
streamin in2;
streamin in3;
streamout out;
out=in0&(select==0);
out=in1&(select==1);
out=in2&(select==2);
out=in3&(select==3);
I hoped that only one of the 4 conditions would be true, and the respective value sent to output?
Cheers
- Flemming
- Posts: 31
- Joined: Thu Aug 07, 2014 9:48 am
Re: About DSP code module
Yes there is a bit of overhead per code module so combining code will usually be of some benefit. Best to test though and see if it is worth it. I'm not as bothered about combining code into one component like I used to be, all in all it doesn't save that much.
Try that code. Yours didn't work because when an & is false out becomes 0, so if select equals 2 then the next line will overwrite out to equal 0 because select is not 3.
The addition to the previous out is key here, because when a condition is false 0 is added to out which of course does nothing and allows the previous value to pass.
It is a bit of a strange way to do conditional statements but this is how the underlying SSE assembler works.
- Code: Select all
streamin select;
streamin in0;
streamin in1;
streamin in2;
streamin in3;
streamout out;
out=in0&(select==0);
out=out+in1&(select==1);
out=out+in2&(select==2);
out=out+in3&(select==3);
Try that code. Yours didn't work because when an & is false out becomes 0, so if select equals 2 then the next line will overwrite out to equal 0 because select is not 3.
The addition to the previous out is key here, because when a condition is false 0 is added to out which of course does nothing and allows the previous value to pass.
It is a bit of a strange way to do conditional statements but this is how the underlying SSE assembler works.
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: About DSP code module
Exo wrote:Yes there is a bit of overhead per code module so combining code will usually be of some benefit. Best to test though and see if it is worth it. I'm not as bothered about combining code into one component like I used to be, all in all it doesn't save that much.
I see, then i'll keep mine separated too. I would hate to compromise modularity for little or no benefit. I still have hopes for the pack/unpack modules to save me some CPU, so i'll experiment a little with them instead.
Exo wrote:Yours didn't work because when an & is false out becomes 0, so if select equals 2 then the next line will overwrite out to equal 0 because select is not 3.
Yes, that is exactly what i am experiencing. Thanks for helping me with this one!
- Flemming
- Posts: 31
- Joined: Thu Aug 07, 2014 9:48 am
Re: About DSP code module
DSP code module creates code that works in SSE as most code in Flowstone. SSE basically means that it processes 4 floating point values in parallel in single command. If you use code block in mono and mono 4 it uses the same CPU (because it executes the same code). SSE means, that the operations are executed on 128bit registers (each containing 4 32bit variables usually in floating point format).
Having 2 code blocks that operate on two mono channels take twice as much CPU as one code block processing 4 channels in mono4 (except the mono pack/unpack modules also take a little CPU). It is hard to notice on simple schematic that uses one or two filters, but in larger schematics it becomes apparent (especially in poly).
Code block in Flowstone has no "if else" type of thing and only fixed "loop" and "hop" thing. The "&" only applies bitmask ...that means:
value&true=value
value&false=0
so:
x=a&B;
is either:
x=a
or
x=0
still it takes the same amount of CPU to pass zero or any value to "x"
However the 4 channels are calculated separately ...in channel [0] the value B might be true, so to "x[0]" the value "a[0]" is passed and in channel [1] the value B is false and to "x[1]" value "0" is passed. channels are processed parallel but completely separate only way to make them interact is the unpack/pack (and shufps in assembly).
So the bitwise AND logic is more like "value or zero" instead of "if else".
to save CPU in code component:
-write code that takes as little computations as possible
-use mono4 instead of mono as much as possible (because it is the same thing basically)
-try to use instructions that take much CPU as little as possible
list of instructions by their CPU cost (from the cheapest to the most CPU heavy)
a=b (copying values)
a+b (adding)
a-b (subtracting or making negative like a+(-b) )
a*b (multiplying)
max(a,b) min(a,b) (a>b) (minimum/maximum/compare take roughly the same CPU as multiplying)
a/b (dividing takes as much as 26x more CPU than multiplying)
sqrt(a) (square root... as much as division)
a[x]= or =a[x] (moving values form/to arrays ...it is hard to explain but it takes a lot more CPU than simple value passing. To make the long story short, moving array values is not done in SSE so it is done 4 times (even if mono is used insead of mono4))
pow(a,b) (power in code takes the most CPU (the same story as moving values for arrays))
BASICALLY:
don't worry about the CPU unless you use less then 10 lines in your code block or you see the CPU meter showing above 20%.
Having 2 code blocks that operate on two mono channels take twice as much CPU as one code block processing 4 channels in mono4 (except the mono pack/unpack modules also take a little CPU). It is hard to notice on simple schematic that uses one or two filters, but in larger schematics it becomes apparent (especially in poly).
Code block in Flowstone has no "if else" type of thing and only fixed "loop" and "hop" thing. The "&" only applies bitmask ...that means:
value&true=value
value&false=0
so:
x=a&B;
is either:
x=a
or
x=0
still it takes the same amount of CPU to pass zero or any value to "x"
However the 4 channels are calculated separately ...in channel [0] the value B might be true, so to "x[0]" the value "a[0]" is passed and in channel [1] the value B is false and to "x[1]" value "0" is passed. channels are processed parallel but completely separate only way to make them interact is the unpack/pack (and shufps in assembly).
So the bitwise AND logic is more like "value or zero" instead of "if else".
to save CPU in code component:
-write code that takes as little computations as possible
-use mono4 instead of mono as much as possible (because it is the same thing basically)
-try to use instructions that take much CPU as little as possible
list of instructions by their CPU cost (from the cheapest to the most CPU heavy)
a=b (copying values)
a+b (adding)
a-b (subtracting or making negative like a+(-b) )
a*b (multiplying)
max(a,b) min(a,b) (a>b) (minimum/maximum/compare take roughly the same CPU as multiplying)
a/b (dividing takes as much as 26x more CPU than multiplying)
sqrt(a) (square root... as much as division)
a[x]= or =a[x] (moving values form/to arrays ...it is hard to explain but it takes a lot more CPU than simple value passing. To make the long story short, moving array values is not done in SSE so it is done 4 times (even if mono is used insead of mono4))
pow(a,b) (power in code takes the most CPU (the same story as moving values for arrays))
BASICALLY:
don't worry about the CPU unless you use less then 10 lines in your code block or you see the CPU meter showing above 20%.
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: About DSP code module
KG_is_back wrote:list of instructions by their CPU cost (from the cheapest to the most CPU heavy)
a=b (copying values)
a+b (adding)
a-b (subtracting or making negative like a+(-b) )
a*b (multiplying)
max(a,b) min(a,b) (a>b) (minimum/maximum/compare take roughly the same CPU as multiplying)
a/b (dividing takes as much as 26x more CPU than multiplying)
sqrt(a) (square root... as much as division)
a[x]= or =a[x] (moving values form/to arrays ...it is hard to explain but it takes a lot more CPU than simple value passing. To make the long story short, moving array values is not done in SSE so it is done 4 times (even if mono is used insead of mono4))
pow(a,b) (power in code takes the most CPU (the same story as moving values for arrays))
Thanks for that, iv'e been wanting to have a list like that. How did you find this order out? Where does comparison fit it, that is the cmpps command? I guess the andps and orps uses the same as the movaps, or even less?
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: About DSP code module
Exo and KG_is_back, thank you so much for taking time to educate me I did read the manual, and the component reference, and i do a lot of searching and experimenting also. But a lot of things are kinda 'vaguely' documented, and i hit my head against the wall. I am so happy that i can get to ask my noob questions here, and receive such great answers from you guys.
- Flemming
- Posts: 31
- Joined: Thu Aug 07, 2014 9:48 am
Re: About DSP code module
Flemming wrote:Exo and KG_is_back, thank you so much for taking time to educate me I did read the manual, and the component reference, and i do a lot of searching and experimenting also. But a lot of things are kinda 'vaguely' documented, and i hit my head against the wall. I am so happy that i can get to ask my noob questions here, and receive such great answers from you guys.
No worries , this community has always been great for helping each other out.
I had plenty of help in my early days just happy to help out others too (help me to keep stuff fresh in my mind too). This software is big and complex and there is plenty to learn!
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: About DSP code module
adamszabo wrote:Thanks for that, iv'e been wanting to have a list like that. How did you find this order out? Where does comparison fit it, that is the cmpps command? I guess the andps and orps uses the same as the movaps, or even less?
I have found somewhere a document that has list of Assembly instructions and their respective CPU costs on different processors. The code component CPU price list I have written above is only roughly based on that, since many code instructions are composite. Just google something like "86x assembly instructions CPU" or so...
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: About DSP code module
Hello,
how do i do exponential funtions like:
x^y
in the Code Module?
thank you,
jotb
how do i do exponential funtions like:
x^y
in the Code Module?
thank you,
jotb
- jotb
- Posts: 23
- Joined: Mon Jul 28, 2014 5:08 pm
Re: About DSP code module
jotb wrote:Hello,
how do i do exponential funtions like:
x^y
in the Code Module?
thank you,
jotb
Hi jotb,
I found something here
viewtopic.php?f=2&t=2448&p=11832
- Flemming
- Posts: 31
- Joined: Thu Aug 07, 2014 9:48 am
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 32 guests