I have a small question about the utilization of registers during some basic operations. Effectively, I have already looked at the assembly code produced during operations such as XOR or AND and those are easy to understand. Effectively, if we consider a = b & c, this will be translated in 3 steps :
- b is moved to %rax
- %rax = %rax + c
- %rax is moved to a
Note that a, b and c are unsigned long variables. This translation is also available if the addition is replaced by a XOR or an OR. Anyway, I have checked if it was also the case for shifts and I find a weird thing : in fact, a = b << c is translated as follow
- b is moved to %rax
- c is moved to %rcx
- %rax = %rax <<(shlq) %cl
- %rax is moved to a
I'm not pretty sure I really understand the second and third steps. I suppose this is due to the fact that %rax (b) cannot be shifted more than 63, otherwise, the result is obviously 0. It seems that %cl is an 8-bit register and so I think that this is a fast way to select only the useful bits and not the 64 bits in %rcx. Is that correct ?
Thank you