SynthMaker

making code more efficient.

Archive · 2008 13 old posts

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

MegaHurtz ·

Hello, Synthmakers

Here`s a little bit of code.

streamin in; streamin hival; streamout out;

float reproc,recall,temp;

temp= hival*-1; reproc = (hival==0) & 1 + (hival>0) & hival; recall = (reproc<0) & temp + (reproc>=0) & reproc; out = (in % recall);

This is ment as a peice needing to be optimised, as im a real code newb i dunno where to start in assembler. Can anyone give me some pointers as to how i`d be able to remove (stack problems) or sse chanels even. This would be a real help througout all of my builds.

Here`s the same in assembler?

streamin in;streamin hival;streamout out;float smIntVarTemp=0.0; float smIntVarTemp2=0.0; float reproc=0; float recall=0; float temp=0; float FM1=-1; float F0=0; float F1=1; movaps xmm0,hival; mulps xmm0,FM1; //Assignment> sLeft=xmm0 movaps temp,xmm0; movaps xmm0,hival; cmpps xmm0,F0,0; movaps xmm1,xmm0; andps xmm1,F1; movaps xmm2,hival; cmpps xmm2,F0,6; movaps xmm3,xmm2; andps xmm3,hival; addps xmm1,xmm3; //Assignment> sLeft=xmm1 movaps reproc,xmm1; movaps xmm0,reproc; cmpps xmm0,F0,1; movaps xmm1,xmm0; andps xmm1,temp; movaps xmm2,reproc; cmpps xmm2,F0,5; movaps xmm3,xmm2; andps xmm3,reproc; addps xmm1,xmm3; //Assignment> sLeft=xmm1 movaps recall,xmm1; movaps xmm0,in; movaps smIntVarTemp,xmm0; movaps xmm0,recall; movaps smIntVarTemp2,xmm0; fld smIntVarTemp2[0]; fld smIntVarTemp[0]; fprem; fstp smIntVarTemp[0]; fstp st(0); fld smIntVarTemp2[1]; fld smIntVarTemp[1]; fprem; fstp smIntVarTemp[1]; fstp st(0); fld smIntVarTemp2[2]; fld smIntVarTemp[2]; fprem; fstp smIntVarTemp[2]; fstp st(0); fld smIntVarTemp2[3]; fld smIntVarTemp[3]; fprem; fstp smIntVarTemp[3]; fstp st(0); movaps xmm0,smIntVarTemp; //Assignment> sLeft=xmm0 movaps out,xmm0;

Sow the general stuff really. Would be Very Thankfull.

Grtz, Lukas.

MegaHurtz ·

Except for the kinda obvious negative hival bug. blasted this out for demo sake.

MyCo ·

Hi!

before you optimize the assembler, you should start optimizing the code. eg. I've found something quite odd here:

reproc = (hival==0) & 1 + (hival>0) & hival; recall = (reproc<0) & temp + (reproc>=0) & reproc;

in the second line you have a comparison (reproc<0) but how can reproc get lower than zero? the output range of the line one is 0 < x < infinity... so if this is correct your code could get reduced to this:

streamin in; streamin hival; streamout out;

float recall;

recall = (hival==0) & 1 + (hival>0) & hival; out = (in % recall);

just try it...

now when the range of hival is only positive, you can reduce more:

streamin in; streamin hival; streamout out;

float recall;

hival=hival - (hival==0) & (hival-1); out = (in % hival);

so there is only one comparison but 2 more subtraction which is probably faster because cmpps sucks 😈

infuzion ·

I find if I do not test constantly (every 5 minutes) my changes by subtracting the original code from my ASM & using a Readout to get 0 (or some other testing method), I'll make alot of new bugs.

MyCo ·

yes, but if you don't know input ranges, there is no chance to test 🙂

MegaHurtz ·

You made me delete my post XD. Thats way better. Only can this be optimised even further?

The root of the problem is using multiple diy interpolations, and curves o.o. Next to pow and pong blah blah. But.. it`s all single chanel.. and monophonic. giving me a 14-17% ish percentage.. compare it to huge 3 to 8% c++ Plugins tells me some optimising is in order. sow some basic pointers will do. Im not much of a hopper.. mainly i can combine some more. I`d like to get rid of some chanels. and stuff like more than 3 voices poly.

infuzion ·

Good math reduction tips MyCo! MyCo wrote: so there is only one comparison but 2 more subtraction which is probably faster because cmpps sucks

maybe (added andps) Core2 65nm: Both addps & cmpps use same ports, 1 uops, same Latency, same Reciprocal throughput. andps add, mult or move port, 1 uops & Latency, 0.33 Reciprocal throughput (same as movaps).

AMD64: addps FADD port, 1 uops, 4 Latency, 1 Reciprocal throughput cmpps FADD port, 2 uops, Latency, & Reciprocal throughput each andps FMUL port, 2 uops, Latency, & Reciprocal throughput each

I would test both versions out on both platforms (AMD & Intel CPUs) to make sure.

exonerate ·

The bottle neck for your code is the modulus, what is this code supposed to be doing exactly?

Maybe it can be done without the modulus.

MegaHurtz ·

the code is ment to be a clipping guard, that starts over when (in>threshold). The functionality is within a range of samples..ai a little to very very much. The speed i want to be using it is a.f.a.p. the only light way of doing it in my oppinion is to fix the threshold to 1. And then separating the float, and subtracting the int. But on a variable range this (reciprocal version) creates very litlle jitter. as the double int would becouse of the divider/multiplyer. Basicly it does have to cut the mustard. And that it does. speaking of perfect.. it is`nt.. I really don`t grasp that 0.1 becomes 0.099999999999. shure you gain jits there.. maybe me? I`d be interested in shaving off cpu on all of my mathematics really, so anything is welcome Including this btw.

MyCo ·

infuzion wrote: addps 1 uops, 4 Latency, 1 Reciprocal throughput cmpps 2 uops, Latency, & Reciprocal throughput each I would test both versions out on both platforms (AMD & Intel CPUs) to make sure.

don't forget the andps instruction that follows each cmpps

infuzion ·

MyCo wrote: don't forget the andps instruction that follows each cmpps

I did forget, thank you MyCo! So I updated the chart above. cmpps still may be faster; it is situational to what CPU is being used, and what instructions are before & after. I would still try both, but your tip is a good one for sure!

MegaHurtz ·

does this apply to all math, vs conditional statements?

MegaHurtz ·

Thx a Bunch.. I did find very helpfull stuff on the wiki too. Leaving me some time for the important things in life.

Bang! * :___: . * () () () () () () * | * .(O _O). 88888<---------D (0X0) (0X0) (0X0) * 888888 88888888888 O| |--O * * ( ) < ( ) <<< ( ) <<< * ** 888888888888888888888888 | | \ \ \ \ \ \ * * 888888 8 000 88888 _| |_ * * 00000 000

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.