[LLVMdev] How do downcast signed integers?

Mikael Lyngvig mikael at lyngvig.org
Sun Nov 24 22:15:12 PST 2013


Doh!  I was thinking in one's complement, even though I know perfectly well
that LLVM and almost all contemporary CPUs use two's complement.  Thank
you!  :-)




2013/11/25 Anton Korobeynikov <anton at korobeynikov.info>

> Hello
>
> > I was looking at "trunc" to downcast a signed integer, say sint32 to
> sint16,
> > but it seems to handle unsigned integers only.
> No. In twos-complement notation (which LLVM assumes) there no
> difference between signed and unsigned truncation - you just throw out
> the spare sign bits and that's all.
>
> Please note that that the "numbers" in LLVM IR is neither signed nor
> unsigned. They are just raw bits. It's up to the instruction in
> question how to interpret them. I'd suggest to clearly outline this in
> the document, since this is the important point.
>
> --
> With best regards, Anton Korobeynikov
> Faculty of Mathematics and Mechanics, Saint Petersburg State University
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131125/43f9e31e/attachment.html>


More information about the llvm-dev mailing list