From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: RFC: Generic Fixed-Point IIR Filter
Date: Thu, 26 Mar 2015 15:34:21 -0500
Date: 2015-03-26T15:34:21-05:00 [thread overview]
Message-ID: <mf1qgd$2hu$1@loke.gir.dk> (raw)
In-Reply-To: 2c2ee86e-b9bd-49e3-aa7f-206f3c4da95e@googlegroups.com
"Patrick Noffke" <patrick.noffke@gmail.com> wrote in message
news:2c2ee86e-b9bd-49e3-aa7f-206f3c4da95e@googlegroups.com...
...
> How is universal_fixed (likely) implemented on a 32-bit processor?
> What happens 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 another uses all the bits for precision?
There's probably not a single implementation; the implementation likely
depends on the smalls and ranges of the input types and the output
(converting) type. (There has to be a convert-to type, universal fixed can
never stand alone.) In particular, in simple cases (where there is a clear
relationship between the small values such that scaling is an integer
operation), probably a 32-bit or 64-bit integer operation would be used. In
cases that aren't so simple, who knows? Janus/Ada falls back on floating
point in that case, because what do you do if the small of one input type is
0.3141596 and the other is 0.0025, and the small of the output is 0.0001?
Hopefully, such things don't occur in code written by people that know what
they're doing, but it's possible and the compiler has to somehow generate
code for it. At least the floating point temporaries have lots of bits
available, so you're probably going to get the right answer if possible.
Anyway, you're better off reasoning from principles. Universal fixed is not
supposed to overflow (it doesn't have a constraint), so I would expect some
sort of 64-bit implementation ultimately.
Note that this is wrong:
>It is therefore 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, despite having intermediate results which do not.
A result of universal-fixed always has to be converted immediately to
another type. It's not legal to use it directly. Specifically, 4.5.5(19.1/2)
says: "The above two fixed-fixed multiplying operators shall not be used in
a context where the expected type for the result is itself universal_fixed
".
That's so the compiler can always know how many bits are needed for the
intermediate results (in order to avoid overflow). But you'll need to figure
those out yourself (and as you noted, you can't declare them inside of the
generic).
There's a reason that fixed point is rarely used!
Randy.
Randy.
next prev parent reply other threads:[~2015-03-26 20:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-26 16:25 RFC: Generic Fixed-Point IIR Filter Patrick Noffke
2015-03-26 17:05 ` Dmitry A. Kazakov
2015-03-26 17:41 ` Jeffrey Carter
2015-03-26 19:44 ` Patrick Noffke
2015-03-26 20:34 ` Randy Brukardt [this message]
2015-03-26 20:39 ` Jeffrey Carter
2015-03-26 21:12 ` Randy Brukardt
2015-03-26 21:30 ` Patrick Noffke
2015-03-26 22:02 ` Jeffrey Carter
2015-03-27 12:17 ` G.B.
2015-03-26 21:17 ` Patrick Noffke
2015-03-26 20:37 ` Jeffrey Carter
2015-03-27 11:37 ` Brian Drummond
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox