authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-06-01 19:54:22+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-06-06 20:34:53+07:00
log5d61f32887c553415215ceadf44cba1bebc7b9da
treedcf7f8b8ee83f4716afdf737db7174ab69643dca
parent8b70abfcc66e375d71acf1e753d3589e38ba1a3d

stage2: sparc64: Implement airSlice


1 files changed, 21 insertions(+), 1 deletions(-)

src/arch/sparc64/CodeGen.zig+21-1
......@@ -517,7 +517,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
517517 .shl_sat => @panic("TODO try self.airShlSat(inst)"),
518518 .min => @panic("TODO try self.airMin(inst)"),
519519 .max => @panic("TODO try self.airMax(inst)"),
520 .slice => @panic("TODO try self.airSlice(inst)"),
520 .slice => try self.airSlice(inst),
521521
522522 .sqrt,
523523 .sin,
......@@ -1647,6 +1647,26 @@ fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
16471647 return self.finishAir(inst, .{ .ptr_stack_offset = stack_offset }, .{ .none, .none, .none });
16481648}
16491649
1650fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
1651 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
1652 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
1653 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1654 const ptr = try self.resolveInst(bin_op.lhs);
1655 const ptr_ty = self.air.typeOf(bin_op.lhs);
1656 const len = try self.resolveInst(bin_op.rhs);
1657 const len_ty = self.air.typeOf(bin_op.rhs);
1658
1659 const ptr_bits = self.target.cpu.arch.ptrBitWidth();
1660 const ptr_bytes = @divExact(ptr_bits, 8);
1661
1662 const stack_offset = try self.allocMem(inst, ptr_bytes * 2, ptr_bytes * 2);
1663 try self.genSetStack(ptr_ty, stack_offset, ptr);
1664 try self.genSetStack(len_ty, stack_offset - ptr_bytes, len);
1665 break :result MCValue{ .stack_offset = stack_offset };
1666 };
1667 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
1668}
1669
16501670fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
16511671 const is_volatile = false; // TODO
16521672 const bin_op = self.air.instructions.items(.data)[inst].bin_op;