Skip to content

Commit 4c89fae

Browse files
committed
Massive refactoring of instruction description
Instruction coding is reworked and now implicitly used by many functions.
1 parent f1107b9 commit 4c89fae

File tree

5 files changed

+310
-199
lines changed

5 files changed

+310
-199
lines changed

riscvmodel/insn.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -276,35 +276,37 @@ def execute(self, model: Model):
276276
model.state.intreg[self.rd] = model.state.intreg[self.rs1] & model.state.intreg[self.rs2]
277277

278278

279-
@isa("fence", RV32I, opcode=0b0001111, funct3=0b000, funct7=0b0000000)
280-
class InstructionFENCE(Instruction):
279+
@isa("fence", RV32I, opcode=0b0001111, funct3=0b000)
280+
class InstructionFENCE(InstructionIType):
281+
isa_format_id = "FENCE"
282+
281283
def execute(self, model: Model):
282284
pass
283285

284286

285-
@isa("fence.i", RV32I, opcode=0b0001111, funct3=0b001, funct7=0b0000000)
286-
class InstructionFENCEI(Instruction):
287+
@isa("fence.i", RV32IZifencei, opcode=0b0001111, funct3=0b001)
288+
class InstructionFENCEI(InstructionIType):
287289
def execute(self, model: Model):
288290
pass
289291

290292

291-
@isa("ecall", RV32I, opcode=0b1110011, funct3=0b000, funct12=0b000000000000)
292-
class InstructionECALL(Instruction):
293+
@isa("ecall", RV32I, opcode=0b1110011, funct3=0b000, imm=0b000000000000)
294+
class InstructionECALL(InstructionIType):
293295
def execute(self, model: Model):
294296
model.environment.call(model.state)
295297

296298
def __str__(self):
297299
return "ecall"
298300

299301

300-
@isa("wfi", RV32I, opcode=0b1110011, funct3=0b000, funct12=0b000100000101)
301-
class InstructionWFI(Instruction):
302+
@isa("wfi", RV32I, opcode=0b1110011, funct3=0b000, imm=0b000100000101, rs1=0b00000, rd=0b00000)
303+
class InstructionWFI(InstructionIType):
302304
def execute(self, model: Model):
303305
pass
304306

305307

306-
@isa("ebreak", RV32I, opcode=0b1110011, funct3=0b000)
307-
class InstructionEBREAK(Instruction):
308+
@isa("ebreak", RV32I, opcode=0b1110011, funct3=0b000, imm=0b000000000001)
309+
class InstructionEBREAK(InstructionIType):
308310
def execute(self, model: Model):
309311
pass
310312

@@ -325,27 +327,27 @@ def execute(self, model: Model):
325327

326328

327329
@isa("csrrc", RV32IZicsr, opcode=0b1110011, funct3=0b011)
328-
class InstructionCSRRC(Instruction):
330+
class InstructionCSRRC(InstructionIType):
329331
def execute(self, model: Model):
330332
pass
331333

332334

333-
@isa("csrrwi", RV32IZicsr, opcode=0b1110011, funct3=0b101)
334-
class InstructionCSRRWI(Instruction):
335-
def execute(self, model: Model):
336-
pass
335+
#@isa("csrrwi", RV32IZicsr, opcode=0b1110011, funct3=0b101)
336+
#class InstructionCSRRWI(Instruction):
337+
# def execute(self, model: Model):
338+
# pass
337339

338340

339-
@isa("csrrsi", RV32IZicsr, opcode=0b1110011, funct3=0b110)
340-
class InstructionCSRRSI(Instruction):
341-
def execute(self, model: Model):
342-
pass
341+
#@isa("csrrsi", RV32IZicsr, opcode=0b1110011, funct3=0b110)
342+
#class InstructionCSRRSI(Instruction):
343+
# def execute(self, model: Model):
344+
# pass
343345

344346

345-
@isa("csrrci", RV32IZicsr, opcode=0b1110011, funct3=0b111)
346-
class InstructionCSRRCI(Instruction):
347-
def execute(self, model: Model):
348-
pass
347+
#@isa("csrrci", RV32IZicsr, opcode=0b1110011, funct3=0b111)
348+
#class InstructionCSRRCI(Instruction):
349+
# def execute(self, model: Model):
350+
# pass
349351

350352

351353
@isa("lwu", RV64I, opcode=0b0000011, funct3=0b110)
@@ -430,7 +432,7 @@ def execute(self, model: Model):
430432
pass
431433

432434

433-
@isaC("c.addi", RV32IC, opcode=1, funct3=0b000)
435+
@isa_c("c.addi", RV32IC, opcode=1, funct3=0b000)
434436
class InstructionCADDI(InstructionCIType):
435437
def expand(self):
436438
pass
@@ -439,7 +441,7 @@ def execute(self, model: Model):
439441
model.state.intreg[self.rd] = model.state.intreg[self.rd] + self.imm
440442

441443

442-
@isaC("c.andi", RV32IC, opcode=1, funct3=0b100)
444+
@isa_c("c.andi", RV32IC, opcode=1, funct3=0b100)
443445
class InstructionCANDI(InstructionCBType):
444446
def expand(self):
445447
pass
@@ -448,7 +450,7 @@ def execute(self, model: Model):
448450
pass
449451

450452

451-
@isaC("c.swsp", RV32IC, opcode=2, funct3=6)
453+
@isa_c("c.swsp", RV32IC, opcode=2, funct3=6)
452454
class InstructionCSWSP(InstructionCSSType):
453455
def expand(self):
454456
pass
@@ -463,7 +465,7 @@ def execute(self, model: Model):
463465
pass
464466

465467

466-
@isaC("c.li", RV32IC, opcode=1, funct3=2)
468+
@isa_c("c.li", RV32IC, opcode=1, funct3=2)
467469
class InstructionCLI(InstructionCIType):
468470
def expand(self):
469471
pass
@@ -472,7 +474,7 @@ def execute(self, model: Model):
472474
model.state.intreg[self.rd] = self.imm
473475

474476

475-
@isaC("c.mv", RV32IC, opcode=2, funct4=8)
477+
@isa_c("c.mv", RV32IC, opcode=2, funct4=8)
476478
class InstructionCMV(InstructionCRType):
477479
def expand(self):
478480
pass

0 commit comments

Comments
 (0)