Skip to content

Commit 0ba9493

Browse files
committed
Make NO_VAL constants templated
1 parent a766e50 commit 0ba9493

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

simulator/infra/macro.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ static constexpr inline size_t count_leading_ones(const T& value) noexcept
112112
return count_leading_zeroes<T>( ~value);
113113
}
114114

115+
/*
116+
* Templated no-value (non-trivial data of given size)
117+
*/
118+
template<typename T> constexpr T NO_VAL = all_ones<T>();
119+
template<> constexpr uint8 NO_VAL<uint8> = NO_VAL8;
120+
template<> constexpr uint16 NO_VAL<uint16> = NO_VAL16;
121+
template<> constexpr uint32 NO_VAL<uint32> = NO_VAL32;
122+
template<> constexpr uint64 NO_VAL<uint64> = NO_VAL64;
123+
115124
/*
116125
* Performs an arithmetic right shift, i.e. shift with progapating
117126
* the most significant bit.

simulator/mips/mips_instr.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,9 @@ class MIPSInstr
135135

136136
enum class RegType : uint8
137137
{
138-
RS,
139-
RT,
140-
RD,
141-
ZERO,
142-
HI,
143-
LO,
144-
HI_LO,
145-
RA
138+
RS, RT, RD,
139+
ZERO, RA,
140+
HI, LO, HI_LO
146141
};
147142

148143
static bool is_explicit_register( RegType type)
@@ -182,11 +177,11 @@ class MIPSInstr
182177
auto sign_extend() const { return static_cast<RegisterSInt>( static_cast<int16>(v_imm)); }
183178
auto zero_extend() const { return static_cast<RegisterUInt>( static_cast<uint16>(v_imm)); }
184179

185-
RegisterUInt v_src1 = static_cast<RegisterUInt>(NO_VAL64);
186-
RegisterUInt v_src2 = static_cast<RegisterUInt>(NO_VAL64);
187-
RegisterUInt v_dst = static_cast<RegisterUInt>(NO_VAL64);
188-
RegisterUInt v_dst2 = static_cast<RegisterUInt>(NO_VAL64);
189-
RegisterUInt mask = all_ones<RegisterUInt>();
180+
RegisterUInt v_src1 = NO_VAL<RegisterUInt>;
181+
RegisterUInt v_src2 = NO_VAL<RegisterUInt>;
182+
RegisterUInt v_dst = NO_VAL<RegisterUInt>;
183+
RegisterUInt v_dst2 = NO_VAL<RegisterUInt>;
184+
RegisterUInt mask = all_ones<RegisterUInt>();
190185

191186
uint16 shamt = NO_VAL16;
192187
Addr mem_addr = NO_VAL32;

traces

Submodule traces updated 1 file

0 commit comments

Comments
 (0)