forked from tenstorrent/whisper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecodedInst.cpp
88 lines (72 loc) · 1.99 KB
/
DecodedInst.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "DecodedInst.hpp"
#include "util.hpp"
using namespace WdRiscv;
uint32_t
DecodedInst::ithOperand(unsigned i) const
{
if (i == 0) return op0();
if (i == 1) return op1();
if (i == 2) return op2();
if (i == 3) return op3();
return 0;
}
int32_t
DecodedInst::ithOperandAsInt(unsigned i) const
{
return static_cast<int32_t>(ithOperand(i));
}
void
DecodedInst::setIthOperandValue(unsigned i, uint64_t value)
{
OperandType type = ithOperandType(i);
switch(type)
{
case OperandType::IntReg:
case OperandType::FpReg:
case OperandType::CsReg:
case OperandType::VecReg:
if (i < sizeof(values_))
values_[i] = value;
break;
case OperandType::Imm:
case OperandType::None:
break;
}
}
static
std::string
insertFieldCountInName(std::string_view name, unsigned count, unsigned n)
{
std::string res = util::join("", name.substr(0, n), std::to_string(count), name.substr(n));
return res;
}
std::string
DecodedInst::name() const
{
if (entry_)
{
auto id = instId();
auto name = std::string(entry_->name());
if (isVector())
{
auto fields = vecFieldCount();
if (fields)
{
// A name like vlre8_v becomes vlrXe8_v where X is the field count.
if (id >= InstId::vlre8_v and id <= InstId::vlre1024_v)
name = insertFieldCountInName(name, fields, 2);
else if ((id >= InstId::vlsege8_v and id <= InstId::vssege1024_v) or
(id >= InstId::vlsege8ff_v and id <= InstId::vlsege1024ff_v))
name = insertFieldCountInName(name, fields, 5);
else if (id >= InstId::vlssege8_v and id <= InstId::vsssege1024_v)
name = insertFieldCountInName(name, fields, 6);
else if (id >= InstId::vluxsegei8_v and id <= InstId::vsoxsegei1024_v)
name = insertFieldCountInName(name, fields, 7);
}
else if (id >= InstId::vmadc_vvm and id <= InstId::vmsbc_vxm and not isMasked())
name = name.substr(0, name.size() - 1); // Remove trailing 'm' if not masked.
}
return name;
}
return "illegal";
}