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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.50.103.41 with SMTP id ft9mr31221560igb.3.1427399081552; Thu, 26 Mar 2015 12:44:41 -0700 (PDT) X-Received: by 10.182.137.195 with SMTP id qk3mr170381obb.38.1427399081465; Thu, 26 Mar 2015 12:44:41 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!z20no3598102igj.0!news-out.google.com!qk8ni265igc.0!nntp.google.com!z20no625213igj.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 26 Mar 2015 12:44:41 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=74.203.194.21; posting-account=bXcJoAoAAAAWI5APBG37o4XwnD4kTuQQ NNTP-Posting-Host: 74.203.194.21 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2c2ee86e-b9bd-49e3-aa7f-206f3c4da95e@googlegroups.com> Subject: Re: RFC: Generic Fixed-Point IIR Filter From: Patrick Noffke Injection-Date: Thu, 26 Mar 2015 19:44:41 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:25268 Date: 2015-03-26T12:44:41-07:00 List-Id: On Thursday, March 26, 2015 at 12:41:29 PM UTC-5, Jeffrey Carter wrote: > On 03/26/2015 09:25 AM, Patrick Noffke wrote: >=20 > All generic formal parameters are non-static. As to a non-static type con= sider >=20 > generic -- P > type T is range <>; > package P is ... >=20 > and then >=20 > function Input return Natural; > -- Obtains a value of subtype Natural from the user >=20 > ... >=20 > subtype U is Integer range 1 .. Input; >=20 > package Q is new P (T =3D> U); >=20 > Clearly subtype U is non-static, and so formal type T is also non-static. >=20 I didn't know you could do this. Thanks. > >=20 > > - If I try to use Fixed_Type for X_Array and Y_Array, then I do in fac= t get a constraint error (due to range overflow for an intermediate calcula= tion). Is there a better way to do a calculation for a fixed-point type wh= en you expect the result to be within the specified range of Fixed_Type, bu= t intermediate calculations may not? >=20 > All your problems result from suffixing type names with _Type :) >=20 I should have known! :-) > I refer you to ARM 4.5.5, specifically =B618-19. Multiplication and divis= ion > between fixed-point values gives results of type universal_fixed, which i= s > implicitly convertible to any fixed-point type. When you write >=20 > Filter.Y_Array (1) :=3D Filter.B (1) * X; >=20 > you are multiplying a Filter_Value_Type * Fixed_Type yielding universal_f= ixed, How is universal_fixed (likely) implemented on a 32-bit processor? What ha= ppens if you multiply two fixed-point types that use all 32-bits for range = and precision? What if one type uses all the bits for the range and anothe= r uses all the bits for precision? I'm targeting an ARM Cortex-M4 processor, but writing test code on an x86_6= 4 PC. In my test code with FSF GNAT, I noticed from a hex print of a Press= ure_Type variable that only the minimum number of bits were used (as I unde= rstand it, with Ada 95 and later, small *could* be smaller than the maximum= allowable small). I know the M4 processor has the SMULL instruction (Signed Multiply (32x32),= 64-bit result) and similar instructions, but I don't yet know if the compi= ler is using these for universal_fixed. > which is then implicitly converted to the type of the LHS, Filter_Value_T= ype. > Your exceptions result from attempting to convert intermediate results to > Fixed_Type, which lacks the range needed to hold the values. It is theref= ore > sometimes possible to avoid the 2nd type if all calculations can be done = in a > single expression which yields a value that fits in the smaller type, des= pite > having intermediate results which do not. That doesn't seem to be case fo= r your > problem, though. >=20 True, for the generic package. But I really only need a 2nd order filter f= or my application, so I should be able to do: Filter.Y_Array (1) :=3D (Filter.B (1) * X (1) + Filter.B (2) * X (2) + Filt= er.B (3) * X (3) - Filter.A (2) * Filter.Y_Array (2) - Filter.A (3) * Filte= r.Y_Array (3)) / Filter.A (1); Then every product is universal_fixed, so the sum is universal_fixed, and i= mplicitly converted to the LHS type. But again, I'd like to know what is h= appening under the hood to implement this. > Some comments on your implementation: >=20 Thank you for those. I will address the issues you point out. Patrick