I have written a lot of C++ code in the last year or so. The C family of languages have types that will vary in size depending on the OS and the CPU.

I thought my Macs had 32-bit CPUs because the “long” type uses 32 bits. Why would Intel sell 32-bit CPUs to Apple? I did not care for the answer.

However, my current work is very sensitive to the CPU word length. So I decided to look into the matter. Turns out that Apple is buying standard 64-bit processors from Intel. But somehow, the C compiler defaults to 32-bit binaries.

Thankfully, the fix is easy. Go from…

g++ -O2 -o test test.cpp

to…

g++ -O2 -m64 -o test test.cpp

For some code I wrote, this meant running twice as fast!

Disclaimers: 1) I have not checked whether the same thing is still true with MacOS 10.5. 2) You might encounter some difficulties if you try to link a 64-bit executable with 32-bit libraries. 3) I am not claiming that your software will run twice as fast with 64-bit words.

No Comments »

No comments yet.

Leave a comment

Warning: When entering a long comment, please ensure that you make copy of your text prior to submitting it. If the server should fail or if you hit a bug, you might lose your work. I am not responsible for your lost effort.

To spammers: I carefully review every single post and make sure that spam gets deleted. You are wasting your time if you are manually entering spam using this form. Read my terms of use to see what I consider to be abusive.

Example: duo plus septem is '9'. The numbers are expressed in latin numerals but you should give your answers using ordinary digits.

 

« Blog's main page

Powered by WordPress