authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-12 10:32:08+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-13 11:47:51+02:00
log4e3573955fd912a6b2eee982f90743a939e8cbb1
treede81e72d09b0da8c768d14b5afa4c66cfa54b716
parentaab0039b42ba40fe666782b4f0bd08d0e5d3c460

x86_64: simplify genInlineMemcpy() when copying from memory


1 files changed, 32 insertions(+), 4 deletions(-)

src/arch/x86_64/CodeGen.zig+32-4
......@@ -7457,11 +7457,25 @@ fn genInlineMemcpy(
74577457 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
74587458
74597459 switch (dst_ptr) {
7460 .memory, .linker_load => {
7461 try self.loadMemPtrIntoRegister(.rdi, Type.usize, dst_ptr);
7460 .memory => |addr| {
7461 try self.genSetReg(Type.usize, .rdi, .{ .immediate = addr });
74627462 // Load the pointer, which is stored in memory
74637463 try self.asmRegisterMemory(.mov, .rdi, Memory.sib(.qword, .{ .base = .rdi }));
74647464 },
7465 .linker_load => |load_struct| {
7466 const atom_index = if (self.bin_file.cast(link.File.MachO)) |macho_file| blk: {
7467 const atom = try macho_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
7468 break :blk macho_file.getAtom(atom).getSymbolIndex().?;
7469 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| blk: {
7470 const atom = try coff_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
7471 break :blk coff_file.getAtom(atom).getSymbolIndex().?;
7472 } else unreachable;
7473
7474 switch (load_struct.type) {
7475 .import => unreachable,
7476 .got, .direct => try self.asmMovLinker(.rdi, atom_index, load_struct),
7477 }
7478 },
74657479 .stack_offset, .ptr_stack_offset => |off| {
74667480 try self.asmRegisterMemory(switch (dst_ptr) {
74677481 .stack_offset => .mov,
......@@ -7485,11 +7499,25 @@ fn genInlineMemcpy(
74857499 }
74867500
74877501 switch (src_ptr) {
7488 .memory, .linker_load => {
7489 try self.loadMemPtrIntoRegister(.rsi, Type.usize, src_ptr);
7502 .memory => |addr| {
7503 try self.genSetReg(Type.usize, .rsi, .{ .immediate = addr });
74907504 // Load the pointer, which is stored in memory
74917505 try self.asmRegisterMemory(.mov, .rsi, Memory.sib(.qword, .{ .base = .rsi }));
74927506 },
7507 .linker_load => |load_struct| {
7508 const atom_index = if (self.bin_file.cast(link.File.MachO)) |macho_file| blk: {
7509 const atom = try macho_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
7510 break :blk macho_file.getAtom(atom).getSymbolIndex().?;
7511 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| blk: {
7512 const atom = try coff_file.getOrCreateAtomForDecl(self.mod_fn.owner_decl);
7513 break :blk coff_file.getAtom(atom).getSymbolIndex().?;
7514 } else unreachable;
7515
7516 switch (load_struct.type) {
7517 .import => unreachable,
7518 .got, .direct => try self.asmMovLinker(.rsi, atom_index, load_struct),
7519 }
7520 },
74937521 .stack_offset, .ptr_stack_offset => |off| {
74947522 try self.asmRegisterMemory(switch (src_ptr) {
74957523 .stack_offset => .mov,