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

Variable-length loops. i.e. loop(n) {...}

DSP related issues, mathematics, processing and techniques

Variable-length loops. i.e. loop(n) {...}

Postby HughBanton » Fri May 01, 2020 2:56 pm

I think I'm right in saying that DSP in FS3 doesn't allow variable-length loops. FS4 does, but as far as I can see there's nothing to prevent doing them in FS3 when you're in assembler. (If I'm wrong I'll head on back to Slack ... :oops: )

So, I'm inputting an int 'loopLength' to define the loop. FS4 typically gives you this assem for a variable-length loop :
Code: Select all
streamin loopLength;
float _temp_;

  // Start of Loop {
movaps xmm0,loopLength;
movaps _temp_,xmm0;
fld _temp_[0]; fistp _temp_[0]; mov eax,_temp_[0];
loop1:
push eax;
  // ...
  // my code
  // ...
pop eax;
dec eax;
jg loop1;
  // } End of Loop

But today I accidentally hit on this as a nice simplification, using cvtss2si to directly get loopLength into eax, instead of all the fld/fistp stuff .. which I barely understand anyway! (Much of my so-called assembler coding has its origins in the accidental :? )
Code: Select all
streamin loopLength;

  // Start of Loop {
cvtss2si eax,loopLength;
loop1:
push eax;
  // ...
  // my code
  // ...
pop eax;
dec eax;
jg loop1;
  // } End of Loop


Appears to work OK, but seems too easy. Can one of the code team tell me if it's generally OK to do this? I foresee pitfalls ...
H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: Variable-length loops. i.e. loop(n) {...}

Postby adamszabo » Fri May 01, 2020 5:05 pm

Nice find! Just make sure your loopLength variable can never be 0 otherwise it crashes.

It seems you can directly do it on a memory address as well:

cvtss2si eax, xmm0;
adamszabo
 
Posts: 657
Joined: Sun Jul 11, 2010 7:21 am

Re: Variable-length loops. i.e. loop(n) {...}

Postby wlangfor@uoguelph.ca » Mon May 04, 2020 3:33 pm

Thank you, this is invaluable advice and I'll definitely keep this feature in mind. I'm making a track a and c-weighted averaging system that will automatically combine truncated instances so as to to provide the roughed average on the fly. Odds are this information may be of some use.

I'll mention you in the credits of the final if that's OK for the assistance.
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 DSP

Who is online

Users browsing this forum: Google [Bot] and 25 guests

cron