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-Thread: 103376,2a34b7ad6c6a0774 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Efficiency of code generated by Ada compilers Date: Sun, 08 Aug 2010 11:49:29 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1281282553 25842 192.74.137.71 (8 Aug 2010 15:49:13 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 8 Aug 2010 15:49:13 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:X8iQXzyoV9i1i3yAhaUwzWXkc5U= Xref: g2news1.google.com comp.lang.ada:12960 Date: 2010-08-08T11:49:29-04:00 List-Id: Gene writes: > In some cases, a built-in Ada construct will generate better code than > a "hand-coded" equivalent in C++. An example I ran into recently was > incrementing a modular type. In Ada, you say I := I + 1;, and the > compiler takes care of "wrapping" to zero. In C++, I've frequently > seen people write i = (i + 1) % n; to simulate the same operation in > the absence of modular types. You will see me writing "I := (I + 1) mod N;" (for signed integer I) in Ada. ;-) >...In this case, GCC/C++ generates a div/ > mod instruction, which is very expensive. That's surprising. It wouldn't be hard to optimize the "I := (I + 1) mod N;" case (which would apply to both C and Ada). And it would be desirable, because in most cases the explicit "mod" (or "%") is more readable. - Bob