register allocator questions

33 views
Skip to first unread message

Palo Marton

unread,
Dec 18, 2013, 4:04:22 PM12/18/13
to asmji...@googlegroups.com
Suppose we he 2 GPVars: A,B and one instruction:

compiler.mov(B,A);

Suppose that this is the last place where A is used and first place where B is used.

3 questions:
1) Is register allocator able to allocate both A and B to the same reigster?
2) If yes, will it prefer it?
3) If yes, will it remove this instruction from resulting assembly?

Palo

Ryan Gonzalez

unread,
Dec 18, 2013, 4:28:36 PM12/18/13
to asmji...@googlegroups.com
Using the Logger:

; Function Prototype:
;
;
; Variables:
;
; ID | Type     | Sz | Home           | Register Access   | Memory Access     |
; ---+----------+----+----------------+-------------------+-------------------+
; 0  | Gpd      | 4  | [None]         | r=1   w=0   x=0   | r=0   w=0   x=0   |
; 1  | Gpd      | 4  | [None]         | r=0   w=1   x=0   | r=0   w=0   x=0   |
;
; Modified registers (2):
; GP : rcx, rdx
; MM : 
; XMM: 

L.0:
; Prolog
push rbp
mov rbp, rsp
; Body
mov ecx, edx
L.1:
; Epilog
mov rsp, rbp
pop rbp
ret

That would be a no. If I A 0 first:

; Function Prototype:
;
;
; Variables:
;
; ID | Type     | Sz | Home           | Register Access   | Memory Access     |
; ---+----------+----+----------------+-------------------+-------------------+
; 0  | Gpd      | 4  | [None]         | r=1   w=1   x=0   | r=0   w=0   x=0   |
; 1  | Gpd      | 4  | [None]         | r=0   w=1   x=0   | r=0   w=0   x=0   |
;
; Modified registers (2):
; GP : rcx, rdx
; MM : 
; XMM: 

L.0:
; Prolog
push rbp
mov rbp, rsp
; Body
mov ecx, 0
mov edx, ecx
L.1:
; Epilog
mov rsp, rbp
pop rbp
ret

Still no.


--
 
---
You received this message because you are subscribed to the Google Groups "asmjit-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asmjit-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Ryan
When your hammer is C++, everything begins to look like a thumb.

Petr Kobalíček

unread,
Dec 18, 2013, 5:00:54 PM12/18/13
to asmji...@googlegroups.com
Hi guys,

the current version of asmjit is not capable of doing that, but I know about that problem and i'm trying to solve it in the next version that is not ready for commit yet. However, i will create special intrinsics for copying.

Best,
Petr


--
Best regards
Petr Kobalicek

Palo Marton

unread,
Dec 19, 2013, 10:28:27 AM12/19/13
to asmji...@googlegroups.com
Reason behind this question is that often I have to JIt code like this:

Y=array1[array2[X]];

You can compile it like:

GPVar TMP(c.newGP(AsmJit::VARIABLE_TYPE_GPD));
c.mov(TMP,  dword_ptr_abs(array2, X, 2));
c.mov(Y,  dword_ptr_abs(array1, TMP, 2));

or

c.mov(Y,  dword_ptr_abs(array2, X, 2));
c.mov(Y,  dword_ptr_abs(array1, Y, 2));

Second solution is a bit ugly, but at the moment it probably has better performance as it uses less registers. But if the compiler knew that it can use the same register for both Y and TMP, then both solution will be equal in performance.

p.


Dňa streda, 18. decembra 2013 23:00:54 UTC+1 petr kobalicek napísal(-a):

Petr Kobalíček

unread,
Dec 19, 2013, 11:02:10 AM12/19/13
to asmjit-dev
I think that this code will compile nicely with the new asmjit I'm working on. It does a variable liveness analysis which should very easily detect this case (because of write-only ops) and optimize.

I have the most work almost done, only function-call feature needs fixing.

--

Palo Marton

unread,
Dec 19, 2013, 11:15:10 AM12/19/13
to asmjit-dev
Wow, great! When do you expect it to be ready for testing? And will this next release include also support for immediate values as parameters of call?

It is not critical for me, as I get performance gain mostly from inlining virtual calls, replacing member access with immediate values and handling some branches at compile time instead of run time. But every small speedup is welcomed! ;-)

p.

Ryan

unread,
Dec 19, 2013, 1:01:01 PM12/19/13
to asmji...@googlegroups.com, Petr Kobalíček
Can't wait! I might do a GitHub mirror of the project, to aid those who hate subversion(like me).
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Reply all
Reply to author
Forward
0 new messages