authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-05-17 04:47:25-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-17 12:03:01-04:00
loge2196a458f7c0feac24036c694282ce31be9edce
tree5fe5c23e00b6713c760abbebad33d5ed8fba483e
parent497eb3182041a199d41c4c4fb7f44fa31d8c41e3

Minor cleanup


1 files changed, 8 insertions(+), 8 deletions(-)

src-self-hosted/codegen.zig+8-8
...@@ -379,12 +379,12 @@ const Function = struct {...@@ -379,12 +379,12 @@ const Function = struct {
379 return self.code.appendSlice(&[_]u8{379 return self.code.appendSlice(&[_]u8{
380 0x45,380 0x45,
381 0x31,381 0x31,
382 0xC0 | (@intCast(u8, @truncate(u3, reg.id())) << 3) | @truncate(u3, reg.id()),382 0xC0 | (@as(u8, reg.id() & 0b111) << 3) | @truncate(u3, reg.id()),
383 });383 });
384 } else {384 } else {
385 return self.code.appendSlice(&[_]u8{385 return self.code.appendSlice(&[_]u8{
386 0x31,386 0x31,
387 0xC0 | (@intCast(u8, reg.id()) << 3) | @intCast(u3, reg.id()),387 0xC0 | (@as(u8, reg.id()) << 3) | reg.id(),
388 });388 });
389 }389 }
390 }390 }
...@@ -403,7 +403,7 @@ const Function = struct {...@@ -403,7 +403,7 @@ const Function = struct {
403 } else {403 } else {
404 try self.code.resize(self.code.items.len + 5);404 try self.code.resize(self.code.items.len + 5);
405 }405 }
406 self.code.items[self.code.items.len - 5] = 0xB8 | @intCast(u8, @truncate(u3, reg.id()));406 self.code.items[self.code.items.len - 5] = 0xB8 | @as(u8, reg.id() & 0b111);
407 const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4];407 const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4];
408 mem.writeIntLittle(u32, imm_ptr, @intCast(u32, x));408 mem.writeIntLittle(u32, imm_ptr, @intCast(u32, x));
409 return;409 return;
...@@ -422,7 +422,7 @@ const Function = struct {...@@ -422,7 +422,7 @@ const Function = struct {
422 const REX = 0x48 | (if (reg.isExtended()) @as(u8, 0x01) else 0);422 const REX = 0x48 | (if (reg.isExtended()) @as(u8, 0x01) else 0);
423 try self.code.resize(self.code.items.len + 10);423 try self.code.resize(self.code.items.len + 10);
424 self.code.items[self.code.items.len - 10] = REX;424 self.code.items[self.code.items.len - 10] = REX;
425 self.code.items[self.code.items.len - 9] = 0xB8 | @intCast(u8, @truncate(u3, reg.id()));425 self.code.items[self.code.items.len - 9] = 0xB8 | @as(u8, reg.id() & 0b111);
426 const imm_ptr = self.code.items[self.code.items.len - 8 ..][0..8];426 const imm_ptr = self.code.items[self.code.items.len - 8 ..][0..8];
427 mem.writeIntLittle(u64, imm_ptr, x);427 mem.writeIntLittle(u64, imm_ptr, x);
428 },428 },
...@@ -444,7 +444,7 @@ const Function = struct {...@@ -444,7 +444,7 @@ const Function = struct {
444 const offset = @intCast(i32, big_offset);444 const offset = @intCast(i32, big_offset);
445 self.code.items[self.code.items.len - 7] = REX;445 self.code.items[self.code.items.len - 7] = REX;
446 self.code.items[self.code.items.len - 6] = 0x8D;446 self.code.items[self.code.items.len - 6] = 0x8D;
447 self.code.items[self.code.items.len - 5] = 0x5 | (@intCast(u8, @truncate(u3, reg.id())) << 3);447 self.code.items[self.code.items.len - 5] = 0b101 | (@as(u8, reg.id() & 0b111) << 3);
448 const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4];448 const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4];
449 mem.writeIntLittle(i32, imm_ptr, offset);449 mem.writeIntLittle(i32, imm_ptr, offset);
450 },450 },
...@@ -460,7 +460,7 @@ const Function = struct {...@@ -460,7 +460,7 @@ const Function = struct {
460 // Since the register is being accessed directly, the R/M mode is three. The reg field (the middle460 // Since the register is being accessed directly, the R/M mode is three. The reg field (the middle
461 // three bits) contain the destination, and the R/M field (the lower three bits) contain the source.461 // three bits) contain the destination, and the R/M field (the lower three bits) contain the source.
462 const REX = 0x48 | (if (reg.isExtended()) @as(u8, 4) else 0) | (if (src_reg.isExtended()) @as(u8, 1) else 0);462 const REX = 0x48 | (if (reg.isExtended()) @as(u8, 4) else 0) | (if (src_reg.isExtended()) @as(u8, 1) else 0);
463 const R = 0xC0 | (@intCast(u8, @truncate(u3, reg.id())) << 3) | @truncate(u3, src_reg.id());463 const R = 0xC0 | (@as(u8, reg.id() & 0b111) << 3) | @truncate(u3, src_reg.id());
464 try self.code.appendSlice(&[_]u8{ REX, 0x8B, R });464 try self.code.appendSlice(&[_]u8{ REX, 0x8B, R });
465 },465 },
466 .memory => |x| {466 .memory => |x| {
...@@ -477,7 +477,7 @@ const Function = struct {...@@ -477,7 +477,7 @@ const Function = struct {
477 // The instruction is thus eight bytes; REX 0x8B 0b00RRR100 0x25 followed by a four-byte disp32.477 // The instruction is thus eight bytes; REX 0x8B 0b00RRR100 0x25 followed by a four-byte disp32.
478 try self.code.resize(self.code.items.len + 8);478 try self.code.resize(self.code.items.len + 8);
479 const REX = 0x48 | if (reg.isExtended()) @as(u8, 1) else 0;479 const REX = 0x48 | if (reg.isExtended()) @as(u8, 1) else 0;
480 const r = 0x04 | (@intCast(u8, @truncate(u3, reg.id())) << 3);480 const r = 0x04 | (@as(u8, reg.id() & 0b111) << 3);
481 self.code.items[self.code.items.len - 8] = REX;481 self.code.items[self.code.items.len - 8] = REX;
482 self.code.items[self.code.items.len - 7] = 0x8B;482 self.code.items[self.code.items.len - 7] = 0x8B;
483 self.code.items[self.code.items.len - 6] = r;483 self.code.items[self.code.items.len - 6] = r;
...@@ -521,7 +521,7 @@ const Function = struct {...@@ -521,7 +521,7 @@ const Function = struct {
521 // Furthermore, if this is an extended register, both B and R must be set in the REX byte, as *both*521 // Furthermore, if this is an extended register, both B and R must be set in the REX byte, as *both*
522 // register operands need to be marked as extended.522 // register operands need to be marked as extended.
523 const REX = 0x48 | if (reg.isExtended()) @as(u8, 0b0101) else 0;523 const REX = 0x48 | if (reg.isExtended()) @as(u8, 0b0101) else 0;
524 const RM = (@intCast(u8, @truncate(u3, reg.id())) << 3) | @truncate(u3, reg.id());524 const RM = (@as(u8, reg.id() & 0b111) << 3) | @truncate(u3, reg.id());
525 try self.code.appendSlice(&[_]u8{ REX, 0x8B, RM });525 try self.code.appendSlice(&[_]u8{ REX, 0x8B, RM });
526 }526 }
527 }527 }