comp.lang.ada
 help / color / mirror / Atom feed
* Why parameter passing by copy?
@ 2000-05-27  0:00 Dale Stanbrough
  2000-05-27  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dale Stanbrough @ 2000-05-27  0:00 UTC (permalink / raw)


Ada requires that scalars be passed by copy. I was under the impression
that this was chosen because it was faster, but i've never seen a 
rational argument for this from the Ada83 perspective of computer
hardware, nor whether such arguments still hold true for modern 
processors.

Can anyone shed any light on this?

Dale




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why parameter passing by copy?
  2000-05-27  0:00 Why parameter passing by copy? Dale Stanbrough
@ 2000-05-27  0:00 ` Robert Dewar
  2000-05-27  0:00 ` Thierry Lelegard
  2000-05-27  0:00 ` Pat Rogers
  2 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 2000-05-27  0:00 UTC (permalink / raw)


In article <dale-277623.23001027052000@news.rmit.edu.au>,
  Dale Stanbrough <dale@cs.rmit.edu.au> wrote:
> Ada requires that scalars be passed by copy. I was under the
impression
> that this was chosen because it was faster, but i've never
seen a
> rational argument for this from the Ada83 perspective of
computer
> hardware, nor whether such arguments still hold true for
modern
> processors.


It needs very little "rational argument". Fortran compilers
have known for a long time that it is more efficient on all
common architectures to pass things by copy, and that is
why Fortran allows it. Ada insisted because we decided it
was not worth having implementation dependence at this point,
since it is so clear that call by copy is more efficient.

In a modern compiler you like to keep everything in registers
where possible, so forcing call by reference would force
things into memory, never mind the unnecessary overhead of
the indirect reference. Parameters are typically passed in
registers, so if you do things right, everything is in
registers where needed, or at worst a register-register move
is needed and memory references are avoided. The desire to
avoid memory references becomes more and more important, so
the decision to pass scalars by copy makes even MORE sense
these days!

The evil efficiency effects of call by reference for small
items can be seen clearly in the awful SPARC ABI, where
small records are required to be passed by reference. We
see a significant performance degradation from this requirement,
so much so that it is tempting to just ignore the ABI here.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why parameter passing by copy?
  2000-05-27  0:00 Why parameter passing by copy? Dale Stanbrough
  2000-05-27  0:00 ` Robert Dewar
  2000-05-27  0:00 ` Thierry Lelegard
@ 2000-05-27  0:00 ` Pat Rogers
  2000-05-28  0:00   ` Robert Dewar
  2 siblings, 1 reply; 5+ messages in thread
From: Pat Rogers @ 2000-05-27  0:00 UTC (permalink / raw)


"Dale Stanbrough" <dale@cs.rmit.edu.au> wrote in message
news:dale-277623.23001027052000@news.rmit.edu.au...
> Ada requires that scalars be passed by copy. I was under the
impression
> that this was chosen because it was faster, but i've never seen a
> rational argument for this from the Ada83 perspective of computer
> hardware, nor whether such arguments still hold true for modern
> processors.
>
> Can anyone shed any light on this?

Passing things by copy precludes aliasing, which can lead to nasty
surprises.  For scalars there is no speed penalty so the language
mandates it for the safety aspect.


--
Pat Rogers                            Consulting and Training in:
http://www.classwide.com      Deadline Schedulability Analysis
progers@classwide.com        Software Fault Tolerance
(281)648-3165                       Real-Time/OO Languages






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why parameter passing by copy?
  2000-05-27  0:00 Why parameter passing by copy? Dale Stanbrough
  2000-05-27  0:00 ` Robert Dewar
@ 2000-05-27  0:00 ` Thierry Lelegard
  2000-05-27  0:00 ` Pat Rogers
  2 siblings, 0 replies; 5+ messages in thread
From: Thierry Lelegard @ 2000-05-27  0:00 UTC (permalink / raw)


> Ada requires that scalars be passed by copy. I was under the impression
> that this was chosen because it was faster, but i've never seen a 
> rational argument for this from the Ada83 perspective of computer
> hardware, nor whether such arguments still hold true for modern 
> processors.

On the contrary, it is even more true for modern processors
than for old ones.

For fast RISC processors, memory is a "slow device". Accessing
a datum in memory (passing the address) is much slower than
passing it in a register (by copy). Most calling standards for
RISC processors pass the arguments (or the first N arguments)
in registers.

________________________________________________________
Thierry Lelegard, Paris, France
E-mail: lelegard@club-internet.fr






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why parameter passing by copy?
  2000-05-27  0:00 ` Pat Rogers
@ 2000-05-28  0:00   ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 2000-05-28  0:00 UTC (permalink / raw)


In article <IKUX4.1974$Rn4.185168@nnrp3.sbc.net>,
  "Pat Rogers" <progers@NOclasswideSPAM.com> wrote:
> Passing things by copy precludes aliasing, which can lead to
> nasty
> surprises.  For scalars there is no speed penalty so the
> language
> mandates it for the safety aspect.

Actually, historically it is at least as much a concern for
efficiency. Everyone recognized that call by copy is more
efficient. It is certainly true that once you have decided
that call by copy is more efficient, it is also a nice benefit
that it is cleaner semantically.

Note that Ada is definitely concerned with efficiency over
avoiding aliasing. We can tell that with objects other than
scalars, where we accept not just call by reference, but
implementation dependence, in an effort to maximize efficiency.

Basically Ada took the same approach as Fortran in this regard.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-05-28  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-27  0:00 Why parameter passing by copy? Dale Stanbrough
2000-05-27  0:00 ` Robert Dewar
2000-05-27  0:00 ` Thierry Lelegard
2000-05-27  0:00 ` Pat Rogers
2000-05-28  0:00   ` Robert Dewar

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