comp.lang.ada
 help / color / mirror / Atom feed
From: Craig Carey <research@ijs.co.nz>
Subject: Re: Ada 200X
Date: Sun, 08 Jun 2003 09:16:32 +1200
Date: 2003-06-08T09:16:32+12:00	[thread overview]
Message-ID: <jvf4evgqd71kuqeoc2c2c81mdcck01g8qa@4ax.com> (raw)
In-Reply-To: slrnbdp49g.ns.lutz@taranis.iks-jena.de

On Tue, 3 Jun 2003 12:14:43 +0000 (UTC), Lutz Donnerhacke <lutz@iks-jena.de>
 wrote:

>* Preben Randhol wrote:
>> Well I wouldn't say Ada is slow. I think C would be just as slow if it
>> *had* bounds checking.
>
>No. C has to do much more checks, because the compiler can not deduce when
>the checks are not necessary.


GCC seemed faster in my tests where checking was disabled narrowly and
it was on by default. The speed difference can be under 12%. But without
the disabling of checking, GNAT Ada can easily be 30% slower.

In GNAT, checks can be enabled with the '-gnato -gnata' compiler option.

Then they can be turned off as desired using "pragma Suppress (...);",
ref RM 11-5:

   http://www.adaic.org/standards/95aarm/html/AA-11-5.html  

---

Some sample techniques for speeding up some Ada 95 programs:

* Suppressing the 'Index_Check' and 'Range_Check' checks can produce
  speed ups in numerical code. E.g. >20% speed improvement.

* Changing the types of variables from "Integer" to, say, "Positive",
"Natural", can speed up code if it reduces checking on bounds.

* Use of the "renames" statement (to rename variables) is often
worthwhile. It seems to me that use of "renames" does not slow down GNAT
code. "pragma Suppress" can slow code down. If optimizing is disabled
then "pragma Inline" can slow the final code down (but it seems unlikely
to slow down optimized GNAT code).

* I used the REDLOG Quantifier Eliminator to permit the safe adding of
 "pragma Suppress()" to a procedure that implemented a "Replace_Slice()"
for a strings package. A problem I had was the the string code in the
Charles package of Mr Heaney was too fast in comparison, which was
resolved by suppressing range checking.

      pragma Suppress (Index_Check);
      pragma Suppress (Length_Check);
      pragma Suppress (Range_Check);
      pragma Suppress (Access_Check); --  Already fast
   ...
      <<REDO_RENAME>>
      declare
         pragma Suppress (Overflow_Check);
         Str      : Vs_String renames Source.Str.all;
      begin
         if Str'Length < New_Len then
            --  Lengthen the string and alter the pointer, Source.Str
            goto REDO_RENAME;   --  Guarantee correct and rename again
         end if;

* The GNAT low level routines to process strings tend to be much faster
than user-side "for" loops subject to pragma Suppress (Index_Check,
Range_Check).

   Note: GNAT's slicing of strings is not perfected; i.e. adding
   "if .. then .. else" code to convert "S (P .. Q) := T;" and
   S := T (U .. V);", into "S := T;" can be produce a decent speed up
   for a String "Assign (L, R) procedure. (Definitely can't use ":="
   due to unexplained historic inefficiency encouraged by RM 7.6's spec
   having the missing Assign () procedure be implemented with Finalize()
   and Adjust(). 

* Turning off tag checking if tagged types are used. E.g. if dispatching
on procedures is avoided and instead "if" (or "case") statements are used:

      if X.all'Tag = A_Rec'Tag then                   --  A & no B fields
         X.all.Value := not X.all.Value;
      else
         declare          --  B_Rec case. Make visible the 2 B_Rec fields
            pragma Suppress (Tag_Check);
            B        : B_Rec renames B_Rec (X.all);   --  Both A & B fields
         begin

* Adding "pragma Inline" if optimizing enabled.

* Having arrays be on the stack and not on the heap
  ("... is array (Positive range <>) of ...") can be perhaps >=3% faster.

* When multiplying two matrices, "pragma Suppress (Index_Check);" can be
added, and the code to check the sizes of the arrays can be explicit.
Also "for K in X'Range (2) loop" could be faster than
     "for K in 1 .. X'Last (2) loop".


Craig Carey
The latest ARG considerations on reforming Ada 95:
   http://www.ada-auth.org/ai-files/REST_AIS.ZIP




  parent reply	other threads:[~2003-06-07 21:16 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-01 21:36 Ada 200X And838N
2003-06-02  2:22 ` Bobby D. Bryant
2003-06-02  4:20 ` Robert I. Eachus
2003-06-02 11:22   ` Larry Kilgallen
2003-06-02 14:09     ` Hyman Rosen
2003-06-02 14:23       ` Vinzent Hoefler
2003-06-02 14:59         ` Hyman Rosen
2003-06-02 15:04           ` Vinzent Hoefler
2003-06-02 15:18             ` Bill Findlay
2003-06-02 15:32               ` Larry Kilgallen
2003-06-02 15:41               ` Vinzent Hoefler
2003-06-02 15:07           ` Larry Kilgallen
2003-06-02 15:04         ` Larry Kilgallen
2003-06-02 14:23     ` Robert I. Eachus
2003-06-02 14:31       ` Vinzent Hoefler
2003-06-02 15:05         ` Larry Kilgallen
2003-06-02 15:06         ` Hyman Rosen
2003-06-02 21:05         ` Robert I. Eachus
2003-06-02 22:59           ` Larry Kilgallen
2003-06-03  4:07             ` Robert I. Eachus
2003-06-03  7:52           ` Jean-Pierre Rosen
2003-06-03  9:09           ` Vinzent Hoefler
2003-06-03 14:54             ` Robert I. Eachus
2003-06-04  7:38               ` Vinzent Hoefler
2003-06-05  7:20                 ` Robert I. Eachus
2003-06-02  5:36 ` Wesley Groleau
2003-06-02  8:02 ` Preben Randhol
2003-06-02 10:50 ` Georg Bauhaus
2003-06-03  2:29 ` Steve
2003-06-03  2:45 ` Gautier Write-only
2003-06-03  8:38   ` Vinzent Hoefler
2003-06-03 11:48   ` Preben Randhol
2003-06-03 12:14     ` Lutz Donnerhacke
2003-06-03 12:35       ` Preben Randhol
2003-06-07 21:16       ` Craig Carey [this message]
2003-06-08 11:14         ` Martin Dowie
2003-06-09 14:07           ` Craig Carey
2003-06-13 14:20             ` Matthew Heaney
2003-06-13 14:00         ` Matthew Heaney
2003-06-03 17:24     ` Robert A Duff
2003-06-03 17:45       ` Preben Randhol
2003-06-03 17:48         ` Preben Randhol
2003-06-03 18:05           ` Vinzent Hoefler
2003-06-04 10:36             ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
2004-10-31  1:51 David Botton
2004-10-31  7:33 ` Martin Dowie
2004-10-31 18:59   ` Jeffrey Carter
2002-12-26 16:17 Ada 200x Adrian Hoe
2002-12-27 19:32 ` Randy Brukardt
2002-12-27 20:55   ` Robert A Duff
replies disabled

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