Index » D » DSP (page 2)

August 13, 2003
I suppose the obious way to specify saturation will be something like:

saturated fixed:12.14  v;

Vadim
"Sean L. Palmer" <palmer.sean@verizon.net> wrote in message
news:bhaafl$eg2$1@digitaldaemon.com...
> Excellent argument.
>
> I actually like your declaration syntax better than mine.  ;)   But I'd
like
> to remove the need for wordy signed/unsigned, by making it more like:
>
> fixed:12.24  or ufixed:8.8
>
> This is more consistent with how D handles int types.
>
> What kind of literals would it have?  Int and float literals implicitly convertible to it?  Or should there be a suffix as there is for most other numeric types?
>
> How could one specify saturation?
>
> Sean
>
> <vadim@7chips.com> wrote in message
news:bh9ns2$2r34$1@digitaldaemon.com...
> > In article <bh7dbg$8f7$1@digitaldaemon.com>, Walter says...
> > >I've done fixed point arithmetic using longs many times. The only time
it
> > >isn't a long is when you input/output it. Then just put the '.' in the
> right
> > >spot.
> >
> > Walter,
> >
> > while it is possible to do foxed point math uisng longs (or shorts) it
is
> > pretty tedious and error prone process that makes writing(and reading)
DSP
> > algorithms unnecessary defiificult.  And the generated code usually
> sucks...
> > Example (in C) using GCC
> >
> > #define FRACBITS 16
> >
> > #define FIX(v)  (int) (0.5 + (v* (1 << FRACBITS)))
> > #define ASFLOAT(v) (float) (v/(float) (1 << FRACBITS))
> > int v32 = FIX(3.2);
> > int v44 = FIX(4.4);
> >
> > int wrong;
> > int good;
> >
> > main()
> > {
> > wrong = v32*v44;
> > good = ((long long)v32*v44) >> FRACBITS;
> >
> > printf("wrong = %f  good = %f should be: %d/100\n", ASFLOAT(wrong),
> > ASFLOAT(good),  32*44) ;
> > }
> >
> > and the code generated is:
> > movl _v32, %eax
> > imull _v44, %eax
> > movl %eax, _wrong
> > movl _v44, %eax
> > imull _v32
> > shrdl $16, %edx, %eax
> > sarl $16, %edx
> > movl %eax, _good
> >
> >
> >
> >
> > in case of built in fixed point type  the compiler is able to generate
> much more
> > efficient code and correctly handle exception conditions (saturations, underflows.
> >
> > It would be really helpful to have the type like
> >
> > signed fixed:12.24  or unsigned fixed:8.8  (with conevrsions from./to
int
> and
> > float)
> >
> >
> > Vadim
>
>


1 2
Next ›   Last »