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

DSP related issues, mathematics, processing and techniques
Post Reply
User avatar
HughBanton
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire
Contact:

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

Post by HughBanton »

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
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

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

Post by adamszabo »

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;
User avatar
wlangfor@uoguelph.ca
Posts: 912
Joined: Tue Apr 03, 2018 5:50 pm
Location: North Bay, Ontario, Canada
Contact:

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

Post by wlangfor@uoguelph.ca »

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
Post Reply