Changing the constructor arguments for RiscVFPState to make it easier to reuse. This change allows the class to be used with other RiscV related/derived architectures that doesn't use the RiscVState class. PiperOrigin-RevId: 660101382 Change-Id: If41be35ffad21ed172f48110dde7773bcbc25be1
diff --git a/riscv/BUILD b/riscv/BUILD index 107a49e..4fcf6b8 100644 --- a/riscv/BUILD +++ b/riscv/BUILD
@@ -344,6 +344,7 @@ "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/log", "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", "@com_google_mpact-sim//mpact/sim/generic:arch_state", "@com_google_mpact-sim//mpact/sim/generic:core", "@com_google_mpact-sim//mpact/sim/generic:instruction", @@ -428,6 +429,7 @@ "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/log", "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:span", "@com_google_mpact-sim//mpact/sim/generic:arch_state", "@com_google_mpact-sim//mpact/sim/generic:core", "@com_google_mpact-sim//mpact/sim/generic:instruction",
diff --git a/riscv/riscv_fp_state.cc b/riscv/riscv_fp_state.cc index e05cac0..543d219 100644 --- a/riscv/riscv_fp_state.cc +++ b/riscv/riscv_fp_state.cc
@@ -50,15 +50,16 @@ LOG(ERROR) << status.message(); } -RiscVFPState::RiscVFPState(RiscVState *rv_state) : rv_state_(rv_state) { +RiscVFPState::RiscVFPState(RiscVCsrSet *csr_set, ArchState *rv_state) + : rv_state_(rv_state) { fcsr_ = new RiscVFcsr(this); frm_ = new RiscVFrm(this); fflags_ = new RiscVFflags(this); host_fp_interface_ = GetHostFloatingPointInterface(); - LogIfError(rv_state_->csr_set()->AddCsr(fcsr_)); - LogIfError(rv_state_->csr_set()->AddCsr(frm_)); - LogIfError(rv_state_->csr_set()->AddCsr(fflags_)); + LogIfError(csr_set->AddCsr(fcsr_)); + LogIfError(csr_set->AddCsr(frm_)); + LogIfError(csr_set->AddCsr(fflags_)); } RiscVFPState::~RiscVFPState() {
diff --git a/riscv/riscv_fp_state.h b/riscv/riscv_fp_state.h index f8fa70a..f5d8a1e 100644 --- a/riscv/riscv_fp_state.h +++ b/riscv/riscv_fp_state.h
@@ -94,7 +94,7 @@ public: RiscVFPState() = delete; RiscVFPState(const RiscVFPState &) = delete; - explicit RiscVFPState(RiscVState *rv_state); + explicit RiscVFPState(RiscVCsrSet *csr_set, ArchState *rv_state); ~RiscVFPState(); FPRoundingMode GetRoundingMode() const; @@ -108,14 +108,14 @@ RiscVFrm *frm() const { return frm_; } RiscVFflags *fflags() const { return fflags_; } // Parent state. - RiscVState *rv_state() const { return rv_state_; } + ArchState *rv_state() const { return rv_state_; } // Host interface. HostFloatingPointInterface *host_fp_interface() const { return host_fp_interface_; } private: - RiscVState *rv_state_; + ArchState *rv_state_; RiscVFcsr *fcsr_ = nullptr; RiscVFrm *frm_ = nullptr; RiscVFflags *fflags_ = nullptr;
diff --git a/riscv/riscv_renode.cc b/riscv/riscv_renode.cc index 4d923b0..cbfd5f0 100644 --- a/riscv/riscv_renode.cc +++ b/riscv/riscv_renode.cc
@@ -100,7 +100,7 @@ // Set up state, decoder, and top. rv_state_ = new RiscVState("RiscVRenode", xlen, mem_profiler_, static_cast<AtomicMemoryOpInterface *>(router_)); - rv_fp_state_ = new RiscVFPState(rv_state_); + rv_fp_state_ = new RiscVFPState(rv_state_->csr_set(), rv_state_); rv_state_->set_rv_fp(rv_fp_state_); std::string reg_name; if (xlen == RiscVXlen::RV32) {
diff --git a/riscv/rv32g_sim.cc b/riscv/rv32g_sim.cc index 43aae14..ab488fc 100644 --- a/riscv/rv32g_sim.cc +++ b/riscv/rv32g_sim.cc
@@ -230,7 +230,7 @@ // Set up architectural state and decoder. RiscVState rv_state("RiscV32", RiscVXlen::RV32, memory, atomic_memory); // For floating point support add the fp state. - RiscVFPState rv_fp_state(&rv_state); + RiscVFPState rv_fp_state(rv_state.csr_set(), &rv_state); rv_state.set_rv_fp(&rv_fp_state); // Create the instruction decoder. RiscV32Decoder rv_decoder(&rv_state, memory);
diff --git a/riscv/rv32g_test_sim.cc b/riscv/rv32g_test_sim.cc index fbda75a..00dac5e 100644 --- a/riscv/rv32g_test_sim.cc +++ b/riscv/rv32g_test_sim.cc
@@ -87,7 +87,7 @@ // Set up architectural state and decoder. RiscVState rv_state("RiscV32", RiscVXlen::RV32, watcher, atomic_memory); // For floating point support add the fp state. - RiscVFPState rv_fp_state(&rv_state); + RiscVFPState rv_fp_state(rv_state.csr_set(), &rv_state); rv_state.set_rv_fp(&rv_fp_state); // Create the instruction decoder. RiscV32Decoder rv_decoder(&rv_state, watcher);
diff --git a/riscv/rv32gv_sim.cc b/riscv/rv32gv_sim.cc index 4f5f911..1748013 100644 --- a/riscv/rv32gv_sim.cc +++ b/riscv/rv32gv_sim.cc
@@ -230,7 +230,7 @@ // Set up architectural state and decoder. RiscVState rv_state("RiscV32GV", RiscVXlen::RV32, memory, atomic_memory); // For floating point support add the fp state. - RiscVFPState rv_fp_state(&rv_state); + RiscVFPState rv_fp_state(rv_state.csr_set(), &rv_state); rv_state.set_rv_fp(&rv_fp_state); // Create the instruction decoder. RiscV32GVecDecoder rv_decoder(&rv_state, memory);
diff --git a/riscv/rv64g_sim.cc b/riscv/rv64g_sim.cc index 6104e46..1c11f7a 100644 --- a/riscv/rv64g_sim.cc +++ b/riscv/rv64g_sim.cc
@@ -206,7 +206,7 @@ // Set up architectural state and decoder. RiscVState rv_state("RiscV64", RiscVXlen::RV64, memory, atomic_memory); // For floating point support add the fp state. - RiscVFPState rv_fp_state(&rv_state); + RiscVFPState rv_fp_state(rv_state.csr_set(), &rv_state); rv_state.set_rv_fp(&rv_fp_state); // Create the instruction decoder. RiscV64Decoder rv_decoder(&rv_state, memory);
diff --git a/riscv/rv64g_test_sim.cc b/riscv/rv64g_test_sim.cc index 797e792..fdb67ad 100644 --- a/riscv/rv64g_test_sim.cc +++ b/riscv/rv64g_test_sim.cc
@@ -92,7 +92,7 @@ // Set up architectural state and decoder. RiscVState rv_state("RiscV64", RiscVXlen::RV64, test_watcher, atomic_memory); // For floating point support add the fp state. - RiscVFPState rv_fp_state(&rv_state); + RiscVFPState rv_fp_state(rv_state.csr_set(), &rv_state); rv_state.set_rv_fp(&rv_fp_state); // Create the instruction decoder. RiscV64Decoder rv_decoder(&rv_state, watcher);
diff --git a/riscv/rv64gv_sim.cc b/riscv/rv64gv_sim.cc index 5ad90aa..4e765b9 100644 --- a/riscv/rv64gv_sim.cc +++ b/riscv/rv64gv_sim.cc
@@ -206,7 +206,7 @@ // Set up architectural state and decoder. RiscVState rv_state("RiscV64", RiscVXlen::RV64, memory, atomic_memory); // For floating point support add the fp state. - RiscVFPState rv_fp_state(&rv_state); + RiscVFPState rv_fp_state(rv_state.csr_set(), &rv_state); rv_state.set_rv_fp(&rv_fp_state); // Create the instruction decoder. RiscV64GVecDecoder rv_decoder(&rv_state, memory);
diff --git a/riscv/test/riscv_fp_test_base.h b/riscv/test/riscv_fp_test_base.h index 45d9504..cce8523 100644 --- a/riscv/test/riscv_fp_test_base.h +++ b/riscv/test/riscv_fp_test_base.h
@@ -290,7 +290,7 @@ RiscVFPInstructionTestBase() { memory_ = new FlatDemandMemory(0); state_ = new RiscVState("test", RiscVXlen::RV32, memory_); - rv_fp_ = new mpact::sim::riscv::RiscVFPState(state_); + rv_fp_ = new mpact::sim::riscv::RiscVFPState(state_->csr_set(), state_); state_->set_rv_fp(rv_fp_); instruction_ = new Instruction(kInstAddress, state_); instruction_->set_size(4);
diff --git a/riscv/test/riscv_top_test.cc b/riscv/test/riscv_top_test.cc index c3f059b..dcd0c78 100644 --- a/riscv/test/riscv_top_test.cc +++ b/riscv/test/riscv_top_test.cc
@@ -165,7 +165,7 @@ RiscVTopTest() { memory_ = new FlatDemandMemory(); state_ = new RiscVState("RV32", RiscVXlen::RV32, memory_); - fp_state_ = new RiscVFPState(state_); + fp_state_ = new RiscVFPState(state_->csr_set(), state_); state_->set_rv_fp(fp_state_); decoder_ = new RiscV32Decoder(state_, memory_);
diff --git a/riscv/test/riscv_vector_fp_test_utilities.h b/riscv/test/riscv_vector_fp_test_utilities.h index d7cd698..96c8120 100644 --- a/riscv/test/riscv_vector_fp_test_utilities.h +++ b/riscv/test/riscv_vector_fp_test_utilities.h
@@ -228,7 +228,7 @@ : public ::mpact::sim::riscv::test::RiscVVectorInstructionsTestBase { public: RiscVFPInstructionsTestBase() { - rv_fp_ = new mpact::sim::riscv::RiscVFPState(state_); + rv_fp_ = new mpact::sim::riscv::RiscVFPState(state_->csr_set(), state_); state_->set_rv_fp(rv_fp_); } ~RiscVFPInstructionsTestBase() override {
diff --git a/riscv/test/riscv_vector_fp_unary_instructions_test.cc b/riscv/test/riscv_vector_fp_unary_instructions_test.cc index 43c6327..8a5f43c 100644 --- a/riscv/test/riscv_vector_fp_unary_instructions_test.cc +++ b/riscv/test/riscv_vector_fp_unary_instructions_test.cc
@@ -108,7 +108,7 @@ : public ::mpact::sim::riscv::test::RiscVVectorInstructionsTestBase { public: RiscVFPUnaryInstructionsTest() { - rv_fp_ = new mpact::sim::riscv::RiscVFPState(state_); + rv_fp_ = new mpact::sim::riscv::RiscVFPState(state_->csr_set(), state_); state_->set_rv_fp(rv_fp_); } ~RiscVFPUnaryInstructionsTest() override {