authorgravatar for 81774659+gracefuu@users.noreply.github.comgracefu <81774659+gracefuu@users.noreply.github.com> 2021-04-08 05:24:17+08:00
committergravatar for 81774659+gracefuu@users.noreply.github.comgracefu <81774659+gracefuu@users.noreply.github.com> 2021-04-08 05:26:56+08:00
log4c71942f84261e9872cd27139c45b6d5fb1ab6c7
tree29edf638919b456298339933be1ac9ec68893054
parentbcc371618fd71185e71a889c09eb68733ca66842
signature Commit is signed but in an unrecognized format.

stage2: Add .div to ir.zig


4 files changed, 18 insertions(+), 0 deletions(-)

src/Sema.zig+1
......@@ -3540,6 +3540,7 @@ fn analyzeArithmetic(
35403540 .subwrap => .subwrap,
35413541 .mul => .mul,
35423542 .mulwrap => .mulwrap,
3543 .div => .div,
35433544 else => return sema.mod.fail(&block.base, src, "TODO implement arithmetic for operand '{s}''", .{@tagName(zir_tag)}),
35443545 };
35453546
src/codegen.zig+10
......@@ -855,6 +855,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
855855 .not => return self.genNot(inst.castTag(.not).?),
856856 .mul => return self.genMul(inst.castTag(.mul).?),
857857 .mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?),
858 .div => return self.genDiv(inst.castTag(.div).?),
858859 .ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?),
859860 .ref => return self.genRef(inst.castTag(.ref).?),
860861 .ret => return self.genRet(inst.castTag(.ret).?),
......@@ -1092,6 +1093,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
10921093 }
10931094 }
10941095
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
10951105 fn genBitAnd(self: *Self, inst: *ir.Inst.BinOp) !MCValue {
10961106 // No side effects, so if it's unreferenced, do nothing.
10971107 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
582582 .mul => try genBinOp(o, inst.castTag(.sub).?, " * "),
583583 // TODO make this do wrapping multiplication for signed ints
584584 .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).?, " / "),
585588
586589 .constant => unreachable, // excluded from function bodies
587590 .alloc => try genAlloc(o, inst.castTag(.alloc).?),
src/ir.zig+4
......@@ -115,6 +115,7 @@ pub const Inst = struct {
115115 unreach,
116116 mul,
117117 mulwrap,
118 div,
118119 not,
119120 floatcast,
120121 intcast,
......@@ -181,6 +182,7 @@ pub const Inst = struct {
181182 .subwrap,
182183 .mul,
183184 .mulwrap,
185 .div,
184186 .cmp_lt,
185187 .cmp_lte,
186188 .cmp_eq,
......@@ -752,6 +754,7 @@ const DumpTzir = struct {
752754 .subwrap,
753755 .mul,
754756 .mulwrap,
757 .div,
755758 .cmp_lt,
756759 .cmp_lte,
757760 .cmp_eq,
......@@ -891,6 +894,7 @@ const DumpTzir = struct {
891894 .subwrap,
892895 .mul,
893896 .mulwrap,
897 .div,
894898 .cmp_lt,
895899 .cmp_lte,
896900 .cmp_eq,