Hi, I have a question about the "sext..to" instruction. In the document, I found two examples: %x = sext i8 -1 to i16 It means: i8 -1 = 1111 1111 --> 1111 1111 1111 1111 = i16 how can it determinate, that the i16 value %x positive is (65535)? And the second example: %y = sext i1 true to i32 1 --> 1111 1111 1111 1111 1111 1111 1111 1111 In this example, %y is -1 I'm not sure about it, when sext to results a positve/negative value? Thank for any advice Quang
Le Anh Quang wrote:> Hi, > I have a question about the "sext..to" instruction. In the document, I found > two examples: > %x = sext i8 -1 to i16 > It means: > i8 -1 = 1111 1111 --> 1111 1111 1111 1111 = i16 > how can it determinate, that the i16 value %x positive is (65535)?i16 65536 = i16 -1. They're both 1111 1111 1111 1111.> And the second example: > > %y = sext i1 true to i32 > 1 --> 1111 1111 1111 1111 1111 1111 1111 1111 > In this example, %y is -1 > > I'm not sure about it, when sext to results a positve/negative value?Since they're the same bits, it doesn't matter at all until you perform you I/O, at which time your code makes the decision as to whether the top bit should be treated as a sign bit or not. The LangRef should probably be updated, as LLVM's AsmPrinter will never print i16 65536, preferring to show all values as signed. Nick Lewycky> Thank for any advice > Quang > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
> I'm not sure about it, when sext to results a positve/negative value?sext does signed-extension, zext does unsigned-extension. This means that zext always extends by zero bits, while with sext the additional bits are all copies of the top bit of the original value. So with sext, if it was negative in the original type when considered as a signed value, then it will be negative in the new type too. Best wishes, Duncan.
Thanks , i see it now :) Quang -----Ursprüngliche Nachricht----- Von: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] Im Auftrag von Duncan Sands Gesendet: Montag, 6. Oktober 2008 19:13 An: llvmdev at cs.uiuc.edu Cc: Le Anh Quang Betreff: Re: [LLVMdev] sext..to instruction> I'm not sure about it, when sext to results a positve/negative value?sext does signed-extension, zext does unsigned-extension. This means that zext always extends by zero bits, while with sext the additional bits are all copies of the top bit of the original value. So with sext, if it was negative in the original type when considered as a signed value, then it will be negative in the new type too. Best wishes, Duncan. _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Possibly Parallel Threads
- [LLVMdev] sext..to instruction
- [LLVMdev] sext..to instruction
- [LLVMdev] [LoopVectorizer] Missed vectorization opportunities caused by sext/zext operations
- Shift-by-signext - sext is bad for analysis - ignore it's use count?
- [LLVMdev] [LoopVectorizer] Missed vectorization opportunities caused by sext/zext operations