Software Archive
Read-only legacy content
17061 Discussions

Using a register to return from a procedure

manhattan95
Beginner
214 Views

With the increase in the number of registers, I was wondering if using a register to return from a procedure was a good idea to improve performance. Instead of using the call instruction to push the return address on the stack and call the procedure, the address is written in a register and the procedure is entered with a jump.

Code:
call Procedure

Procedure:
; code...
ret

replaced by

lea return_register, ReturnAdress
jmp Procedure
ReturnAdress:

Procedure:
; code...
jmp return_register

What do you think of this approach ?

0 Kudos
2 Replies
Intel_Software_Netw1
214 Views
We are forwarding your question to our engineering contacts and will let you know how they respond.
Regards,

Lexi S.

IntelSoftware NetworkSupport

http://www.intel.com/software

Contact us

Message Edited by intel.software.network.support on 12-02-2005 01:10 PM

0 Kudos
Intel_Software_Netw1
214 Views

Our engineers responded as follows:

Placing the return address in a register instead of the stack is an excellent idea. This technique would definitely increase performance by reducing the number of memory references when jumping to and from procedures. In fact, the Itanium 2 processor employs exactly such a technique, with eight registers reserved for destination addresses.

For IA-32, this would be extremely difficult to implement because of the requirement to support legacy code. Previously written programs must still execute correctly on newer processors, so this approach would require completely new call and return instructions as well as reserving a register for storing the return address. Because registers in IA-32 are few in number, programmers can typically realize a greater performance improvement by using the available registers to hold data values instead of a return address. This allows them to save multiple memory accesses during the course of a procedure instead of just two for call and return.


The Itanium 2 processor has 128 general purpose integer registers and has the luxury of being able to dedicate eight more registers to pointer addresses. The IA-32 processor architecture, however, with only 8 or 16 available registers, can realize better performance by keeping its registers as general purpose data stores.

==

Regards,

Lexi S.

IntelSoftware NetworkSupport

http://www.intel.com/software

Contact us

Message Edited by intel.software.network.support on 12-02-2005 01:10 PM

0 Kudos
Reply