Support

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

Question about Conditional Stream Statements

For general discussion related FlowStone

Question about Conditional Stream Statements

Postby guyman » Mon Sep 21, 2020 6:59 am

What's goodio y'all - been a minute. Hope everyone is riding out the storm.

few quick questions

I've been using what I believe is the most efficient implementation of conditional statements in dspcode..
I believe I picked it up on the forum a while ago.

Code: Select all
y = b + (a - b)&(x == 2);


which states

Code: Select all
if x = 2
then y = a
else y = b


has been doing right by me, but is there a way to append more results in the "same line of code" and maintain this current structure/efficiency? like...

Code: Select all
if x = 2
then y = a
and
z = t
else
y = b
and
z = w

or something like...

Code: Select all
if x = 2 or 3
then y = a
else y = b


or perhaps other variations... Would it increase efficiency by creating these types of logic statements I'm describing? or would it be the same as having multiple logic statements structure these conditions once it gets to assem? or would it be worse? is it "faster" or "saving cpu"

Also is the first example of conditional statement I posted real time, or a sample (or more) delay?
If it is real time, is this?
Code: Select all
if x = y
then x = a
else x = x


It sure would be nice if there were modules/hom files that were like the "stream math functions" for all of these conditional/logic style functions.. optimized much like the stream multiply etc...
or perhaps this is a great opportunity to create a logic/conditional database of efficient assem implementations(if it's not already in existence) of many of these sorts of things.....

If my memory serves correct, some post stated that the way of doing it in the manual is not that efficient or "optimized".. so unless I'm way off base, please don't push it back to the manual... I want the best way conceived of as of date...

Forgive any ignorance or presumptions
idiot savant << me << endl;
Peace.
~That Guy
User avatar
guyman
 
Posts: 187
Joined: Fri Mar 02, 2018 8:27 pm

Re: Question about Conditional Stream Statements

Postby guyman » Mon Sep 21, 2020 7:08 am

Oh and...
I made this while under a uh... certain influence one evening.. back when I was just getting started with logic and conditional statements... shortly after I found that first line of code above...
It's a little tool for creating conditional statements in that style... it's a mess and pretty ugly - but if you don't use
ifthenelse in dsp often.. it might come in handy.
IfThenElse Mono Stream Comparator Translator.fsm
(11.28 KiB) Downloaded 219 times

maybe if we get this thread going... I'll make a ruby thingy that encompasses all of it.
User avatar
guyman
 
Posts: 187
Joined: Fri Mar 02, 2018 8:27 pm

Re: Question about Conditional Stream Statements

Postby trogluddite » Mon Sep 21, 2020 6:19 pm

Nice gizmo -thanks! Even after all these years, I still get these statements inside-out and back-to-front, so I'm sure folks will find it useful!

guyman wrote:is there a way to append more results in the "same line of code"

Not in the same line of code, no. However, if the same conditional test needs to change several different variables, there's a little trick that you can use...

DSP-code (and assembly) don't really have a "boolean" variable type, but you CAN store a boolean bitmask in a regular float variable. This allows the result of the test condition to be re-used as many times as you like without having to keep running the test over again - you just have to be careful to remember that the variable isn't really a float!! To take your example...
Code: Select all
float test; // Fake "boolean" variable.

test = (x == 2);
y = b + (a - b) & test;
z = w + (t - w) & test;

In DSP-code this can sometimes save a few CPU cycles, sometimes not - it depends whether the amount of re-use outweighs writing the extra variable value. I find it very handy when I'm putting together complex code - a meaningful "boolean" variable name can often make it easier to see what the code is doing (I sometimes use several of them just for this reason, then remove any surplus once the code is working).

In ASM, this kind of re-use is usually even simpler, and a very natural optimisation - there's nearly always a saving, as the "boolean" value can just stay in an "xmm" register without being written to a variable. So using the above form in DSP-code is quite handy again, as it makes the optimisation easier to see when you convert to ASM.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1706
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Question about Conditional Stream Statements

Postby wlangfor@uoguelph.ca » Mon Sep 21, 2020 7:03 pm

Useful, thanks
My youtube channel: DSPplug
My Websites: www.dspplug.com KVRaudio flowstone products
User avatar
wlangfor@uoguelph.ca
 
Posts: 912
Joined: Tue Apr 03, 2018 5:50 pm
Location: North Bay, Ontario, Canada


Return to General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 26 guests