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(...@@ -7457,11 +7457,25 @@ fn genInlineMemcpy(
7457 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });7457 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
74587458
7459 switch (dst_ptr) {7459 switch (dst_ptr) {
7460 .memory, .linker_load => {7460 .memory => |addr| {
7461 try self.loadMemPtrIntoRegister(.rdi, Type.usize, dst_ptr);7461 try self.genSetReg(Type.usize, .rdi, .{ .immediate = addr });
7462 // Load the pointer, which is stored in memory7462 // Load the pointer, which is stored in memory
7463 try self.asmRegisterMemory(.mov, .rdi, Memory.sib(.qword, .{ .base = .rdi }));7463 try self.asmRegisterMemory(.mov, .rdi, Memory.sib(.qword, .{ .base = .rdi }));
7464 },7464 },
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 },
7465 .stack_offset, .ptr_stack_offset => |off| {7479 .stack_offset, .ptr_stack_offset => |off| {
7466 try self.asmRegisterMemory(switch (dst_ptr) {7480 try self.asmRegisterMemory(switch (dst_ptr) {
7467 .stack_offset => .mov,7481 .stack_offset => .mov,
...@@ -7485,11 +7499,25 @@ fn genInlineMemcpy(...@@ -7485,11 +7499,25 @@ fn genInlineMemcpy(
7485 }7499 }
74867500
7487 switch (src_ptr) {7501 switch (src_ptr) {
7488 .memory, .linker_load => {7502 .memory => |addr| {
7489 try self.loadMemPtrIntoRegister(.rsi, Type.usize, src_ptr);7503 try self.genSetReg(Type.usize, .rsi, .{ .immediate = addr });
7490 // Load the pointer, which is stored in memory7504 // Load the pointer, which is stored in memory
7491 try self.asmRegisterMemory(.mov, .rsi, Memory.sib(.qword, .{ .base = .rsi }));7505 try self.asmRegisterMemory(.mov, .rsi, Memory.sib(.qword, .{ .base = .rsi }));
7492 },7506 },
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 },
7493 .stack_offset, .ptr_stack_offset => |off| {7521 .stack_offset, .ptr_stack_offset => |off| {
7494 try self.asmRegisterMemory(switch (src_ptr) {7522 try self.asmRegisterMemory(switch (src_ptr) {
7495 .stack_offset => .mov,7523 .stack_offset => .mov,