Registers used during left shift operation
<p>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 &amp; c, this will be translated in 3 steps :</p>

<ol>
<li>b is moved to %rax</li>
<li>%rax = %rax + c</li>
<li>%rax is moved to a</li>
</ol>

<p>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 &lt;&lt; c is translated as follow</p>

<ol>
<li>b is moved to %rax</li>
<li>c is moved to %rcx</li>
<li>%rax = %rax &lt;&lt;(shlq) %cl</li>
<li>%rax is moved to a</li>
</ol>

<p>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 ?</p>

<p>Thank you</p>