From the original SynthMaker forum (2004–2014), with its members’ names and dates.
aliasant ·
I know this is most likely not possible. At least not easy to do but still.
Wouldnt it be great if you could take your asm code and transfer it to a code?
Same way we take our ( not optimized) code and transfer it to asm.
If this was possible it would be very easy to learn how to write better code from the beginning.
Disco_Steve ·
you can take non optimised code and turn it into asm, connect a text primitive to the string output on the code module, and the asm is displayed, copy this text into an asm module and whalla code to asm 🙂
going the other way is not so easy. when the code is converted to asm, each line is compiled and then stack one after the other. so the asm 'reads' like the code does.
however when optimising, bits are removed and moved around, so a direct transfer back to code would be impossible. almost no compiler could do it well. the best thing to do it to write a comment after every line of asm code so as to follow it through.
helpful?
Steve
aliasant ·
Well Steve. naa. hehe. I knew that already but sometimes I write a small piece of code and after translating it to asm I realize that the code is so well written its not possible to optimize it more.
Most times, however, its the other way around. The code written is not very well written and after asm and optimizing I save more then 50%. That tells me that I could probably have written that code in a much smarter way from the beginning saving me a lot of asm time.
Thats why it would have been cool to translate the optimized asm code back to code so that I can see how I SHOULD have written it. Following?
Disco_Steve ·
okay, true, but the compiler is stupid! if you do something simple then the compiler will give you 'perfect' asm, but if you do something clever, then 'perfect' code will still not give 'perfect' asm. the fact the compiler sometimes gives out 'perfect' asm suggests than the compiler in SM is quite good 🙂.
'perfect' code wont always yield perfect asm, and most 'perfect' asm cant be written exactly as code.
I agree though it would be a nice feature to have, but I don't think mother nature will let it happen 🙁
aliasant ·
Disco_Steve wrote: okay, true, but the compiler is stupid! if you do something simple then the compiler will give you 'perfect' asm, but if you do something clever, then 'perfect' code will still not give 'perfect' asm. the fact the compiler sometimes gives out 'perfect' asm suggests than the compiler in SM is quite good 🙂.
'perfect' code wont always yield perfect asm, and most 'perfect' asm cant be written exactly as code.
I agree though it would be a nice feature to have, but I don't think mother nature will let it happen 🙁
hehe 🙂
I think your right.
But maybe someday someone could program a simple converter. Not for real use but dummy code. Just to help understanding the parts were the code could have been written smarter.
In SM we cant code the squareroot and other things but they work in asm so if asm would be converted some how there are lots of parts that wouldnt be possible to convert straight over but the dummy code could instead write "squareroot" in orange or something so that one knows that in this place I calculated the squareroot. Same with eg. the rectify. We have that masked version in asm so if the converter recognizes the rectify code in asm it can translate it as "rectified" in orange or if there is a code version write that out. Could be an option if you want it to just type those things or insert a functioning code. babbling now. Was going to file a bug report...
Disco_Steve ·
it sounds like you know what you want, so make it yourself! read in the asm as text and decompile it.
aliasant ·
I have no idea how.
I do however occasionally convert back from asm if I lost the original code and its kinda fun.
I was planning on doing a small experiment.
Write a small ,1 line code, convert it to asm, optimize it and then use that to convert back to see what I get.
As long as its less then 8 "things" in it it can be kept on 1 line.
Ill get back if I do it. Not important. Just for fun.
aliasant ·
Ok. I did the experiment and the result was surprising and intriguing.
For this I used Exonerates optimized Envelope Follower and as comparison I used the standard SM Envelope Follower ( The same as Exo used for his optimization.
I started working back from the asm code.
First thing was to put in the rectifying code.
Then, in the AsM code there is a compare if greater or equal between the out and the rectified in.
You can look in the OSM what I did after this. Wrote all the moves down in the asm code.
It turned out that the compare part wasnt even used. I can skip it and it still produces the exact same result.
update: I just looked a little closer at Exos asm code and its clear that the compare result is never used so when removing that from the code it drops from 9 cycles to 7 . sweeeet. It is quite odd that no one has discovered this before?
update2: I was wrong. It is used. Cant believe I missed it. LOL well. My red face will calm eventually.
Still my coded version uses 27 cycles and the original used 34 so its a clear gain.
Here is the asm code with my comments:
//Envelope follower //ASM optimized by Exonerate 9 Cycles
streamin in;streamout out;
streamin attack;
streamin release;
int ABSMASK=2147483647;
movaps xmm6,out;
movaps xmm0,in;
movaps xmm1,attack;
movaps xmm5,release;
andps xmm0,ABSMASK;
movaps xmm7,xmm0;
cmpps xmm0,xmm6,5; // out = Greater or Equal to rectified in
subps xmm1,xmm5; // subtract release from attack
andps xmm0,xmm1; // And compared
addps xmm5,xmm0; //Add release (A)
subps xmm6,xmm7; //subtract out from rect
mulps xmm5,xmm6; // multiply with (A)
addps xmm5,xmm7; // Add rect
movaps out,xmm5; // move to out
Here is the end result:
//Converted back from ASM 26 cycles
streamin in;
streamin attack;
streamin release;streamout out;
float rect,compare;
rect = in * (1 - in < 0 & 2);
compare = out >= rect;
out = ((attack - release) & compare) + release *(out - rect) + rect;
It seems I cant upload to this forum so if anyone wants the osm, PM me with your mail.
Wrote something here? To have a post removed or your name hidden, write to [email protected].