diff --git a/docs/LangRef.html b/docs/LangRef.html index 97b53123564..1504a807625 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -115,10 +115,22 @@
; Emulate a conditional br instruction - %Val = cast bool %value to int + %Val = zext bool %value to int switch int %Val, label %truedest [int 0, label %falsedest ] ; Emulate an unconditional br instruction @@ -2740,7 +2797,163 @@ came from in the last terminator instruction. ++ ++ + + +Syntax:
++ <result> = trunc <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
++The 'trunc' instruction truncates its operand to the type ty2. +
+ +Arguments:
++The 'trunc' instruction takes a value to trunc, which must +be an integer type, and a type that specifies the size +and type of the result, which must be an integral +type.
+ +Semantics:
++The 'trunc' instruction truncates the high order bits in value +and converts the reamining bits to ty2. The bit size of value +must be larger than the bit size of ty2. Equal sized types are not +allowed. This implies that a trunc cannot be a no-op cast. It +will always truncate bits.
+ +When truncating to bool, the truncation is done as a comparison against +zero. If the value was zero, the bool result will be false. +If the value was non-zero, the bool result will be true.
+ +Example:
++ %X = trunc int 257 to ubyte ; yields ubyte:1 + %Y = trunc int 123 to bool ; yields bool:true +++ ++ + + +Syntax:
++ <result> = zext <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'zext' instruction zero extends its operand to type +ty2.
+ + +Arguments:
+The 'zext' instruction takes a value to cast, which must be of +integral type, and a type to cast it to, which must +also be of integral type. The bit size of the +value must be smaller than or equal to the bit size of the +destination type, ty2.
+ +Semantics:
+The zext fills the high order bits of the value with zero +bits until it reaches the size of the destination type, ty2. When the +the operand and the type are the same size, no bit filling is done and the +cast is considered a no-op cast because no bits change (only the type +changes).
+ +When zero extending to bool, the extension is done as a comparison against +zero. If the value was zero, the bool result will be false. +If the value was non-zero, the bool result will be true.
+ +Example:
++ %X = zext int 257 to ulong ; yields ulong:257 + %Y = zext bool true to int ; yields int:1 +++ ++ + + +Syntax:
++ <result> = sext <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'sext' sign extends value to the type ty2.
+ +Arguments:
++The 'sext' instruction takes a value to cast, which must be of +integral type, and a type to cast it to, which must +also be of integral type.
+ +Semantics:
++The 'sext' instruction performs a sign extension by copying the sign +bit (highest order bit) of the value until it reaches the bit size of +the type ty2. When the the operand and the type are the same size, +no bit filling is done and the cast is considered a no-op cast because +no bits change (only the type changes).
+ +When sign extending to bool, the extension is done as a comparison against +zero. If the value was zero, the bool result will be false. +If the value was non-zero, the bool result will be true.
+ +Example:
+ ++ %X = sext sbyte -1 to ushort ; yields ushort:65535 + %Y = sext bool true to int ; yields int:-1 +++ ++ + +Syntax:
++ <result> = fpext <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'fpext' extends a floating point value to a larger +floating point value.
+ +Arguments:
+The 'fpext' instruction takes a +floating point value to cast, +and a floating point type to cast it to.
+ +Semantics:
+The 'fpext' instruction extends the value from one floating +point type to another. If the type of the value and ty2 are +the same, the instruction is considered a no-op cast because no bits +change.
+ +Example:
++ %X = fpext float 3.1415 to double ; yields double:3.1415 + %Y = fpext float 1.0 to float ; yields float:1.0 (no-op) ++@@ -2748,52 +2961,211 @@ came from in the last terminator instruction.+ + + +Syntax:
- <result> = cast <ty> <value> to <ty2> ; yields ty2 + <result> = fptrunc <ty> <value> to <ty2> ; yields ty2Overview:
+The 'fptrunc' instruction truncates value to type +ty2.
--The 'cast' instruction is used as the primitive means to convert -integers to floating point, change data type sizes, and break type safety (by -casting pointers). + +
Arguments:
+The 'fptrunc' instruction takes a floating + point value to cast and a floating point type to +cast it to. The size of value must be larger than the size of +ty2. This implies that fptrunc cannot be used to make a +no-op cast.
+ +Semantics:
+The 'fptrunc' instruction converts a +floating point value from a larger type to a smaller +type. If the value cannot fit within the destination type, ty2, then +the results are undefined.
+ +Example:
++ %X = fptrunc double 123.0 to float ; yields float:123.0 + %Y = fptrunc double 1.0E+300 to float ; yields undefined +++ ++ + + +Syntax:
++ <result> = fp2uint <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'fp2uint' converts a floating point value to its +unsigned integer equivalent of type ty2. +
+ +Arguments:
+The 'fp2uint' instruction takes a value to cast, which must be a +floating point value, and a type to cast it to, which +must be an integral type.
+ +Semantics:
+The 'fp2uint' instruction converts its +floating point operand into the nearest (rounding +towards zero) unsigned integer value. If the value cannot fit in ty2, +the results are undefined.
+ +When converting to bool, the conversion is done as a comparison against +zero. If the value was zero, the bool result will be false. +If the value was non-zero, the bool result will be true.
+ +Example:
++ %X = fp2uint double 123.0 to int ; yields int:123 + %Y = fp2uint float 1.0E+300 to bool ; yields bool:true + %X = fp2uint float 1.04E+17 to ubyte ; yields undefined:1 +++ ++ + + +Syntax:
++ <result> = fp2sint <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'fp2sint' instruction converts +floating point value to type ty2.
Arguments:
- --The 'cast' instruction takes a value to cast, which must be a first -class value, and a type to cast it to, which must also be a first class type. -
+The 'fp2sint' instruction takes a value to cast, which must be a +floating point value, and a type to cast it to, which +must also be an integral type.
Semantics:
+The 'fp2sint' instruction converts its +floating point operand into the nearest (rounding +towards zero) signed integer value. If the value cannot fit in ty2, +the results are undefined.
--This instruction follows the C rules for explicit casts when determining how the -data being cast must change to fit in its new container. -
- --When casting to bool, any value that would be considered true in the context of -a C 'if' condition is converted to the boolean 'true' values, -all else are 'false'. -
- --When extending an integral value from a type of one signness to another (for -example 'sbyte' to 'ulong'), the value is sign-extended if the -source value is signed, and zero-extended if the source value is -unsigned. bool values are always zero extended into either zero or -one. -
+When converting to bool, the conversion is done as a comparison against +zero. If the value was zero, the bool result will be false. +If the value was non-zero, the bool result will be true.
Example:
-- %X = cast int 257 to ubyte ; yields ubyte:1 - %Y = cast int 123 to bool ; yields bool:true + %X = fp2sint double -123.0 to int ; yields int:-123 + %Y = fp2sint float 1.0E-247 to bool ; yields bool:true + %X = fp2sint float 1.04E+17 to sbyte ; yields undefined:1 +++ ++ + + +Syntax:
++ <result> = uint2fp <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'uint2fp' instruction regards value as an unsigned +integer and converts that value to the ty2 type.
+ + +Arguments:
+The 'uint2fp' instruction takes a value to cast, which must be an +integral value, and a type to cast it to, which must +be a floating point type.
+ +Semantics:
+The 'uint2fp' instruction interprets its operand as an unsigned +integer quantity and converts it to the corresponding floating point value. If +the value cannot fit in the floating point value, the results are undefined.
+ + +Example:
++ %X = uint2fp int 257 to float ; yields float:257.0 + %Y = uint2fp sbyte -1 to double ; yields double:255.0 +++ ++ + + +Syntax:
++ <result> = sint2fp <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'sint2fp' instruction regards value as a signed +integer and converts that value to the ty2 type.
+ +Arguments:
+The 'sint2fp' instruction takes a value to cast, which must be an +integral value, and a type to cast it to, which must be +a floating point type.
+ +Semantics:
+The 'sint2fp' instruction interprets its operand as a signed +integer quantity and converts it to the corresponding floating point value. If +the value cannot fit in the floating point value, the results are undefined.
+ +Example:
++ %X = sint2fp int 257 to float ; yields float:257.0 + %Y = sint2fp sbyte -1 to double ; yields double:-1.0 +++ +Syntax:
++ <result> = bitconvert <ty> <value> to <ty2> ; yields ty2 ++ +Overview:
+The 'bitconvert' instruction converts value to type +ty2 without changing any bits.
+ +Arguments:
+The 'bitconvert' instruction takes a value to cast, which must be +a first class value, and a type to cast it to, which must also be a first class type. The bit sizes of value +and the destination type, ty2, must be identical.
+ +Semantics:
+The 'bitconvert' instruction converts value to type +ty2 as if the value had been stored to memory and read back as type +ty2. That is, no bits are changed during the conversion. The +bitconvert instruction may be used to construct no-op casts that +the zext, sext, and fpext instructions do not permit.
+ +Example:
++ %X = bitconvert ubyte 255 to sbyte ; yields sbyte:-1 + %Y = bitconvert uint* %x to uint ; yields uint:%x