authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-11 19:50:23+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-11 20:05:50+01:00
log433558a92f005d3ad68528c62ffd6006c48b80bd
tree65c9132fecd73d2c77e44ed02625058e43d786b2
parentf279ccb8078db9df92f02e23f70486f1950b92ed

x86_64: clean up


5 files changed, 10 insertions(+), 19 deletions(-)

src/arch/x86_64/Emit.zig+2-2
......@@ -177,12 +177,12 @@ fn encode(emit: *Emit, mnemonic: Instruction.Mnemonic, ops: struct {
177177 op3: Instruction.Operand = .none,
178178 op4: Instruction.Operand = .none,
179179}) InnerError!void {
180 const inst = Instruction.new(mnemonic, .{
180 const inst = try Instruction.new(mnemonic, .{
181181 .op1 = ops.op1,
182182 .op2 = ops.op2,
183183 .op3 = ops.op3,
184184 .op4 = ops.op4,
185 }) catch unreachable;
185 });
186186 return inst.encode(emit.code.writer());
187187}
188188
src/arch/x86_64/Encoding.zig+1-1
......@@ -121,7 +121,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct {
121121 .encoding = encoding,
122122 };
123123 var cwriter = std.io.countingWriter(std.io.null_writer);
124 inst.encode(cwriter.writer()) catch unreachable;
124 inst.encode(cwriter.writer()) catch unreachable; // Not allowed to fail here unless OOM.
125125 return cwriter.bytes_written;
126126 }
127127 };
src/arch/x86_64/Mir.zig+4-7
......@@ -24,9 +24,6 @@ instructions: std.MultiArrayList(Inst).Slice,
2424/// The meaning of this data is determined by `Inst.Tag` value.
2525extra: []const u32,
2626
27pub const Mnemonic = encoder.Instruction.Mnemonic;
28pub const Operand = encoder.Instruction.Operand;
29
3027pub const Inst = struct {
3128 tag: Tag,
3229 ops: Ops,
......@@ -69,8 +66,6 @@ pub const Inst = struct {
6966 imul,
7067 ///
7168 int3,
72 /// Conditional jump
73 jcc,
7469 /// Jump
7570 jmp,
7671 /// Load effective address
......@@ -99,8 +94,6 @@ pub const Inst = struct {
9994 sar,
10095 /// Integer subtraction with borrow
10196 sbb,
102 /// Set byte on condition
103 setcc,
10497 /// Logical shift left
10598 shl,
10699 /// Logical shift right
......@@ -135,6 +128,10 @@ pub const Inst = struct {
135128
136129 /// Conditional move
137130 cmovcc,
131 /// Conditional jump
132 jcc,
133 /// Set byte on condition
134 setcc,
138135
139136 /// Mov absolute to/from memory wrt segment register to/from rax
140137 mov_moffs,
src/arch/x86_64/bits.zig-7
......@@ -242,13 +242,6 @@ pub const Register = enum(u7) {
242242 };
243243 }
244244
245 pub fn isRexInvalid(reg: Register) bool {
246 return switch (@enumToInt(reg)) {
247 @enumToInt(Register.ah)...@enumToInt(Register.bh) => true,
248 else => false,
249 };
250 }
251
252245 pub fn enc(reg: Register) u4 {
253246 const base = switch (@enumToInt(reg)) {
254247 // zig fmt: off
src/arch/x86_64/encoder.zig+3-2
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const assert = std.debug.assert;
3const log = std.log.scoped(.x86_64_encoder);
34const math = std.math;
45
56const bits = @import("bits.zig");
......@@ -106,7 +107,7 @@ pub const Instruction = struct {
106107 .op3 = args.op3,
107108 .op4 = args.op4,
108109 })) orelse {
109 std.log.warn("{s} {s} {s} {s} {s}", .{
110 log.debug("no encoding found for: {s} {s} {s} {s} {s}", .{
110111 @tagName(mnemonic),
111112 @tagName(Encoding.Op.fromOperand(args.op1)),
112113 @tagName(Encoding.Op.fromOperand(args.op2)),
......@@ -115,7 +116,7 @@ pub const Instruction = struct {
115116 });
116117 return error.InvalidInstruction;
117118 };
118 std.log.debug("{}", .{encoding});
119 log.debug("selected encoding: {}", .{encoding});
119120 return .{
120121 .op1 = args.op1,
121122 .op2 = args.op2,