Performance - Bitwise operations on 64-bit and 32-bit integers?

Apr 4, 2014 at 7:19am
Do bitwise operations on 64-bit integers take time linear in the numbers of bits(64) or constant time ?

1
2
3
4
5
6
long long x,y;

x = (1<<59);
y = (1<<60);
javascript:PostPreview()
x ^= y


Suppose I had the line 6 from the above code inside many nested loops, is it safe to assume it will take a constant number of operations? Or do I need to assume that it takes about 64 operations so that it is something similar(but slightly faster) to looping through all the bits and XORing them?
What about 32-bit integers (int) ?

Thanks.
Apr 4, 2014 at 8:11am
Modern 64-bit CPUs do bitwise operations in ~1 cycle, including bit shifts and xor. There is no separate unit for shifting 32-bit integers and 64 bit integers. Looping through them manually would be definitely much slower.
Last edited on Apr 4, 2014 at 8:13am
Apr 4, 2014 at 10:06am
What happens with 32-bit CPUs?
Apr 4, 2014 at 12:42pm
modern 32bit processors (x86) support 32bit instructions for 64-bit operations (simd instruction sets like mmx or sse). Compile some code and watch disassembly, then you can read in x86 reference manual timings of instructions used.
Apr 5, 2014 at 2:33am
Thank you.
Topic archived. No new replies allowed.