Yes (see my reply on that thread).
> In my experience with signal processing and control loops, having a
> library that implements fixed-point, fractional arithmetic with
> saturation on addition and shift-up is often faster that floating point
> _or_ "pure" integer math, and sidesteps a number of problems with both.
> It's at the cost of a learning curve with anyone using the package, but
> it works well.
>
When you add things like saturation into the mix, it gets more
complicated. That is going to be much less overhead for integer
arithmetic than for floating point (unless you have a processor that has
hardware support for floating point saturated instructions).
But yes, a well-written library is normally going to be better than
poorly written "direct" code, as well as saving you from having to get
all the little details correct (you shouldn't worry about your code
being fast until you are sure it is correct!). A lot of ready-made
libraries are not well written, however, or have other disadvantages.
I've seen libraries that were compiled without optimisation - and were
thus far slower than necessary. And many libraries are full of
hand-made assembly that is out of date, yet remains there for historic
reasons even when it now does more harm than good.
Like everything in this field, there are no simple answers.
> On all the processors I've tried it except for x86 processors, there's
> been a 3-20x speedup once I've hand-written the assembly code to do the
> computation (and that's without understanding or trying to accommodate
> any pipelines that may exist).
While x86 typically means "desktop" rather than "embedded", there are
steadily more powerful cpu's making their way into the embedded space.
I've been using some PowerPC cores recently, and see there's a large
number of factors that affect the real-world speed of the code. Often
floating point (when supported by hardware) will be faster than scaled
integer code, and C code will often be much faster than hand-written
assembly (because it is hard for the assembly programmer to track
pipelines or to make full use of the core's weirder instructions).
>
> But on the x86 -- which is the _only_ processor that I've tried it that
> had floating point -- 32-bit fractional arithmetic is slower than 64-bit
> floating point.
>
> So, yes -- whether integer (or fixed point) arithmetic is going to be
> faster than floating point depends _a lot_ on the processor. So instead
> of automatically deciding to do everything "the hard way" and feeling
> clever and virtuous thereby, you should _benchmark_ the performance of a
> code sample with floating point vs. whatever fixed-point poison you
> choose.
Absolutely.
>
> Then, even if fixed point is significantly faster, you should look at the
> time consumed by floating point and ask if it's really necessary to save
> that time: even cheapo 8-bit processors run pretty fast these days, and
> can implement fairly complex control laws at 10 or even 100Hz using
> double-precision floating point arithmetic. If floating point will do,
> fixed point is a waste of effort. And if floating point is _faster_,
> fixed point is just plain stupid.
>
It's always tempting to worry too much about speed, and work hard to get
the fastest solution. But if you've got code that works correctly, is
high quality (clear, reliable, maintainable, etc.), and runs fast enough
for the job - then you are finished. It doesn't matter if you could run
faster by switching to floating point or fixed point - good enough is
good enough.
> So, benchmark, think, make an informed decision, and then that virtuous
> glow that surrounds you after you make your decision will be earned.
>
Yes.