diff options
| author | Travis Staloch <twostepted@gmail.com> | 2021-09-02 13:50:24 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-28 17:02:43 -0700 |
| commit | 29f41896ed9d99e82a88f4b63efa182ca0d2f93c (patch) | |
| tree | 1e6eb1159df89f79b04f050da662653925c77b1c /src/codegen.zig | |
| parent | 79bc5891c1c4cde0592fe1b10b6c9a85914155cf (diff) | |
| download | zig-29f41896ed9d99e82a88f4b63efa182ca0d2f93c.tar.gz zig-29f41896ed9d99e82a88f4b63efa182ca0d2f93c.zip | |
sat-arithmetic: add operator support
- adds initial support for the operators +|, -|, *|, <<|, +|=, -|=, *|=, <<|=
- uses operators in addition to builtins in behavior test
- adds binOpExt() and assignBinOpExt() to AstGen.zig. these need to be audited
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 7c359e90c0..a1f812388f 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -826,10 +826,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { // zig fmt: off .add, .ptr_add => try self.airAdd(inst), .addwrap => try self.airAddWrap(inst), + .addsat => try self.airArithmeticOpSat(inst, "addsat"), .sub, .ptr_sub => try self.airSub(inst), .subwrap => try self.airSubWrap(inst), + .subsat => try self.airArithmeticOpSat(inst, "subsat"), .mul => try self.airMul(inst), .mulwrap => try self.airMulWrap(inst), + .mulsat => try self.airArithmeticOpSat(inst, "mulsat"), .div => try self.airDiv(inst), .rem => try self.airRem(inst), .mod => try self.airMod(inst), @@ -848,6 +851,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .xor => try self.airXor(inst), .shr => try self.airShr(inst), .shl => try self.airShl(inst), + .shl_sat => try self.airArithmeticOpSat(inst, "shl_sat"), .alloc => try self.airAlloc(inst), .arg => try self.airArg(inst), @@ -1320,6 +1324,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); } + fn airArithmeticOpSat(self: *Self, inst: Air.Inst.Index, comptime name: []const u8) !void { + const bin_op = self.air.instructions.items(.data)[inst].bin_op; + const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) { + else => return self.fail("TODO implement " ++ name ++ " for {}", .{self.target.cpu.arch}), + }; + return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); + } + fn airMul(self: *Self, inst: Air.Inst.Index) !void { const bin_op = self.air.instructions.items(.data)[inst].bin_op; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else switch (arch) { |
