mirror of
https://github.com/ziglang/zig.git
synced 2024-12-04 02:48:50 +00:00
x86_64: simplify airArrayElemVal() when pulling array from memory
This commit is contained in:
parent
c8c5951e23
commit
e05a51cb62
@ -2897,7 +2897,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
|
|||||||
const offset_reg_lock = self.register_manager.lockRegAssumeUnused(offset_reg);
|
const offset_reg_lock = self.register_manager.lockRegAssumeUnused(offset_reg);
|
||||||
defer self.register_manager.unlockReg(offset_reg_lock);
|
defer self.register_manager.unlockReg(offset_reg_lock);
|
||||||
|
|
||||||
const addr_reg = try self.register_manager.allocReg(null, gp);
|
const addr_reg = (try self.register_manager.allocReg(null, gp)).to64();
|
||||||
switch (array) {
|
switch (array) {
|
||||||
.register => {
|
.register => {
|
||||||
const off = @intCast(i32, try self.allocMem(
|
const off = @intCast(i32, try self.allocMem(
|
||||||
@ -2906,19 +2906,32 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
|
|||||||
array_ty.abiAlignment(self.target.*),
|
array_ty.abiAlignment(self.target.*),
|
||||||
));
|
));
|
||||||
try self.genSetStack(array_ty, off, array, .{});
|
try self.genSetStack(array_ty, off, array, .{});
|
||||||
try self.asmRegisterMemory(.lea, addr_reg.to64(), Memory.sib(.qword, .{
|
try self.asmRegisterMemory(.lea, addr_reg, Memory.sib(.qword, .{
|
||||||
.base = .rbp,
|
.base = .rbp,
|
||||||
.disp = -off,
|
.disp = -off,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
.stack_offset => |off| {
|
.stack_offset => |off| {
|
||||||
try self.asmRegisterMemory(.lea, addr_reg.to64(), Memory.sib(.qword, .{
|
try self.asmRegisterMemory(.lea, addr_reg, Memory.sib(.qword, .{
|
||||||
.base = .rbp,
|
.base = .rbp,
|
||||||
.disp = -off,
|
.disp = -off,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
.memory, .linker_load => {
|
.memory => |addr| try self.genSetReg(Type.usize, addr_reg, .{ .immediate = addr }),
|
||||||
try self.loadMemPtrIntoRegister(addr_reg, Type.usize, array);
|
.linker_load => |load_struct| {
|
||||||
|
const atom_index = if (self.bin_file.cast(link.File.MachO)) |macho_file| blk: {
|
||||||
|
const atom = try macho_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
|
||||||
|
break :blk macho_file.getAtom(atom).getSymbolIndex().?;
|
||||||
|
} else if (self.bin_file.cast(link.File.Coff)) |coff_file| blk: {
|
||||||
|
const atom = try coff_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
|
||||||
|
break :blk coff_file.getAtom(atom).getSymbolIndex().?;
|
||||||
|
} else unreachable;
|
||||||
|
|
||||||
|
switch (load_struct.type) {
|
||||||
|
.import => unreachable,
|
||||||
|
.got => try self.asmMovLinker(addr_reg, atom_index, load_struct),
|
||||||
|
.direct => try self.asmLeaLinker(addr_reg, atom_index, load_struct),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
else => return self.fail("TODO implement array_elem_val when array is {}", .{array}),
|
else => return self.fail("TODO implement array_elem_val when array is {}", .{array}),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user