The line shl eax, cl hides a condition that is not visible in the command name. If CL is 32, the contents of the 32-bit operand are not converted to zero. The effective shift number is zero. This is not a limit test or the processor refusing to do too much work: modern x86 uses only certain low-order count bits. Therefore, the marginal note in such a listing should refer primarily to the right-hand operand. The instruction received one number and derived the shift amount from only part of it.
It’s easy to write the expression C x << n next to it and decide that it must behave the same way. This is where the review ceases to be just reading instructions. A language determines the validity of an expression before a particular machine decides how to execute it. For the model C in question with a 32-bit unsigned int, the value of n equal to 32 is already outside the allowed shift range. The observed behavior of machine SHL does not extend this range. The program and listing are at different levels of the contract.
Mark next to CL: the counter is masked. Intel SDM Volume 2, describes SAL/SHL, SHR and SAR with a mask of five least significant bits for a regular 32-bit operand. The numbers 0, 32 and 64 give one effective counter: 0. The values 1 and 33 give 1. This is conveniently understood as the remainder of division by 32 for the non-negative byte counter in question. But a convenient arithmetic description does not mean that the processor first tries to shift all the bits and then returns them back.
Note near EAX: width matters separately. For a 64-bit operand with a corresponding REX.W, the least significant six bits of the counter are used, and the repetition bound becomes 64. Omitting this detail can turn a correct explanation of one listing into an erroneous explanation of another. The destination register name, prefix, and encoding mode contain some of the semantics here. The mere presence of a 64-bit processor does not make any of its integer commands an operation on 64 bits.
There is a particularly unpleasant sequel. For an eight-bit operand, the counter mask is not compressed to three bits. Regular SHL still uses a five-bit effective counter. Therefore, a byte shift by 8 is not equal to a byte shift by 0: the original bits leave the stored result. The habit of automatically taking the remainder according to the destination width does not describe all operations. It may be suitable for a certain rotation, but it is not a universal rule for every shift and every size.
Different operations remain in the margin
Left is still not a sufficient definition. SHL shifts the bits to the high end, filling the vacated low-order positions with zeros. SHR shifts right with zero padding. SAR, when shifted right, propagates the sign bit. For a negative value, such an operation does not have to coincide with the usual integer division of the language. For example, arithmetic shifting the representation of −3 to the right by one yields −2, whereas dividing −3 by 2 in C11 rounds toward zero and yields −1. This is an analytical example, not a CPU test result.
This means that the comment “divide by a power of two” also needs a scope of applicability. For a suitable unsigned value, a logical right shift has the natural meaning of division with the remainder discarded. For the negative sign case, the rounding question changes the answer. The compiler is able to add correction when it implements division rather than shift. If you see additional instructions in a listing, they cannot be declared redundant just because one SAR looks shorter. They can preserve the rule of the original operation.
Now a note beside the flags. With an effective zero counter, a normal shift does not change the arithmetic flags. You cannot read the CF after such an SHL and confidently call it the last bit evicted: in this execution, no bit was shifted out. For non-zero counters, definitions and undefined cases of flags must be taken from the command description; You especially can’t extend the OF rule for shifting by one to an arbitrary amount. Here we are not building an algorithm based on flags, but we are noting a hidden dependency that may be lost in a comment.
This null case explains why checking only a few nice inputs doesn’t help much. Shifts of 1, 2 or 3 match well with a simple movement picture. At the border of width, another question is revealed: what did the author even want to define for an argument that is too large? If the answer should be zero, the machine mask itself does not provide it. If the bits are meant to wrap around, SHL has been chosen where a rotation is needed. Before discussing speed, it is necessary to name the desired mathematical function.

Consider an explicitly hypothetical interface: it receives a 32-bit unsigned word and a non-negative number n; if n is less than 32, returns a logical shift, otherwise returns zero. For a regular x86 model of C with a 32-bit unsigned int, notation with a conditional operator can express this contract: n < 32 ? x << n : 0. Only the selected branch is evaluated. Therefore, the illegal shift is not performed for large n. This is a significant difference from trying to first calculate x << n and then reset the answer already obtained.
Another function might intentionally use a circular counter: x << (n & 31) in the same explicit type model. Now n equal to 32 legally leads to an effective zero even at the source level. The function is defined, but defined differently. Masking is not a universal fix: it changes the contract. For decoding the length of a field or packet boundary, replacing a large number with a small one may be exactly the error that the program should have rejected, rather than a neat optimization.
Read the expression type before the register
Draft C11 Standard N1570, dated April 12, 2011, specifies integer shift operand promotions in section 6.5.7. The validity of the counter refers to the width of the promoted left operand. Declaring a variable as an unsigned char therefore does not promise eight-bit expression arithmetic. On a common system, its value is first represented as an int. When subsequently stored into a byte, another conversion occurs. The target object size and calculation width cannot be substituted for each other.
Even a constant’s suffix can change the reading of a line. Expressions with 1, 1u and a suitable wide unsigned unit specify different type assumptions. To construct the most significant bit, the source type must have the required width and allow the selected result according to the rules of a particular language. Converting an already evaluated result to a wider type does not widen the operation that produced it. The conversion must take place where the left shift operand is formed, and not just where its result is received.
C11 has additional restrictions for signed left shift; a negative operand is not made safe because the resulting bits look familiar. The right shift of a negative signed value in this document is implementation defined. Therefore, the examples above are deliberately separated from promises about any modern language. Current C++ Working Text should be read separately: similar syntax does not certify the same semantics across editions. Historical Draft C is not presented here as the latest edition of the standard.
The note next to negative n is even shorter: you need to notice it first. If the interface accepts a signed counter, checking only n < 32 will let a negative number through. Our hypothetical function previously assumed a non-negative input; a different interface requires a different verification contract. Converting a negative value to unsigned should also not occur without the author noticing. It can help formulate the range check, but the reader needs to be able to see exactly what range is being checked after the transformation and why it is appropriate for the purpose.
This implies a limitation of the usual experiment with a debug build. If in one program an incorrect shift gives the previous value, this is evidence of the assembled sequence, and not evidence that the source behavior is defined. When optimizing, the compiler uses valid expression values as assumptions. It is not required to preserve a convenient hardware mask for an input to which the language has not assigned a behavior. The difference in results between builds sometimes begins even before the choice of instructions, at the level of program transformation and exclusion of unacceptable cases from reasoning.
GCC documents shift checks as part of the UndefinedBehaviorSanitizer, including shift-base and shift-exponent checks. Such a tool is useful for executed paths, but does not prove that the unexecuted branch is safe for all inputs. It also doesn’t choose the desired semantics instead of the developer. If the library must return zero when the counter is large, the boundary test must check exactly this requirement. The absence of a diagnostic message does not replace the written requirement, and the presence of a message does not explain what function they wanted to implement.
SIMD instructions have different rules for handling large counters. Some families saturate the result with zeros when the width of the element is reached, while rotations and new variable operations have their own definitions. Carrying the scalar &31 into the explanation of all vector shifts would be another error of scale. First, a specific instruction and element size are selected, then its counter is read. The word shift denotes a family of ideas, but an architectural contract exists for a specific coding.
The adjacent boundary input is also useful. If n is 31 for a 32-bit word, the original least significant bit after the left shift becomes the most significant bit, and the remaining original bits leave the result. With n equal to 32, the machine mask suddenly returns an effective zero. This is not a smooth continuation of the previous relationship. A function with a zero result beyond the bound and a function with a cyclic counter have different breakpoints. Testing only the values within the range is not able to distinguish their designs. Even exactly the same code on the entire allowed subset does not answer the question of what the library promises to other callers. Therefore, specification testing must include an input at the boundary itself and one immediately after it, while maintaining the validity of each expression of the language.
For review, this changes the usefulness of the disassembler. It allows you to check what is selected in a particular build, see the width and additional verification. It does not replace reading the type and preconditions of the original function. The converse is also true: a valid language expression does not promise a single form of listing or a fixed delay. This material does not contain a comparative benchmark, measurements or processor recommendation. Sources verified November 4, 2026; The verified revision of Intel SDM 325383-093US is dated September 2026, and the shift rules are not announced as new today.
The last note next to the function should therefore sound specific: what values of n are allowed, what happens beyond the limit, and what type determines the width. Then the CPU command with a masked count stops looking like a mystery. It has a precise rule; the program should have its own, consistent with the task. The coincidence of these rules on several small numbers does not say anything about the most interesting input – the one that reached the word boundary.



