Newsgroup: comp.lang.c++


Date: Wed, 26 Apr 2006 00:29:35 +0300
From: Diomidis Spinellis <dds@aueb.gr>
Organization: Athens University of Economics and Business
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.2) Gecko/20060404 SeaMonkey/1.0.1
MIME-Version: 1.0
Newsgroups: comp.lang.c++
Subject: Re: obtaining callstack level
References: <1145929379.611965.199020@t31g2000cwb.googlegroups.com> <e2kgju$60a$1@volcano1.grnet.gr> <1145969816.383741.208110@i40g2000cwc.googlegroups.com> <4b6m1oF100h6uU1@individual.net>
In-Reply-To: <4b6m1oF100h6uU1@individual.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Alf P. Steinbach wrote:
> * Michiel.Salters@tomtom.com:
>> Diomidis Spinellis wrote:
>>> seannakasone@yahoo.com wrote:
>>>> Is there a way to get the callstack level in c++?  for example, take
>>>> the following code:
>>
>>> If you're not interested in a precise number, but can accept a measure
>>> that would indicate the stack depth in bytes you can obtain the address
>>> of one of the function's plain local variables through the & operator
>>> and cast it to a char * pointer.  I've used this technique to track the
>>> use of stack space during the runtime of a program; see the snapshots at
>>> <http://www.spinellis.gr/codequality/stack.gif?clcpp>.  This technique
>>> is not portable, but will work on most computer architectures.
>>
>> The Itanium of course being one of those where it doesn't work; it has
>> two
>> stacks. C++ doesn't care; you can still implement Standard C++ on it.
>> Yet such features explain why Standard C++ doesn't have "a" callstack
>> level; it doesn't really make sense.
> 
> Although a bit off-topic, would you care to elaborate?  It's a long time 

My understanding is that the Itanium has SPARC-like register windows 
backed by a hardware assisted so-called register stack engine (RSE). 
When a function calls another arguments are placed into the general 
purpose registers Gr32-Gr128.  Through an alloc instruction the called 
function specifies the layout of its stack frame (input registers, local 
registers, and output registers).  This has the effect of mapping the 
calling function's output registers to the called function's input 
registers, and thus passing the function arguments through the registers 
without any overhead. The registers get renamed at the point of the 
call, so that all functions will always see their registers starting at 
Gr32.  When the 96 general purpose registers used for implementing the 
scheme run out, a spill will burst-write registers to the special 
register stack; later when the stack is unwound a fill will read the 
contents back from memory.

Why are two stacks needed?  My guess is that it was simpler to optimize 
the RSE hardware (for example caching or the burst mode alignment 
requirements) if the return addresses and the normal stack push/pop 
instructions didn't interfere with the register spill stack.

You can find a few more details in this article: 
http://www.intel.com/cd/ids/developer/asmo-na/eng/20314.htm?page=1

-- 
Diomidis Spinellis
Code Quality: The Open Source Perspective (Addison-Wesley 2006)
http://www.spinellis.gr/codequality?clcpp



Newsgroup comp.lang.c++ contents
Newsgroup list
Diomidis Spinellis home page

Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.