Fixed missing getter for riscv32 zb*. PiperOrigin-RevId: 672685779 Change-Id: I584307fd59a797cc2b11048d1f450f401dae2285
diff --git a/riscv/BUILD b/riscv/BUILD index 2466ca1..bf1b1e8 100644 --- a/riscv/BUILD +++ b/riscv/BUILD
@@ -493,6 +493,7 @@ "riscv_getters_rv64.h", "riscv_getters_vector.h", "riscv_getters_zba.h", + "riscv_getters_zbb32.h", "riscv_getters_zbb64.h", ], deps = [
diff --git a/riscv/riscv32gzb_encoding.cc b/riscv/riscv32gzb_encoding.cc index 63aedc5..ed26f29 100644 --- a/riscv/riscv32gzb_encoding.cc +++ b/riscv/riscv32gzb_encoding.cc
@@ -29,6 +29,7 @@ #include "riscv/riscv_getters.h" #include "riscv/riscv_getters_rv32.h" #include "riscv/riscv_getters_zba.h" +#include "riscv/riscv_getters_zbb32.h" #include "riscv/riscv_register.h" #include "riscv/riscv_state.h" @@ -67,6 +68,8 @@ simple_resource_getters_, this); AddRiscVZbaSourceGetters<SourceOpEnum, Extractors, RV32Register, RVFpRegister>(source_op_getters_, this); + AddRiscVZbb32SourceGetters<SourceOpEnum, Extractors, RV32Register, + RVFpRegister>(source_op_getters_, this); // Verify that there are getters for each enum value. for (int i = *SourceOpEnum::kNone; i < *SourceOpEnum::kPastMaxValue; ++i) { if (source_op_getters_.find(i) == source_op_getters_.end()) {
diff --git a/riscv/riscv_getters_rv32.h b/riscv/riscv_getters_rv32.h index fde16f0..3f51eab 100644 --- a/riscv/riscv_getters_rv32.h +++ b/riscv/riscv_getters_rv32.h
@@ -100,6 +100,10 @@ int num = Extractors::CS::ExtractCsRs2(common->inst_word()); return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num)); }); + Insert(getter_map, *Enum::kCfrs2, [common]() -> generic::SimpleResource * { + int num = Extractors::CR::ExtractRs2(common->inst_word()); + return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num)); + }); } } // namespace riscv
diff --git a/riscv/riscv_getters_zbb32.h b/riscv/riscv_getters_zbb32.h new file mode 100644 index 0000000..f640a48 --- /dev/null +++ b/riscv/riscv_getters_zbb32.h
@@ -0,0 +1,53 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_ZBB32_H_ +#define THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_ZBB32_H_ + +#include <cstdint> +#include <new> + +#include "mpact/sim/generic/immediate_operand.h" +#include "mpact/sim/generic/type_helpers.h" +#include "riscv/riscv_encoding_common.h" +#include "riscv/riscv_getter_helpers.h" + +namespace mpact { +namespace sim { +namespace riscv { + +using ::mpact::sim::generic::operator*; // NOLINT: is used below (clang error). + +// The following function adds source operand getters to the given getter map. +// The function uses the template parameters to get the correct enum type +// for the instruction set being decoded. The Extractors parameter is used to +// get the correct instruction format extractor for the instruction set. The +// IntRegister and FpRegister parameters are used to get the correct register +// types for the instruction set. +template <typename Enum, typename Extractors, typename IntRegister, + typename FpRegister> +void AddRiscVZbb32SourceGetters(SourceOpGetterMap &getter_map, + RiscVEncodingCommon *common) { + // Source operand getters. + Insert(getter_map, *Enum::kRUimm5, [common]() { + uint32_t uimm = Extractors::RType::ExtractRUimm5(common->inst_word()); + return new generic::ImmediateOperand<uint32_t>(uimm); + }); +} + +} // namespace riscv +} // namespace sim +} // namespace mpact + +#endif // THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_ZBB32_H_