| author | |
| committer | |
| log | 110c18588688e4c03010e372668bbb0ab90e4735 |
| tree | 94b6ff036bb2c2c723fdd258cf3a7280e49348c1 |
| parent | c6b4fe00660d00d0748dc01f660ed7ac24f54db0 |
If we don't touch the stack, ellide `sub rsp, imm32` to `nop`.3 files changed, 15 insertions(+), 0 deletions(-)
src/arch/x86_64/CodeGen.zig+6| ... | @@ -405,6 +405,12 @@ fn gen(self: *Self) InnerError!void { | ... | @@ -405,6 +405,12 @@ fn gen(self: *Self) InnerError!void { |
| 405 | const aligned_stack_end = mem.alignForward(stack_end, self.stack_align); | 405 | const aligned_stack_end = mem.alignForward(stack_end, self.stack_align); |
| 406 | if (aligned_stack_end > 0) { | 406 | if (aligned_stack_end > 0) { |
| 407 | self.mir_instructions.items(.data)[backpatch_reloc].imm = @intCast(i32, aligned_stack_end); | 407 | self.mir_instructions.items(.data)[backpatch_reloc].imm = @intCast(i32, aligned_stack_end); |
| 408 | } else { | ||
| 409 | self.mir_instructions.set(backpatch_reloc, .{ | ||
| 410 | .tag = .nop, | ||
| 411 | .ops = undefined, | ||
| 412 | .data = undefined, | ||
| 413 | }); | ||
| 408 | } | 414 | } |
| 409 | 415 | ||
| 410 | if (self.exitlude_jump_relocs.items.len == 1) { | 416 | if (self.exitlude_jump_relocs.items.len == 1) { |
src/arch/x86_64/Emit.zig+6| ... | @@ -134,6 +134,7 @@ pub fn emitMir(emit: *Emit) InnerError!void { | ... | @@ -134,6 +134,7 @@ pub fn emitMir(emit: *Emit) InnerError!void { |
| 134 | .@"test" => try emit.mirTest(inst), | 134 | .@"test" => try emit.mirTest(inst), |
| 135 | 135 | ||
| 136 | .brk => try emit.mirBrk(), | 136 | .brk => try emit.mirBrk(), |
| 137 | .nop => try emit.mirNop(), | ||
| 137 | 138 | ||
| 138 | .call_extern => try emit.mirCallExtern(inst), | 139 | .call_extern => try emit.mirCallExtern(inst), |
| 139 | 140 | ||
| ... | @@ -185,6 +186,11 @@ fn mirBrk(emit: *Emit) InnerError!void { | ... | @@ -185,6 +186,11 @@ fn mirBrk(emit: *Emit) InnerError!void { |
| 185 | encoder.opcode_1byte(0xcc); | 186 | encoder.opcode_1byte(0xcc); |
| 186 | } | 187 | } |
| 187 | 188 | ||
| 189 | fn mirNop(emit: *Emit) InnerError!void { | ||
| 190 | const encoder = try Encoder.init(emit.code, 1); | ||
| 191 | encoder.opcode_1byte(0x90); | ||
| 192 | } | ||
| 193 | |||
| 188 | fn mirSyscall(emit: *Emit) InnerError!void { | 194 | fn mirSyscall(emit: *Emit) InnerError!void { |
| 189 | const encoder = try Encoder.init(emit.code, 2); | 195 | const encoder = try Encoder.init(emit.code, 2); |
| 190 | encoder.opcode_2byte(0x0f, 0x05); | 196 | encoder.opcode_2byte(0x0f, 0x05); |
src/arch/x86_64/Mir.zig+3| ... | @@ -247,6 +247,9 @@ pub const Inst = struct { | ... | @@ -247,6 +247,9 @@ pub const Inst = struct { |
| 247 | /// Breakpoint | 247 | /// Breakpoint |
| 248 | brk, | 248 | brk, |
| 249 | 249 | ||
| 250 | /// Nop | ||
| 251 | nop, | ||
| 252 | |||
| 250 | /// Pseudo-instructions | 253 | /// Pseudo-instructions |
| 251 | /// call extern function | 254 | /// call extern function |
| 252 | /// Notes: | 255 | /// Notes: |