Maschine code injection (custom compiler?)

Post any examples or modules that you want to share here
Youlean
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maschine code injection (custom compiler?)

Post by Youlean »

I am now reading the thread where this was discussed, and I must disagree that address needs to be divisible with 16. As far as I know address is just starting point of memory and whole memory will be size in bytes + address, so if you need to process SSE, you will need size of float * 4 = bytes...
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Maschine code injection (custom compiler?)

Post by KG_is_back »

Youlean wrote: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?


Because SSE operations require data to be 128bit aligned. When you declare variable in DSPcode or in Assembler, it is an SSEvariable, which is 128bit aligned by default and may be used with SSE operations.

The point of this topic is to create an alternate memory-block, which may be used instead of normal flowstone variables. For example if in your code you need SSE variable "float x=3;" you will have to convert array [3.0 , 3.0 , 3.0, 3.0] into 128bit aligned mem, to make it work. Although we can make 128bit aligned memory by making any mem and rounding its pointer up to nearest multiple of 16, we cannot initiate such array simply, as in case of "float array to mem" prim.

Can your DLL be modified to fill the mem with a provided float array?

Here is a little code that can read from mem at specific index. Note that address is expected to be in int format.

Code: Select all

streamin pointer;
streamin index;
streamout out;

mov eax,pointer[0];
cmp eax,0;
jz ErrorNoMem;

cvtps2dq xmm0,index;
pslld xmm0,2;
paddd xmm0,pointer;
movd eax,xmm0;
mov eax,[eax];
mov out[0],eax;

ErrorNoMem:

Youlean
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maschine code injection (custom compiler?)

Post by Youlean »

Hm, it seams that I can not read from address at all. I always get crash when I connect address to ASM...
Attachments
Mem Address Final 2fsm.fsm
(42.57 KiB) Downloaded 1264 times
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Maschine code injection (custom compiler?)

Post by KG_is_back »

ah, now I see the problem... You output address as integer in float format. My ASM code expects it in int format. That might be a problem overall. floats can only hold 24bit integers looslessly. If the address is bigger than 24bit integer (which can very well happen since it's a 32bit address) it will get rounded and the code might crash.

Can you somehow output a float, that has identical binary structure to the int version of the address?

otherwise, here is a fixed version of ASM that should work when address is given as integer in float format (however, it still may not work because of rounding issue):

Code: Select all

streamin pointer;
streamin index;
streamout out;
int temp=0;
cvtps2dq xmm0,pointer;
movaps temp,xmm0;
movd eax,xmm0;
cmp eax,0;
jz ErrorNoMem;

cvtps2dq xmm0,index;
pslld xmm0,2;
paddd xmm0,temp;
movd eax,xmm0;
mov eax,[eax];
mov out[0],eax;

ErrorNoMem:
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Maschine code injection (custom compiler?)

Post by tulamide »

Youlean wrote:I am now reading the thread where this was discussed, and I must disagree that address needs to be divisible with 16. As far as I know address is just starting point of memory and whole memory will be size in bytes + address, so if you need to process SSE, you will need size of float * 4 = bytes...

You are wrong. It is essential that the memory address is aligned. This is for speed reasons. Unaligned memory addresses may not work at all or are at least half as fast, if they are accepted. Here are two links that may help you and a quote:
"SSE (Streaming SIMD Extensions) defines 128-bit (16-byte) packed data types (4 of 32-bit float data) and access to data can be improved if the address of data is aligned by 16-byte; divisible evenly by 16. "

http://www.songho.ca/misc/alignment/dataalign.html
(scroll down to "Data Alignment for SSE")

https://www.aes.tu-berlin.de/fileadmin/ ... nsions.pdf
The best rule is from this paper: "An n-byte transfer must be set on an n-byte boundary."
"There lies the dog buried" (German saying translated literally)
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Maschine code injection (custom compiler?)

Post by MyCo »

The memory allocation in FS should be 128Bit aligned. I don't think we should do our own workaround, this should be done by FS internally. Otherwise it's just stupid.
Youlean
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maschine code injection (custom compiler?)

Post by Youlean »

Thanks tulamide!
I have made 128bit allocated memory. Now only problem would be address. I can output address as a float, but can ASM read float address?
Youlean
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maschine code injection (custom compiler?)

Post by Youlean »

Here is the DLL..
Attachments
Mem Adress.fsm
(201.55 KiB) Downloaded 1275 times
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Maschine code injection (custom compiler?)

Post by MyCo »

Just cast the pointer of the address (that is some type of 32Bit integer in your code) to a float pointer, something like that:

Code: Select all

int addr = memory allocation
float x = *((float*)&addr)
// write x to the frame output


Then you'll get a float in the frame output that has the binary representation of int address
Youlean
Posts: 176
Joined: Mon Jun 09, 2014 2:49 pm

Re: Maschine code injection (custom compiler?)

Post by Youlean »

MyCo wrote:Just cast the pointer of the address (that is some type of 32Bit integer in your code) to a float pointer, something like that:

Code: Select all

int addr = memory allocation
float x = *((float*)&addr)
// write x to the frame output


Then you'll get a float in the frame output that has the binary representation of int address

I was thinking of that...
Here is the dll...
Attachments
Mem Adress float out.fsm
(201.3 KiB) Downloaded 1268 times
Post Reply