locked
Float vs. double performance on ARM

    Question

  • I have heard from lots of sources that floats and doubles does not have any difference in computational performance on x86.

    Is the same true on ARM architecture? If I don't need the precision of a double, should I use floats in a C++ Windows Store app?

    Wednesday, January 23, 2013 9:53 AM

Answers

  • In short: For good performance in C++, use float in all cases unless you actually need double.

    The long version:

    With the legacy x87 FPU model of floating-point which has been used for most of the history of x86, the primary difference between 'float' and 'double' was the amount of memory used and data moved in and out. Generally speaking, however, even with legacy x87 floating-point there is significant performance savings using single-precision x87 modes rather than the default double-precision. This is the primary reason why the legacy Direct3D 9 API would change the FPU settings to make the x87 operate in 'single-precision' mode by default.

    With SSE/SSE2 instructions, there is no global 'mode' to change. Instead there are distinct instructions for doing single-precision vs. double-precision. In general, single-precision versions can do more work at the same time when doing SIMD-style programming (4 float at a time rather than 2 double at a time). This mode of floating-point is used whenever you compile for Windows x64, use /arch:SSE2 with x86, or when using the DirectXMath library.

    For ARM, double-precision performance varies widely. The key point is that the current generation of ARM-NEON (the ARM version of SSE/SSE2) does not support double at all. It only supports float data types. Another good reason to stick with floats.

    In addition to the computational aspects of float vs double, remember that float takes up 4 bytes of memory while double takes up 8 bytes. As such, you are moving twice the data around using double instead of float.

    With C# and JavaScript, you don't really have this level of control, but for C++ you do.

    For a longer dissertation on floating-point see the excellent series of posts from Bruce Dawson.


    Thursday, January 24, 2013 1:50 AM

All replies

  • In short: For good performance in C++, use float in all cases unless you actually need double.

    The long version:

    With the legacy x87 FPU model of floating-point which has been used for most of the history of x86, the primary difference between 'float' and 'double' was the amount of memory used and data moved in and out. Generally speaking, however, even with legacy x87 floating-point there is significant performance savings using single-precision x87 modes rather than the default double-precision. This is the primary reason why the legacy Direct3D 9 API would change the FPU settings to make the x87 operate in 'single-precision' mode by default.

    With SSE/SSE2 instructions, there is no global 'mode' to change. Instead there are distinct instructions for doing single-precision vs. double-precision. In general, single-precision versions can do more work at the same time when doing SIMD-style programming (4 float at a time rather than 2 double at a time). This mode of floating-point is used whenever you compile for Windows x64, use /arch:SSE2 with x86, or when using the DirectXMath library.

    For ARM, double-precision performance varies widely. The key point is that the current generation of ARM-NEON (the ARM version of SSE/SSE2) does not support double at all. It only supports float data types. Another good reason to stick with floats.

    In addition to the computational aspects of float vs double, remember that float takes up 4 bytes of memory while double takes up 8 bytes. As such, you are moving twice the data around using double instead of float.

    With C# and JavaScript, you don't really have this level of control, but for C++ you do.

    For a longer dissertation on floating-point see the excellent series of posts from Bruce Dawson.


    Thursday, January 24, 2013 1:50 AM
  • Thanks for the detailed explanation! (and the series of blog posts you linked is just great :))
    Thursday, January 24, 2013 8:46 AM