| author | |
| committer | |
| log | 4c71942f84261e9872cd27139c45b6d5fb1ab6c7 |
| tree | 29edf638919b456298339933be1ac9ec68893054 |
| parent | bcc371618fd71185e71a889c09eb68733ca66842 |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 18 insertions(+), 0 deletions(-)
src/Sema.zig+1| ... | @@ -3540,6 +3540,7 @@ fn analyzeArithmetic( | ... | @@ -3540,6 +3540,7 @@ fn analyzeArithmetic( |
| 3540 | .subwrap => .subwrap, | 3540 | .subwrap => .subwrap, |
| 3541 | .mul => .mul, | 3541 | .mul => .mul, |
| 3542 | .mulwrap => .mulwrap, | 3542 | .mulwrap => .mulwrap, |
| 3543 | .div => .div, | ||
| 3543 | else => return sema.mod.fail(&block.base, src, "TODO implement arithmetic for operand '{s}''", .{@tagName(zir_tag)}), | 3544 | else => return sema.mod.fail(&block.base, src, "TODO implement arithmetic for operand '{s}''", .{@tagName(zir_tag)}), |
| 3544 | }; | 3545 | }; |
| 3545 | 3546 |
src/codegen.zig+10| ... | @@ -855,6 +855,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -855,6 +855,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 855 | .not => return self.genNot(inst.castTag(.not).?), | 855 | .not => return self.genNot(inst.castTag(.not).?), |
| 856 | .mul => return self.genMul(inst.castTag(.mul).?), | 856 | .mul => return self.genMul(inst.castTag(.mul).?), |
| 857 | .mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?), | 857 | .mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?), |
| 858 | .div => return self.genDiv(inst.castTag(.div).?), | ||
| 858 | .ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?), | 859 | .ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?), |
| 859 | .ref => return self.genRef(inst.castTag(.ref).?), | 860 | .ref => return self.genRef(inst.castTag(.ref).?), |
| 860 | .ret => return self.genRet(inst.castTag(.ret).?), | 861 | .ret => return self.genRet(inst.castTag(.ret).?), |
| ... | @@ -1092,6 +1093,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -1092,6 +1093,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 1092 | } | 1093 | } |
| 1093 | } | 1094 | } |
| 1094 | 1095 | ||
| 1096 | fn genDiv(self: *Self, inst: *ir.Inst.BinOp) !MCValue { | ||
| 1097 | // No side effects, so if it's unreferenced, do nothing. | ||
| 1098 | if (inst.base.isUnused()) | ||
| 1099 | return MCValue.dead; | ||
| 1100 | switch (arch) { | ||
| 1101 | else => return self.fail(inst.base.src, "TODO implement div for {}", .{self.target.cpu.arch}), | ||
| 1102 | } | ||
| 1103 | } | ||
| 1104 | |||
| 1095 | fn genBitAnd(self: *Self, inst: *ir.Inst.BinOp) !MCValue { | 1105 | fn genBitAnd(self: *Self, inst: *ir.Inst.BinOp) !MCValue { |
| 1096 | // No side effects, so if it's unreferenced, do nothing. | 1106 | // No side effects, so if it's unreferenced, do nothing. |
| 1097 | if (inst.base.isUnused()) | 1107 | if (inst.base.isUnused()) |
src/codegen/c.zig+3| ... | @@ -582,6 +582,9 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi | ... | @@ -582,6 +582,9 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi |
| 582 | .mul => try genBinOp(o, inst.castTag(.sub).?, " * "), | 582 | .mul => try genBinOp(o, inst.castTag(.sub).?, " * "), |
| 583 | // TODO make this do wrapping multiplication for signed ints | 583 | // TODO make this do wrapping multiplication for signed ints |
| 584 | .mulwrap => try genBinOp(o, inst.castTag(.sub).?, " * "), | 584 | .mulwrap => try genBinOp(o, inst.castTag(.sub).?, " * "), |
| 585 | // TODO use a different strategy for div that communicates to the optimizer | ||
| 586 | // that wrapping is UB. | ||
| 587 | .div => try genBinOp(o, inst.castTag(.div).?, " / "), | ||
| 585 | 588 | ||
| 586 | .constant => unreachable, // excluded from function bodies | 589 | .constant => unreachable, // excluded from function bodies |
| 587 | .alloc => try genAlloc(o, inst.castTag(.alloc).?), | 590 | .alloc => try genAlloc(o, inst.castTag(.alloc).?), |
src/ir.zig+4| ... | @@ -115,6 +115,7 @@ pub const Inst = struct { | ... | @@ -115,6 +115,7 @@ pub const Inst = struct { |
| 115 | unreach, | 115 | unreach, |
| 116 | mul, | 116 | mul, |
| 117 | mulwrap, | 117 | mulwrap, |
| 118 | div, | ||
| 118 | not, | 119 | not, |
| 119 | floatcast, | 120 | floatcast, |
| 120 | intcast, | 121 | intcast, |
| ... | @@ -181,6 +182,7 @@ pub const Inst = struct { | ... | @@ -181,6 +182,7 @@ pub const Inst = struct { |
| 181 | .subwrap, | 182 | .subwrap, |
| 182 | .mul, | 183 | .mul, |
| 183 | .mulwrap, | 184 | .mulwrap, |
| 185 | .div, | ||
| 184 | .cmp_lt, | 186 | .cmp_lt, |
| 185 | .cmp_lte, | 187 | .cmp_lte, |
| 186 | .cmp_eq, | 188 | .cmp_eq, |
| ... | @@ -752,6 +754,7 @@ const DumpTzir = struct { | ... | @@ -752,6 +754,7 @@ const DumpTzir = struct { |
| 752 | .subwrap, | 754 | .subwrap, |
| 753 | .mul, | 755 | .mul, |
| 754 | .mulwrap, | 756 | .mulwrap, |
| 757 | .div, | ||
| 755 | .cmp_lt, | 758 | .cmp_lt, |
| 756 | .cmp_lte, | 759 | .cmp_lte, |
| 757 | .cmp_eq, | 760 | .cmp_eq, |
| ... | @@ -891,6 +894,7 @@ const DumpTzir = struct { | ... | @@ -891,6 +894,7 @@ const DumpTzir = struct { |
| 891 | .subwrap, | 894 | .subwrap, |
| 892 | .mul, | 895 | .mul, |
| 893 | .mulwrap, | 896 | .mulwrap, |
| 897 | .div, | ||
| 894 | .cmp_lt, | 898 | .cmp_lt, |
| 895 | .cmp_lte, | 899 | .cmp_lte, |
| 896 | .cmp_eq, | 900 | .cmp_eq, |