| author | |
| committer | |
| log | 0c30799d4039c30f95eee29e2c2f8f604e8b9880 |
| tree | e9d2a2698abd269d1ecb1fa59051e0950f0954c0 |
| parent | 91ad96b88a88016043cb0d069aa9db47747170b6 |
3 files changed, 24 insertions(+), 4 deletions(-)
src/Sema.zig+7-1| ... | ... | @@ -7474,11 +7474,17 @@ fn zirShl( |
| 7474 | 7474 | } |
| 7475 | 7475 | const val = switch (air_tag) { |
| 7476 | 7476 | .shl_exact => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_exact", .{}), |
| 7477 | ||
| 7477 | 7478 | .shl_sat => if (lhs_ty.zigTypeTag() == .ComptimeInt) |
| 7478 | 7479 | try lhs_val.shl(rhs_val, sema.arena) |
| 7479 | 7480 | else |
| 7480 | 7481 | try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, sema.mod.getTarget()), |
| 7481 | .shl => try lhs_val.shl(rhs_val, sema.arena), | |
| 7482 | ||
| 7483 | .shl => if (lhs_ty.zigTypeTag() == .ComptimeInt) | |
| 7484 | try lhs_val.shl(rhs_val, sema.arena) | |
| 7485 | else | |
| 7486 | try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, sema.mod.getTarget()), | |
| 7487 | ||
| 7482 | 7488 | else => unreachable, |
| 7483 | 7489 | }; |
| 7484 | 7490 |
src/value.zig+13| ... | ... | @@ -2883,6 +2883,19 @@ pub const Value = extern union { |
| 2883 | 2883 | return fromBigInt(arena, result_bigint.toConst()); |
| 2884 | 2884 | } |
| 2885 | 2885 | |
| 2886 | pub fn shlTrunc( | |
| 2887 | lhs: Value, | |
| 2888 | rhs: Value, | |
| 2889 | ty: Type, | |
| 2890 | arena: Allocator, | |
| 2891 | target: Target, | |
| 2892 | ) !Value { | |
| 2893 | const shifted = try lhs.shl(rhs, arena); | |
| 2894 | const int_info = ty.intInfo(target); | |
| 2895 | const truncated = try shifted.intTrunc(arena, int_info.signedness, int_info.bits); | |
| 2896 | return truncated; | |
| 2897 | } | |
| 2898 | ||
| 2886 | 2899 | pub fn shr(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2887 | 2900 | // TODO is this a performance issue? maybe we should try the operation without |
| 2888 | 2901 | // resorting to BigInt first. |
test/behavior/math.zig+4-3| ... | ... | @@ -632,7 +632,10 @@ test "allow signed integer division/remainder when values are comptime known and |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | test "quad hex float literal parsing accurate" { |
| 635 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | |
| 635 | if (builtin.zig_backend != .stage1) { | |
| 636 | // TODO https://github.com/ziglang/zig/issues/10737 | |
| 637 | return error.SkipZigTest; | |
| 638 | } | |
| 636 | 639 | |
| 637 | 640 | const a: f128 = 0x1.1111222233334444555566667777p+0; |
| 638 | 641 | |
| ... | ... | @@ -724,8 +727,6 @@ test "quad hex float literal parsing accurate" { |
| 724 | 727 | } |
| 725 | 728 | |
| 726 | 729 | test "truncating shift left" { |
| 727 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | |
| 728 | ||
| 729 | 730 | try testShlTrunc(maxInt(u16)); |
| 730 | 731 | comptime try testShlTrunc(maxInt(u16)); |
| 731 | 732 | } |