Phix: #ilasm

new topic     » topic index » view thread      » older message » newer message

Hallo,

This isn't meant to be a criticism or a complaint. It's just something I've noticed.

Phix is leisurely and slow when it comes to c_func/c_proc. That's not a problem for most applications.

But sometimes it becomes a bottleneck. That's why I followed your recommendations and came up with this solution it's certainly still far from ideal, but it's already significantly faster. But still slower than Euphoria c_func/c_proc.

constant DrawPixel_=GetProcAddress(ray,"DrawPixel") 
global procedure _DrawPixel(integer x,integer y,sequence color) 
integer col=bytes_to_int(color) 
--/**/#ilASM{  
--/**/  [64] 
--/**/      mov rcx,[x] 
--/**/      mov rdx,[y] 
--/**/      mov r8,[col] 
--/**/      sub rsp, 40                 -- Shadow Space (32) + Alignment (8) 
--/**/      mov rax,[DrawPixel_] 
--/**/      call rax 
--/**/  --  call "libraylib","DrawPixel"         -- Direkter Sprung 
--/**/      add rsp, 40 
--/**/  } 
--/* 
    c_proc(xDrawPixel,{x,y,col}) 
--*/ 
end procedure 
constant DrawPixelV_=GetProcAddress(ray,"DrawPixelV") 
global procedure _DrawPixelV(sequence pos,sequence color) 
atom reg=V2toReg(pos) 
integer col=bytes_to_int(color) 
--/**/#ilASM{  
--/**/  [64] 
--/**/      mov rax,[reg] 
--/**/      call :%pLoadMint     
--/**/      mov rcx,rax   
--/**/      mov rdx,[col] 
--/**/      sub rsp, 40                 -- Shadow Space (32) + Alignment (8) 
--/**/      mov rax,[DrawPixelV_] 
--/**/      call rax 
--/**/  --  call "libraylib","DrawPixelV"        -- Direkter Sprung 
--/**/      add rsp, 40 
--/**/  } 
--/* 
    c_proc(xDrawPixelV,{reg,col}) 
--*/ 
end procedure 

That's why I wanted to know how a C compiler does it. I was lucky DrawPixel in raylib simply calls DrawPixelV, and it looks like this:

00000001d64790ea <DrawPixel>: 
   1d64790ea:	48 83 ec 28          	sub    rsp,0x28 
   1d64790ee:	89 d0                	mov    eax,edx 
   1d64790f0:	44 89 c2             	mov    edx,r8d 
   1d64790f3:	66 0f ef c0          	pxor   xmm0,xmm0 
   1d64790f7:	f3 0f 2a c1          	cvtsi2ss xmm0,ecx 
   1d64790fb:	66 0f ef c9          	pxor   xmm1,xmm1 
   1d64790ff:	f3 0f 2a c8          	cvtsi2ss xmm1,eax 
   1d6479103:	66 0f 7e c8          	movd   eax,xmm1 
   1d6479107:	48 c1 e0 20          	shl    rax,0x20 
   1d647910b:	66 0f 7e c1          	movd   ecx,xmm0 
   1d647910f:	48 09 c1             	or     rcx,rax 
   1d6479112:	e8 c2 fd ff ff       	call   1d6478ed9 <DrawPixelV> 
   1d6479117:	90                   	nop 
   1d6479118:	48 83 c4 28          	add    rsp,0x28 
   1d647911c:	c3                   	ret     

I think there are a few assembly instructions missing in ilasm to reproduce that. Or maybe I just couldn't find them.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu