Archived

This topic is now archived and is closed to further replies.

Speed: 64-bit vs. 32-bit INTs

This topic is 5375 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Which INTs are faster to do mathematical calculations on, 32 or 64-bit? As far as I know, Pentiums are 32-bit processors with 64-bit data bus. Which leads me to believe that 32-bit ints are faster, since all registers are 32-bit. I have no idea how ALU deals with 64-bit ints so I need clarification on this issue.

Share this post


Link to post
Share on other sites
If you are using C or C++, use the ''int'' data type. The standard says ''int'' must be defined as the native type of the processor which will always be the fastest. Operations on 64 bit numbers are emulated on 32 bit machines and are thus much slower (for ex, iirc, a multiply or add takes 4 instructions for 64 bit data vs only 1 for 32 bit daya)

Share this post


Link to post
Share on other sites
id say which one you use depends on how large of a number you need... if youre not doing anything where you expect ginormous numbers then a regular int would be more than adequate. but if for some reason you need a number as large as 18,446,744,073,709,551,615 (2 to the 64th) then yeah youll need a 64 bit int... personaly i stay away from them tho, ive had trouble getting them to work with functions that need 32 bit integers =/ and Extrarius is right, a 64 bit int is definately slower. but like i said, sometimes you need ints that big...

Share this post


Link to post
Share on other sites
If its for RDTSC, you should probably use the full 64 bit counter so your code doesn''t break when computers get REALLY fast. Make it easier on yourself to support ''legacy code'' 70 years from now =-)

If its milisecond-level accuracy then 32 bit should be fine.

Share this post


Link to post
Share on other sites
Normal emulation of 64 bit ops:
addition/subtraction: 2 instructions (add, adc / sub, sbb)
shift: 2 instructions (shld, shl)
multiplication: if |operands| <= 32 bit, 1 instruction (although higher latency for MSW)

You can also use the FPU: no speed loss for 64 bit ints, but it may be clumsy to use, depending on algo.

Finally, if you have SSE2 support, it''s all good - you can do 2 64 bit ops in one instruction.

Share this post


Link to post
Share on other sites
quote:
Original post by Extrarius
If you are using C or C++, use the 'int' data type. The standard says 'int' must be defined as the native type of the processor which will always be the fastest. Operations on 64 bit numbers are emulated on 32 bit machines and are thus much slower (for ex, iirc, a multiply or add takes 4 instructions for 64 bit data vs only 1 for 32 bit daya)


I hate when people say stuff like that. No, it will not ALWAYS be the fastest. 16-bit variables can easily be faster, because it can go through the memory bus faster (can send 4 at a time over a 64-bit bus), and we all know that the memory interface is MUCH slower than the CPU. We also know that 16-bit variables are calculated JUST AS FAST as 32-bit, so, worst case scenario.. it's equally fast, and best case, it can be up to almost 2x as fast! (ok, some VERY hard to produce cases, the 32-bit data type "could" be faster if you're converting between data types a lot with 16-bit data types, like, if you have all int's, and one short, you won't see any benefits, but if you used all shorts, you would). Just because it's the default data type, doesn't necessarily mean it's the fastest. Take the new amd hammer CPU's for example... 64-bit data type, BUT, they can (in certain cases) perform 2 32-bit instructions in parallel, while the same 64-bit op only does a single instruction. This can lead to a much improved 32-bit performance, even OVER the default data type. My point? Just because something is default, doesn't make it better than everything else, especially in this case.


--- Edit ---
Just wanted to state, that yes, 32-bit will be faster than 64-bit in most cases, especially on a 32-bit cpu.

[edited by - Ready4Dis on March 25, 2003 10:30:36 AM]

Share this post


Link to post
Share on other sites