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 {
379379 return self.code.appendSlice(&[_]u8{
380380 0x45,
381381 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()),
383383 });
384384 } else {
385385 return self.code.appendSlice(&[_]u8{
386386 0x31,
387 0xC0 | (@intCast(u8, reg.id()) << 3) | @intCast(u3, reg.id()),
387 0xC0 | (@as(u8, reg.id()) << 3) | reg.id(),
388388 });
389389 }
390390 }
......@@ -403,7 +403,7 @@ const Function = struct {
403403 } else {
404404 try self.code.resize(self.code.items.len + 5);
405405 }
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);
407407 const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4];
408408 mem.writeIntLittle(u32, imm_ptr, @intCast(u32, x));
409409 return;
......@@ -422,7 +422,7 @@ const Function = struct {
422422 const REX = 0x48 | (if (reg.isExtended()) @as(u8, 0x01) else 0);
423423 try self.code.resize(self.code.items.len + 10);
424424 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);
426426 const imm_ptr = self.code.items[self.code.items.len - 8 ..][0..8];
427427 mem.writeIntLittle(u64, imm_ptr, x);
428428 },
......@@ -444,7 +444,7 @@ const Function = struct {
444444 const offset = @intCast(i32, big_offset);
445445 self.code.items[self.code.items.len - 7] = REX;
446446 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);
448448 const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4];
449449 mem.writeIntLittle(i32, imm_ptr, offset);
450450 },
......@@ -460,7 +460,7 @@ const Function = struct {
460460 // Since the register is being accessed directly, the R/M mode is three. The reg field (the middle
461461 // three bits) contain the destination, and the R/M field (the lower three bits) contain the source.
462462 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());
464464 try self.code.appendSlice(&[_]u8{ REX, 0x8B, R });
465465 },
466466 .memory => |x| {
......@@ -477,7 +477,7 @@ const Function = struct {
477477 // The instruction is thus eight bytes; REX 0x8B 0b00RRR100 0x25 followed by a four-byte disp32.
478478 try self.code.resize(self.code.items.len + 8);
479479 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);
481481 self.code.items[self.code.items.len - 8] = REX;
482482 self.code.items[self.code.items.len - 7] = 0x8B;
483483 self.code.items[self.code.items.len - 6] = r;
......@@ -521,7 +521,7 @@ const Function = struct {
521521 // Furthermore, if this is an extended register, both B and R must be set in the REX byte, as *both*
522522 // register operands need to be marked as extended.
523523 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());
525525 try self.code.appendSlice(&[_]u8{ REX, 0x8B, RM });
526526 }
527527 }