comp.lang.ada
 help / color / mirror / Atom feed
From: "Stuart" <stuart@0.0>
Subject: Re: Stackusage at runtime
Date: Tue, 4 Nov 2008 15:40:46 -0000
Date: 2008-11-04T15:40:46+00:00	[thread overview]
Message-ID: <491068b1$1_1@glkas0286.greenlnk.net> (raw)
In-Reply-To: bf764407-9606-4ee4-aa22-cbb6d00dd84c@d36g2000prf.googlegroups.com

<andi.vontobel@gmx.ch> wrote in message 
news:bf764407-9606-4ee4-aa22-cbb6d00dd84c@d36g2000prf.googlegroups.com...

> Is it possible to figure out how much of the stack is used at a
> specific moment?
> -> Ada95 Crosscompiler to PPC
> (It is a little bit hard to optimize the stacksize ...)

Compare the value of the stack pointer to its base value!

For a PowerPC it is very likely that the code will be conforming to the 
Embedded Application Binary Interface (EABI), so the stack pointer will be 
register r1 (aka gpr1).  Reading this will require a bit of machine code - 
either use package machine code or call out to an assembler routine 
depending on how 'pure' you want to be.

Making this a subprogram would allow you to quickly find the stack pointer 
value anywhere in your program.  Depending on what you actually need you 
might need to make adjustments for the stack frame of the subprogram 
returning the value (but I would suspect this is quite small and the 
discrepancy introduced to be of minimal interest if you are optimizing the 
programme).

The base value of the stack is often defined by a symbol (you will need to 
check your compiler's documentation) though take care as to whether you need 
the address represented by the symbol or the value at that address (in my 
experience it is usually the former).

As a pedagogical point - the Ada language does not really define what the 
stack (if any) is used for, so your results may not be universally 
applicable (but I suspect that is not a significant concern).

-- 
Stuart






  parent reply	other threads:[~2008-11-04 15:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04  7:55 Stackusage at runtime andi.vontobel
2008-11-04 11:44 ` Georg Bauhaus
2008-11-04 12:56   ` Andy
2008-11-04 15:40 ` Stuart [this message]
2008-11-04 19:05   ` Andi
2008-11-04 20:44     ` Niklas Holsti
2008-11-05 18:50     ` Niklas Holsti
2008-11-04 19:41 ` Yes it is possible. " anon
2008-11-05  9:31   ` Ludovic Brenta
2008-11-05 21:55     ` anon
2008-11-05 23:07       ` Ludovic Brenta
2008-11-06  5:00         ` anon
2008-11-06 10:17           ` Georg Bauhaus
2008-11-06 18:18         ` Pascal Obry
2008-11-07 10:19           ` Georg Bauhaus
2008-11-07 11:58           ` anon
2008-11-04 20:07 ` Per Sandberg
2008-11-05  7:33   ` Andy
2008-11-05 16:50     ` Per Sandberg
2008-11-05 17:31       ` Jean-Pierre Rosen
2008-11-05 18:19         ` Keith Thompson
2008-11-05 21:38   ` nobody
2008-11-05 20:14 ` sjw
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox