dev: add method to set initial register value out of constructor.

The initial value of register is set in constructor but there is no
standard way to assign the initial value and default value at the same
time out of that. So we decided to add an extra method to set the
initialValue to current register value. The usecase would be:

reg.get().field1 = val1;
reg.get().field2 = val2;
reg.resetInitialValue();

Change-Id: Ibc5454e2945cc6aff943e6599043edd8ca442f5f
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67917
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
This commit is contained in:
hungweihsu
2023-02-09 05:39:15 +00:00
committed by Hung-Wei Hsu
parent ea9239ae09
commit e10be09dcf
2 changed files with 25 additions and 0 deletions

View File

@@ -759,6 +759,9 @@ class RegisterBank : public RegisterBankBase
// constructor. This is intended to be used in a resetter function.
const Data &initialValue() const { return _resetData; }
// Reset the initial value, which is normally set in the constructor,
// to the register's current value.
void resetInitialValue() { _resetData = _data; }
/*
* Interface for accessing the register's state, for use by the

View File

@@ -881,6 +881,28 @@ TEST_F(TypedRegisterTest, DefaultResetter)
EXPECT_EQ(reg.get(), initial_value);
}
// Set initial value later than constructor
TEST_F(TypedRegisterTest, LateInitialValueAssignment)
{
BackingType initial_value = reg.get();
BackingType new_initial_value = initial_value + 1;
reg.get() = new_initial_value;
reg.resetInitialValue();
EXPECT_EQ(reg.get(), new_initial_value);
EXPECT_EQ(reg.initialValue(), new_initial_value);
reg.get() = new_initial_value + 1;
EXPECT_EQ(reg.get(), new_initial_value + 1);
EXPECT_EQ(reg.initialValue(), new_initial_value);
reg.reset();
EXPECT_EQ(reg.get(), new_initial_value);
EXPECT_EQ(reg.initialValue(), new_initial_value);
}
// Set a custom resetter for a register.
TEST_F(TypedRegisterTest, Resetter)
{