Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #7815
| From | Tim Wescott <tim@seemywebsite.com> |
|---|---|
| Subject | Re: Floating point vs fixed arithmetics (signed 64-bit) |
| Newsgroups | comp.arch.embedded |
| References | <f492a14e-767b-4ed1-b889-653f2c8dc12d@pd5g2000pbc.googlegroups.com> <jdm3n7pd6aavn3cfbg5ugvl6fmbh738sdv@4ax.com> <u0o3n75ffv4gqng8qh16fdap2ugevln58q@4ax.com> <qcs3n7ponjd09bq27qgb648fnmovco9mn1@4ax.com> <P6idndrAmPpHIe_SnZ2dnUVZ7vOdnZ2d@lyse.net> |
| Message-ID | <--adnfOVp7zu1e7SnZ2dnUVZ_rWdnZ2d@web-ster.com> (permalink) |
| Date | 2012-03-28 12:20 -0500 |
On Wed, 28 Mar 2012 09:17:14 +0200, David Brown wrote: > On 27/03/2012 19:02, David T. Ashley wrote: >> On Tue, 27 Mar 2012 18:52:09 +0300, upsidedown@downunder.com wrote: >> >>> On Tue, 27 Mar 2012 11:28:18 -0400, David T. Ashley >>> <dashley@gmail.com> wrote: >>> >>> >>>> Without FPU support, assuming that the processor has basic integer >>>> multiplication instructions, integer operations are ALWAYS faster >>>> than floating-point operations. Usually _far_ faster. And always >>>> more precise. >>> >>> Floating point instructions MUL/DIV are trivial, just multiply/divide >>> the mantissa and add/sub the exponent. >>> >>> With FP add/sub you have to denormalize one operand and then normalize >>> the result, which can be quite time consuming, without sufficient HW >>> support. >>> >>> This can be really time consuming, if the HW is designed by an idiot. >> >> Your observations are valid. But I have yet to see a practical example >> of something that can be done faster and with equal accuracy in >> floating point vs. using integer operations. >> >> > It depends on the chip, the type of floating point hardware it has, the > operations you need, the compiler, and the code quality. For a lot of > heavy calculations done with integer arithmetic, you need a number of > "extra" instructions as well as the basic add, subtract, multiply and > divides. You might need shifts for scaling, mask operations, extra code > to get the signs right, etc. And the paths for these are likely to be > highly serialised, with each depending directly on the results of the > previous operation, which slows down pipelining. With hardware floating > point, you have a much simpler instruction stream, which can result in > faster throughput even if the actual latency for the calculations is the > same. > > This effect increases with the size and complexity of the processor. > Obviously it is dependent on the processor having floating point > hardware for the precision needed (single or double), but once you have > any sort of hardware floating point you should re-check all your > assumptions about speed differences. You could be wrong in either > direction. The key point is "it is dependent on the processor having floating point hardware for the precision needed". And, I might add, on other things -- see Walter Banks's comments in another sub-thread about 32-bit floating point vs. 32-bit integer math. 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. 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). 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. 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. So, benchmark, think, make an informed decision, and then that virtuous glow that surrounds you after you make your decision will be earned. -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Floating point vs fixed arithmetics (signed 64-bit) kishor <kiishor@gmail.com> - 2012-03-26 02:22 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) "Boudewijn Dijkstra" <sp4mtr4p.boudewijn@indes.com> - 2012-03-26 12:08 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) Arlet Ottens <usenet+5@c-scape.nl> - 2012-03-26 13:14 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-26 13:24 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) kishor <kiishor@gmail.com> - 2012-03-26 05:24 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) Fredrik Östman <Fredrik_Oestman@work.invalid> - 2012-03-26 12:38 +0000
Re: Floating point vs fixed arithmetics (signed 64-bit) kishor <kiishor@gmail.com> - 2012-03-26 06:33 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) Arlet Ottens <usenet+5@c-scape.nl> - 2012-03-26 15:49 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-26 15:45 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) Fredrik Östman <Fredrik_Oestman@work.invalid> - 2012-03-26 14:34 +0000
Re: Floating point vs fixed arithmetics (signed 64-bit) Arlet Ottens <usenet+5@c-scape.nl> - 2012-03-26 15:34 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.com> - 2012-03-26 12:25 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Arlet Ottens <usenet+5@c-scape.nl> - 2012-03-26 20:19 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-03-26 16:45 -0400
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.com> - 2012-03-26 17:15 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Rich Webb <bbew.ar@mapson.nozirev.ten> - 2012-03-26 19:09 -0400
Re: Floating point vs fixed arithmetics (signed 64-bit) kishor <kiishor@gmail.com> - 2012-03-27 04:59 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-27 15:25 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) David T. Ashley <dashley@gmail.com> - 2012-03-29 13:17 -0400
Re: Floating point vs fixed arithmetics (signed 64-bit) "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2012-03-27 11:28 +0100
Re: Floating point vs fixed arithmetics (signed 64-bit) David T. Ashley <dashley@gmail.com> - 2012-03-27 11:28 -0400
Re: Floating point vs fixed arithmetics (signed 64-bit) upsidedown@downunder.com - 2012-03-27 18:52 +0300
Re: Floating point vs fixed arithmetics (signed 64-bit) David T. Ashley <dashley@gmail.com> - 2012-03-27 13:02 -0400
Re: Floating point vs fixed arithmetics (signed 64-bit) Walter Banks <walter@bytecraft.com> - 2012-03-27 13:56 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.com> - 2012-03-27 14:17 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Walter Banks <walter@bytecraft.com> - 2012-03-27 15:35 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.please> - 2012-03-27 22:36 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-28 09:00 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) j.m.granville@gmail.com - 2012-03-30 04:08 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) Mark Borgerson <mborgerson@comcast.net> - 2012-04-02 22:52 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) John Devereux <john@devereux.me.uk> - 2012-04-03 11:33 +0100
Re: Floating point vs fixed arithmetics (signed 64-bit) Anders.Montonen@kapsi.spam.stop.fi.invalid - 2012-04-03 12:05 +0000
Re: Floating point vs fixed arithmetics (signed 64-bit) John Devereux <john@devereux.me.uk> - 2012-04-03 16:34 +0100
Re: Floating point vs fixed arithmetics (signed 64-bit) Paul <paul@pcserviceselectronics.co.uk> - 2012-04-04 09:35 +0100
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.com> - 2012-04-03 13:52 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Mark Borgerson <mborgerson@comcast.net> - 2012-04-04 16:50 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) John Devereux <john@devereux.me.uk> - 2012-04-05 11:48 +0100
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-28 09:17 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.com> - 2012-03-28 12:20 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Andrew Reilly <areilly---@bigpond.net.au> - 2012-03-28 22:44 +0000
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.com> - 2012-03-28 18:35 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-29 10:58 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) Mark Borgerson <mborgerson@comcast.net> - 2012-03-29 07:56 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.com> - 2012-03-29 16:52 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) Mark Borgerson <mborgerson@comcast.net> - 2012-03-29 21:19 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) Tim Wescott <tim@seemywebsite.please> - 2012-03-30 00:42 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) upsidedown@downunder.com - 2012-03-29 07:19 +0300
Re: Floating point vs fixed arithmetics (signed 64-bit) Andrew Reilly <areilly---@bigpond.net.au> - 2012-03-29 11:53 +0000
Re: Floating point vs fixed arithmetics (signed 64-bit) Walter Banks <walter@bytecraft.com> - 2012-03-29 09:40 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) upsidedown@downunder.com - 2012-03-29 23:46 +0300
Re: Floating point vs fixed arithmetics (signed 64-bit) Walter Banks <walter@bytecraft.com> - 2012-03-29 09:28 -0500
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-29 16:58 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) David Brown <david@westcontrol.removethisbit.com> - 2012-03-29 10:09 +0200
Re: Floating point vs fixed arithmetics (signed 64-bit) Clifford Heath <cjh@no.spam.please.net> - 2012-04-01 18:08 +1000
Re: Floating point vs fixed arithmetics (signed 64-bit) dp <dp@tgi-sci.com> - 2012-03-28 02:38 -0700
Re: Floating point vs fixed arithmetics (signed 64-bit) upsidedown@downunder.com - 2012-03-28 22:59 +0300
csiph-web