aboutsummaryrefslogtreecommitdiff
path: root/src/arch/riscv64/Encoding.zig
diff options
context:
space:
mode:
authorDavid Rubin <daviru007@icloud.com>2024-04-16 16:39:31 -0700
committerDavid Rubin <daviru007@icloud.com>2024-05-11 02:17:24 -0700
commita30af172e8dc360cb0a71a5c4dfd904120555715 (patch)
treee43bb564776492b6fa18187b4a379a82be5cdbb1 /src/arch/riscv64/Encoding.zig
parenta615fbc1f8330e455d02fdda5c6de257b0cde7f4 (diff)
downloadzig-a30af172e8dc360cb0a71a5c4dfd904120555715.tar.gz
zig-a30af172e8dc360cb0a71a5c4dfd904120555715.zip
riscv: math progress
Diffstat (limited to 'src/arch/riscv64/Encoding.zig')
-rw-r--r--src/arch/riscv64/Encoding.zig6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/arch/riscv64/Encoding.zig b/src/arch/riscv64/Encoding.zig
index c23ba10d9b..7953bb0cca 100644
--- a/src/arch/riscv64/Encoding.zig
+++ b/src/arch/riscv64/Encoding.zig
@@ -16,6 +16,7 @@ pub const Mnemonic = enum {
andi,
slli,
srli,
+ srai,
addi,
jalr,
@@ -69,6 +70,7 @@ pub const Mnemonic = enum {
.jalr => .{ .opcode = 0b1100111, .funct3 = 0b000, .funct7 = null },
.slli => .{ .opcode = 0b0010011, .funct3 = 0b001, .funct7 = null },
.srli => .{ .opcode = 0b0010011, .funct3 = 0b101, .funct7 = null },
+ .srai => .{ .opcode = 0b0010011, .funct3 = 0b101, .funct7 = null, .offset = 1 << 10 },
.lui => .{ .opcode = 0b0110111, .funct3 = null, .funct7 = null },
@@ -123,6 +125,7 @@ pub const InstEnc = enum {
.andi,
.slli,
.srli,
+ .srai,
=> .I,
.lui,
@@ -299,7 +302,7 @@ pub const Data = union(InstEnc) {
.I = .{
.rd = ops[0].reg.id(),
.rs1 = ops[1].reg.id(),
- .imm0_11 = ops[2].imm.asBits(u12),
+ .imm0_11 = ops[2].imm.asBits(u12) + enc.offset,
.opcode = enc.opcode,
.funct3 = enc.funct3.?,
@@ -374,6 +377,7 @@ const Enc = struct {
opcode: u7,
funct3: ?u3,
funct7: ?u7,
+ offset: u12 = 0,
};
fn verifyOps(mnem: Mnemonic, ops: []const Operand) bool {