SynthMaker

learning synthmaker ASM?

Archive · 2010 20 old posts

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

datsound ·

what is the best way to learn ASM as it is written in synthmaker?

are there any suitable tutorials online? a list of codes of increasing complexity?

my first project is to make a+b+c. 🙂

I will collate all the learning information i find for ASM in a list here, help if you may. Thankyou.

______________________________________________________ Syntmaker opcodes: [old link]

______________________________________________________ 1/ an example from vector graphics:

! MOVAPS xmm1, xmm0 ' copy xmm0 to xmm1: xmm1 = 292.41 | 4251.04 | 408.04 | 0.00 ! SHUFPS xmm0, xmm1, &H4E ' shuffle xmm0 with xmm1, so xmm0 = 412.09 | 0.00 | 292.41 | 4251.04 ! ADDPS xmm0, xmm1 ' add suffled xmm0+xmm1, so xmm0 = 704.50 | 704.50 | 4251.04 | 4251.04 ! MOVAPS xmm1, xmm0 ' put result to xmm1 xmm1 = 704.50 | 704.50 | 4251.04 | 4251.04 ! SHUFPS xmm1, xmm1, &H11 ' shuffle xmm1 with xmm0, so xmm1 = 4251.04 | 4251.04 | 704.50 | 704.50 ! ADDPS xmm0, xmm1 ' add xmm1 + xmm0, , so xmm0 = 4955.54 | 4955.54 | 4955.54 | 4955.54 < -- this is result of x^2+y^2+z^2 ! SQRTPS xmm0, xmm0 ' perform SQR ! MOVDQU [eax], xmm0 ' Now VA(4) has result (including Va(1..3) )______________________________________________________

MichaelBenjamin ·

basically that asm you will mostly use is like a puzzle/pyramid swapping game with 8 slots. best if you start with some simple a+b+c and see what it does then like you said. opcode list is in the wiki: search "opcodes".

some basic rules: operation goes from right to left, right register stays unchanged with most operations and left register changes, so if you have this;

movaps xmm0,input; movaps xmm1,value; mulps xmm0,xmm1; // input*value with result written to xmm0 - xmm1 where value is stored, stays as it is addps xmm1,xmm0; // =(input*value)+value and the result is stored in xmm1 movaps out1,xmm1; //write (input*value)+value to output variable movaps out2,xmm0;//write (input*value) to output variable

that example doesnt make much sense of its own, but if you would need input*value later on you could just leave it in xmm0 and so save some cpu. also keep in mind that all xmm registers loose memory between each sample that is processed, if you want to transfer values to the next sample, you need to write them to a variable.

edit: i messed up right/left

datsound ·

TY that explains it! So the 8 operator slots are xmm0-xmm7. cheers

for ASM beginners... Here is how to add.. a+b+ ...... +f !. is it written efficiently?

streamin a; streamin b; streamin c; streamin d; streamin e; streamin f;

streamout o;

movaps xmm0,a; movaps xmm1,b; movaps xmm2,c; movaps xmm3,d; movaps xmm4,e; movaps xmm5,f;

addps xmm0,xmm1; addps xmm0,xmm2; addps xmm0,xmm3; addps xmm0,xmm4; addps xmm0,xmm5; addps xmm0,xmm6;

movaps o,xmm0;

theun ·

Are you sure you want to dive into ASM? 😉 In the beginning it may feel a bit awkward, but once you understand some of the conventions it will become easier. But there are some traps, like the one that Michael addressed in his post. Probably testing of a piece of SM code (code box) will be easier than testing of a piece of asm (asm box). Often it is a good start to write the module you want in "code", test it to be sure that is does what you want, and then transform it to asm (use a text box first, you can cut and paste with Ctrl C and Ctrl V). Now try to understand how the asm works, and often you may find some easy improvements/optimizations.

Opcodes currently supported by SM are listed here: [old link] I am quite sure there have only been minor changes (if any) after this list was compiled, so it still gives a pretty good overview.

Opcodes are rather simplistic instructions, like MOV A,B (means: move the value that is in register B to register A) ADD A,B (means: add the value that is in register A to the value that is in register B, and put the result in register A) and so on

SSE codes are particularly interesting for e.g. DSP/multimedia calculations as they can take 4 values at the same time and do the same calculations on all 4 at the same time. These codes can be recognized as they all have "PS" behind the "normal" name of the opcode, so MOVaPS, ADDPS, CMPPS.

If you want to dive really deep into what a specific opcode does you may have a look at the bulk of documentation at the intel site: http://www.intel.com/products/processor/manuals/index.htm (you'll find this link also in the SM wiki). If you want more help where to exactly find (i.e. in which intel guide) more about opcodes, please come back here and ask.

I hope this helps a little. 😉 Regards

Mo ·

datsound wrote: for ASM beginners... Here is how to add.. a+b+ ...... +f !. is it written efficiently?

You haven't defined xmm6, so that line is unnecessary. Also you don't need to move all variables to each own register, but simple add the streamin directly:

streamin a; streamin b; streamin c; streamin d; streamin e; streamin f;

streamout o;

movaps xmm0,a; addps xmm0,b; addps xmm0,c; addps xmm0,d; addps xmm0,e; addps xmm0,f;

movaps o,xmm0;

datsound ·

theun wrote: Are you sure you want to dive into ASM? 😉 Regards

🙂 i am sure about learning ASM, i will buy a brand new keyboard and all the ASM books from amazon and i will become a specialist ASM guy 🙂 as i cant write english very well it seems maybe i will have more luck in ASM. thanks that was very clear. Understanding just the basics is also good for taking abit of maths and customizing a complicated ASM to a synth.

Mo... that was an especially good correction there, it made the osm faster.

theun ·

I remember an interesting topic about code and asm in SM: Code tips x a beginner

It's one of the longest topics (11 pages) at the forum probably. It's over 2 years old, but that doesn't matter as there hasn't been many (if any) changes regarding code or asm. The first pages are about the code component, but from page 4 or 5 the focus is more and more on ASM examples.

Finally, don't spend too much money at amazon, if you can get the knowledge you want for free 🙂

Regards, Theun

trogluddite ·

As theun said, don't waste too much on the books - they'll contain a lot of x86 stuff that doesn't really apply in SM, as it's heavily biased to sse. Anyhow, you'll find plenty of help here on the forum.

My top tip: Careful with your typing!! - variable names are case-sensitive, and the assembly primitive does not check variable names to see if they are valid (Update please, admin)- so it's very easy to think you have a bug, when in fact you just spelled a variable wrong (a reliable keyboard is definitely a good idea!)

MichaelBenjamin ·

you want to keep asm at synthmaker, yes dont buy any books (but maybe that also was a joke?) - if its one topic you dont need to buy any books about, if you got internet access, its about computers. the sse 4 channel asm which sm is mostly built around is really simple, and by reading the mentioned topics you can quickly (some months?) get your head around it. its always the same 8 register per sample puzzle (which can be quite fun to solve). the single channel asm on the other side is much more bizarre, and i dont understand it really untill now, but the surface suffices to get some basic things running and there still 64 ideas unprogrammed, so really no need to get into it. besides, i think more that sms compiler rather should be made more intelligent per default and the code box be updated with new commands so one doesnt need to get into asm just to make a sqrt or to shove off the usual 50% wasted cpu on every module.

trogluddite ·

MichaelBenjamin wrote: besides, i think more that sms compiler rather should be made more intelligent per default and the code box be updated with new commands so one doesnt need to get into asm just to make a sqrt or to shove off the usual 50% wasted cpu on every module.

Amen - bump bump bump!

datsound ·

MichaelBenjamin wrote: you want to keep asm at synthmaker, yes dont buy any books (but maybe that also was a joke?) - if its one topic you dont need to buy any books about, if you got internet access, its about computers. the sse 4 channel asm

No really i have bought like 20 books on asm from amazon now. ohh dam i will have to send them back. 🙂 and i bought special half moon glasses so i can read them and type at the same time and a new coffee machine and ear muffs. lol! it;s ASM time. (Sorry!!! i was joking!) really it is a very good language in the SM version, with that number of variables it is quite reasonable to learn imho.

check it out i found an exponential approximation from a maths website, it is 98.8 percent faster than shifrins exact version, un-hopped... for shaping purposes only as the base input is inaccurate, just that it is near perfect exponent curve approximations.

infuzion ·

[old link]

datsound ·

Thanks Infuzion.

I added he usual hop code to this ASM and it didnt work. dont know why.

streamin a; streamout o; float f = 0.0000000001; movaps xmm0,a;

//mov eax,ecx;and eax,127;cmp eax,0;jnz end0;

mulps xmm0,xmm0; addps xmm0,f; mulps xmm0,xmm0; //end0:

movaps o,xmm0;

Mo ·

datsound wrote: I added he usual hop code to this ASM and it didnt work. dont know why.

It's because you exclude the hop using //. See the color syntax in the assembler. If black it's probably not right or excluded. You can just remove the //'s for the hop and the code will work. Use // to exclude a code line or comment from the code block or /* code */ to exclude more lines of code.

MichaelBenjamin ·

btw heres a tip to smooth out the cpu if you got lots of hopped modules that go into samplerate modules: mov eax,ecx; and eax,127; cmp eax,0;//<---- jnz end0;

change the zero to something between 0 and hop (127 in this case) and the code doesnt get executed on the first sample, but one the sample you choose. that is to prevent asio stream breakups when you use larger schematics with hops, especially with synths. without this, since for the first sample, all the code needs to be executed you end up with cpu spikes and probably the mentioned asio stutter. if modules are not 100% time critical and can be shifted some samples you can set your modules to be executed one after the other, giving much smoother performance and making it easier for your cpu to calculate.

this is best done at a late stage of programming, after beta testing, rebuilding, whatever, since you lose sync-ability with this. also keep in mind that if you process in parallel into another hopped module you may get additional processing lag.

trogluddite ·

datsound wrote: I added he usual hop code to this ASM and it didnt work

The reason it's not working is because the output 'movaps o,xmm0' is outside the hop. The hopped part would only execute once every 128 samples; but the output assignment will execute for every single sample - for the 127 samples where the hop is not executed, it's impossible to know what value xmm0 will have - so you will get an essentially random number sent to the output for 127 samples out of every 128. That's because, unlike variables (which are written to memory), the xmm registers will be used by any other sse code running on the CPU (not just code/asm primitives, the stock primitives and any other appilcations that are running will use them too). There are two solutions - write the xmm0 value to a temporary variable within the hop, then read the variable outside the hop before sending it to the output - or (much better), just do the output assignment 'movaps o,xmm0' within the hopped part. This is important to remember whenever you use hopping or stages in your assembly - although the code you see on screen looks like a single list of commands, hops and stages break the flow of the code into sections that don't get executed in the sequence you see on screen - so you have to refresh the values in the xmm registers at each 're-entry' point into the code.

datsound ·

Thankyou. Is it wise to hop the movaps at the end of the code that sends to output?

movaps o,xmm0; end0: how come the following code worked, the difference being that the following hop doesnt contain xmm info, it sends the xmm to float variables that do all the f-operations inside the hop?

... float fAns = 0.0; float fHlf = 0.5; //--- Get the base/exponent values... movaps xmm0,bas; movaps fBas,xmm0; movaps xmm0,exp; movaps fExp,xmm0; //--- base^exponent [0]... mov eax,ecx;and eax,127;cmp eax,0;jnz end0; fld fExp[0]; fld fBas[0]; fyl2x; fld st(0);............

trogluddite ·

datsound wrote: Is it wise to hop the movaps at the end of the code that sends to output?

Yes, there's no problem with that - the streamin/streamout connectors can be treated just like variables, they are really no more than memory locations where the current value for the external links is stored. The only exception is that you should never write to a streamin - the streamin values must only ever be changed by the external link coming into the primitive.

The second example works because, as you say, the hopped section does not rely on xmm values being remembered from outside the hop. The variables are just memory locations that won't change unless you explicitly write to them. Using xmm's inside a hop isn't a problem per se - you just have to remember to read/write the values to memory (variables) to pass them between hopped and un-hopped parts of the code (likewise passing values between stages if you use them)

You could actually tighten up that code by not bothering with the temporary variables fBas and Fexp - you can just read the streamin's directly inside the hop...

fld exp[0]; fld bas[0];

...this saves 127 out of 128 samples of copying values to the temp variables that will never be used by the hopped part.

oddson ·

theun wrote: ...start to write the module you want in "code", test it to be sure that is does what you want, and then transform it to asm (use a text box first, you can cut and paste with Ctrl C and Ctrl V). Now try to understand how the asm works, and often you may find some easy improvements/optimizations...

That's likely the best advice... I'm not an ASM guy but what I have learned has largely been through this method.

datsound ·

I want to say a big thankyou for helping me to understand the basics, i will post this on the wiki for others to learn from and will progress as much as possible from reading others code.

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.