If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Maschine code injection (custom compiler?)
29 posts
• Page 1 of 3 • 1, 2, 3
Maschine code injection (custom compiler?)
Hi,
just played a bit with some less used assembler instructions, and discovered that FS supports "call eax". With this and the recently added memory address stuff, you can do some weird hacking
I've attached a small example that shows, how you can write machine code into a memory and let the assembler primitive execute it. That's basically how FS stream system works internally...
Don't know how usefull this is, but with some creativity, we could build our own language in FS and compile it directly to maschine code running at sample rate.
Regards
Maik
just played a bit with some less used assembler instructions, and discovered that FS supports "call eax". With this and the recently added memory address stuff, you can do some weird hacking
I've attached a small example that shows, how you can write machine code into a memory and let the assembler primitive execute it. That's basically how FS stream system works internally...
Don't know how usefull this is, but with some creativity, we could build our own language in FS and compile it directly to maschine code running at sample rate.
Regards
Maik
- Attachments
-
- Machine code (MyCo).fsm
- (2.44 KiB) Downloaded 1588 times
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Maschine code injection (custom compiler?)
MyCo wrote:Don't know how usefull this is,
A game changer, I'd say...
I remember doing some tests with the call eax; myself, but at that time I had no idea what I'm doing.
There is another thing that comes to my mind. do only FS-available opcodes work or do any opcodes work?
If any opcodes work then it should be possible to run any code. This includes external functions form DLLs. All we need to do is to mod a DLL to dump the addresses of the individual functions and we can run DLLs on streams. It will not be very efficient though if called every sample. But perhaps it can be usable for things like FFT, which is called on once in a while.
Not to mention a compiler could be done using this.
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Maschine code injection (custom compiler?)
KG_is_back wrote:do only FS-available opcodes work or do any opcodes work?
Any opcodes work, it is written completely unchanged into memory and the assembler code jumps directly into the memory and executes it as it would be a program.
Problem is managing memory for variables. You'll have to allocate some memory for em, either a separate memory or you have to add some space after your program code, and then in your code you have to give the right address. It can get very difficult to do that by hand, because you'll have to calculate addresses all the time.
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Maschine code injection (custom compiler?)
MyCo wrote:KG_is_back wrote:do only FS-available opcodes work or do any opcodes work?
Any opcodes work, it is written completely unchanged into memory and the assembler code jumps directly into the memory and executes it as it would be a program.
Problem is managing memory for variables. You'll have to allocate some memory for em, either a separate memory or you have to add some space after your program code, and then in your code you have to give the right address. It can get very difficult to do that by hand, because you'll have to calculate addresses all the time.
Not necesairly. You may simply change the ebp (base pointer) to refference the first position in memory, where variables reside. If I recall correctly variables are read form memory by address in form [ebp + integer] (at least that's what we see when you connect something to analyser prim and observe the ASM code generated by it)
It may look something like this:
- Code: Select all
//main program:
push ebx;
push eax;
mov ebx,addressOfVariables;
mov eax,addressOfCode;
call eax;
pop eax;
pop ebx;
//the called code:
push ebp;
mov ebp,ebx;
//your code
pup ebp;
ret;
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Maschine code injection (custom compiler?)
Yeah, I know that. But you have to keep the relative offsets in mind when you do that by hand. I would rather use only a single memory, and have the variable memory after the "ret" statement. That way you just have to care about one memory being valid.
Another "one memory only" option would be, to format the memory like that:
but this adds another useless jmp
Another "one memory only" option would be, to format the memory like that:
- Code: Select all
jmp code;
variable memory
code:
...
ret
but this adds another useless jmp
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Maschine code injection (custom compiler?)
I considered both aproaches you mentioned above...
"jmp" takes only one cycle and processor easily predicts it, so it's not really a big deal.
Problem with one memory is that when mem is allocated it is not necesairly 128bit aligned, which is a must for SSE instructions (this is machine specific, as proven in another topic).
Only way to produce 128bit aligned memory is either to use DLL to create it, or to keep triggering "mem create prim"/float-array-to-mem prim until the memory is 128bit aligned by random. Perhaps Ruby frame may be used for the task too.
Also, to make the thing work in poly, you'd need to have unique mem for variables for each group of 4 channels. Preferable choice would be to create array in DSPcode/assembler and send it's pointer to the code as ebp. Flowstone would then manage the memory automatically for poly. That is not possible right now, unfortunately. and also we would have to put the values into it at stage0; (which I suspect is happening anyway for variables in stream).
"jmp" takes only one cycle and processor easily predicts it, so it's not really a big deal.
Problem with one memory is that when mem is allocated it is not necesairly 128bit aligned, which is a must for SSE instructions (this is machine specific, as proven in another topic).
Only way to produce 128bit aligned memory is either to use DLL to create it, or to keep triggering "mem create prim"/float-array-to-mem prim until the memory is 128bit aligned by random. Perhaps Ruby frame may be used for the task too.
Also, to make the thing work in poly, you'd need to have unique mem for variables for each group of 4 channels. Preferable choice would be to create array in DSPcode/assembler and send it's pointer to the code as ebp. Flowstone would then manage the memory automatically for poly. That is not possible right now, unfortunately. and also we would have to put the values into it at stage0; (which I suspect is happening anyway for variables in stream).
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Maschine code injection (custom compiler?)
I have done some experiments with mem, and it is not possible to reliably produce 128bit aligned mem. I tried by creating a loop that retriggers "float array to mem" prim until its address is divisible by 8. It works like 50% times. Sometimes, the address simply oscillates between two values non-divisible by 16. Ruby frames behave in exactly the same way (I suspect they are identical to mems inside flowstone).
This may also be highly machine specific. Perhaps we should ask Malc to add optional 128bit alignment mode. Maybe a prim with boolean input, that would enable 128bit alignment vs. native alignment. This would also improve SSE processing of loaded waves.
This may also be highly machine specific. Perhaps we should ask Malc to add optional 128bit alignment mode. Maybe a prim with boolean input, that would enable 128bit alignment vs. native alignment. This would also improve SSE processing of loaded waves.
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Maschine code injection (custom compiler?)
KG_is_back wrote:I have done some experiments with mem, and it is not possible to reliably produce 128bit aligned mem. I tried by creating a loop that retriggers "float array to mem" prim until its address is divisible by 8. It works like 50% times. Sometimes, the address simply oscillates between two values non-divisible by 16. Ruby frames behave in exactly the same way (I suspect they are identical to mems inside flowstone).
This may also be highly machine specific. Perhaps we should ask Malc to add optional 128bit alignment mode. Maybe a prim with boolean input, that would enable 128bit alignment vs. native alignment. This would also improve SSE processing of loaded waves.
Hey KG, what about mem DLL that I created? Can you actually use mem that was created with DLL?
- Youlean
- Posts: 176
- Joined: Mon Jun 09, 2014 2:49 pm
Re: Maschine code injection (custom compiler?)
Youlean wrote:KG_is_back wrote:I have done some experiments with mem, and it is not possible to reliably produce 128bit aligned mem. I tried by creating a loop that retriggers "float array to mem" prim until its address is divisible by 8. It works like 50% times. Sometimes, the address simply oscillates between two values non-divisible by 16. Ruby frames behave in exactly the same way (I suspect they are identical to mems inside flowstone).
This may also be highly machine specific. Perhaps we should ask Malc to add optional 128bit alignment mode. Maybe a prim with boolean input, that would enable 128bit alignment vs. native alignment. This would also improve SSE processing of loaded waves.
Hey KG, what about mem DLL that I created? Can you actually use mem that was created with DLL?
I definitelly can... Actually I was just working on it, but I suck at C++ does your DLL produce 128bit (16byte) aligned memory?
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Maschine code injection (custom compiler?)
KG_is_back wrote:Youlean wrote:KG_is_back wrote:I have done some experiments with mem, and it is not possible to reliably produce 128bit aligned mem. I tried by creating a loop that retriggers "float array to mem" prim until its address is divisible by 8. It works like 50% times. Sometimes, the address simply oscillates between two values non-divisible by 16. Ruby frames behave in exactly the same way (I suspect they are identical to mems inside flowstone).
This may also be highly machine specific. Perhaps we should ask Malc to add optional 128bit alignment mode. Maybe a prim with boolean input, that would enable 128bit alignment vs. native alignment. This would also improve SSE processing of loaded waves.
Hey KG, what about mem DLL that I created? Can you actually use mem that was created with DLL?
I definitelly can... Actually I was just working on it, but I suck at C++ does your DLL produce 128bit (16byte) aligned memory?
I can edit it so that it does... Do you know why it actually needs to be 128bit aligned? Can this be connected to fact that different machines take different amounts of bytes to store float value?
Can you make me simple read from address in asm so I can test mem create?
- Youlean
- Posts: 176
- Joined: Mon Jun 09, 2014 2:49 pm
29 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: Google [Bot] and 32 guests