+ def calculate_store_action(self):
+ """ decode store action
+ """
+ c = {}
+ # load opcode
+ for op in [ funct3_sb, funct3_sh, funct3_sw, ]:
+ c[op] = self.decode_action.eq(decode_action_store)
+ # default
+ c["default"] = \
+ self.decode_action.eq(decode_action_trap_illegal_instruction)
+
+ return Case(self.funct3, c)
+
+ def calculate_load_action(self):
+ """ decode load action
+ """
+ c = {}
+ # load opcode
+ for op in [ funct3_lb, funct3_lbu, funct3_lh, funct3_lhu, funct3_lw, ]:
+ c[op] = self.decode_action.eq(decode_action_load)
+ # default
+ c["default"] = \
+ self.decode_action.eq(decode_action_trap_illegal_instruction)
+
+ return Case(self.funct3, c)
+
+ def calculate_op_action(self):
+ """ decode op action
+ """
+ c = {}
+ immz = Constant(0, 12)
+ regz = Constant(0, 5)
+ # fence
+ c[funct3_slli] = \
+ If((self.funct7 == Constant(0, 7)),
+ self.decode_action.eq(decode_action_op_op_imm)).\
+ Else(
+ self.decode_action.eq(decode_action_trap_illegal_instruction))
+ # fence.i
+ c[funct3_srli_srai] = \
+ If((self.funct7 == Constant(0, 7) | \
+ (self.funct7 == Constant(0x20, 7))),
+ self.decode_action.eq(decode_action_op_op_imm)).\
+ Else(
+ self.decode_action.eq(decode_action_trap_illegal_instruction))
+ # default
+ c["default"] = \
+ self.decode_action.eq(decode_action_op_op_imm)
+
+ return Case(self.funct3, c)
+
+ def calculate_misc_action(self):
+ """ decode misc mem action
+ """
+ c = {}
+ immz = Constant(0, 12)
+ regz = Constant(0, 5)
+ # fence
+ c[funct3_fence] = \
+ If((self.immediate[8:12] == immz) & (self.rs1 == regz) & \
+ (self.rd == regz),
+ self.decode_action.eq(decode_action_fence)).\
+ Else(
+ self.decode_action.eq(decode_action_trap_illegal_instruction))
+ # fence.i
+ c[funct3_fence_i] = \
+ If((self.immediate[0:12] == immz) & (self.rs1 == regz) & \
+ (self.rd == regz),
+ self.decode_action.eq(decode_action_fence_i)).\
+ Else(
+ self.decode_action.eq(decode_action_trap_illegal_instruction))
+ # default
+ c["default"] = \
+ self.decode_action.eq(decode_action_trap_illegal_instruction)
+
+ return Case(self.funct3, c)
+
+ def calculate_action(self):
+ """ calculate action
+ """
+ c = {}
+ # load opcode
+ c[opcode_load] = self.calculate_load_action()
+ c[opcode_misc_mem] = self.calculate_misc_action()
+ c[opcode_op_imm] = self.calculate_op_action()
+ c[opcode_op] = self.calculate_op_action()
+ c[opcode_lui] = self.decode_action.eq(decode_action_lui_auipc)
+ c[opcode_auipc] = self.decode_action.eq(decode_action_lui_auipc)
+ c[opcode_store] = self.calculate_store_action()
+
+ return Case(self.opcode, c)
+
+"""