flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Using rip relative addressing for branch optimations

Author
Thread Post new topic Reply to topic
Mat



Joined: 30 Sep 2008
Posts: 11
Mat
Hello,

I want to replace the following code chema:
Code:
call $+n
pop r12
add r12, n
    

with something like:
Code:
mov r12,rip+n
    

for using r12 as link register instead of pushing return addresses onto the stack. But it seems, RIP relative addressing is bound to indirect load or store operations and I need the content of RIP + index instead.

Is that possible ?

-Mat.

_________________
make it yourself or you screwed !
Post 06 Jan 2010, 14:47
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3041
Location: vpcmipstrm
bitRAKE
LEA gets the address, MOV gets the content at address, but your words seem to indicate you need something like?
Code:
mov r12,[rip+n]
mov r12,[r12]    
When POP R12 occurs I'm not sure what is on the stack - code is too vague.
Post 06 Jan 2010, 15:08
View user's profile Send private message Visit poster's website Reply with quote
Mat



Joined: 30 Sep 2008
Posts: 11
Mat
thanks, the solution was
Code:
mov rdx, address
lea r12,[rip+2]
jmp rdx
    

return is then simply:
Code:
jmp r12
    

the extra mov was necessary because I handle with 64 bit linear addresses (and the call routine can be mapped above 4 GB theoretically).

-Mat.
Post 06 Jan 2010, 15:15
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3041
Location: vpcmipstrm
bitRAKE
Any routine which gets called more than once would benefit (in terms of code size and cache useage) from a vector table:
Code:
Table:
...
dq address
...

   lea r12,[rip+6]
     jmp qword [rip+index]    
Of course, this doesn't effect the return, and also adds flexiblity to change the destination across the code base by changing a single address.
Post 07 Jan 2010, 03:09
View user's profile Send private message Visit poster's website Reply with quote
Mat



Joined: 30 Sep 2008
Posts: 11
Mat
I know and using these technique for token-threading interpreters (Forth) but this time the target is an JIT compiler which generates native code (again Forth) so because code addresses are only known at compile time the only sense for it would be something like an address cache and this wouldn't be worth the effort.

Regards,
Mat.
Post 08 Jan 2010, 19:15
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.