authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-24 15:24:03+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-24 17:02:29+01:00
log77352c5bea7e328006394b93bc239c3e34b464c9
treeb7742b7ab5800f09d1e9a5a9c581724e1ca73ce3
parent4e801c27839be3f7ff209aa0f22c158b6340c69b

x64: implement aggregate_init for arrays


1 files changed, 13 insertions(+), 2 deletions(-)

src/arch/x86_64/CodeGen.zig+13-2
...@@ -5672,7 +5672,7 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {...@@ -5672,7 +5672,7 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
56725672
5673fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {5673fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
5674 const result_ty = self.air.typeOfIndex(inst);5674 const result_ty = self.air.typeOfIndex(inst);
5675 const len = result_ty.vectorLen();5675 const len = result_ty.arrayLen();
5676 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;5676 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
5677 const elements = @bitCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);5677 const elements = @bitCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
5678 const abi_size = @intCast(u32, result_ty.abiSize(self.target.*));5678 const abi_size = @intCast(u32, result_ty.abiSize(self.target.*));
...@@ -5692,7 +5692,18 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -5692,7 +5692,18 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
5692 }5692 }
5693 break :res MCValue{ .stack_offset = stack_offset };5693 break :res MCValue{ .stack_offset = stack_offset };
5694 },5694 },
5695 .Array => return self.fail("TODO implement aggregate_init for arrays", .{}),5695 .Array => {
5696 const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align));
5697 const elem_ty = result_ty.childType();
5698 const elem_size = @intCast(u32, elem_ty.abiSize(self.target.*));
5699
5700 for (elements) |elem, elem_i| {
5701 const elem_mcv = try self.resolveInst(elem);
5702 const elem_off = @intCast(i32, elem_size * elem_i);
5703 try self.genSetStack(elem_ty, stack_offset - elem_off, elem_mcv, .{});
5704 }
5705 break :res MCValue{ .stack_offset = stack_offset };
5706 },
5696 .Vector => return self.fail("TODO implement aggregate_init for vectors", .{}),5707 .Vector => return self.fail("TODO implement aggregate_init for vectors", .{}),
5697 else => unreachable,5708 else => unreachable,
5698 }5709 }