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 {...@@ -177,12 +177,12 @@ fn encode(emit: *Emit, mnemonic: Instruction.Mnemonic, ops: struct {
177 op3: Instruction.Operand = .none,177 op3: Instruction.Operand = .none,
178 op4: Instruction.Operand = .none,178 op4: Instruction.Operand = .none,
179}) InnerError!void {179}) InnerError!void {
180 const inst = Instruction.new(mnemonic, .{180 const inst = try Instruction.new(mnemonic, .{
181 .op1 = ops.op1,181 .op1 = ops.op1,
182 .op2 = ops.op2,182 .op2 = ops.op2,
183 .op3 = ops.op3,183 .op3 = ops.op3,
184 .op4 = ops.op4,184 .op4 = ops.op4,
185 }) catch unreachable;185 });
186 return inst.encode(emit.code.writer());186 return inst.encode(emit.code.writer());
187}187}
188188
src/arch/x86_64/Encoding.zig+1-1
...@@ -121,7 +121,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct {...@@ -121,7 +121,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct {
121 .encoding = encoding,121 .encoding = encoding,
122 };122 };
123 var cwriter = std.io.countingWriter(std.io.null_writer);123 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.
125 return cwriter.bytes_written;125 return cwriter.bytes_written;
126 }126 }
127 };127 };
src/arch/x86_64/Mir.zig+4-7
...@@ -24,9 +24,6 @@ instructions: std.MultiArrayList(Inst).Slice,...@@ -24,9 +24,6 @@ instructions: std.MultiArrayList(Inst).Slice,
24/// The meaning of this data is determined by `Inst.Tag` value.24/// The meaning of this data is determined by `Inst.Tag` value.
25extra: []const u32,25extra: []const u32,
2626
27pub const Mnemonic = encoder.Instruction.Mnemonic;
28pub const Operand = encoder.Instruction.Operand;
29
30pub const Inst = struct {27pub const Inst = struct {
31 tag: Tag,28 tag: Tag,
32 ops: Ops,29 ops: Ops,
...@@ -69,8 +66,6 @@ pub const Inst = struct {...@@ -69,8 +66,6 @@ pub const Inst = struct {
69 imul,66 imul,
70 ///67 ///
71 int3,68 int3,
72 /// Conditional jump
73 jcc,
74 /// Jump69 /// Jump
75 jmp,70 jmp,
76 /// Load effective address71 /// Load effective address
...@@ -99,8 +94,6 @@ pub const Inst = struct {...@@ -99,8 +94,6 @@ pub const Inst = struct {
99 sar,94 sar,
100 /// Integer subtraction with borrow95 /// Integer subtraction with borrow
101 sbb,96 sbb,
102 /// Set byte on condition
103 setcc,
104 /// Logical shift left97 /// Logical shift left
105 shl,98 shl,
106 /// Logical shift right99 /// Logical shift right
...@@ -135,6 +128,10 @@ pub const Inst = struct {...@@ -135,6 +128,10 @@ pub const Inst = struct {
135128
136 /// Conditional move129 /// Conditional move
137 cmovcc,130 cmovcc,
131 /// Conditional jump
132 jcc,
133 /// Set byte on condition
134 setcc,
138135
139 /// Mov absolute to/from memory wrt segment register to/from rax136 /// Mov absolute to/from memory wrt segment register to/from rax
140 mov_moffs,137 mov_moffs,
src/arch/x86_64/bits.zig-7
...@@ -242,13 +242,6 @@ pub const Register = enum(u7) {...@@ -242,13 +242,6 @@ pub const Register = enum(u7) {
242 };242 };
243 }243 }
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
252 pub fn enc(reg: Register) u4 {245 pub fn enc(reg: Register) u4 {
253 const base = switch (@enumToInt(reg)) {246 const base = switch (@enumToInt(reg)) {
254 // zig fmt: off247 // zig fmt: off
src/arch/x86_64/encoder.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const log = std.log.scoped(.x86_64_encoder);
3const math = std.math;4const math = std.math;
45
5const bits = @import("bits.zig");6const bits = @import("bits.zig");
...@@ -106,7 +107,7 @@ pub const Instruction = struct {...@@ -106,7 +107,7 @@ pub const Instruction = struct {
106 .op3 = args.op3,107 .op3 = args.op3,
107 .op4 = args.op4,108 .op4 = args.op4,
108 })) orelse {109 })) orelse {
109 std.log.warn("{s} {s} {s} {s} {s}", .{110 log.debug("no encoding found for: {s} {s} {s} {s} {s}", .{
110 @tagName(mnemonic),111 @tagName(mnemonic),
111 @tagName(Encoding.Op.fromOperand(args.op1)),112 @tagName(Encoding.Op.fromOperand(args.op1)),
112 @tagName(Encoding.Op.fromOperand(args.op2)),113 @tagName(Encoding.Op.fromOperand(args.op2)),
...@@ -115,7 +116,7 @@ pub const Instruction = struct {...@@ -115,7 +116,7 @@ pub const Instruction = struct {
115 });116 });
116 return error.InvalidInstruction;117 return error.InvalidInstruction;
117 };118 };
118 std.log.debug("{}", .{encoding});119 log.debug("selected encoding: {}", .{encoding});
119 return .{120 return .{
120 .op1 = args.op1,121 .op1 = args.op1,
121 .op2 = args.op2,122 .op2 = args.op2,