Reputation: 33827
I have 64-bit machine, and some set of data in range -32000 : 32000, so int16_t is sufficient to store it.
Questions:
If it is 64-bit machine, then operations on int64_t are atomic, and cost (in terms of speed) the same as operations on int16_t? If so, storing data in 64-bit saves space but not speed?
For parallel application, I can actually save speed by storing in int16_t, because cache is also 64-bit, and te more data I store in cache - the faster the threads can access it?
Is that right?
Upvotes: 2
Views: 316
Reputation: 15496
There is no general answer one can give, as there are many 64 bit architectures. There are the different x86 flavours, the Itanium, the old Alpha, the Sparc, and now the ARM.
In general it is right, smaller data type means you can fit more data into your cache, which is good for speed (and space, too).
Whether the operation is at the same speed depends very much on the architecture. As already mentioned there are cpus that have vector units, that can work on 64 bit data types or on 4 times as much 16 bit values. A point that may slow down the 16 bit operation, is the alignment. Certain 64 bit processors demand that its data is 8 byte aligned (unaligned is possible, but slower).
Upvotes: 1
Reputation: 6566
If your compiler can transform your code to use SSE or AVX, using 64 bit integers instead of 16 bit integers will slow your code down theoretically up to a factor of 4. Even if your compiler cant do this optimization on its own, you can probably manually transform your code so it uses SSE, and gain a good speedup that way.
If you cant use SSE, using 32bit integers is probably the best choice, since you still need less memory, and 64bit CPUs are still optimized to handle 32bit values as fast as 64bit values, since many programs arent using 64bit yet.
Upvotes: 2
Reputation: 612993
It's impossible to be sure without knowledge of the algorithm and some timing. You forgot to account for false sharing which is going to be more significant with 16 bit integers.
So, to answer the question, you will have to do some timing.
Upvotes: 2