On 15/05/13 08:30, A.P. Horst wrote:
> 
> On 15-5-2013 0:31, Paul Sokolovsky wrote:
>> Hello,
>>
>> On Wed, 15 May 2013 09:35:14 +1200
>> Daniel Beer <dlb...@gmail.com> wrote:
>>
>>> On Tue, May 14, 2013 at 09:26:46PM +0300, Paul Sokolovsky wrote:
>>>> More interesting question is such support for static (if not global)
>>>> variables. When trying to do Elliptic Curve Cryptography on MSP430
>>>> value line devices which top up at 0.5K RAM, you really wish that
>>>> compiler could "pack" together static buffers of functions which
>>>> cannot be active at the same time ;-). If anyone know of that to be
>>>> done by gcc, would be nice to get some pointers.
>>> If you have static buffers which are never in use simultaneously, why
>>> not keep them together in a union { }?
>> Yes, the talk was about offloading the work of proving
>> non-simultaneous access constraints and creation of that union to the
>> compiler ;-). Shouldn't be hard for the case of scalar static variables
>> (function-local dataflow analysis and interprocedural control flow
>> analysis), so I wondered if someone knows it to be implemented. To be
>> really useful this should be applied to structural/array vars though,
>> and that's much harder.
>>
> 
> This would be absolutely impossible because the compiler is generally 
> unaware of it's environment. If the application is run on a preemptive 
> scheduling operating system, then such schemes could go horribly wrong. 
> Of course, you could protect the memory with a mutex, but this would 
> defeat the purpose of easy optimization. Anyway, if you really want it I 
> think it is best done via an explicit way with unions such that it is 
> clear what is being shared, and it compatible amongst compilers.
> 
> Arie
> 

The general case is impossible (since it reduces to the halting
problem), and even without pre-emption it is impractical to get optimal
results (since it would take exponential time).  However, for many
practical situations it /is/ possible to do quite a good job.  In
particular, whole-program optimisation and heavy use of "static" can
help the compiler determine when different variables are in use.

gcc does not do this sort of analysis and global data reuse, but some
embedded compilers /do/.  In particular, some of the more high-end
compilers for very small microcontrollers (Keil's 8051 compiler and
ByteCraft's compilers being examples) do exactly this sort of analysis.
 For these chips, stacks are impractical due to the lack of useful
addressing modes, so function parameters, return values, and local
variables all end up in fixed locations in ram (unless functions are
re-entrant - in which case a stack is needed giving a huge performance
hit).  This sort of global lifetime analysis is essential to reduce the
ram usage.

For more general code on more sensible processors, such as the msp430,
it would be hard to make such analysis algorithms that always work, run
in a sensible amount of time, and give you a significant benefit for the
effort.



------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to