[LLVMdev] Why is there no ashl/lshl?
Tim Northover
t.p.northover at gmail.com
Mon May 6 23:17:34 PDT 2013
Hi,
> 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). Either because of this or because of other uses I
can't think of right now almost all modern CPUs implement it in
hardware, and hence LLVM has an instruction for it.
In contrast, it's not quite clear what an arithmetic left-shift would
be. If you want to keep x << 1 == x*2 then the logical one already
does this. If you want to define it to shift in the least-significant
bit at each stage then some concrete use is needed; I can't think of a
common one.
> I'm also a bit confused by one example in the reference manual:
> <result> = lshr i8 -2, 1 ; yields {i8}:result = 0x7FFFFFFF
> Is this an error in the manual? The result is supposed to be an i8 yet a
> i32 is shown.
I think so. I've changed it to 0x7F.
Cheers.
Tim.
More information about the llvm-dev
mailing list