comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier <Gautier.deMontmollin@maths.unine.ch>
Subject: Re: Matrix Multiplication
Date: 1999/12/15
Date: 1999-12-15T00:00:00+00:00	[thread overview]
Message-ID: <385811F7.F3FFEB06@maths.unine.ch> (raw)
In-Reply-To: 3857D640.C1991F0C@quadruscorp.com

> It would seem that if the compiler were smart, it would compute I and J
> once and find the position once, then reuse it throughout the loop.

GNAT does reuse adresses. A bright proof in c.l.a (by Samuel Tardieu):

<< [a(b(c,d+e(f,g)).h(i,j)) :=  a(b(c,d+e(f,g)).h(i,j)) + 1;]

Where did you get the impression that the optimizer would miss this? 
 For example, using GNAT, the following expression generates: (ix86 code) 
                           
 t__pXb: movl t__jXb,%edx                             |
         decl %edx                                    |
         movl t__iXb,%eax                             |
         decl %eax                                    |
         leal (%eax,%eax,4),%eax                      |
         sall $3,%eax                                 |
         leal (%eax,%edx,4),%edx                      |
         movl t__gXb,%ecx                             |
         decl %ecx                                    | Address computation
         movl t__fXb,%eax                             |
         decl %eax                                    |
         leal (%eax,%eax,4),%eax                      |
         sall $3,%eax                                 |
         movl t__eXb(%eax,%ecx,4),%eax                |
         addl t__dXb,%eax                             |
         imull $400,%eax,%eax                         |
         leal -400(%edx,%eax),%eax                    |
         imull $4000,t__cXb,%edx                      |
         movl t__bXb-4000(%eax,%edx),%eax             |
         decl %eax                                    |
         incl t__aXb(,%eax,4)            <--- Increment done here!
         ret
                           
 The code used to generate this was: (-O3 -fomit-frame-pointer -gnatp) 
                           
 package T is
   pragma Elaborate_Body;
 end T;
                           
 package body T is
   pragma Warnings (Off); -- Uninitialized variables
                           
   type Two_Ints is array (Integer range <>, Integer range <>) of Integer; 
                           
   type Rec is record
     H : Two_Ints (1 .. 10, 1 .. 10);
   end record;
                           
   type Two_Recs is array (Integer range <>, Integer range <>) of Rec; 
                           
   A : array (1 .. 10) of Integer;
   B : Two_Recs (1 .. 10, 1 .. 10);
   C : Integer;
   D : Integer;
   E : Two_Ints (1 .. 10, 1 .. 10);
   F : Integer;
   G : Integer;
   I : Integer;
   J : Integer;
                           
   procedure P is
     begin
       a(b(c,d+e(f,g)).h(i,j)) :=  a(b(c,d+e(f,g)).h(i,j)) + 1;
     end P;
                           
 end T;

>>

But there are *rare* cases where such "invariants" are not provable as such,
and a renames helps, even with GNAT. On the other side, some Ada 83 compilers
do not seem to optimize these things (Compaq Ada, Alsys).

-- 
Gautier

_____\\________________\_______\_________
http://members.xoom.com/gdemont/gsoft.htm




  parent reply	other threads:[~1999-12-15  0:00 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-14  0:00 Matrix Multiplication William Dale
1999-12-14  0:00 ` David C. Hoos, Sr.
1999-12-14  0:00 ` Gautier
1999-12-15  0:00   ` Gautier
     [not found]   ` <5l1f5s4kck891a2s6o8bhvkirm4q79hm6c@4ax.com>
1999-12-15  0:00     ` Gautier
1999-12-15  0:00       ` Marin D. Condic
1999-12-15  0:00         ` Ted Dennison
1999-12-15  0:00           ` Gautier
1999-12-15  0:00             ` Tucker Taft
1999-12-16  0:00             ` Ted Dennison
1999-12-16  0:00             ` Ted Dennison
1999-12-15  0:00         ` Gautier [this message]
1999-12-16  0:00           ` Marin D. Condic
1999-12-27  0:00             ` Jeffrey L Straszheim
     [not found] ` <01bf4708$99ef98f0$022a6282@dieppe>
1999-12-15  0:00   ` Gautier
1999-12-15  0:00   ` Robert A Duff
1999-12-15  0:00     ` Marin D. Condic
1999-12-16  0:00     ` Pascal Obry
1999-12-16  0:00       ` Greg Martin
1999-12-16  0:00       ` Brian Rogoff
1999-12-16  0:00     ` Dieter Britz
1999-12-15  0:00 ` Ted Dennison
1999-12-15  0:00   ` William B. Clodius
1999-12-15  0:00     ` Ted Dennison
1999-12-15  0:00       ` William B. Clodius
1999-12-16  0:00         ` Robert A Duff
1999-12-16  0:00           ` William B. Clodius
1999-12-15  0:00 ` E. Robert Tisdale
     [not found]   ` <3856FD3F.8291A71C@ucar.edu>
1999-12-15  0:00     ` E. Robert Tisdale
1999-12-14  0:00       ` Richard Maine
1999-12-15  0:00 ` Greg Lindahl
1999-12-15  0:00   ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
1999-12-15  0:00 Carlisle, Martin
1999-12-15  0:00 ` Mario Klebsch
1999-12-19  0:00   ` Robert Dewar
1999-12-19  0:00 ` Robert Dewar
1999-12-19  0:00 ` Robert Dewar
1999-12-16  0:00 Carlisle, Martin
1999-12-16  0:00 ` Howard W. LUDWIG
     [not found] <637de084-0e71-4077-a1c5-fc4200cad3cf@googlegroups.com>
2012-07-10  8:39 ` Does Ada need elemental functions to make it suitable for scientific work? Nasser M. Abbasi
2012-07-10  9:07   ` Dmitry A. Kazakov
2012-07-12  0:31     ` robin.vowels
2012-07-12  7:12       ` Dmitry A. Kazakov
2012-07-29 13:39         ` Robin Vowels
2012-07-29 14:22           ` Dmitry A. Kazakov
2012-07-29 20:54             ` glen herrmannsfeldt
     [not found]               ` <apib1897s56dkultqmfl3emvk1os3tfdak@invalid.netcom.com>
2012-07-30  4:15                 ` glen herrmannsfeldt
     [not found]                   ` <nfhd181tv9u87mcqfb7rgd8lm48ihr9f4r@invalid.netcom.com>
2012-07-31  8:53                     ` MATRIX MULTIPLICATION Robin Vowels
2012-07-31  9:05                       ` Robin Vowels
replies disabled

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