diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-09-28 15:45:58 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-28 16:12:24 -0700 |
| commit | 79bc5891c1c4cde0592fe1b10b6c9a85914155cf (patch) | |
| tree | 92999a5e04df045c03d63e4d02e53ad796c70911 /src/codegen.zig | |
| parent | 1e805df81d51a338eefaff0535e5f1cca9e22028 (diff) | |
| download | zig-79bc5891c1c4cde0592fe1b10b6c9a85914155cf.tar.gz zig-79bc5891c1c4cde0592fe1b10b6c9a85914155cf.zip | |
stage2: more arithmetic support
* AIR: add `mod` instruction for modulus division
- Implement for LLVM backend
* Sema: implement `@mod`, `@rem`, and `%`.
* Sema: fix comptime switch evaluation
* Sema: implement comptime shift left
* Sema: fix the logic inside analyzeArithmetic to handle all the
nuances between the different mathematical operations.
- Implement comptime wrapping operations
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 4eda3f2594..7c359e90c0 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -832,6 +832,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .mulwrap => try self.airMulWrap(inst), .div => try self.airDiv(inst), .rem => try self.airRem(inst), + .mod => try self.airMod(inst), .cmp_lt => try self.airCmp(inst, .lt), .cmp_lte => try self.airCmp(inst, .lte), @@ -1353,6 +1354,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); } + fn airMod(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) { + else => return self.fail("TODO implement mod for {}", .{self.target.cpu.arch}), + }; + return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none }); + } + fn airBitAnd(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) { |
