Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!crdgw1!crdos1!davidsen From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) Newsgroups: comp.arch Subject: Re: register save Message-ID: <3241@crdos1.crd.ge.COM> Date: 11 Mar 91 21:41:20 GMT References: <1991Mar11.192116.1974@dgbt.doc.ca> Reply-To: davidsen@crdos1.crd.ge.com (bill davidsen) Organization: GE Corp R&D Center, Schenectady NY Lines: 40 In article <1991Mar11.192116.1974@dgbt.doc.ca> don@dgbt.doc.ca (Donald McLachlan) writes: | The only way I can think to generalise this would be to always | put the return address in a dedicated register. This would require that | the "call" would first push the old contents onto the stack and then | load in the new return address. The previous return info has to be saved, but not by the CALL instruction. There are lots of non-recursive languages (FORTRAN) which don't need to worry about another call and could save the return address as needed. Also, a smart compiler would fake a CALL and let the target procedure return directly to the caller when desirable.[possible. | Now that all the mechanics are out of the way (the way I see them) | only one question remains. HOW MUCH DOES THIS ACTUALLY SAVE??? | I interpret this as ... What is the ratio of calls to "leaf functions" | versus calls to "non-leaf functions"? Wish I had the time to do a few measurements. My guess is that it would be over half the calls with common coding practices, but that's pure gut feeling, so don't expect me to prove it. Any ability of the compiler to inline procedures allows more procedures to be leaf, so it will provide more benefit when optimized. I also note that some languages can pass the arguments inline in the code, using various techniques to avoid executing them. No, it doesn't require self modifying code, just an extra level of indirection (saying they're bad languages doesn't mean you can't design hardware to run them well). If you must have a pointer back to the caller in a register anyway, you can use it in the return. The world is not *exclusively* C. One nice thing about it is that it shouldn't ever have a penalty in performance... the worst case appears to be no worse than what we usually use now, and the bext case seems to save two memory accesses and two changes in the stack pointer. -- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "Most of the VAX instructions are in microcode, but halt and no-op are in hardware for efficiency"