aboutsummaryrefslogtreecommitdiff
path: root/src/Air.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-01 16:13:58 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-01 16:13:58 -0700
commitddf14323ea9b2c75ac5ed286525d27730a192b53 (patch)
treea8b586e69bef580747553f63da828f947f28aa21 /src/Air.zig
parent6ae0825e7f87fc9b73a4b968964196b0e164f062 (diff)
downloadzig-ddf14323ea9b2c75ac5ed286525d27730a192b53.tar.gz
zig-ddf14323ea9b2c75ac5ed286525d27730a192b53.zip
stage2: implement `@truncate`
Diffstat (limited to 'src/Air.zig')
-rw-r--r--src/Air.zig11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Air.zig b/src/Air.zig
index d202c079bc..d923bf0b02 100644
--- a/src/Air.zig
+++ b/src/Air.zig
@@ -206,10 +206,16 @@ pub const Inst = struct {
/// Convert from one float type to another.
/// Uses the `ty_op` field.
floatcast,
- /// TODO audit uses of this. We should have explicit instructions for integer
- /// widening and truncating.
+ /// Returns an integer with a different type than the operand. The new type may have
+ /// fewer, the same, or more bits than the operand type. However, the instruction
+ /// guarantees that the same integer value fits in both types.
+ /// See `trunc` for integer truncation.
/// Uses the `ty_op` field.
intcast,
+ /// Truncate higher bits from an integer, resulting in an integer with the same
+ /// sign but an equal or smaller number of bits.
+ /// Uses the `ty_op` field.
+ trunc,
/// ?T => T. If the value is null, undefined behavior.
/// Uses the `ty_op` field.
optional_payload,
@@ -452,6 +458,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
.load,
.floatcast,
.intcast,
+ .trunc,
.optional_payload,
.optional_payload_ptr,
.wrap_optional,