comp.lang.ada
 help / color / mirror / Atom feed
From: adam@irvine.com
Subject: Re: Pointer Arithmetic (was: Wanted: Ada STL....)
Date: 1999/02/03
Date: 1999-02-03T00:00:00+00:00	[thread overview]
Message-ID: <798d2s$cce$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 36B78CDD.1372@lanl.gov

In article <36B78CDD.1372@lanl.gov>,
  William Clodius <wclodius@lanl.gov> wrote:

> For most machines in use the most efficient implementations of arrays is
> as a single contiguous block that is accessed by mapping indices
> directly to the equivalent pointer operations. (The exceptions are more
> easilly mapped to arrays and not to pointers.) It is true that mapping
> involving an index other than the most rapidly varying one can be
> thought of as involving a multiplication, but the same is true of the
> equivalent pointer arithmetic. In both cases the same functionality can
> be obtained by adding a (n easilly determined)  finite integer to the
> current memory index. The analysis for the compiler to do this is so
> simple, I would not be surprized if Ada Lovelace discussed it for
> Babage's machine in the 1800s.  Any compiler that does not perform that
> analysis is broken.
>
> It is sometimes thought that because it is relatively easy for the
> programmer to move some of the pointer arithmetic outside the loop, that
> pointer arithmetic is more efficient, but the algorithms necessary to
> perform that motion by the compiler have been available since the first
> Fortran compiler, ca. 1957. Any compiler that does not perform that
> analysis is a toy and not a professional system. It is more likely that
> a programmer will not perform the necessary analysis for the pointers,
> than that a compiler will not perform the analysis.

I'm not quite following everything you say.  I agree that if you're using
the index variable inside a FOR loop, it should be easy for the compiler to
optimize the index operations so that no multiplication is used, e.g.

    for I in Arr'range loop
        Do_Something_With (Arr (I));
    end loop;

But what if the operation of stepping through the array isn't so neatly
packaged?  Note that while I was talking about stepping through an array,
I never said anything about this stepping taking place inside a single loop.
It's certainly conceivable (if you have a package that declares
an iterator, for example) that the index manipulation might not even be
handled within the same subprogram call.  You might have to provide a
routine that steps to the next element of the array, then saves the index
in a global variable or an object's "work area" before the subprogram exits,
and then use the saved index the next time the subprogram is called.  It
seems to me that it would be a lot harder for a compiler to perform the
analysis required to determine that the index should be implemented with
pointer arithmetic.  Granted, when a program starts getting this complex,
it's hard for me to come up with a real-life example where the few nanoseconds
saved by avoiding multiplications would really make a difference.

				-- Adam

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




  reply	other threads:[~1999-02-03  0:00 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-31  0:00 Wanted: Ada STL. Reward: Ada's Future Alexy V Khrabrov
1999-01-31  0:00 ` Simon Wright
1999-02-01  0:00 ` Jeff Carter
1999-02-08  0:00   ` Michael F Brenner
1999-02-01  0:00 ` Matthew Heaney
1999-02-01  0:00   ` Alexy V Khrabrov
1999-02-01  0:00     ` Matthew Heaney
1999-02-01  0:00       ` Jeff Carter
1999-02-01  0:00 ` Brian Rogoff
1999-02-01  0:00   ` Ehud Lamm
1999-02-02  0:00     ` Pointer Arithmetic (was: Wanted: Ada STL....) adam
1999-02-02  0:00       ` William Clodius
1999-02-03  0:00         ` adam [this message]
1999-02-03  0:00           ` William Clodius
1999-02-03  0:00           ` Nick Roberts
1999-02-03  0:00           ` robert_dewar
1999-02-03  0:00             ` Jean-Pierre Rosen
1999-02-03  0:00       ` Nick Roberts
1999-02-03  0:00         ` robert_dewar
1999-02-03  0:00           ` Robert A Duff
1999-02-03  0:00       ` robert_dewar
1999-02-02  0:00     ` Wanted: Ada STL. Reward: Ada's Future Brian Rogoff
1999-02-02  0:00       ` robert_dewar
1999-02-04  0:00         ` Ehud Lamm
1999-02-03  0:00       ` John English
1999-02-03  0:00         ` Matthew Heaney
1999-02-03  0:00           ` Brian Rogoff
1999-02-04  0:00             ` Stephen Leake
1999-02-04  0:00               ` Brian Rogoff
1999-02-05  0:00                 ` Stephen Leake
1999-02-05  0:00                   ` Brian Rogoff
1999-02-04  0:00               ` Matthew Heaney
1999-02-04  0:00               ` Hyman Rosen
1999-02-05  0:00                 ` Stephen Leake
1999-02-05  0:00                   ` Hyman Rosen
1999-02-05  0:00               ` John English
1999-02-05  0:00                 ` Tucker Taft
1999-02-05  0:00                   ` Richard D Riehle
1999-02-05  0:00                   ` Brian Rogoff
1999-02-05  0:00                 ` Brian Rogoff
1999-02-06  0:00                   ` Matthew Heaney
1999-02-05  0:00           ` Nick Roberts
1999-02-05  0:00           ` John English
1999-02-04  0:00         ` Ehud Lamm
1999-02-04  0:00           ` Pat Rogers
1999-02-04  0:00             ` Larry Kilgallen
1999-02-04  0:00               ` Pat Rogers
1999-02-04  0:00                 ` Larry Kilgallen
1999-02-05  0:00                   ` robert_dewar
1999-02-05  0:00                     ` Tom Moran
1999-02-05  0:00                       ` dewar
1999-02-05  0:00                         ` Tom Moran
1999-02-05  0:00                           ` dewar
1999-02-05  0:00                             ` dennison
1999-02-06  0:00                               ` dewar
1999-02-08  0:00                                 ` dennison
1999-02-08  0:00                                   ` robert_dewar
1999-02-08  0:00                                     ` dennison
1999-02-09  0:00                                       ` robert_dewar
1999-02-09  0:00                                         ` dennison
1999-02-09  0:00                                     ` Nick Roberts
1999-02-07  0:00                               ` Simon Wright
1999-02-08  0:00                               ` Corey Minyard
1999-02-08  0:00                                 ` Open Source Licensing (was: Wanted: Ada STL. Reward: Ada's Future) dennison
1999-02-08  0:00                                   ` Corey Minyard
1999-02-09  0:00                                     ` dennison
1999-02-09  0:00                                       ` Corey Minyard
1999-02-09  0:00                                     ` robert_dewar
1999-02-09  0:00                                       ` Corey Minyard
1999-02-09  0:00                                 ` Wanted: Ada STL. Reward: Ada's Future robert_dewar
1999-02-09  0:00                                   ` dennison
1999-02-10  0:00                                     ` robert_dewar
1999-02-07  0:00                           ` Simon Wright
1999-02-05  0:00                     ` Larry Kilgallen
     [not found]                     ` <36ba730b.35540068@ <79fmg1$fn0$1@nnrp1.dejanews.com>
1999-02-06  0:00                       ` Larry Kilgallen
1999-02-05  0:00                 ` robert_dewar
1999-02-05  0:00               ` robert_dewar
1999-02-05  0:00                 ` Larry Kilgallen
1999-02-05  0:00                   ` robert_dewar
1999-02-05  0:00                     ` Tucker Taft
1999-02-05  0:00                     ` dennison
1999-02-05  0:00                       ` robert_dewar
1999-02-05  0:00                         ` dennison
1999-02-06  0:00                       ` Nick Roberts
     [not found]                     ` <79f24e$t14 <36BB4162.52FC6D9F@averstar.com>
1999-02-05  0:00                       ` robert_dewar
1999-02-05  0:00                       ` dennison
1999-02-04  0:00           ` Al Christians
1999-02-04  0:00           ` Brian Rogoff
1999-02-05  0:00             ` Matthew Heaney
1999-02-05  0:00               ` Brian Rogoff
1999-02-08  0:00                 ` John English
1999-02-05  0:00           ` John English
1999-02-09  0:00             ` micro_ada
1999-02-05  0:00         ` Nick Roberts
1999-02-08  0:00           ` John English
1999-02-02  0:00     ` Richard D Riehle
1999-02-03  0:00       ` robert_dewar
1999-02-01  0:00 ` dennison
1999-02-01  0:00 ` Jerry van Dijk
1999-02-01  0:00   ` Marin David Condic
1999-02-01  0:00 ` Stanley R. Allen
1999-02-05  0:00 ` Corey Minyard
replies disabled

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