コード例 #1
0
        public void StoreSpTest()
        {
            // C.SWSP
            var pairSwSp = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCSS(2, 0x3F, 01, 6),
                Coding            = te.ToBytes(0x86, 0xDF),
                ExpectedPayload32 = te.BuildSType(8, 2, 2, 1, 0xFC)
            };

            te.Test(pairSwSp);

            // C.SDSP
            var pairSdSp = new RvcTestPair(architecture, false)
            {
                //ExpectedPayload = te.LoadCSS(2, 0x3F, 01, 7)
                Coding = te.ToBytes(0x86, 0xFF)
            };

            te.Test(pairSdSp);

            // C.SQSP
            // C.FSWSP
            // C.FSDSP
        }
コード例 #2
0
ファイル: RvcFor64Q01.cs プロジェクト: sovr610/PatoSim
        public void ControlTransferInstructionTest()
        {
            // C.J
            var pairCj = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCJ(1, 0x3FF, 5),
                Coding            = te.ToBytes(0xFD, 0xBF),
                ExpectedPayload32 = te.BuildJType(0x1B, 0, 0x7FE)
            };

            te.Test(pairCj);


            // C.BEQZ
            var pairBeqz = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCB(1, 1, 0xFF, 6),
                Coding            = te.ToBytes(0xFD, 0xDC),
                ExpectedPayload32 = te.BuildBType(0x18, 9, 0, 0, 0x1FE)
            };

            te.Test(pairBeqz);

            //// C.BNEZ
            var pairBnez = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCB(1, 1, 0xFF, 7),
                Coding            = te.ToBytes(0xFD, 0xFC),
                ExpectedPayload32 = te.BuildBType(0x18, 9, 0, 1, 0x1FE)
            };

            te.Test(pairBnez);
        }
コード例 #3
0
ファイル: RvcFor64Q02.c.cs プロジェクト: sovr610/PatoSim
        public void LoadSpTest()
        {
            // C.LWSP
            var pairLwsp = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCI(2, 0x3F, 1, 2),
                Coding            = new byte[] { 0xFE, 0x50 },
                ExpectedPayload32 = te.BuildIType(0, 1, 2, 2, 0xFC)
            };

            te.Test(pairLwsp);

            // C.LDSP (RV64 / 128)
            var pairLdsp = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCI(2, 0x3F, 1, 3),
                Coding            = new byte[] { 0xFE, 0x70 },
                ExpectedPayload32 = te.BuildIType(0, 1, 3, 2, 0x1F8)
            };

            te.Test(pairLdsp);

            // C.LQSP



            // C.FLWSP



            // C.FLDSP
        }
コード例 #4
0
        public void IntegerRegisterImmediateTest()
        {
            var pairAddi4Spn = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCIW(0, 1, 0xFFFF, 0),
                Coding            = te.ToBytes(0xE4, 0x1F),
                ExpectedPayload32 = te.BuildIType(4, 9, 0, 2, 0x3FC)
            };

            te.Test(pairAddi4Spn);
        }
コード例 #5
0
        public void NopTest()
        {
            // C.NOP
            var pairNop = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0x01, 0x00),
                ExpectedPayload   = te.LoadCI(0x01, 0, 0, 0),
                ExpectedPayload32 = te.BuildIType(0x04, 0, 0, 0, 0)
            };

            te.Test(pairNop);
        }
コード例 #6
0
        public void BreakpointIntrusionTest()
        {
            // C.EBREAK
            var pairBreak = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0x02, 0x90),
                ExpectedPayload   = te.LoadJCR(2, 0, 0, 9, 4),
                ExpectedPayload32 = te.BuildIType_Unsigned(0x1C, 0, 0, 0, 1)
            };

            te.Test(pairBreak);
        }
コード例 #7
0
        public void IntegerRegisterImmediateTest()
        {
            // C.SLLI

            var pairSlli = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFE, 0x10),
                ExpectedPayload   = te.LoadCI(2, 0x3F, 1, 0),
                ExpectedPayload32 = te.BuildIType(0x04, 1, 1, 1, 0x3F)
            };

            te.Test(pairSlli);
        }
コード例 #8
0
        public void IntegerConstantGenerationTest()
        {
            // Test for positive numbers
            // C.LI Pos
            var pairLiPos = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x40),
                ExpectedPayload   = te.LoadCI(1, 0x1F, 1, 2),
                ExpectedPayload32 = te.BuildIType(4, 1, 0, 0, 0x1F)
            };

            te.Test(pairLiPos);

            // C.LI Neg
            var pairLiNeg = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x50),
                ExpectedPayload   = te.LoadCI(1, 0x3F, 1, 2),
                ExpectedPayload32 = te.BuildIType(4, 1, 0, 0, -1)
            };

            te.Test(pairLiNeg);


            // C.LUI
            // Inst32 Opcode 0x0D
            var pairLui1 = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x70),
                ExpectedPayload   = te.LoadCI(1, 0x3F, 1, 3),
                ExpectedPayload32 = te.BuildUType(0x0D, 1, 0xFFFFF000)
            };

            te.Test(pairLui1);

            var pairLui2 = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x60),
                ExpectedPayload   = te.LoadCI(1, 0x1F, 1, 3),
                ExpectedPayload32 = te.BuildUType(0x0D, 1, 0x1F000)
            };

            te.Test(pairLui2);
        }
コード例 #9
0
        public void StoreRegisterTest()
        {
            // C.SW
            var pairLw = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCS(00, 1, 0x1F, 2, 6),
                Coding            = te.ToBytes(0x64, 0xDD),
                ExpectedPayload32 = te.BuildSType(8, 2, 10, 9, 0x7C)
            };

            te.Test(pairLw);

            // C.SD
            var pairLd = new RvcTestPair(architecture, false)
            {
                //ExpectedPayload = te.LoadCS(00, 1, 0x1F, 2, 7),
                Coding = te.ToBytes(0x64, 0xFD)
            };

            te.Test(pairLd);
        }
コード例 #10
0
        public void LoadRegisterTest()
        {
            // C.LW
            var pairLw = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadCL(00, 1, 0x1F, 2, 2),
                Coding            = te.ToBytes(0x64, 0x5D),
                ExpectedPayload32 = te.BuildIType(00, 9, 2, 10, 0x7C)
            };

            te.Test(pairLw);

            // C.LD
            var pairLd = new RvcTestPair(architecture, false)
            {
                //ExpectedPayload = te.LoadCL(00, 1, 0x1F, 2, 3),
                Coding = te.ToBytes(0x64, 0x7D)
            };

            te.Test(pairLd);
        }
コード例 #11
0
        public void ControlTransferInstructionTest()
        {
            // C.JR
            var pairCjr = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadJCR(2, 2, 0, 8, 4),
                Coding            = te.ToBytes(0x02, 0x81),
                ExpectedPayload32 = te.BuildIType(0x19, 0, 0, 2, 0)
            };

            te.Test(pairCjr);

            // C.JALR
            var pairCjalr = new RvcTestPair(architecture)
            {
                ExpectedPayload   = te.LoadJCR(2, 2, 0, 9, 4),
                Coding            = te.ToBytes(0x02, 0x91),
                ExpectedPayload32 = te.BuildIType(0x19, 1, 0, 2, 0)
            };

            te.Test(pairCjalr);
        }
コード例 #12
0
        public void IntegerRegisterRegisterTest()
        {
            // C.MV
            var pairMv = new RvcTestPair(architecture)
            {
                // RS2 = 10, RD = 11
                Coding            = te.ToBytes(0xAA, 0x85),
                ExpectedPayload   = te.LoadJCR(2, 11, 10, 8, 4),
                ExpectedPayload32 = te.BuildRType(0x0C, 0, 10, 11, 0, 0)
            };

            te.Test(pairMv);

            // C.ADD
            var pairAdd = new RvcTestPair(architecture)
            {
                // RS2 = 10, RD = 11
                Coding            = te.ToBytes(0xAA, 0x95),
                ExpectedPayload   = te.LoadJCR(2, 11, 10, 9, 4),
                ExpectedPayload32 = te.BuildRType(0x0C, 11, 10, 11, 0, 0)
            };

            te.Test(pairAdd);
        }
コード例 #13
0
        public void IntegerRegisterImmediateTest()
        {
            //C.ADDI
            var pairAddi = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x10),
                ExpectedPayload   = te.LoadCI(1, 0x3F, 1, 0),
                ExpectedPayload32 = te.BuildIType(0x04, 1, 0, 1, 0x3F)
            };

            te.Test(pairAddi);

            //C.ADDIW
            // Not testable on RV32I
            //var pairAddiw = new RvcTestPair(architecture,false)
            //{
            //    Coding = te.ToBytes(0xFD, 0x30),
            //    ExpectedPayload = te.LoadCI(1, 0x3F, 1, 1)
            //};

            //te.Test(pairAddiw);

            //C.ADDI16SP
            var pairAddi16sp = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0x7D, 0x71),
                ExpectedPayload   = te.LoadCI(1, 0x3F, 2, 3),
                ExpectedPayload32 = te.BuildIType(0x04, 2, 0, 2, 0x03F0)
            };

            te.Test(pairAddi16sp);

            // C.SRLI
            var pairSrli = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x80),
                ExpectedPayload   = te.LoadCB_Integer(1, 1, 0x1F, 00, 4),
                ExpectedPayload32 = te.BuildIType(0x04, 9, 5, 9, 0x1F)
            };

            te.Test(pairSrli);

            // C.SRAI
            var pairSrai = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x84),
                ExpectedPayload   = te.LoadCB_Integer(1, 1, 0x1F, 01, 4),
                ExpectedPayload32 = te.BuildIType(0x04, 9, 5, 9, 0x41F)
            };

            te.Test(pairSrai);

            // C.ANDI
            var pairAndi = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xFD, 0x98),
                ExpectedPayload   = te.LoadCB_Integer(1, 1, 0x3F, 02, 4),
                ExpectedPayload32 = te.BuildIType(0x04, 9, 7, 9, -1)
            };

            te.Test(pairAndi);


            // add rd rs1 rs2 31..25 = 0  14..12 = 0 6..2 = 0x0C 1..0 = 3
            // sub rd rs1 rs2 31..25 = 32 14..12 = 0 6..2 = 0x0C 1..0 = 3
            // sll rd rs1 rs2 31..25 = 0  14..12 = 1 6..2 = 0x0C 1..0 = 3
            // slt rd rs1 rs2 31..25 = 0  14..12 = 2 6..2 = 0x0C 1..0 = 3
            // sltu rd rs1 rs2 31..25 = 0  14..12 = 3 6..2 = 0x0C 1..0 = 3
            // xor rd rs1 rs2 31..25 = 0  14..12 = 4 6..2 = 0x0C 1..0 = 3
            // srl rd rs1 rs2 31..25 = 0  14..12 = 5 6..2 = 0x0C 1..0 = 3
            // sra rd rs1 rs2 31..25 = 32 14..12 = 5 6..2 = 0x0C 1..0 = 3
            // or rd rs1 rs2 31..25 = 0  14..12 = 6 6..2 = 0x0C 1..0 = 3
            // and rd rs1 rs2 31..25 = 0  14..12 = 7 6..2 = 0x0C 1..0 = 3

            // C.SUB
            var pairCASub = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0x89, 0x8C),
                ExpectedPayload   = te.LoadCA(1, 1, 2, 0, 0, 0x23),
                ExpectedPayload32 = te.BuildRType(0x0C, 9, 10, 9, 0, 0x32)
            };

            te.Test(pairCASub);

            // C.XOR
            var pairCAXor = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xA9, 0x8C),
                ExpectedPayload   = te.LoadCA(1, 1, 2, 1, 1, 0x23),
                ExpectedPayload32 = te.BuildRType(0x0C, 9, 10, 9, 4, 0)
            };

            te.Test(pairCAXor);

            // C.OR
            var pairCAor = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xC9, 0x8C),
                ExpectedPayload   = te.LoadCA(1, 1, 2, 2, 2, 0x23),
                ExpectedPayload32 = te.BuildRType(0x0C, 9, 10, 9, 6, 0)
            };

            te.Test(pairCAor);

            // C.AND
            var pairCAand = new RvcTestPair(architecture)
            {
                Coding            = te.ToBytes(0xE9, 0x8C),
                ExpectedPayload   = te.LoadCA(1, 1, 2, 3, 3, 0x23),
                ExpectedPayload32 = te.BuildRType(0x0C, 9, 10, 9, 7, 0)
            };

            te.Test(pairCAand);
        }
コード例 #14
0
ファイル: RvcTestEnvironment.cs プロジェクト: sovr610/PatoSim
        public void Test(RvcTestPair pair)
        {
            RvcDecoder   decoderUT  = null;
            IRvcComposer compuserUT = null;

            if (pair.TargetArchitecture == Architecture.Rv32I)
            {
                decoderUT  = decoder32;
                compuserUT = composer32;
            }

            if (pair.TargetArchitecture == Architecture.Rv64I)
            {
                decoderUT  = decoder64;
                compuserUT = composer64;
            }

            if (pair.IsValid)
            {
                var payloadUT = decoderUT.Decode(pair.Coding);
                Assert.AreEqual(payloadUT.Type, pair.ExpectedPayload.Type);
                Assert.AreEqual(payloadUT.Op, pair.ExpectedPayload.Op);
                Assert.AreEqual(payloadUT.Funct3, pair.ExpectedPayload.Funct3);
                Assert.AreEqual(payloadUT.Rd, pair.ExpectedPayload.Rd);
                Assert.AreEqual(payloadUT.Rs1, pair.ExpectedPayload.Rs1);
                Assert.AreEqual(payloadUT.Rs2, pair.ExpectedPayload.Rs2);
                Assert.AreEqual(payloadUT.Immediate, pair.ExpectedPayload.Immediate);
            }
            else
            {
                bool excpeptionCaught = false;
                try
                {
                    var payload = decoderUT.Decode(pair.Coding);
                }
                catch (RiscVSimException)
                {
                    excpeptionCaught = true;
                }
                catch (System.Exception ex)
                {
                    Assert.Fail("Invalid exception caught!");
                }

                Assert.IsTrue(excpeptionCaught, "Invalid opcode for this architecture!");
            }

            // If InstructionPayload is available generate and compare it via the composer
            if (pair.ExpectedPayload32 != null)
            {
                var payloadUT          = decoderUT.Decode(pair.Coding);
                var instruction        = compuserUT.ComposeInstruction(payloadUT);
                var instructionPayload = compuserUT.Compose(instruction, payloadUT);

                Assert.AreEqual(pair.ExpectedPayload32.OpCode, instructionPayload.OpCode);
                Assert.AreEqual(pair.ExpectedPayload32.Rd, instructionPayload.Rd);
                Assert.AreEqual(pair.ExpectedPayload32.Rs1, instructionPayload.Rs1);
                Assert.AreEqual(pair.ExpectedPayload32.Rs2, instructionPayload.Rs2);
                Assert.AreEqual(pair.ExpectedPayload32.Funct3, instructionPayload.Funct3);
                Assert.AreEqual(pair.ExpectedPayload32.Funct7, instructionPayload.Funct7);
                Assert.AreEqual(pair.ExpectedPayload32.SignedImmediate, instructionPayload.SignedImmediate);
                Assert.AreEqual(pair.ExpectedPayload32.UnsignedImmediate, instructionPayload.UnsignedImmediate);
                Assert.AreEqual(pair.ExpectedPayload32.SignedImmediateComplete, instructionPayload.SignedImmediateComplete);
            }
        }