floats in code module (can someone please help me)
Archive · 200511 old posts
From the original SynthMaker forum (2004–2014), with its members’ names and dates.
NothanUmber ·
Today I tried to get float calcuations working inside the code component - without success so far. (Would be very nice if that would be possible - with the new midi to float conversion module one would then be able to handle even midi data inside the code component) Could someone please have a look at this schematic, in theory it should work but for sure I didn't take care for some important SynthMaker-way-of-working (or there is simply a general mistake in my thinking.)
but that doesn't change anything on the main problem (no result).
P.S.: Have I already mentioned that recursice functions or at least while- or conditional goto-constructs would be very cool inside the code component? 😉
unkargherth ·
By the own strucuture of code component, conditionals, looping and function calls are'nt implmentable without changing the whole module sctruture ( and posibly all the SM internal structure too
NothanUmber ·
unkargherth wrote: By the own strucuture of code component, conditionals, looping and function calls are'nt implmentable without changing the whole module sctruture ( and posibly all the SM internal structure too
Hm, if one looks at the the asm-text-output of certain code-component programs it seems to use conditional jumps (jnz etc...). Isn't the worst thing that can happen that one has to insert some noops for the alus that don't have anything to do if the number of code lines before the jump is not dividable by 4? (Perhaps I underestimate the problem and things are a little bit more complex, but I think something like whiles (or gotos) would greatly increase the possibilities of the code component so it could be worth the effort but I'm willing to wait;) )
P.S.: any ideas what could be wrong with the osm file above anyone?
unkargherth ·
BY looking output of asm, you could dduce that when jumps ans so onare there in a controllable , know way ( as when you call any of included functions ( rndint and so on)
Givin the user the posibility of doing manually, breaks the assumed ( by now ) rule that code can be "copypasted" when needed without touching anything on it. That's what i supose that assembler module exist but is officially unsupported
Obviously i can be totally wrong on it. I'm only making supositions
jorge ·
It would be possible to implement conditional jumps but the Code component is made for efficiency, the idea is to achieve better performance than C++. You can think of the Code component as an SSE Sound Code component while C++ is a more general language that doesnt need to extract maximum power of SSE instructions. Of course you can also use SSE with special C++ intrinsic SSE instructions but it's a lot harder than just using a prepared framework like SM. What most people do when using SSE in C++ is to process 4 consecutive values from the same channel in one go, SM takes a different approach which is to calculate 4 parallel values simultaneously, one from each channel.
In case you dont know, SSE processes 4 float values with one instruction. You cant have efficient conditional jumps because you cant process only the floats that are greater than 1.0 for example. You other process all or none.
There are efficient ways around it which you can use with the Code component. For example:
instead of:
if ( a > 1.0) a = a - 1.0;
you can use the following with the same result
a = a - ( a > 1.0) & 1.0 ;
Which reminds me of a good example in which I think you get better performance from SM than standard C++.
In the code above, ( a > 1.0 ) gets converted to a mask which you can efficiently & ( logical and ) with 1.0. In C++ you'd probably use instead ( a > 1.0 ) * 1.0 which I think has an unnecessary transparent conversion to float. Actually in C++ you'd probably use a conditional jump which would be even less efficient.
Another thing to note is that CPUs do predictions on conditional jumps to try to prefetch instructions/data that it thinks it might need later on. By not using any conditional jumps, the predictions never go wrong making the code run faster.
NothanUmber ·
Thanks for the answer, I try to give some examples in order to check if my understanding of the problem makes sense (I've never programmed any "real" sse code, so my assumptions could be entirely wrong...):
the comparison a < 1 would have to run on one separate cycle so we'd need at least two cycles even if it looks like this
while(a < 1) { (alu 1, alus 2 to 4: noop)
a=a+1; (alu 1)
(alus 2 to 4: noop)
}
so 3 alus don't have to do anything at all and we "lost" 6 otherwise possible calculations. (So a block length that is dividable by 4 is better here)
(Same case with if x then block else block constructs or gotos)
But: If we have if's and whiles and gotos like mentioned, can't one continue to write optimized code like now and only have a slowdown once one uses the new features? So we could write "linear" code whereever possible (and replace ifs with arithmetic ones like you showed above) and only use whiles and gotos where it's absolutely neccessary, on things that are not possible with the current code component. (Think of any arbitrary computable function that is not writable in a closed form or ones where such a form is much more difficult to find and understand than an iterative calculation)
NothanUmber
jorge ·
NothanUmber wrote: But: If we have if's and whiles and gotos like mentioned, can't one continue to write optimized code like now and only have a slowdown once one uses the new features?
Yes, that's very possible but efficiency has been a priority until now, maybe as SM matures conditional jumps will be included. I wonder what effect it would have on the quality of the code users create, in general they'd probably take the easy less efficient route.
NothanUmber ·
Perhaps you could only enable these features if the user writes "I'M REALLY KNOWING WHAT I'M DOING MODE = ON" and "I AM A BELIEVER" on top of his scripts and add a lengthy explanation to the docus with a multiple choice test on the end and people only get the activation code once they scored 99.5% of all reachable points and promise to obey to the first rule (you shall not have a synth making software besides SynthMaker) 😉
ake ·
If you want to know more about SSE, Intel has a rather good tutorial.
NothanUmber wrote: Perhaps you could only enable these features if the user writes "I'M REALLY KNOWING WHAT I'M DOING MODE = ON" and "I AM A BELIEVER" on top of his scripts and add a lengthy explanation to the docus with a multiple choice test on the end and people only get the activation code once they scored 99.5% of all reachable points and promise to obey to the first rule (you shall not have a synth making software besides SynthMaker) 😉
🙂 yeah. I was thinking more like you'd go to the settings menu, it would open a dialog box, there would be a button saying "advanced", you'd press the button and it would open another dialog box with 10 tabs, one of them would be for the code component where you'd see a license and disclaimer, you'd have to press accept and then there would be a progress bar, when the progress bar would get to the end another would start, after that you'd see a button saying "Next" which you'd have to press.....,
Wrote something here? To have a post removed or your name hidden, write to [email protected].