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

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

optimization question - custom selectors

For general discussion related FlowStone

Re: optimization question - custom selectors

Postby Duckett » Wed Feb 09, 2022 4:06 am

Just wanted to chime in to add: examples like these are a good way for someone like me who's less, ah, code-minded to wrap their head around what going on, and be less prone to "How do I....?" when a short chunk o' code does a certain job in the smallest fastest way ;)
We have to train ourselves so that we can improvise on anything... a bird, a sock, a fuming beaker! This, too, can be music. Anything can be music. -Biff Debris
User avatar
Duckett
 
Posts: 132
Joined: Mon Dec 14, 2015 12:39 am

Re: optimization question - custom selectors

Postby tester » Wed Feb 09, 2022 12:03 pm

Basically what I'm doing with selectors and multiplexers, is to redirect audio streams between nodes (organic modes, not poly). So hoping is not an option, because this will introduce distortions. This is simple operation, but done multiple times at once. Traditional selectors/multiplexers are not an option, because they force internal rewire of blue guts, which may even cause from time to time crashes. From past experience, buses are not that good too; the best way is to make signal either to pass through (or multiply by 1) or ignore it (or multiply by 0). And these are multi-choice switches, not 2-state.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: optimization question - custom selectors

Postby HughBanton » Wed Feb 09, 2022 3:48 pm

If I may make one final offering ... (this should all really be in the DSP forum section but wotever ..)

In DSP we are not offered a basic "if" statement. Instead, we need to employ masking techniques because we're generally dealing with poly streams that regularly contain 4 conflicting states, and only a mask can cover this.

However that doesn't mean you can't do an "IF" in ASM if you really want! After all, both loop{} and hop{} actually employ if-type conditional jumps each time they check on the loop or hop counter, i.e. whether to loop back again, or not.

The situation we're discussing here - selecting an input>output function according to a Selector Switch index - is very much an IF condition, and can be implemented like this :

Code: Select all
   // ASSEM - 4-way Selector using 'if' jumps :
streamin sw;
streamin in0, in1, in2, in3;
streamout out;

movaps xmm0,sw; cvtps2dq xmm0,xmm0; movd eax,xmm0;
cmp eax,1; je jump1; // if sw==1, go to 'jump1'
cmp eax,2; je jump2; // if sw==2, go to 'jump2'
cmp eax,3; je jump3; // if sw==3, go to 'jump3'

       // if sw==0
movaps xmm0,in0; movaps out,xmm0;
jmp end0; //go to end

jump1: // if sw==1
movaps xmm0,in1; movaps out,xmm0;
jmp end0; //go to end

jump2: // if sw==2
movaps xmm0,in2; movaps out,xmm0;
jmp end0; //go to end

jump3: // if sw==3
movaps xmm0,in3; movaps out,xmm0;
end0:

Only the matching condition is executed, the other 3 'wrong' conditions are all skipped over, so possibly this is the fastest method of all? You can certainly add as many inputs as you like with this one!

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: optimization question - custom selectors

Postby martinvicanek » Wed Feb 09, 2022 9:37 pm

@Hugh, now you are hooked, it seems. :lol:
Indeed, your last selector code runs a few notches faster, in spite of the branching involved. I suppose it is because cmp is faster than cmpps. There is a subtle difference, though: In your (faster) code, you are evaluating only the first of four channels of the sw input variable, whereas cmpps actually compares all four channels. If sw has individual values for each channel, the results of the two codes will be different (although I assume that this will not be the typical use case :mrgreen: ).

One last remark: Instructions like streamin sw, in0, in1, in2, in3; or float F0=0, F1=1, F2=2, F3=3; or je will only work in the FS alphas, and people may be put off when throwing your code in a FS3.0.6 or FS3.0.8.1 ASM codebox. I think in this forum we should better stick to FS3 syntax. :roll:
User avatar
martinvicanek
 
Posts: 1322
Joined: Sat Jun 22, 2013 8:28 pm

Re: optimization question - custom selectors

Postby HughBanton » Thu Feb 10, 2022 10:47 am

Ooops :oops: . I'd completely forgotten you can't 'comma' ins & outs & floats in 3.0.6.

So I made a start on reworking it, and adding a matching multiplexer - similar in>out lines but in the reverse order.

But nor, it seems, can you do these forward jumps anyway in 3.0.6, so stopped in my tracks! Sorry folks.

All very quaint, it is ...

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: optimization question - custom selectors

Postby HughBanton » Tue Feb 15, 2022 4:30 pm

And finally ..

MV tells me that 'forward jumps' in ASM were inroduced in 3.0.8 (but don't work in 3.0.6), and of course they work in FS4 which is an ASM goldmine in comparison.

Anyway, method above is valid in 3.0.8 onwards for making a custom selector or a custom multiplexer (with an Int selector input), or if you needed some complicated selectable routing.

tester wrote:Also, from the past, I remember, there was some asm hack, that allows to "stop" some inputs from processing, like the selectors do. But I don't remember the details now.

Oh, that's interesting. I can't find it either but I could find several uses for something like that! .. anyone? I'm aware that when a Selector is used on mono streams it does indeed 'disconnect' the un-selected processing behind, can offer a big cpu saving. Certainly none of the methods we've posted here do that.

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 51 guests