diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-30 15:23:40 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-30 15:23:40 -0700 |
| commit | 0c30799d4039c30f95eee29e2c2f8f604e8b9880 (patch) | |
| tree | e9d2a2698abd269d1ecb1fa59051e0950f0954c0 /src/value.zig | |
| parent | 91ad96b88a88016043cb0d069aa9db47747170b6 (diff) | |
| download | zig-0c30799d4039c30f95eee29e2c2f8f604e8b9880.tar.gz zig-0c30799d4039c30f95eee29e2c2f8f604e8b9880.zip | |
Sema: fix comptime shl for fixed-width integers
Diffstat (limited to 'src/value.zig')
| -rw-r--r-- | src/value.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/value.zig b/src/value.zig index df1531533b..6c2403e13b 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2883,6 +2883,19 @@ pub const Value = extern union { return fromBigInt(arena, result_bigint.toConst()); } + pub fn shlTrunc( + lhs: Value, + rhs: Value, + ty: Type, + arena: Allocator, + target: Target, + ) !Value { + const shifted = try lhs.shl(rhs, arena); + const int_info = ty.intInfo(target); + const truncated = try shifted.intTrunc(arena, int_info.signedness, int_info.bits); + return truncated; + } + pub fn shr(lhs: Value, rhs: Value, allocator: Allocator) !Value { // TODO is this a performance issue? maybe we should try the operation without // resorting to BigInt first. |
