[LLVMdev] Why is there no ashl/lshl?

Duncan Sands baldrick at free.fr
Tue May 7 01:05:05 PDT 2013


Hi Tim,

>> There is a distinction between logical/arithmetic shift right, but why
>> not for shift left?
>
> The arithmetic right shift has the nice property that it preserves the
> fact that x >> 1 == x/2 for negative signed numbers (unlike the
> logical shift).

except when x is -1.

That said, this is correct: the reason for distinct signed and unsigned
right shifts is basically the same reason we have signed and unsigned
division instructions.

The reason that we don't have distinct signed and unsigned left shift
operators is the same reason we don't have signed and unsigned multiplication
instructions.

Ciao, Duncan.



More information about the llvm-dev mailing list