-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFile.cpp
More file actions
57 lines (48 loc) · 2.32 KB
/
testFile.cpp
File metadata and controls
57 lines (48 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include "Decoder.h"
void testDecode() {
Decoder decoder;
struct TestCase {
uint32_t instr;
Decoder::DecodedInstr expected;
};
TestCase tests[] = {
{0x003100B3, {0x33, 0x0, 0x00, 1, 2, 3, 0, "R"}}, // add x1,x2,x3 (probably correct)
{0x00A10093, {0x13, 0x0, 0x00, 1, 2, 0, 10, "I"}}, // addi x1,x2,10 corrected literal
{0x00112023, {0x23, 0x2, 0x00, 0, 2, 1, 0, "S"}}, // sw x1,0(x2) (check this too)
{0x00208863, {0x63, 0x0, 0x00, 0, 1, 2, 16, "B"}} // beq x1,x2,16 (double check this one)
};
for (const auto& test : tests) {
auto decoded = decoder.decode(test.instr);
bool pass = (decoded.opcode == test.expected.opcode) &&
(decoded.funct3 == test.expected.funct3) &&
(decoded.funct7 == test.expected.funct7) &&
(decoded.rd == test.expected.rd) &&
(decoded.rs1 == test.expected.rs1) &&
(decoded.rs2 == test.expected.rs2) &&
(decoded.imm == test.expected.imm) &&
(decoded.type == test.expected.type);
std::cout << "Test instruction 0x" << std::hex << test.instr
<< (pass ? " PASSED\n" : " FAILED\n");
if (!pass) {
std::cout << "Decoded opcode: 0x" << std::hex << (int)decoded.opcode << "\n";
std::cout << "Decoded funct3: 0x" << std::hex << (int)decoded.funct3 << "\n";
std::cout << "Decoded funct7: 0x" << std::hex << (int)decoded.funct7 << "\n";
std::cout << "Decoded rd: " << (int)decoded.rd << "\n";
std::cout << "Decoded rs1: " << (int)decoded.rs1 << "\n";
std::cout << "Decoded rs2: " << (int)decoded.rs2 << "\n";
std::cout << "Decoded imm: " << decoded.imm << "\n";
std::cout << "Decoded type: " << decoded.type << "\n";
uint32_t instr = test.instr;
std::cout << "Instruction: 0x" << std::hex << instr << "\n";
std::cout << "imm12 = " << ((instr >> 31) & 1) << "\n";
std::cout << "imm11 = " << ((instr >> 7) & 1) << "\n";
std::cout << "imm10_5 = " << ((instr >> 25) & 0x3F) << "\n";
std::cout << "imm4_1 = " << ((instr >> 8) & 0xF) << "\n";
}
}
}
int main() {
testDecode();
return 0;
}