From: guerby@gnat.com (Laurent Guerby)
Subject: Re: ESP code rewritten in Ada
Date: 1996/11/05
Date: 1996-11-05T00:00:00+00:00 [thread overview]
Message-ID: <ws9iv7k6tf8.fsf@schonberg.cs.nyu.edu> (raw)
In-Reply-To: 327F5B2B.47E3@lmtas.lmco.com
>-- General-purpose low-pass filter,
>-- implementing a first-order lag.
>-- Instantiate a copy for each input
>-- such that copy has same lifetime
>-- as input.
>generic
> Shift : Positive;
> -- Gain is 2 to the negative Shift.
> -- E.g., shift => 4 implies gain = 1/16
> -- 2**Shift must fit in max precision
>
> type Signal is range <>;
> -- Signal should be at least Shift+1
> -- bits less than max precision
>
>package Filter is
> function Lag (U : Signal) return Signal;
I would add a pragma Inline here, so the generated code may look
even more competitive ;-).
>end Filter;
>
>with System;
>package body Filter is
>
> type Long is range
> System.Min_Int .. System.Max_Int;
This may drag unreasonable arithmetic on a given machine. May be
it's better to add a "base" type to the generic formal (type Long is
range <>). Or to compute the needed range:
type Long is range 0 .. 2 ** Shift;
But this may damage compiler optimization.
> X : Long := 0;
>
> function Lag (U : Signal) return Signal is
> D : constant Long := Long(2**Shift);
> begin
> X := X + Long(U) - X / D;
> return Signal (X / D);
> end Lag;
>
>end Filter;
--
Laurent Guerby <guerby@gnat.com>, Team Ada.
"Use the Source, Luke. The Source will be with you, always (GPL)."
next prev parent reply other threads:[~1996-11-05 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-11-05 0:00 ESP code rewritten in Ada Ken Garlington
1996-11-05 0:00 ` Laurent Guerby [this message]
1996-11-06 0:00 ` whiting_ms@corning.com (Matt Whiting)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox