diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-04-12 10:32:08 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-04-13 11:47:51 +0200 |
| commit | 4e3573955fd912a6b2eee982f90743a939e8cbb1 (patch) | |
| tree | de81e72d09b0da8c768d14b5afa4c66cfa54b716 /src | |
| parent | aab0039b42ba40fe666782b4f0bd08d0e5d3c460 (diff) | |
| download | zig-4e3573955fd912a6b2eee982f90743a939e8cbb1.tar.gz zig-4e3573955fd912a6b2eee982f90743a939e8cbb1.zip | |
x86_64: simplify genInlineMemcpy() when copying from memory
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/x86_64/CodeGen.zig | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index bcd30013aa..96350cb164 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -7457,11 +7457,25 @@ fn genInlineMemcpy( try self.spillRegisters(&.{ .rdi, .rsi, .rcx }); switch (dst_ptr) { - .memory, .linker_load => { - try self.loadMemPtrIntoRegister(.rdi, Type.usize, dst_ptr); + .memory => |addr| { + try self.genSetReg(Type.usize, .rdi, .{ .immediate = addr }); // Load the pointer, which is stored in memory try self.asmRegisterMemory(.mov, .rdi, Memory.sib(.qword, .{ .base = .rdi })); }, + .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, .direct => try self.asmMovLinker(.rdi, atom_index, load_struct), + } + }, .stack_offset, .ptr_stack_offset => |off| { try self.asmRegisterMemory(switch (dst_ptr) { .stack_offset => .mov, @@ -7485,11 +7499,25 @@ fn genInlineMemcpy( } switch (src_ptr) { - .memory, .linker_load => { - try self.loadMemPtrIntoRegister(.rsi, Type.usize, src_ptr); + .memory => |addr| { + try self.genSetReg(Type.usize, .rsi, .{ .immediate = addr }); // Load the pointer, which is stored in memory try self.asmRegisterMemory(.mov, .rsi, Memory.sib(.qword, .{ .base = .rsi })); }, + .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, .direct => try self.asmMovLinker(.rsi, atom_index, load_struct), + } + }, .stack_offset, .ptr_stack_offset => |off| { try self.asmRegisterMemory(switch (src_ptr) { .stack_offset => .mov, |
