Re: using MFC VC++ - which is more efficient - float or double?



Float has other nasty implications. The results of division certainly are different, and
the cumulative error on int may be massive but nonetheless is deterministic and expected,
whereas most people don't understand the effects of cumulative error on floating point,
and for them, it is effectively nondeterministic. Think of the rancorous debates by those
who keep insisting that binary floating point should behave exactly like decimal numbers.

Also, the tests did not show how ALU pipelining works, or note that the ALU on the
machines have three units: two integer units and one floating point unit, so in principle
each clock cycle can dispatch up to three instructions; since instruction ordering is
asynchronous (with the illusion of sequentiality always maintained), blends of
instructions can create different performance. This is why fixed tests of the sort I did
may be *indicative* of behavior, but are never *definitive*; only measurement of the
actual application, working on its actual application data, compiled in release mode, can
be used to guide optimization decisions.

For example, an L2 cache miss can cost 20-100 CPU cycles. Ultimately, data access can
dominate computation, so computation speeds are often irrelevant. A page fault, by the
way, costs 20,000,000-60,000,000 CPU clock cycles, so things like copies to compact data
to reduce page spread (representing lists as arrays, for example) can pay off completely
disproportionally to their naively-perceived "inefficiency". Algorithms that maximize
cache hits can buy a factor of 10-20 improvement in performance, while reordering
statements to improve instruction flow might gain 3% on a good day.

Ultimately, the best performance gains are from architecture redesign, not lines-of-code
tweaking.
joe

On Fri, 24 Jul 2009 18:53:25 -0700, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:

So what is the takeaway from all this? Since Intel processors are widely
used by people we are selling our software to, it looks like we should still
choose integers when floating point is not needed, and not use float for
everything.

-- David


"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:96hj65l277dcedfa435ujub8ofab1ccvi2@xxxxxxxxxx
Which is why I gave detailed specifications of my CPU.
joe

On Thu, 23 Jul 2009 19:32:44 +0100, David Lowndes <DavidL@xxxxxxxxxxxxxxx>
wrote:

Now I'm very confused! My tests give quite different results. I'm
looking mostly at a debug build as I assume optimization will cloud the
results. I'm seeing on the order of 25x faster 32 bit int timing.

The results (int vs float speed) may depend on the type of processor.

Dave
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • [PATCH][PPC64] Handle altivec assist exception properly
    ... This is the PPC64 counterpart of the PPC32 Altivec assist exception ... Fortunately there are only a limited set of altivec instructions ... +static unsigned int eexp2 ... +/* Round to floating integer, ...
    (Linux-Kernel)
  • Re: Good C Question | pointer problem
    ... int main{ ... This allocates an array of 100 chars and putting the result in ptr. ... This will give you 100/sizeof (float) entries. ... You did not store any floating point values at fpor fp ...
    (comp.programming)
  • Re: static_cast<unsigned int> question...
    ... > unsigned int test2; ... This is caused by the way the float type store number internally. ... floating point value to: ... This is also the reason why comparing two floating point values with the ...
    (comp.lang.cpp)
  • Re: docs for (double) related to (int) or ???
    ... double seems to be related to int. ... No double is a commonly used term for floating point representations. ... For instance, in C, a float may use two bytes of storage, while a double could use four bytes. ... With more bits, you have higher precision. ...
    (comp.lang.php)
  • Re: 0.0 versus 0.0f
    ... You said it treats it as a float rather than an int. ... the Microsoft C compiler does not complain about ... integer or floating point. ...
    (microsoft.public.vc.mfc)

Loading