return m
+class DecodeCR(Elaboratable):
+ """DecodeRc from instruction
+
+ decodes Record bit Rc
+ """
+ def __init__(self, dec):
+ self.dec = dec
+ self.cr_out = Data(3, "cr")
+ self.insn_in = Signal(32, reset_less=True)
+ self.sel_in = Signal(1, reset_less=True)
+
+ def elaborate(self, platform):
+ m = Module()
+ comb = m.d.comb
+
+ # select Record bit out field
+ with m.If(self.sel_in):
+ comb += self.cr_out.data.eq(self.dec.BF[0:-1])
+
+ comb += self.cr_out.ok.eq(self.sel_in)
+ return m
+
class DecodeOE(Elaboratable):
"""DecodeOE from instruction
self.write_spr = Data(10, name="spro")
self.read_spr1 = Data(10, name="spr1")
self.read_spr2 = Data(10, name="spr2")
+ self.cr_sel = Data(3, name="cr_sel")
#self.read_data1 = Signal(64, reset_less=True)
#self.read_data2 = Signal(64, reset_less=True)
#self.read_data3 = Signal(64, reset_less=True)
m.submodules.dec_o = dec_o = DecodeOut(self.dec)
m.submodules.dec_rc = dec_rc = DecodeRC(self.dec)
m.submodules.dec_oe = dec_oe = DecodeOE(self.dec)
+ m.submodules.dec_cr = dec_cr = DecodeCR(self.dec)
# copy instruction through...
for i in [self.e.insn, dec_a.insn_in, dec_b.insn_in,
dec_c.insn_in, dec_o.insn_in, dec_rc.insn_in,
- dec_oe.insn_in]:
+ dec_oe.insn_in, dec_cr.insn_in]:
comb += i.eq(self.dec.opcode_in)
# ...and subdecoders' input fields
comb += dec_o.sel_in.eq(self.dec.op.out_sel)
comb += dec_rc.sel_in.eq(self.dec.op.rc_sel)
comb += dec_oe.sel_in.eq(self.dec.op.rc_sel) # XXX should be OE sel
+ comb += dec_cr.sel_in.eq(self.dec.op.cr_out)
# decode LD/ST length
with m.Switch(self.dec.op.ldst_len):
comb += self.e.input_cr.eq(self.dec.op.cr_in)
comb += self.e.output_cr.eq(self.dec.op.cr_out)
+ comb += self.e.cr_sel.eq(dec_cr.cr_out)
+
return m
assert(rc == 1)
else:
assert(rc == 0)
-
+
class RegImmOp:
in2_sel = yield pdecode2.dec.op.in2_sel
if in2_sel in [In2Sel.CONST_SI_HI.value, In2Sel.CONST_UI_HI.value]:
assert(imm == (self.imm << 16))
- else:
+ else:
assert(imm == self.imm)
rc = yield pdecode2.e.rc.data
else:
assert(False)
+
+class CmpRegOp:
+ def __init__(self):
+ self.ops = {
+ "cmp": InternalOp.OP_CMP,
+ }
+ self.opcodestr = random.choice(list(self.ops.keys()))
+ self.opcode = self.ops[self.opcodestr]
+ self.r1 = Register(random.randrange(32))
+ self.r2 = Register(random.randrange(32))
+ self.cr = Register(random.randrange(8))
+
+ def generate_instruction(self):
+ string = "{} {}, 0, {}, {}\n".format(self.opcodestr,
+ self.cr.num,
+ self.r1.num,
+ self.r2.num)
+ return string
+
+ def check_results(self, pdecode2):
+ r1sel = yield pdecode2.e.read_reg1.data
+ r2sel = yield pdecode2.e.read_reg2.data
+ crsel = yield pdecode2.e.cr_sel.data
+
+ assert(r1sel == self.r1.num)
+ assert(r2sel == self.r2.num)
+ assert(crsel == self.cr.num)
+
+
+
class DecoderTestCase(FHDLTestCase):
def get_assembled_instruction(self, instruction):
def test_ldst_imm(self):
self.run_tst(LdStOp, "ldst_imm")
+ def test_cmp_reg(self):
+ self.run_tst(CmpRegOp, "cmp_reg")
+
if __name__ == "__main__":
unittest.main()