[LLVMdev] sext..to instruction

Matthijs Kooijman matthijs at stdin.nl
Tue Oct 7 02:24:21 PDT 2008

Hi Le Anh,

> how can it determinate, that the i16 value %x positive is (65535)?
> And the second example:
I guess you should read up on the "two's complement" format, which is how a
signed value is stored in most architectures (and in these examples).

In short, a sext operation takes the highest bit of the original number (the
sign bit) and copies it into all the higher positions. This makes sure that
the number and the sign do not change, due to the way two's complement works.

In general, the sext operation can enlarge a signed value, while preserving
both sign and magnitude, even when the target you are compiling for has some
other way of storing signed numbers.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20081007/5eed2629/attachment.sig>

More information about the llvm-dev mailing list