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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,51d2a071b516bbfb X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,5f2354778c35ff45,start X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Hard real-time systems Date: 1998/06/19 Message-ID: #1/1 X-Deja-AN: 364030699 References: <358510A8.5E62@dmu.ac.uk> <6m6vkp$8un@gurney.reilly.home> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.eiffel,comp.lang.ada Date: 1998-06-19T00:00:00+00:00 List-Id: 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...