public RvcTestEnvironment() { decoder32 = new RvcDecoder(Architecture.Rv32I); decoder64 = new RvcDecoder(Architecture.Rv64I); composer32 = new RvcComposer32(); composer64 = new RvcComposer64(); }
public void Init(ulong programCounter) { // Set the instruction decoder and type decoder instructionDecoder = new InstructionDecoder(EndianType.Little); typeDecoder = new TypeDecoder(); rvcDecoder = new RvcDecoder(architecture); InitDetails(programCounter); environment.ApplyOutputParameter(configuration.Debug, configuration.VerboseMode); isInitialized = true; }
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); } }