Page 1 of 1
Help with jumping this code?
Posted: Thu Nov 12, 2015 10:34 pm
by Father
I was trying to do a little bypass on the delay cpde like this:
Code: Select all
streamin in;
streamout out;
streamin delay;
monoin bypass;
int arrayindex=0;
float memmax=44099.0;
float index=0;
float F1P0=1.0;
float mem[44100];
mov eax,bypass[0];
cmp eax,0;
jz skip;
stage2;
movaps xmm0,index;
cvtps2dq xmm0,xmm0;
movaps arrayindex,xmm0;
push eax;
mov eax,arrayindex[0];shl eax,4; fld in[0];fstp mem[eax];
mov eax,arrayindex[1];shl eax,4;add eax,4; fld in[1];fstp mem[eax];
mov eax,arrayindex[2];shl eax,4;add eax,8; fld in[2];fstp mem[eax];
mov eax,arrayindex[3];shl eax,4;add eax,12;fld in[3];fstp mem[eax];
pop eax;
stage1;
stage3;
movaps xmm0,index;
addps xmm0,F1P0;
movaps xmm1,xmm0;
cmpps xmm1,delay,1;
andps xmm0,xmm1;
minps xmm0,memmax;
movaps index,xmm0;
cvtps2dq xmm0,xmm0;
movaps arrayindex,xmm0;
push eax;
mov eax,arrayindex[0];shl eax,4; fld mem[eax];fstp out[0];
mov eax,arrayindex[1];shl eax,4;add eax,4; fld mem[eax];fstp out[1];
mov eax,arrayindex[2];shl eax,4;add eax,8; fld mem[eax];fstp out[2];
mov eax,arrayindex[3];shl eax,4;add eax,12;fld mem[eax];fstp out[3];
pop eax;
stage1;
skip:
But obviously its not right because it crashes. what it is that im doing wrong?
Re: Help with jumping this code?
Posted: Thu Nov 12, 2015 11:47 pm
by KG_is_back
The problem is, you have put the "skip:" label into another stage. put it before the "stage1;" line and it should work fine...
Re: Help with jumping this code?
Posted: Fri Nov 13, 2015 12:03 am
by Father
KG_is_back wrote:The problem is, you have put the "skip:" label into another stage. put it before the "stage1;" line and it should work fine...
Nope doesn't work. Actually i tried to place the jump and skip on different places, but the plugin crashes the FL every time (when bypass is true). This only happens with this particular code..im guessing because it has different stages..or eax register gets messed up somehow

Re: Help with jumping this code?
Posted: Fri Nov 13, 2015 12:24 am
by Father
Okay i had to use jump for each stage separately.
Code: Select all
stage2
jz skip1
.
skip1:
stage3
jz skip2
.
skip2:
I wish there was a stream selector so it could truly bypass a module or code without processing it. wouldn't it be nice?
Re: Help with jumping this code?
Posted: Fri Nov 13, 2015 12:33 am
by KG_is_back
Oh... there are multiple stages this has.... You can only jump within the same stage. In fact, the different stages get compiled to different parts of the code (they only share the variables). Flowstone streams work kind of like this:
First compiler puts together stage(0) code from all modules, in the correct order (based on links in your schematic), then the same with all other stages. On runtime, it first calls the joined stage(0) code (which effectively means all stage(0) code getx executed in all modules). Then stage1 then stage 2 etc.
If you put a jump into one stage and label into another, two things may happen:
1. on runtime, code starts to execute one stage and when it jumps it continues in second stage.
2. Since the stage code is effectively a function call, Operating system will simply not allow it to jump outside the stage and code crashes.
3. The compiler may simply not be able to compile the code, because you are effectively doing this (C code):
Code: Select all
void stage1(*variables){
... //some code
goto skip;
...//some code
}
void stage2(*variables){
...//some code
skip:
...// some code
}
That's a pretty messy code routing right there.
Stream selectors exist... simply connect the module to a selector prim... though it will cause glitches, because flowstone will have to recompile code...
Re: Help with jumping this code?
Posted: Fri Nov 13, 2015 1:20 am
by Father
I see. that makes sense. thanks for taking the time to explain it.
KG_is_back wrote:Stream selectors exist... simply connect the module to a selector prim... though it will cause glitches, because flowstone will have to recompile code...
Yes its not on the fly. I meant a selector with a stream index input so it can switch without glitch and delay. Not possible?
Could be like the If/else code you have in your compiler that executes only one of two code blocks.
Re: Help with jumping this code?
Posted: Fri Nov 13, 2015 2:15 am
by KG_is_back
The problem is much more complicated then it seems at first glance.
1.poly-compatible IF statement is very complicated, because groups of 4 streams are processed in parallel. If any one of them needs to be executed, all of them have to be. If you check the code my compiler optputs for IF statement you'll understand. to check if any channel needs to run takes about 8 instructions. And you have to modify each assignment, so that it writes to the memory only if the channel is active, which itself needs 2 xmm registers and about 5 operations per assignment. If you would like to skip someone's assembler module, which uses all 8 xmm registers at the place of assignment you're screwed.
Suppose then you want only a mono compatible selector (one that has the index part mono only), so you avoid any of above mentioned problems. You are still screwed because:
2. Suppose you have 3 modules. Module 1 has its output connected to modules 2 and 3 and each one of them has a selector after it. 4scenarios may happen. All selectors are on, so all 3 modules need to execute. First selector (the one after module 2) is off, so modules 1 and 3 need to run. Second selector is off - modules 1 and 2 need to run. Or both selectors are off, so all 3 modules should be off.
As you can see you need to jump different parts of the code, depending on the particular variation of the selectors, and every time you switch the selector you need to find which one is it. The number of variations rises exponentially with the number of selectors.
And that doesn't even take into consideration selectors, that switch order of modules, in which case, you would need to have pre-compiled code for each variation, to prevent jumping more complicated then the code it supposed to govern.
I also wasn't aware of this issue until I've tried to implement the DSP code compiler. It is one of those problems that have very simple definition, but extremely complex solution. Ever heard of "travelling salesman"-problem? This is very similar thing...