comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Use aggregates (Was: Allocation question)
Date: Tue, 12 May 2009 16:18:50 -0500
Date: 2009-05-12T16:18:50-05:00	[thread overview]
Message-ID: <gucp46$bfd$1@munin.nbi.dk> (raw)
In-Reply-To: 26af755b-0b90-429f-a688-86bf307da2b5@o20g2000vbh.googlegroups.com

"Martin" <martin.dowie@btopenworld.com> wrote in message 
news:26af755b-0b90-429f-a688-86bf307da2b5@o20g2000vbh.googlegroups.com...
>> This is not always a good idea. On some targets, GNAT places the
>> aggregate on the stack and this can raise a Storage_Error. In avionics
>> programs, I remember replacing aggregates with loops for this reason.
>
>And not just GNAT...in fact, I'm struggling to remember a compiler
>that _doesn't_ do the "large and slow (and stupid?)" aggregate for
>assignment (or initialisation).

You must have not used many Ada compilers. I known that I personally wrote 
some 6000 lines of code to handle avoiding aggregate temporaries in 
Janus/Ada, and that was done after noting that most of the other Ada 
compilers that we tried did a much better job of it. Indeed, I've very 
dubious that GNAT does not do it in most cases.

But it is important to realize that Ada's rules about what does and does not 
get modified in an assignment can prevent such an optimization. The reason I 
had to write so much code was to detect all of the cases where the 
optimization cannot be done safely (safely in an Ada sense; the original 
programmer probably wouldn't care about the different), such as assigning 
different parts of the target object, certain exception cases, and the like.

Truely simple cases, such as (others => 0) when the constraint is static 
surely always should get done, but there are a lot of cases in the grey 
areas.

In any case, Ada compiler vendors don't make their compilers worse than 
necessary for no reason. There are a lot of things that can prevent 
optimizations, they're not because the vendor is "lazy". You could optimize 
without any of the rules Ada has, but the resulting program would not have 
very predictable results. That's a big deal for safety-critical uses, and 
(for me at least) important so that I can use optimization and no worry 
about whether it is going to change the behavior of the program in an 
important way.

                         Randy.





  parent reply	other threads:[~2009-05-12 21:18 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-11 10:23 Allocation question Olivier Scalbert
2009-05-11 10:38 ` Georg Bauhaus
2009-05-11 10:40 ` Ludovic Brenta
2009-05-11 12:14   ` Olivier Scalbert
2009-05-11 12:18     ` Ludovic Brenta
2009-05-11 13:01       ` Olivier Scalbert
2009-05-11 12:26   ` Jacob Sparre Andersen
2009-05-11 13:27     ` Ludovic Brenta
2009-05-11 10:51 ` Use aggregates (Was: Allocation question) Jacob Sparre Andersen
2009-05-11 11:46   ` Olivier Scalbert
2009-05-11 12:16   ` Ludovic Brenta
2009-05-11 21:26     ` sjw
2009-05-12  5:58       ` GNAT, aggregates and efficiency (Was: Use aggregates) Jacob Sparre Andersen
2009-05-12 18:57         ` sjw
2009-05-12  7:47     ` Use aggregates (Was: Allocation question) Martin
2009-05-12 10:24       ` Brian Drummond
2009-05-12 11:07         ` Georg Bauhaus
2009-05-12 11:14           ` Georg Bauhaus
2009-05-12 21:18       ` Randy Brukardt [this message]
2009-05-13 16:38         ` Martin
2009-05-13 20:38           ` Randy Brukardt
2009-05-14 10:48             ` Martin
2009-05-12  9:13   ` Emacs Stephen Leake
2009-05-12  9:38     ` Emacs Ludovic Brenta
2009-05-12  9:46     ` Emacs Olivier Scalbert
2009-05-11 10:57 ` Allocation question Philipp Riegger
2009-05-11 12:18   ` Georg Bauhaus
2009-05-11 12:36     ` Philipp Riegger
2009-05-11 23:32 ` Brian Drummond
2009-05-12  1:09 ` tmoran
replies disabled

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