| ... | ... | @@ -379,12 +379,12 @@ const Function = struct { |
| 379 | 379 | return self.code.appendSlice(&[_]u8{ |
| 380 | 380 | 0x45, |
| 381 | 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 | 384 | } else { |
| 385 | 385 | return self.code.appendSlice(&[_]u8{ |
| 386 | 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 | 403 | } else { |
| 404 | 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 | 407 | const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4]; |
| 408 | 408 | mem.writeIntLittle(u32, imm_ptr, @intCast(u32, x)); |
| 409 | 409 | return; |
| ... | ... | @@ -422,7 +422,7 @@ const Function = struct { |
| 422 | 422 | const REX = 0x48 | (if (reg.isExtended()) @as(u8, 0x01) else 0); |
| 423 | 423 | try self.code.resize(self.code.items.len + 10); |
| 424 | 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 | 426 | const imm_ptr = self.code.items[self.code.items.len - 8 ..][0..8]; |
| 427 | 427 | mem.writeIntLittle(u64, imm_ptr, x); |
| 428 | 428 | }, |
| ... | ... | @@ -444,7 +444,7 @@ const Function = struct { |
| 444 | 444 | const offset = @intCast(i32, big_offset); |
| 445 | 445 | self.code.items[self.code.items.len - 7] = REX; |
| 446 | 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 | 448 | const imm_ptr = self.code.items[self.code.items.len - 4 ..][0..4]; |
| 449 | 449 | mem.writeIntLittle(i32, imm_ptr, offset); |
| 450 | 450 | }, |
| ... | ... | @@ -460,7 +460,7 @@ const Function = struct { |
| 460 | 460 | // Since the register is being accessed directly, the R/M mode is three. The reg field (the middle |
| 461 | 461 | // three bits) contain the destination, and the R/M field (the lower three bits) contain the source. |
| 462 | 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 | 464 | try self.code.appendSlice(&[_]u8{ REX, 0x8B, R }); |
| 465 | 465 | }, |
| 466 | 466 | .memory => |x| { |
| ... | ... | @@ -477,7 +477,7 @@ const Function = struct { |
| 477 | 477 | // The instruction is thus eight bytes; REX 0x8B 0b00RRR100 0x25 followed by a four-byte disp32. |
| 478 | 478 | try self.code.resize(self.code.items.len + 8); |
| 479 | 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 | 481 | self.code.items[self.code.items.len - 8] = REX; |
| 482 | 482 | self.code.items[self.code.items.len - 7] = 0x8B; |
| 483 | 483 | self.code.items[self.code.items.len - 6] = r; |
| ... | ... | @@ -521,7 +521,7 @@ const Function = struct { |
| 521 | 521 | // Furthermore, if this is an extended register, both B and R must be set in the REX byte, as *both* |
| 522 | 522 | // register operands need to be marked as extended. |
| 523 | 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 | 525 | try self.code.appendSlice(&[_]u8{ REX, 0x8B, RM }); |
| 526 | 526 | } |
| 527 | 527 | } |