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

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.
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
What happens with 32-bit CPUs?
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.
Thank you.
Topic archived. No new replies allowed.