Search code examples
c++double32bit-64bit

64-bit floats compiled with 32-bit compiler on 64-bit OS


I hope this has not been covered before, but if I compile a 32-bit program in C++ that uses 64-bit floating point numbers (double), and run it on a 64-bit OS, will it still take as many clock cycles to move the 64-bit float to the CPU and back to RAM as it would on a 32-bit OS because it's compiled for 32-bit. Or would it take less clock cycles to because the OS moves in 64-bit at a time, even though the program is compiled in 32-bit compiler.

The reason I ask is because I'm using VS express which has 32-bit only, and I'm wondering if I can use 64-bit floats while maintaining speed or if 32-bit floats will be faster, even though I'm using a 64-bit OS, and trust me, the program that I want to write will use tens of thousand of floating-point numbers that will have many calculations and bitwise operations performed on them (looking into neural networks).

Thank you.


Solution

  • The 32 vs 64 bits you're hearing about is how many bits are in the address. It has little to do with how many bits are used to represent a double. In particular, 32-bit programs still represent a double in 64 bits, and modern processors have hardware that can process 64 bit floats natively (even if they can only process 32 bit integers natively).

    So to answer your question, no it shouldn't matter. The speed of floating point operations should not depend on the 32 or 64 -bitness of either the OS or the compiler.