From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,b375f07e05d12c7a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-14 03:54:29 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.uni2.dk!news.net.uni-c.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: efficient vector/matrix operations in Ada Date: Tue, 14 Aug 2001 12:54:28 +0200 Organization: Centre for Chaos and Turbulence Studies, Niels Bohr Institute Message-ID: <3B790364.FE1E33FC@nbi.dk> References: <3B6F40C1.FD215D1D@sneakemail.com> <3B6F5ABC.3C40E189@sneakemail.com> <9f6e2b77.0108100854.66b084b4@posting.google.com> <3B783732.A3A1EB82@mindspring.com> NNTP-Posting-Host: alf.nbi.dk Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.net.uni-c.dk 997786469 37158 130.225.212.55 (14 Aug 2001 10:54:29 GMT) X-Complaints-To: usenet@news.net.uni-c.dk NNTP-Posting-Date: Tue, 14 Aug 2001 10:54:29 +0000 (UTC) X-Mailer: Mozilla 4.78 [en] (X11; U; OSF1 V4.0 alpha) X-Accept-Language: fo,da,no,sv,is,de,fr,en Xref: archiver1.google.com comp.lang.ada:11904 Date: 2001-08-14T12:54:28+02:00 List-Id: Russ: I haven't looked at the code generated by "my" compiler, so I will just come with some general remarks... > Larry Hazel wrote in message news:<3B783732.A3A1EB82@mindspring.com>... [...] > > Seems to me if a compiler can't generate the most efficient code for > > > > A = B + C + D > > > > or > > > > A := B + C + D > > > > in any language, you need a different compiler. It doesn't always make a large difference, but I would definitely prefer a compiler which could do the optimisation. > I'm no compiler expert, but I seriously doubt that you are correct > here. Come to think of it, I'll just say that you are flat out > wrong--and I'll eat crow if you are right. I think it is time to go hunting now... > The difference (in C++) > between > > A = B + C + D; > and > A = B; A += C; A += D; > > is more fundamental than a compiler can account for. Don't forget that > "+" and "+=" are user-defined operators to start with. The former says > to add B, C, and D, place the result in a temporary matrix, and copy > that matrix by value back into A. The latter says to copy B into A, > Add C directly to the result, then add D directly to that result. The > latter needs no temporary matrices, whereas the former requires a > temporary for each "+" operator. A special preprocessor could possibly > convert the former to the latter, but I don't see how a compiler could > possibly do it. It shouldn't be too hard for a compiler to figure out if a user-defined operator, "+", can do the calculation "A := A + B" without having to allocate an intermediate buffer (at least all the cases, where the operation is simply a loop over all elements in the composite type). If you know that, then it is pretty simple to generate the two versions of the assignment and compare their execution times. > This is all old hat in the C++ community. Ada is a great language, but > it missed the boat here. Sorry? What's the difference between: A += B; and Add (Target => A, Addend => B); (except for a few extra characters)? > By the way, if you think the arithmetic operators should be called > "+:=", "-:=", etc., I give up. When you come to the point, where this kind of optimisations are necessary, it really doesn't matter if the operators are called "+:=", ":+", "+=" or are written as a procedure call. Jacob -- http://hugin.ldraw.org/Jacob/edb/digitale_nyheder Om redakt�rens opgave p� internetnyhedstjenester.