SynthMaker

SVF3 Lowpass (ASM OPTIMIZED by MDMA)

Archive · 2012 9 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

MDMA ·

So I've been digging in into the wiki and forums to be able to start coding and optimizing my own stuff and just got addicted!!!

ASM is the shit!!!

I've just done my first optimization and was amazed! So basically I've removed everything I could from the native SVF3 filter in order to turn it into a lowpass only filter, I liked it's sound but needed to reduce cpu usage and so got my first experiment with asm!

I've included an cycle analyser but the difference is huge there because the original has all those other filters but that is how much it saved me on my current project.

I know is not much and many of you could make a much better job but I thought I'd give a contribution to the forum, after all I've been having much help from you all!!!

Peace and light to all!

trogluddite ·

MDMA wrote: optimizing my own stuff and just got addicted!!

Take care, friend! 😇 - Luckily, the forum retains its strong links with ASMAA (Assembly, Sent, Me, Absoluteluly-over-the-edge, Anonymous) - and we will always be here to help when the addiction begins to have negative effects on your rellations with the rest of the human race.

Enjoy the journey, The (very drunk) Luddite. 😈

cyto ·

Good job, MDMA!! Very well done.

MDMA wrote: ASM is the shit!!!

I remember having the exact same reaction when I first started messing around with it. I had thought that all the talk about "asm optimization" was just people with too much time on their hands until I saw the effect it can have on the performance of your design. It is quite dramatic the difference it can make!

I briefly looked over your example and it looks really well done. I will give you one little pointer: To any extent possible, try to avoid unnecessary movement to and from memory locations (ie moving stuff to/from those xmm registers into/out of the variables). Whenever you make such a move, it takes a little more time and you run into the possibility of cache misses. Not a big deal, but the more you get into this, the more little things like this make a difference. For example, these are the last few lines of your main code...

mulps xmm0,bp1; movaps xmm1,lp1; addps xmm1,xmm0; movaps lp1,xmm1; subps xmm4,lp1; mulps xmm7,bp1; subps xmm4,xmm7; mulps xmm5,xmm4; addps xmm5,bp1; movaps bp1,xmm5; movaps xmm0,lp1; movaps lowpass,xmm0;

Here is a slightly better way to do it...

//put bp1 in a register //so you don't need to //keep accessing the //memory location movaps xmm2,bp1; mulps xmm0,xmm2;//!! movaps xmm1,lp1; addps xmm1,xmm0; movaps lp1,xmm1; //xmm1 still has the value //for lp1, so we'll just call //that register when we need //it. subps xmm4,xmm1;//!! mulps xmm7,xmm2;//!! subps xmm4,xmm7; mulps xmm5,xmm4; addps xmm5,xmm2;//!! movaps bp1,xmm5; movaps xmm0,xmm1;//!! movaps lowpass,xmm0;

It's not much, but notice there are four less calls to memory and this adds up in larger code blocks.

Aside from my nitpicking, it still is very impressive. Keep on keeping on 🙂

-cyto

MDMA ·

Thanks guys, I did'nt though it was that good, lol.

cyto wrote: To any extent possible, try to avoid unnecessary movement to and from memory locations (ie moving stuff to/from those xmm registers into/out of the variables). Whenever you make such a move, it takes a little more time and you run into the possibility of cache misses. Not a big deal, but the more you get into this, the more little things like this make a difference. For example, these are the last few lines of your main code...

mulps xmm0,bp1; movaps xmm1,lp1; addps xmm1,xmm0; movaps lp1,xmm1; subps xmm4,lp1; mulps xmm7,bp1; subps xmm4,xmm7; mulps xmm5,xmm4; addps xmm5,bp1; movaps bp1,xmm5; movaps xmm0,lp1; movaps lowpass,xmm0;

Here is a slightly better way to do it...

//put bp1 in a register //so you don't need to //keep accessing the //memory location movaps xmm2,bp1; mulps xmm0,xmm2;//!! movaps xmm1,lp1; addps xmm1,xmm0; movaps lp1,xmm1; //xmm1 still has the value //for lp1, so we'll just call //that register when we need //it. subps xmm4,xmm1;//!! mulps xmm7,xmm2;//!! subps xmm4,xmm7; mulps xmm5,xmm4; addps xmm5,xmm2;//!! movaps bp1,xmm5; movaps xmm0,xmm1;//!! movaps lowpass,xmm0;

It's not much, but notice there are four less calls to memory and this adds up in larger code blocks.

Aside from my nitpicking, it still is very impressive. Keep on keeping on 🙂

-cyto

Cyto, its a good thing you call me on this mate, I had no idea it worked like that, one less mistake I'll be doing in the future. Thank you

infuzion ·

Be careful; only go deep into ASM if you will: 1) Use the code block several times in a single OSM (eg envelopes, one of the filters in a 5 band EQ, etc) 2) Will re-use the code in several OSMs (like your filter) 3) Will take out much unneeded capability to cut drastically the opcode count (eg cutting the 4 channel x86 ASM for the POWer down to 1 or 2 channels) 4) Really will make a big difference (I once cut SM's compresser to 20% of the cycles needed, by cutting out unneeded features, code mergers)

Otherwise, you will waste time with ASM. Intel's Core2 internal ASM optimization is decent, & I'm sure is better with newer CPUs. Not sure about AMD's new chips. This fact combined with the ridiculous speed of CPUs makes minor ASM tweaks a waste of time IMHO. I'm very good at it; only 4 or so board members here are better than me, & there has been a few times I said, "5 cycles saved; what a waste of an hour!".

I may try my hand of optimizing a few segments in Google's v8 JavaScript engine, that runs Chrome, Node.js, & a few other things. If successful, the wattage power savings alone could keep a small village lit.

cyto ·

infuzion wrote: Be careful; only go deep into ASM if you will: 1) Use the code block several times in a single OSM (eg envelopes, one of the filters in a 5 band EQ, etc) 2) Will re-use the code in several OSMs (like your filter) 3) Will take out much unneeded capability to cut drastically the opcode count (eg cutting the 4 channel x86 ASM for the POWer down to 1 or 2 channels) 4) Really will make a big difference (I once cut SM's compresser to 20% of the cycles needed, by cutting out unneeded features, code mergers)

You forgot one very important case:

5)You need to accomplish something that simply can't be done in code/primitives.

That's the biggest allure of asm to me. The ability to implement conditional branches, wrangle memory buffers to my will, use bitwise logic to manipulate data. All of these things are next to impossible outside of assembly.

-cyto

infuzion ·

cyto wrote: Here is a slightly better way to do it...

More slightly better:

//movaps xmm0,xmm1;//!! movaps lowpass,xmm1; Unless you need to use the xmm0 for more math later before the end; I'm assume "lowpass" is the output.

MDMA ·

infuzion wrote: cyto wrote: Here is a slightly better way to do it...

More slightly better:

//movaps xmm0,xmm1;//!! movaps lowpass,xmm1; Unless you need to use the xmm0 for more math later before the end; I'm assume "lowpass" is the output.

Lol, how have I not noticed that?

And thanks for the tips, you guys are good folks, there's def. a good SM community going on!

infuzion ·

cyto wrote: infuzion wrote: Be careful; only go deep into ASM if you will...

You forgot one very important case: 5)You need to accomplish something that simply can't be done in code/primitives. That's the biggest allure of asm to me. The ability to implement conditional branches, wrangle memory buffers to my will, use bitwise logic to manipulate data. All of these things are next to impossible outside of assembly.

Oh yes, & variable looping also!

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.