There is a distinction between logical/arithmetic shift right, but why not for shift left? 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. -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130507/3d18d282/attachment.sig>
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.
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.
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] > On Behalf Of Tim Northover > 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.Only if the left-most (shiftcount + 1) bits are all-0 or all-1. I've used machines that distinguished logical and arithmetic left shift to detect when this condition fails (arith shift would trap). --paulr
Possibly Parallel Threads
- [LLVMdev] Why is there no ashl/lshl?
- [LLVMdev] Why is there no ashl/lshl?
- [LLVMdev] Why is there no ashl/lshl?
- [LLVMdev] ScheduleDAGInstrs/R600 test potential issue with implicit defs
- [LLVMdev] ScheduleDAGInstrs/R600 test potential issue with implicit defs