comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Beware: Rep spec on an enumeration type causes code explosion
Date: 1997/12/12
Date: 1997-12-12T00:00:00+00:00	[thread overview]
Message-ID: <dewar.881948014@merv> (raw)
In-Reply-To: 34921C4D.4B0D@dynamite.com.au


Alan says

<<Concur. Matches my own experience exactly. Although we didn't test to
see what the performance hit would have been if we'd have used the
rep type throughout. Any experimental data on this?
>>

The experimental data would be VERY sensitive both to the compiler 
implementation and the code used.

As long as the only operations are assignments and comparisons, the use
of holey enumeration types (let's call them HETS from now on) should
be completely without additional overhead.

Loops through HETS may or may not add significant overhead. I described
the GNAT approach which reduces the overhead to a single extra load on
each loop iteration. On the other hand, one would guess from Tuck's
repeated notes to watch out for the loop case that perhaps the Intermetrics
front end does not do this particular optimization [I really don't know
whether the optimization is worth while or not, I have no data that says
it is, this is NOT a GNAT decision that was customer driven, it is just
something that seemed reasonable to me at the time when I wrote the code :-)]

Arrays indexed by HETS may or may not take a hit depending on whether they
used the POS or representation values for indexing. Both GNAT and the
Intermetrics front ends (the only ones for which I know the story) started
by using the representation values, which is the time efficient choice. But
GNAT (and I believe Intermetrics as well) were forced to switch to the
POS choice, because legacy code, particularly Verdix code, requires this.
The use of POS values is space efficient, but can introduce a significant
time penalty.

Succ and Pred values are exceedingly likely to introduce significant
overhead, and I don't see any way around this that is general (but
see below).

Finally a case statment may involve a significant penalty because it could
involve a very sparse case.

Now: what exactly is this overhead we are worrying about. It is the effort
of converting a representation value to a POS value.

What GNAT does is generate a case statement, here is an example:

   type Enum is (A,B,C);
   for Enum use (1,5,10);

this causes the generation of a routine:

      function _rep_to_pos (A : enum; F : boolean) return integer is
      begin
         case unsigned!(A) is
            when 1 =>
               return 0;
            when 5 =>
               return 1;
            when 10 =>
               return 2;
            when others =>
               if F then
                  [program_error]
               else
                  return -1;
               end if;
         end case;
      end _rep_to_pos;

How efficient the case is depends on how sparse the case is, but in any
case the optimization considerations are those that apply in any case
to a case statement. In the case where the range is fairly compact, the
case will be a simple indexed jump which is not too bad.

A nice optimzation would be to replace _rep_to_pos by an array indexed
by the representation value in cases where the range is relatively compact
(that's on my list of things to do, but I don't know what the priority is).

I really don't know what other compilers do here! But I suspect this whole
area may be quite compiler dependent, so I suggest that you benchmark your
particular usage against the compilers you are considering using, advice
that always makes sense!

Robert Dewar
Ada Core Technologies





  reply	other threads:[~1997-12-12  0:00 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-05  0:00 Beware: Rep spec on an enumeration type causes code explosion Joe Gwinn
1997-12-06  0:00 ` Ken Garlington
1997-12-06  0:00 ` Corey Minyard
1997-12-08  0:00   ` Joe Gwinn
1997-12-10  0:00     ` Robert Dewar
1997-12-06  0:00 ` Robert Dewar
1997-12-08  0:00   ` Joe Gwinn
1997-12-09  0:00     ` Stanley R. Allen
1997-12-06  0:00 ` Robert Dewar
1997-12-06  0:00 ` Robert Dewar
1997-12-06  0:00 ` Robert Dewar
1997-12-08  0:00   ` Joe Gwinn
1997-12-06  0:00 ` Kevin D. Heatwole
     [not found]   ` <dewar.881478386@merv>
1997-12-07  0:00     ` Robert Dewar
1997-12-09  0:00   ` Jim Gleason
1997-12-06  0:00 ` Tucker Taft
1997-12-06  0:00   ` Robert Dewar
1997-12-06  0:00   ` Robert Dewar
1997-12-08  0:00   ` Joe Gwinn
1997-12-08  0:00     ` Mats Weber
1997-12-09  0:00     ` Tucker Taft
1997-12-09  0:00       ` Matthew Heaney
1997-12-10  0:00         ` Charles Hixson
1997-12-10  0:00       ` Jean-Pierre Rosen
1997-12-10  0:00       ` Robert Dewar
1997-12-10  0:00       ` Stanley R. Allen
1997-12-14  0:00         ` Robert Dewar
1997-12-10  0:00       ` Stephen Leake
1997-12-14  0:00         ` Robert Dewar
1997-12-10  0:00       ` Ken Garlington
1997-12-11  0:00         ` John G. Volan
1997-12-11  0:00           ` Ken Garlington
1997-12-12  0:00             ` Matthew Heaney
1997-12-12  0:00               ` Ken Garlington
1997-12-16  0:00                 ` John G. Volan
1997-12-17  0:00                   ` Ken Garlington
1997-12-12  0:00           ` Alan E & Carmel J Brain
1997-12-12  0:00             ` Robert Dewar [this message]
1997-12-15  0:00               ` Tucker Taft
1997-12-16  0:00                 ` Brian Rogoff
1997-12-12  0:00           ` Joe Gwinn
1997-12-12  0:00             ` Robert Dewar
1997-12-16  0:00             ` John G. Volan
1997-12-17  0:00               ` Joe Gwinn
1997-12-17  0:00                 ` John G. Volan
1997-12-18  0:00                   ` Joe Gwinn
1997-12-17  0:00               ` Ken Garlington
1997-12-11  0:00       ` Rakesh Malhotra
1997-12-11  0:00         ` Matthew Heaney
1997-12-12  0:00           ` Rakesh Malhotra
1997-12-12  0:00           ` Samuel Tardieu
1997-12-12  0:00             ` Robert Dewar
1997-12-12  0:00           ` Robert Dewar
1997-12-14  0:00         ` Alan E & Carmel J Brain
1997-12-12  0:00       ` Joe Gwinn
1997-12-15  0:00         ` Robert Dewar
1997-12-16  0:00           ` Joe Gwinn
1997-12-16  0:00             ` Robert Dewar
1997-12-09  0:00     ` Geert Bosch
1997-12-10  0:00       ` Robert Dewar
1997-12-06  0:00 ` David Marshall
1997-12-06  0:00 ` Robert Dewar
1997-12-06  0:00   ` Matthew Heaney
1997-12-10  0:00   ` GNORT information ( Was Re: Beware: Rep spec on an enumeration type causes code explosion ) Mark Bennison
1997-12-10  0:00     ` Robert Dewar
1997-12-07  0:00 ` Beware: Rep spec on an enumeration type causes code explosion Larry Kilgallen
  -- strict thread matches above, loose matches on Subject: below --
1997-12-09  0:00 tmoran
1997-12-11  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-12-11  0:00 ` Robert Dewar
1997-12-11  0:00 Marin David Condic, 561.796.8997, M/S 731-96
replies disabled

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