comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Hard real-time systems
Date: 1998/06/19
Date: 1998-06-19T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.98Jun18200604@spectre.mitre.org> (raw)
In-Reply-To: 6m6vkp$8un@gurney.reilly.home


In article <6m6vkp$8un@gurney.reilly.home> reilly@zeta.org.au (Andrew Reilly) writes:

 > A question for the Ada camp: does Ada let you deal with the
 > notion of an accumulator that is wider than the source operands?
 > For example, the natural DSP operation a = a + x1 * y1 on the
 > 56k has x1 and y1 of the type described above, but a is a 56-bit
 > variable in the range [-256,256-2^{-47}].  Also, the natural
 > conversion from a to 24-bit quantity produces saturation on
 > overflow.  Are there any high-level languages with types that
 > can do that?  Maybe that's not a language issue.

   Ada naturally supports the first class of operations.  For fixed
point types, the language defined fixed * fixed --> fixed and fixed /
fixed --> fixed operations return an unbounded type which must be
converted to some (bounded) numeric type.  So if you write:
 
procedure fixed56 is
 
    type Fixed_56 is delta 2.0**(-47) range -256.0..256.0;
    type Fixed_24 is delta 2.0**(-23) range -1.0..1.0;
    type Vector is array(Integer range <>) of Fixed_24;

    A: Fixed_56 := 0.0;
    X, Y: Vector(1..100) := (others => 0.5);

   begin 

    for I in X'Range loop
      A := A + X(I) * Y(I);
    end loop;
    
end fixed56;

    On a compiler targeted to that chip, you should get the very
efficient code you expect.  BUT, and this is the nice thing about Ada,
I just compiled that on a Sun to check that the code was correct.  It
won't be very efficient on some older Suns, but it will still give the
same answers.

    Now to the, for Ada, tougher question.  Saturating types can be
supported easily for integer and floating types, but for fixed point
types, you need compiler support for non-standard fixed-point types,
or you have to use non-standard syntax for some of the saturating
operations.  The saturating conversion would best be provided as a
compiler defined operation.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




       reply	other threads:[~1998-06-19  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <358510A8.5E62@dmu.ac.uk>
     [not found] ` <EuMMDF.7rM@syd.csa.com.au>
     [not found]   ` <EunACp.E1H@ecf.toronto.edu>
     [not found]     ` <6m6vkp$8un@gurney.reilly.home>
1998-06-19  0:00       ` Robert I. Eachus [this message]
1998-06-19  0:00         ` Hard real-time systems Mats Weber
1998-06-19  0:00           ` Saturated Arithmetic Markus Kuhn
replies disabled

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