This adds additional bit manipulation instructions to the RiscV 64 bit simulator.
It also factors out some of the encoding initializers so that they can be
reused across multiple decoders without having to replicate them.

This also fixes a decoding issue due to underspecified encodings of some vector memory instructions.

PiperOrigin-RevId: 671853580
Change-Id: I432fa74b929a06c211534f12a9e6e836a3d7f049
diff --git a/riscv/BUILD b/riscv/BUILD
index e6e4984..2466ca1 100644
--- a/riscv/BUILD
+++ b/riscv/BUILD
@@ -24,14 +24,22 @@
 exports_files([
     "riscv32g.bin_fmt",
     "riscv32g.isa",
+    "riscv32gzb.bin_fmt",
+    "riscv32gzb.isa",
     "riscv32v.bin_fmt",
     "riscv32v.isa",
+    "riscv32zb.bin_fmt",
+    "riscv32zb.isa",
+    "riscv64gzb.bin_fmt",
+    "riscv64gzb.isa",
     "riscv64g.bin_fmt",
     "riscv64g.isa",
     "riscv64v.bin_fmt",
     "riscv64v.isa",
-    "riscv_vector.isa",
+    "riscv64zb.bin_fmt",
+    "riscv64zb.isa",
     "riscv_vector.bin_fmt",
+    "riscv_vector.isa",
 ])
 
 config_setting(
@@ -122,7 +130,6 @@
     name = "riscv_g",
     srcs = [
         "riscv_a_instructions.cc",
-        "riscv_b_instructions.cc",
         "riscv_d_instructions.cc",
         "riscv_f_instructions.cc",
         "riscv_i_instructions.cc",
@@ -133,7 +140,6 @@
     ],
     hdrs = [
         "riscv_a_instructions.h",
-        "riscv_b_instructions.h",
         "riscv_d_instructions.h",
         "riscv_f_instructions.h",
         "riscv_i_instructions.h",
@@ -183,6 +189,7 @@
     deps = [
         ":riscv_g",
         ":riscv_state",
+        "@com_google_absl//absl/base",
         "@com_google_absl//absl/numeric:bits",
         "@com_google_mpact-sim//mpact/sim/generic:instruction",
     ],
@@ -349,12 +356,16 @@
     name = "riscv64gv_isa",
     src = "riscv64v.isa",
     includes = [
+        "riscv32zb.isa",
         "riscv64g.isa",
+        "riscv64gzb.isa",
+        "riscv64zb.isa",
         "riscv_vector.isa",
     ],
     isa_name = "RiscV64GV",
     prefix = "riscv64gv",
     deps = [
+        ":riscv_bitmanip_instructions",
         ":riscv_g",
         ":riscv_v",
         "@com_google_absl//absl/functional:bind_front",
@@ -366,7 +377,9 @@
     src = "riscv64v.bin_fmt",
     decoder_name = "RiscV64GV",
     includes = [
+        "riscv32zb.bin_fmt",
         "riscv64g.bin_fmt",
+        "riscv64zb.bin_fmt",
         "riscv_vector.bin_fmt",
     ],
     prefix = "riscv64gv",
@@ -375,6 +388,75 @@
     ],
 )
 
+mpact_isa_decoder(
+    name = "riscv64gvzb_isa",
+    src = "riscv64v.isa",
+    includes = [
+        "riscv32zb.isa",
+        "riscv64g.isa",
+        "riscv64gzb.isa",
+        "riscv64zb.isa",
+        "riscv_vector.isa",
+    ],
+    isa_name = "RiscV64GVZB",
+    prefix = "riscv64gvzb",
+    deps = [
+        ":riscv_bitmanip_instructions",
+        ":riscv_g",
+        ":riscv_v",
+        "@com_google_absl//absl/functional:bind_front",
+    ],
+)
+
+mpact_bin_fmt_decoder(
+    name = "riscv64gvzb_bin_fmt",
+    src = "riscv64v.bin_fmt",
+    decoder_name = "RiscV64GVZB",
+    includes = [
+        "riscv32zb.bin_fmt",
+        "riscv64g.bin_fmt",
+        "riscv64zb.bin_fmt",
+        "riscv_vector.bin_fmt",
+    ],
+    prefix = "riscv64gvzb",
+    deps = [
+        ":riscv64gvzb_isa",
+    ],
+)
+
+mpact_isa_decoder(
+    name = "riscv64gzb_isa",
+    src = "riscv64gzb.isa",
+    includes = [
+        "riscv32zb.isa",
+        "riscv64g.isa",
+        "riscv64zb.isa",
+    ],
+    isa_name = "RiscV64GZB",
+    prefix = "riscv64gzb",
+    deps = [
+        ":riscv_bitmanip_instructions",
+        ":riscv_g",
+        ":riscv_v",
+        "@com_google_absl//absl/functional:bind_front",
+    ],
+)
+
+mpact_bin_fmt_decoder(
+    name = "riscv64gzb_bin_fmt",
+    src = "riscv64gzb.bin_fmt",
+    decoder_name = "RiscV64GZB",
+    includes = [
+        "riscv32zb.bin_fmt",
+        "riscv64g.bin_fmt",
+        "riscv64zb.bin_fmt",
+    ],
+    prefix = "riscv64gzb",
+    deps = [
+        ":riscv64gzb_isa",
+    ],
+)
+
 cc_library(
     name = "riscv32g_decoder",
     srcs = [
@@ -407,6 +489,11 @@
     hdrs = [
         "riscv_getter_helpers.h",
         "riscv_getters.h",
+        "riscv_getters_rv32.h",
+        "riscv_getters_rv64.h",
+        "riscv_getters_vector.h",
+        "riscv_getters_zba.h",
+        "riscv_getters_zbb64.h",
     ],
     deps = [
         ":riscv_encoding_common",
@@ -415,7 +502,10 @@
         "@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:type_helpers",
     ],
 )
 
@@ -452,6 +542,32 @@
 )
 
 cc_library(
+    name = "riscv64g_bitmanip_decoder",
+    srcs = [
+        "riscv64g_bitmanip_decoder.cc",
+        "riscv64gzb_encoding.cc",
+    ],
+    hdrs = [
+        "riscv64g_bitmanip_decoder.h",
+        "riscv64gzb_encoding.h",
+    ],
+    copts = ["-O3"],
+    deps = [
+        ":riscv64gzb_bin_fmt",
+        ":riscv64gzb_isa",
+        ":riscv_encoding_common",
+        ":riscv_getters",
+        ":riscv_state",
+        "@com_google_absl//absl/log",
+        "@com_google_absl//absl/strings",
+        "@com_google_mpact-sim//mpact/sim/generic:core",
+        "@com_google_mpact-sim//mpact/sim/generic:instruction",
+        "@com_google_mpact-sim//mpact/sim/generic:type_helpers",
+        "@com_google_mpact-sim//mpact/sim/util/memory",
+    ],
+)
+
+cc_library(
     name = "riscv32g_vec_decoder",
     srcs = [
         "riscv32g_vec_decoder.cc",
@@ -521,6 +637,7 @@
         ":riscv64gv_bin_fmt",
         ":riscv64gv_isa",
         ":riscv_state",
+        "@com_google_absl//absl/base",
         "@com_google_absl//absl/container:flat_hash_map",
         "@com_google_absl//absl/functional:any_invocable",
         "@com_google_absl//absl/log",
@@ -536,6 +653,40 @@
 )
 
 cc_library(
+    name = "riscv64gzb_vec_decoder",
+    srcs = [
+        "riscv64gzb_vec_decoder.cc",
+        "riscv64gzb_vec_encoding.cc",
+    ],
+    hdrs = [
+        "riscv64gzb_vec_decoder.h",
+        "riscv64gzb_vec_encoding.h",
+    ],
+    copts = ["-O3"],
+    deps = [
+        ":riscv64gvzb_bin_fmt",
+        ":riscv64gvzb_isa",
+        ":riscv_encoding_common",
+        ":riscv_getters",
+        ":riscv_state",
+        "@com_google_absl//absl/base",
+        "@com_google_absl//absl/container:flat_hash_map",
+        "@com_google_absl//absl/functional:any_invocable",
+        "@com_google_absl//absl/functional:bind_front",
+        "@com_google_absl//absl/log",
+        "@com_google_absl//absl/strings",
+        "@com_google_absl//absl/strings:str_format",
+        "@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",
+        "@com_google_mpact-sim//mpact/sim/generic:program_error",
+        "@com_google_mpact-sim//mpact/sim/generic:type_helpers",
+        "@com_google_mpact-sim//mpact/sim/util/memory",
+    ],
+)
+
+cc_library(
     name = "riscv_top",
     srcs = [
         "riscv_top.cc",
@@ -552,6 +703,7 @@
         "@com_google_absl//absl/container:flat_hash_map",
         "@com_google_absl//absl/functional:any_invocable",
         "@com_google_absl//absl/functional:bind_front",
+        "@com_google_absl//absl/log",
         "@com_google_absl//absl/log:check",
         "@com_google_absl//absl/status",
         "@com_google_absl//absl/status:statusor",
@@ -802,6 +954,7 @@
     deps = [
         ":debug_command_shell",
         ":riscv64g_vec_decoder",
+        ":riscv64gzb_vec_decoder",
         ":riscv_arm_semihost",
         ":riscv_fp_state",
         ":riscv_state",
@@ -813,6 +966,7 @@
         "@com_google_absl//absl/strings",
         "@com_google_absl//absl/strings:str_format",
         "@com_google_absl//absl/time",
+        "@com_google_mpact-sim//mpact/sim/generic:core",
         "@com_google_mpact-sim//mpact/sim/generic:core_debug_interface",
         "@com_google_mpact-sim//mpact/sim/generic:counters",
         "@com_google_mpact-sim//mpact/sim/generic:instruction",
diff --git a/riscv/riscv32gzb.bin_fmt b/riscv/riscv32gzb.bin_fmt
index 65e6ef0..e42a60d 100644
--- a/riscv/riscv32gzb.bin_fmt
+++ b/riscv/riscv32gzb.bin_fmt
@@ -1,3 +1,10 @@
+// Copyright 2024 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,
@@ -11,7 +18,9 @@
   includes {
     #include "riscv/riscv32gzb_decoder.h"
   }
-  RiscV32GZBInst32 = {RiscVGInst32, RiscVZbaInst32, RiscVZbbInst32, RiscVZbcInst32, RiscVZbsInst32};
+  RiscV32GZBInst32 = {RiscVGInst32, RiscVZbaInst32, RiscVZbbInst32,
+                      RiscVZbbInst32Only, RiscVZbbImmInst32, RiscVZbcInst32,
+                      RiscVZbsInst32, RiscVZbsImmInst32};
   RiscV32GZBInst16 = {RiscVCInst16};
 }
 
diff --git a/riscv/riscv32gzb.isa b/riscv/riscv32gzb.isa
index 490d7a0..6add27d 100644
--- a/riscv/riscv32gzb.isa
+++ b/riscv/riscv32gzb.isa
@@ -22,7 +22,8 @@
 #include "riscv/riscv32g.isa"
 #include "riscv/riscv32zb.isa"
 
-slot riscv32gzb : riscv32g, riscv32_zba, riscv32_zbb, riscv32_zbc, riscv32_zbs {
+slot riscv32gzb : riscv32g, riscv32_zba, riscv32_zbb, riscv32_zbb_imm,
+                  riscv32_zbc, riscv32_zbs, riscv32_zbs_imm {
   default size = 4;
   default opcode =
     disasm: "Illegal instruction at 0x%(@:08x)",
diff --git a/riscv/riscv32gzb_encoding.cc b/riscv/riscv32gzb_encoding.cc
index 6538bcb..63aedc5 100644
--- a/riscv/riscv32gzb_encoding.cc
+++ b/riscv/riscv32gzb_encoding.cc
@@ -27,6 +27,8 @@
 #include "riscv/riscv32gzb_enums.h"
 #include "riscv/riscv_encoding_common.h"
 #include "riscv/riscv_getters.h"
+#include "riscv/riscv_getters_rv32.h"
+#include "riscv/riscv_getters_zba.h"
 #include "riscv/riscv_register.h"
 #include "riscv/riscv_state.h"
 
@@ -57,6 +59,14 @@
       dest_op_getters_, this);
   AddRiscVSimpleResourceGetters<SimpleResourceEnum, Extractors>(
       simple_resource_getters_, this);
+  AddRiscV32SourceGetters<SourceOpEnum, Extractors, RV32Register, RVFpRegister>(
+      source_op_getters_, this);
+  AddRiscV32DestGetters<DestOpEnum, Extractors, RV32Register, RVFpRegister>(
+      dest_op_getters_, this);
+  AddRiscV32SimpleResourceGetters<SimpleResourceEnum, Extractors>(
+      simple_resource_getters_, this);
+  AddRiscVZbaSourceGetters<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/riscv32zb.bin_fmt b/riscv/riscv32zb.bin_fmt
index 5f932ff..9560cfe 100644
--- a/riscv/riscv32zb.bin_fmt
+++ b/riscv/riscv32zb.bin_fmt
@@ -31,14 +31,20 @@
   minu:   RType : func7 == 0b000'0101, func3 == 0b101, opcode == 0b011'0011;
   sext_b: RType : func7 == 0b011'0000, rs2 == 0b0'0100, func3 == 0b001, opcode == 0b001'0011;
   sext_h: RType : func7 == 0b011'0000, rs2 == 0b0'0101, func3 == 0b001, opcode == 0b001'0011;
-  zext_h: RType : func7 == 0b000'0100, rs2 == 0b0'0000, func3 == 0b100, opcode == 0b011'0011;
   rol:    RType : func7 == 0b011'0000, func3 == 0b001, opcode == 0b011'0011;
   ror:    RType : func7 == 0b011'0000, func3 == 0b101, opcode == 0b011'0011;
-  rori:   RType : func7 == 0b011'0000, func3 == 0b101, opcode == 0b001'0011;
   orcb:   RType : func7 == 0b001'0100, rs2 == 0b0'0111, func3 == 0b101, opcode == 0b001'0011;
   rev8:   RType : func7 == 0b011'0100, rs2 == 0b1'1000, func3 == 0b101, opcode == 0b001'0011;
 };
 
+instruction group RiscVZbbInst32Only[32] : Inst32Format {
+  zext_h: RType : func7 == 0b000'0100, rs2 == 0b0'0000, func3 == 0b100, opcode == 0b011'0011;
+}
+
+instruction group RiscVZbbImmInst32[32] : Inst32Format {
+  rori:   RType : func7 == 0b011'0000, func3 == 0b101, opcode == 0b001'0011;
+}
+
 instruction group RiscVZbcInst32[32] : Inst32Format {
   clmul:  RType : func7 == 0b000'0101, func3 == 0b001, opcode == 0b011'0011;
   clmulh: RType : func7 == 0b000'0101, func3 == 0b011, opcode == 0b011'0011;
@@ -47,11 +53,14 @@
 
 instruction group RiscVZbsInst32[32] : Inst32Format {
   bclr:   RType : func7 == 0b010'0100, func3 == 0b001, opcode == 0b011'0011;
-  bclri:  RType : func7 == 0b010'0100, func3 == 0b001, opcode == 0b001'0011;
   bext:   RType : func7 == 0b010'0100, func3 == 0b101, opcode == 0b011'0011;
-  bexti:  RType : func7 == 0b010'0100, func3 == 0b101, opcode == 0b001'0011;
   binv:   RType : func7 == 0b011'0100, func3 == 0b001, opcode == 0b011'0011;
-  binvi:  RType : func7 == 0b011'0100, func3 == 0b001, opcode == 0b001'0011;
   bset:   RType : func7 == 0b001'0100, func3 == 0b001, opcode == 0b011'0011;
+};
+
+instruction group RiscVZbsImmInst32[32] : Inst32Format {
+  bclri:  RType : func7 == 0b010'0100, func3 == 0b001, opcode == 0b001'0011;
+  bexti:  RType : func7 == 0b010'0100, func3 == 0b101, opcode == 0b001'0011;
+  binvi:  RType : func7 == 0b011'0100, func3 == 0b001, opcode == 0b001'0011;
   bseti:  RType : func7 == 0b001'0100, func3 == 0b001, opcode == 0b001'0011;
-};
\ No newline at end of file
+};
diff --git a/riscv/riscv32zb.isa b/riscv/riscv32zb.isa
index 02502c1..d878c3f 100644
--- a/riscv/riscv32zb.isa
+++ b/riscv/riscv32zb.isa
@@ -112,15 +112,11 @@
     rol{: rs1, rs2 : rd},
       resources: ThreeOp,
       disasm: "rol", "%rd, %rs1, %rs2",
-      semfunc: "&RV32::RiscVrol";
+      semfunc: "&RV32::RiscVRol";
     ror{: rs1, rs2 : rd},
       resources: ThreeOp,
       disasm: "ror", "%rd, %rs1, %rs2",
-      semfunc: "&RV32::RiscVror";
-    rori{: rs1, r_uimm5 : rd},
-      resources: TwoOp,
-      disasm: "rori", "%rd, %rs1, %r_uimm5",
-      semfunc: "&RV32::RiscVror";
+      semfunc: "&RV32::RiscVRor";
     // OR combine.
     orcb{: rs1 : rd},
       resources: TwoOp,
@@ -134,6 +130,21 @@
   }
 }
 
+slot riscv32_zbb_imm {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources TwoOp = { next_pc, rs1 : rd[..rd]};
+  resources ThreeOp = { next_pc, rs1, rs2 : rd[..rd]};
+  opcodes {
+    rori{: rs1, r_uimm5 : rd},
+      resources: TwoOp,
+      disasm: "rori", "%rd, %rs1, %r_uimm5",
+      semfunc: "&RV32::RiscVRor";
+  }
+}
+
 slot riscv32_zbc {
   default size = 4;
   default opcode =
@@ -170,33 +181,44 @@
       resources: ThreeOp,
       disasm: "bclr", "%rd, %rs1, %rs2",
       semfunc: "&RV32::RiscVBclr";
-    bclri{: rs1, r_uimm5 : rd},
-      resources: TwoOp,
-      disasm: "bclri", "%rd, %rs1, %r_uimm5",
-      semfunc: "&RV32::RiscVBclr";
     bext{: rs1, rs2 : rd},
       resources: ThreeOp,
       disasm: "bext", "%rd, %rs1, %rs2",
       semfunc: "&RV32::RiscVBext";
-    bexti{: rs1, r_uimm5 : rd},
-      resources: TwoOp,
-      disasm: "bexti", "%rd, %rs1, %r_uimm5",
-      semfunc: "&RV32::RiscVBext";
     binv{: rs1, rs2 : rd},
       resources: ThreeOp,
       disasm: "binv", "%rd, %rs1, %rs2",
       semfunc: "&RV32::RiscVBinv";
-    binvi{: rs1, r_uimm5 : rd},
-      resources: TwoOp,
-      disasm: "binvi", "%rd, %rs1, %r_uimm5",
-      semfunc: "&RV32::RiscVBinv";
     bset{: rs1, rs2 : rd},
       resources: ThreeOp,
       disasm: "bset", "%rd, %rs1, %rs2",
       semfunc: "&RV32::RiscVBset";
+  }
+}
+
+slot riscv32_zbs_imm {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources TwoOp = { next_pc, rs1 : rd[..rd]};
+  opcodes {
+    // Single-bit instructions.
+    bclri{: rs1, r_uimm5 : rd},
+      resources: TwoOp,
+      disasm: "bclri", "%rd, %rs1, %r_uimm5",
+      semfunc: "&RV32::RiscVBclr";
+    bexti{: rs1, r_uimm5 : rd},
+      resources: TwoOp,
+      disasm: "bexti", "%rd, %rs1, %r_uimm5",
+      semfunc: "&RV32::RiscVBext";
+    binvi{: rs1, r_uimm5 : rd},
+      resources: TwoOp,
+      disasm: "binvi", "%rd, %rs1, %r_uimm5",
+      semfunc: "&RV32::RiscVBinv";
     bseti{: rs1, r_uimm5 : rd},
       resources: TwoOp,
       disasm: "bseti", "%rd, %rs1, %r_uimm5",
       semfunc: "&RV32::RiscVBset";
   }
-}
+}
\ No newline at end of file
diff --git a/riscv/riscv64g.bin_fmt b/riscv/riscv64g.bin_fmt
index 0224dab..cd553e3 100644
--- a/riscv/riscv64g.bin_fmt
+++ b/riscv/riscv64g.bin_fmt
@@ -338,41 +338,6 @@
   sfence_vma_zn : RType : func7 == 0b000'1001, rs2 != 0, rs1 == 0, func3 == 0, rd == 0, opcode == 0b111'0011;
   sfence_vma_nz : RType : func7 == 0b000'1001, rs2 == 0, rs1 != 0, func3 == 0, rd == 0, opcode == 0b111'0011;
   sfence_vma_nn : RType : func7 == 0b000'1001, rs2 != 0, rs1 != 0, func3 == 0, rd == 0, opcode == 0b111'0011;
-  // RV64 Zba instructions.
-  adduw    : RType  : func7 == 0b000'0100, func3 == 0b000, opcode == 0b011'1011;
-  sh1add   : RType  : func7 == 0b001'0000, func3 == 0b010, opcode == 0b011'0011;
-  sh2add   : RType  : func7 == 0b001'0000, func3 == 0b100, opcode == 0b011'0011;
-  sh3add   : RType  : func7 == 0b001'0000, func3 == 0b110, opcode == 0b011'0011;
-  sh1adduw : RType  : func7 == 0b001'0000, func3 == 0b010, opcode == 0b011'1011;
-  sh2adduw : RType  : func7 == 0b001'0000, func3 == 0b100, opcode == 0b011'1011;
-  sh3adduw : RType  : func7 == 0b001'0000, func3 == 0b110, opcode == 0b011'1011;
-  slliuw   : RSType : func6 ==  0b00'0010, func3 == 0b001, opcode == 0b001'1011;
-  // RV64 Zbb instructions.
-  andn  : RType   : func7  == 0b010'0000,       func3 == 0b111, opcode == 0b011'0011;
-  orn   : RType   : func7  == 0b010'0000,       func3 == 0b110, opcode == 0b011'0011;
-  xnor  : RType   : func7  == 0b010'0000,       func3 == 0b100, opcode == 0b011'0011;
-  clz   : F12Type : func12 == 0b0110'0000'0000, func3 == 0b001, opcode == 0b001'0011;
-  clzw  : F12Type : func12 == 0b0110'0000'0000, func3 == 0b001, opcode == 0b001'1011;
-  ctz   : F12Type : func12 == 0b0110'0000'0001, func3 == 0b001, opcode == 0b001'0011;
-  ctzw  : F12Type : func12 == 0b0110'0000'0001, func3 == 0b001, opcode == 0b001'1011;
-  cpop  : F12Type : func12 == 0b0110'0000'0010, func3 == 0b001, opcode == 0b001'0011;
-  cpopw : F12Type : func12 == 0b0110'0000'0010, func3 == 0b001, opcode == 0b001'1011;
-  max   : RType   : func7  == 0b000'0101,       func3 == 0b110, opcode == 0b011'0011;
-  maxu  : RType   : func7  == 0b000'0101,       func3 == 0b111, opcode == 0b011'0011;
-  min   : RType   : func7  == 0b000'0101,       func3 == 0b100, opcode == 0b011'0011;
-  minu  : RType   : func7  == 0b000'0101,       func3 == 0b101, opcode == 0b011'0011;
-  sexth : F12Type : func12 == 0b0110'0000'0101, func3 == 0b001, opcode == 0b001'0011;
-  sextb : F12Type : func12 == 0b0110'0000'0100, func3 == 0b001, opcode == 0b001'0011;
-  zextw : F12Type : func12 == 0b0000'1000'0000, func3 == 0b100, opcode == 0b011'0011;
-  zexth : F12Type : func12 == 0b0000'1000'0000, func3 == 0b100, opcode == 0b011'1011;
-  rol   : RType   : func7  == 0b011'0000,       func3 == 0b001, opcode == 0b011'0011;
-  rolw  : RType   : func7  == 0b011'0000,       func3 == 0b001, opcode == 0b011'1011;
-  ror   : RType   : func7  == 0b011'0000,       func3 == 0b101, opcode == 0b011'0011;
-  rorw  : RType   : func7  == 0b011'0000,       func3 == 0b101, opcode == 0b011'1011;
-  rori  : RSType  : func6  == 0b01'1000,        func3 == 0b101, opcode == 0b001'0011;
-  roriw : RType  : func7 == 0b011'0000,         func3 == 0b101, opcode == 0b001'1011;
-  orcb  : F12Type : func12 == 0b0010'1000'0111, func3 == 0b101, opcode == 0b001'0011;
-  rev8  : F12Type : func12 == 0b0110'1011'1000, func3 == 0b101, opcode == 0b001'0011;
 };
 
 // Compact instruction formats.
diff --git a/riscv/riscv64g.isa b/riscv/riscv64g.isa
index 906e616..eb0461d 100644
--- a/riscv/riscv64g.isa
+++ b/riscv/riscv64g.isa
@@ -40,7 +40,7 @@
 
 
 // This should be the RiscV64G set, where G stands for IMAFDZicsr_Zifencei.
-slot riscv64g : riscv64i, riscv64c, riscv64m, riscv64_amo_arithmetic, riscv64f, riscv64d, zba, zbb, zicsr, zfencei, privileged {
+slot riscv64g : riscv64i, riscv64c, riscv64m, riscv64_amo_arithmetic, riscv64f, riscv64d, zicsr, zfencei, privileged {
   default size = 4;
   default opcode =
     disasm: "Illegal instruction at 0x%(@:08x)",
@@ -109,13 +109,13 @@
       resources: TwoOp,
       disasm: "sraiw", "%rd, %rs1, 0x%(I_uimm5:x)",
       semfunc: "&RV64::RiscVISraw";
-    lui{: S_imm20 : rd},
+    lui{: U_imm20 : rd},
       resources: { next_pc : rd[0..]},
-      disasm: "lui", "%rd, 0x%(S_imm20:08x)",
+      disasm: "lui", "%rd, 0x%(U_imm20:08x)",
       semfunc: "&RV64::RiscVILui";
-    auipc{: S_imm20 : rd},
+    auipc{: U_imm20 : rd},
       resources: { next_pc : rd[0..]},
-      disasm: "auipc", "%rd, 0x%(S_imm20:08x)",
+      disasm: "auipc", "%rd, 0x%(U_imm20:08x)",
       semfunc: "&RV64::RiscVIAuipc";
     add{: rs1, rs2 : rd},
       resources: ThreeOp,
@@ -890,7 +890,7 @@
       disasm: "c.lw", "%rd, %I_ci_uimm6x4(%x2)",
       semfunc: "&RV64::RiscVILw", "&RV64::RiscVILwChild";
     cldsp{(: x2, I_ci_uimm6x8 : ), (: : rd)},
-      resources:{next_pc,x2 : frd[0..]},
+      resources:{next_pc,x2 : rd[0..]},
       disasm: "c.ldsp", "%rd, %I_ci_uimm6x8(%x2)",
       semfunc: "&RV64::RiscVILd", "&RV64::RiscVILdChild";
     cfldsp{(: x2, I_ci_uimm6x8 : ), (: : drd)},
@@ -1035,122 +1035,3 @@
       semfunc: "&RiscVIEbreak";
   }
 }
-
-slot zba {
-  includes {
-    #include "riscv/riscv_b_instructions.h"
-  }
-  default size = 4;
-  default latency = global_latency;
-  opcodes {
-    adduw{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVAddUw",
-      disasm: "add.uw %rd, %rs1, %rs2";
-    sh1add{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVSh1add",
-      disasm: "sh1add %rd, %rs1, %rs2";
-    sh2add{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVSh2add",
-      disasm: "sh2add %rd, %rs1, %rs2";
-    sh3add{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVSh3add",
-      disasm: "sh3add %rd, %rs1, %rs2";
-    sh1adduw{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVSh1adduw",
-      disasm: "sh1add.uw %rd, %rs1, %rs2";
-    sh2adduw{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVSh2adduw",
-      disasm: "sh2add.uw %rd, %rs1, %rs2";
-    sh3adduw{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVSh3adduw",
-      disasm: "sh3add.uw %rd, %rs1, %rs2";
-    slliuw{: rs1, I_uimm6 : rd},
-      semfunc: "&RV64::RiscVSlliuw",
-      disasm: "slli.uw %rd, %rs1, 0x%(I_uimm6:x)";
-  }
-}
-
-slot zbb {
-  includes {
-    #include "riscv/riscv_b_instructions.h"
-  }
-  default size = 4;
-  default latency = global_latency;
-  opcodes {
-    andn{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVAndn",
-      disasm: "andn %rd, %rs1, %rs2";
-    orn{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVOrn",
-      disasm: "orn %rd, %rs1, %rs2";
-    xnor{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVXnor",
-      disasm: "xnor %rd, %rs1, %rs2";
-    clz{: rs1 : rd},
-      semfunc: "&RV64::RiscVClz",
-      disasm: "clz %rd, %rs1";
-    clzw{: rs1 : rd},
-      semfunc: "&RV64::RiscVClzw",
-      disasm: "clzw %rd, %rs1";
-    ctz{: rs1 : rd},
-      semfunc: "&RV64::RiscVCtz",
-      disasm: "ctz %rd, %rs1";
-    ctzw{: rs1 : rd},
-      semfunc: "&RV64::RiscVCtzw",
-      disasm: "ctzw %rd, %rs1";
-    cpop{: rs1 : rd},
-      semfunc: "&RV64::RiscVCpop",
-      disasm: "cpop %rd, %rs1";
-    cpopw{: rs1 : rd},
-      semfunc: "&RV64::RiscVCpopw",
-      disasm: "cpopw %rd, %rs1";
-    max{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVMax",
-      disasm: "max %rd, %rs1, %rs2";
-    maxu{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVMaxu",
-      disasm: "maxu %rd, %rs1, %rs2";
-    min{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVMin",
-      disasm: "min %rd, %rs1, %rs2";
-    minu{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVMinu",
-      disasm: "minu %rd, %rs1, %rs2";
-    sexth{: rs1 : rd},
-      semfunc: "&RV64::RiscVSexth",
-      disasm: "sext.h %rd, %rs1";
-    sextb{: rs1 : rd},
-      semfunc: "&RV64::RiscVSextb",
-      disasm: "sext.b %rd, %rs1";
-    zextw{: rs1 : rd},
-      semfunc: "&RV64::RiscVZextw",
-      disasm: "zext.w %rd, %rs1";
-    zexth{: rs1 : rd},
-      semfunc: "&RV64::RiscVZexth",
-      disasm: "zext.h %rd, %rs1";
-    rol{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVRol",
-      disasm: "rol %rd, %rs1, %rs2";
-    rolw{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVRolw",
-      disasm: "rolw %rd, %rs1, %rs2";
-    ror{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVRor",
-      disasm: "ror %rd, %rs1, %rs2";
-    rorw{: rs1, rs2 : rd},
-      semfunc: "&RV64::RiscVRorw",
-      disasm: "rorw %rd, %rs1, %rs2";
-    rori{: rs1, I_uimm6 : rd},
-      semfunc: "&RV64::RiscVRori",
-      disasm: "rori %rd, %rs1, 0x%(I_uimm6:x)";
-    roriw{: rs1, I_uimm6 : rd},
-      semfunc: "&RV64::RiscVRoriw",
-      disasm: "roriw %rd, %rs1, 0x%(I_uimm6:x)";
-    orcb{: rs1 : rd},
-      semfunc: "&RV64::RiscVOrcb",
-      disasm: "orc.b %rd, %rs1";
-    rev8{: rs1 : rd},
-      semfunc: "&RV64::RiscVRev8",
-      disasm: "rev8 %rd, %rs1";
-  }
-}
diff --git a/riscv/riscv64g_bitmanip_decoder.cc b/riscv/riscv64g_bitmanip_decoder.cc
new file mode 100644
index 0000000..708d4b2
--- /dev/null
+++ b/riscv/riscv64g_bitmanip_decoder.cc
@@ -0,0 +1,103 @@
+// Copyright 2024 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.
+
+#include "riscv/riscv64g_bitmanip_decoder.h"
+
+#include <cstdint>
+#include <new>
+#include <string>
+
+#include "mpact/sim/generic/instruction.h"
+#include "mpact/sim/generic/type_helpers.h"
+#include "mpact/sim/util/memory/memory_interface.h"
+#include "riscv/riscv64gzb_decoder.h"
+#include "riscv/riscv64gzb_encoding.h"
+#include "riscv/riscv64gzb_enums.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact {
+namespace sim {
+namespace riscv {
+
+using ::mpact::sim::generic::operator*;  // NOLINT: is used below (clang error).
+
+RiscV64GBitmanipDecoder::RiscV64GBitmanipDecoder(RiscVState *state,
+                                                 util::MemoryInterface *memory)
+    : state_(state), memory_(memory) {
+  // Need a data buffer to load instructions from memory. Allocate a single
+  // buffer that can be reused for each instruction word.
+  inst_db_ = state_->db_factory()->Allocate<uint32_t>(1);
+  // Allocate the isa factory class, the top level isa decoder instance, and
+  // the encoding parser.
+  riscv_isa_factory_ = new RV64GZBIsaFactory();
+  riscv_isa_ =
+      new isa64gzb::RiscV64GZBInstructionSet(state, riscv_isa_factory_);
+  riscv_encoding_ = new isa64gzb::RiscV64GZBEncoding(state);
+}
+
+RiscV64GBitmanipDecoder::~RiscV64GBitmanipDecoder() {
+  delete riscv_isa_;
+  delete riscv_isa_factory_;
+  delete riscv_encoding_;
+  inst_db_->DecRef();
+}
+
+generic::Instruction *RiscV64GBitmanipDecoder::DecodeInstruction(
+    uint64_t address) {
+  // First check that the address is aligned properly. If not, create and return
+  // an instruction object that will raise an exception.
+  if (address & 0x1) {
+    auto *inst = new generic::Instruction(0, state_);
+    inst->set_size(1);
+    inst->SetDisassemblyString("Misaligned instruction address");
+    inst->set_opcode(*isa64gzb::OpcodeEnum::kNone);
+    inst->set_address(address);
+    inst->set_semantic_function([this](generic::Instruction *inst) {
+      state_->Trap(/*is_interrupt*/ false, inst->address(),
+                   *ExceptionCode::kInstructionAddressMisaligned,
+                   inst->address() ^ 0x1, inst);
+    });
+    return inst;
+  }
+
+  // If the address is greater than the max address, return an instruction
+  // that will raise an exception.
+  if (address > state_->max_physical_address()) {
+    auto *inst = new generic::Instruction(0, state_);
+    inst->set_size(0);
+    inst->SetDisassemblyString("Instruction access fault");
+    inst->set_opcode(*isa64gzb::OpcodeEnum::kNone);
+    inst->set_address(address);
+    inst->set_semantic_function([this](generic::Instruction *inst) {
+      state_->Trap(/*is_interrupt*/ false, inst->address(),
+                   *ExceptionCode::kInstructionAccessFault, inst->address(),
+                   nullptr);
+    });
+    return inst;
+  }
+
+  // Read the instruction word from memory and parse it in the encoding parser.
+  memory_->Load(address, inst_db_, nullptr, nullptr);
+  uint32_t iword = inst_db_->Get<uint32_t>(0);
+  riscv_encoding_->ParseInstruction(iword);
+
+  // Call the isa decoder to obtain a new instruction object for the instruction
+  // word that was parsed above.
+  auto *instruction = riscv_isa_->Decode(address, riscv_encoding_);
+  return instruction;
+}
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
diff --git a/riscv/riscv64g_bitmanip_decoder.h b/riscv/riscv64g_bitmanip_decoder.h
new file mode 100644
index 0000000..52c35a5
--- /dev/null
+++ b/riscv/riscv64g_bitmanip_decoder.h
@@ -0,0 +1,89 @@
+// Copyright 2024 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_RISCV64G_BITMANIP_DECODER_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV64G_BITMANIP_DECODER_H_
+
+#include <cstdint>
+#include <memory>
+
+#include "mpact/sim/generic/data_buffer.h"
+#include "mpact/sim/generic/decoder_interface.h"
+#include "mpact/sim/generic/instruction.h"
+#include "mpact/sim/generic/type_helpers.h"
+#include "mpact/sim/util/memory/memory_interface.h"
+#include "riscv/riscv64gzb_decoder.h"
+#include "riscv/riscv64gzb_encoding.h"
+#include "riscv/riscv64gzb_enums.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact {
+namespace sim {
+namespace riscv {
+
+using ::mpact::sim::generic::Instruction;
+using ::mpact::sim::generic::operator*;  // NOLINT: clang-tidy false positive.
+
+// This is the factory class needed by the generated decoder. It is responsible
+// for creating the decoder for each slot instance. Since the riscv architecture
+// only has a single slot, it's a pretty simple class.
+class RV64GZBIsaFactory : public isa64gzb::RiscV64GZBInstructionSetFactory {
+ public:
+  std::unique_ptr<isa64gzb::Riscv64gzbSlot> CreateRiscv64gzbSlot(
+      ArchState *state) override {
+    return std::make_unique<isa64gzb::Riscv64gzbSlot>(state);
+  }
+};
+
+// This class implements the generic DecoderInterface and provides a bridge
+// to the (isa specific) generated decoder classes.
+class RiscV64GBitmanipDecoder : public generic::DecoderInterface {
+ public:
+  using SlotEnum = isa64gzb::SlotEnum;
+  using OpcodeEnum = isa64gzb::OpcodeEnum;
+
+  RiscV64GBitmanipDecoder(RiscVState *state, util::MemoryInterface *memory);
+  RiscV64GBitmanipDecoder() = delete;
+  ~RiscV64GBitmanipDecoder() override;
+
+  // This will always return a valid instruction that can be executed. In the
+  // case of a decode error, the semantic function in the instruction object
+  // instance will raise an internal simulator error when executed.
+  generic::Instruction *DecodeInstruction(uint64_t address) override;
+  // Return the number of opcodes supported by this decoder.
+  int GetNumOpcodes() const override { return *OpcodeEnum::kPastMaxValue; }
+  // Return the name of the opcode at the given index.
+  const char *GetOpcodeName(int index) const override {
+    return isa64gzb::kOpcodeNames[index];
+  }
+
+  // Getter.
+  isa64gzb::RiscV64GZBEncoding *riscv_encoding() const {
+    return riscv_encoding_;
+  }
+
+ private:
+  RiscVState *state_;
+  util::MemoryInterface *memory_;
+  generic::DataBuffer *inst_db_;
+  isa64gzb::RiscV64GZBEncoding *riscv_encoding_;
+  RV64GZBIsaFactory *riscv_isa_factory_;
+  isa64gzb::RiscV64GZBInstructionSet *riscv_isa_;
+};
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV64G_BITMANIP_DECODER_H_
diff --git a/riscv/riscv64g_encoding.cc b/riscv/riscv64g_encoding.cc
index abfe7e6..6f1c68d 100644
--- a/riscv/riscv64g_encoding.cc
+++ b/riscv/riscv64g_encoding.cc
@@ -14,15 +14,19 @@
 
 #include "riscv/riscv64g_encoding.h"
 
+#include <cstdint>
+#include <new>
 #include <string>
 #include <utility>
 
 #include "absl/log/log.h"
+#include "absl/strings/str_cat.h"
 #include "mpact/sim/generic/immediate_operand.h"
 #include "mpact/sim/generic/literal_operand.h"
-#include "mpact/sim/generic/operand_interface.h"
+#include "mpact/sim/generic/simple_resource.h"
 #include "mpact/sim/generic/simple_resource_operand.h"
 #include "riscv/riscv64g_bin_decoder.h"
+#include "riscv/riscv64g_decoder.h"
 #include "riscv/riscv64g_enums.h"
 #include "riscv/riscv_register.h"
 #include "riscv/riscv_state.h"
@@ -32,7 +36,6 @@
 namespace riscv {
 namespace isa64 {
 
-// TODO
 using generic::SimpleResourceOperand;
 
 // Generic helper functions to create register operands.
@@ -401,9 +404,9 @@
             encoding64::s_type::ExtractSImm(inst_word_));
       }));
   source_op_getters_.insert(
-      std::make_pair(static_cast<int>(SourceOpEnum::kSImm20), [this]() {
+      std::make_pair(static_cast<int>(SourceOpEnum::kUImm20), [this]() {
         return new generic::ImmediateOperand<int32_t>(
-            encoding64::u_type::ExtractSImm(inst_word_));
+            encoding64::u_type::ExtractUImm(inst_word_));
       }));
   source_op_getters_.insert(
       std::make_pair(static_cast<int>(SourceOpEnum::kX0), [this]() {
diff --git a/riscv/riscv64g_encoding.h b/riscv/riscv64g_encoding.h
index 9bf705a..da9a3ed 100644
--- a/riscv/riscv64g_encoding.h
+++ b/riscv/riscv64g_encoding.h
@@ -15,7 +15,7 @@
 #ifndef MPACT_RISCV_RISCV_RISCV64G_ENCODING_H_
 #define MPACT_RISCV_RISCV_RISCV64G_ENCODING_H_
 
-#include <functional>
+#include <cstdint>
 #include <string>
 
 #include "absl/container/flat_hash_map.h"
diff --git a/riscv/riscv64g_vec_decoder.cc b/riscv/riscv64g_vec_decoder.cc
index b917a0f..d7d3abd 100644
--- a/riscv/riscv64g_vec_decoder.cc
+++ b/riscv/riscv64g_vec_decoder.cc
@@ -16,6 +16,7 @@
 
 #include <cstdint>
 #include <memory>
+#include <new>
 #include <string>
 
 #include "mpact/sim/generic/instruction.h"
diff --git a/riscv/riscv64g_vec_encoding.cc b/riscv/riscv64g_vec_encoding.cc
index bb63050..524b005 100644
--- a/riscv/riscv64g_vec_encoding.cc
+++ b/riscv/riscv64g_vec_encoding.cc
@@ -15,10 +15,12 @@
 #include "riscv/riscv64g_vec_encoding.h"
 
 #include <cstdint>
+#include <new>
 #include <string>
 #include <utility>
 #include <vector>
 
+#include "absl/base/casts.h"
 #include "absl/log/log.h"
 #include "absl/strings/str_cat.h"
 #include "absl/types/span.h"
@@ -495,9 +497,10 @@
             encoding64::s_type::ExtractSImm(inst_word_));
       }));
   source_op_getters_.insert(
-      std::make_pair(static_cast<int>(SourceOpEnum::kSImm20), [this]() {
+      std::make_pair(static_cast<int>(SourceOpEnum::kUImm20), [this]() {
+        uint32_t uimm = encoding64::u_type::ExtractUImm(inst_word_);
         return new generic::ImmediateOperand<int32_t>(
-            encoding64::u_type::ExtractSImm(inst_word_));
+            absl::bit_cast<int32_t>(uimm));
       }));
   source_op_getters_.insert(
       std::make_pair(static_cast<int>(SourceOpEnum::kX0), [this]() {
diff --git a/riscv/riscv64gzb.bin_fmt b/riscv/riscv64gzb.bin_fmt
new file mode 100644
index 0000000..0744bd4
--- /dev/null
+++ b/riscv/riscv64gzb.bin_fmt
@@ -0,0 +1,30 @@
+// Copyright 2024 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.
+
+
+decoder RiscV64GZB {
+  namespace mpact::sim::riscv::isa64gzb;
+  opcode_enum = "OpcodeEnum";
+  includes {
+    #include "riscv/riscv64gzb_decoder.h"
+  }
+  RiscV64GZBInst32 = {RiscVGInst32, RiscVZbaInst32, RiscVZbaInst64,
+                      RiscVZbbInst32, RiscVZbbInst64, RiscVZbcInst32,
+                      RiscVZbsInst32, RiscVZbsImmInst64};
+  RiscV64GZBInst16 = {RiscVCInst16};
+}
+
+#include "riscv/riscv64g.bin_fmt"
+#include "riscv/riscv64zb.bin_fmt"
+#include "riscv/riscv32zb.bin_fmt"
diff --git a/riscv/riscv64gzb.isa b/riscv/riscv64gzb.isa
new file mode 100644
index 0000000..c3a53f0
--- /dev/null
+++ b/riscv/riscv64gzb.isa
@@ -0,0 +1,31 @@
+// Copyright 2024 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.
+
+isa RiscV64GZB {
+  namespace mpact::sim::riscv::isa64gzb;
+  slots {
+    riscv64gzb;
+  }
+}
+
+#include "riscv/riscv64g.isa"
+#include "riscv/riscv64zb.isa"
+
+slot riscv64gzb : riscv64g, riscv64_zba , riscv64_zbb, riscv64_zbb_imm,
+                  riscv64_zbc, riscv64_zbs, riscv64_zbs_imm {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+}
diff --git a/riscv/riscv64gzb_encoding.cc b/riscv/riscv64gzb_encoding.cc
new file mode 100644
index 0000000..631b4fd
--- /dev/null
+++ b/riscv/riscv64gzb_encoding.cc
@@ -0,0 +1,164 @@
+// Copyright 2024 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
+//
+//     http://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.
+
+#include "riscv/riscv64gzb_encoding.h"
+
+#include <cstdint>
+#include <new>
+
+#include "absl/log/log.h"
+#include "absl/strings/str_cat.h"
+#include "mpact/sim/generic/simple_resource.h"
+#include "mpact/sim/generic/simple_resource_operand.h"
+#include "mpact/sim/generic/type_helpers.h"
+#include "riscv/riscv64gzb_bin_decoder.h"
+#include "riscv/riscv64gzb_decoder.h"
+#include "riscv/riscv64gzb_enums.h"
+#include "riscv/riscv_encoding_common.h"
+#include "riscv/riscv_getters.h"
+#include "riscv/riscv_getters_zba.h"
+#include "riscv/riscv_register.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact::sim::riscv::isa64gzb {
+
+using ::mpact::sim::generic::operator*;  // NOLINT: clang-tidy false positive.
+
+RiscV64GZBEncoding::RiscV64GZBEncoding(RiscVState *state)
+    : state_(state),
+      inst_word_(0),
+      opcode_(OpcodeEnum::kNone),
+      format_(FormatEnum::kNone) {
+  resource_pool_ = new generic::SimpleResourcePool("RiscV64GZB", 128);
+  resource_delay_line_ =
+      state_->CreateAndAddDelayLine<generic::SimpleResourceDelayLine>(8);
+  // Initialize getters.
+  source_op_getters_.emplace(*SourceOpEnum::kNone, []() { return nullptr; });
+  dest_op_getters_.emplace(*DestOpEnum::kNone,
+                           [](int latency) { return nullptr; });
+  simple_resource_getters_.emplace(*SimpleResourceEnum::kNone,
+                                   []() { return nullptr; });
+  complex_resource_getters_.emplace(
+      *ComplexResourceEnum::kNone,
+      [](int latency, int end) { return nullptr; });
+  AddRiscVSourceGetters<SourceOpEnum, Extractors, RV64Register, RVFpRegister>(
+      source_op_getters_, this);
+  AddRiscVZbaSourceGetters<SourceOpEnum, Extractors, RV64Register,
+                           RVFpRegister>(source_op_getters_, this);
+  AddRiscVDestGetters<DestOpEnum, Extractors, RV64Register, RVFpRegister>(
+      dest_op_getters_, this);
+  AddRiscVZbaDestGetters<DestOpEnum, Extractors, RV64Register, RVFpRegister>(
+      dest_op_getters_, this);
+  AddRiscVSimpleResourceGetters<SimpleResourceEnum, Extractors>(
+      simple_resource_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()) {
+      LOG(ERROR) << "No getter for source op enum value " << i;
+    }
+  }
+  for (int i = *DestOpEnum::kNone; i < *DestOpEnum::kPastMaxValue; ++i) {
+    if (dest_op_getters_.find(i) == dest_op_getters_.end()) {
+      LOG(ERROR) << "No getter for destination op enum value " << i;
+    }
+  }
+  for (int i = *SimpleResourceEnum::kNone;
+       i < *SimpleResourceEnum::kPastMaxValue; ++i) {
+    if (simple_resource_getters_.find(i) == simple_resource_getters_.end()) {
+      LOG(ERROR) << "No getter for simple resource enum value " << i;
+    }
+  }
+}
+
+RiscV64GZBEncoding::~RiscV64GZBEncoding() { delete resource_pool_; }
+
+void RiscV64GZBEncoding::ParseInstruction(uint32_t inst_word) {
+  inst_word_ = inst_word;
+  if ((inst_word_ & 0x3) == 3) {
+    auto [opcode, format] = DecodeRiscV64GZBInst32WithFormat(inst_word_);
+    opcode_ = opcode;
+    format_ = format;
+    return;
+  }
+  auto [opcode, format] = DecodeRiscV64GZBInst16WithFormat(
+      static_cast<uint16_t>(inst_word & 0xffff));
+  opcode_ = opcode;
+  format_ = format;
+}
+
+ResourceOperandInterface *RiscV64GZBEncoding::GetComplexResourceOperand(
+    SlotEnum, int, OpcodeEnum, ComplexResourceEnum resource, int begin,
+    int end) {
+  int index = static_cast<int>(resource);
+  auto iter = complex_resource_getters_.find(index);
+  if (iter == complex_resource_getters_.end()) {
+    LOG(WARNING) << "No complex resource getter found for resource: " << index;
+    return nullptr;
+  }
+  return (iter->second)(begin, end);
+}
+
+ResourceOperandInterface *RiscV64GZBEncoding::GetSimpleResourceOperand(
+    SlotEnum, int, OpcodeEnum, SimpleResourceVector &resource_vec, int end) {
+  if (resource_vec.empty()) return nullptr;
+  auto *resource_set = resource_pool_->CreateResourceSet();
+  for (auto resource_enum : resource_vec) {
+    int index = static_cast<int>(resource_enum);
+    auto iter = simple_resource_getters_.find(index);
+    if (iter == simple_resource_getters_.end()) {
+      LOG(WARNING) << "No getter for simple resource " << index;
+      continue;
+    }
+    auto *resource = (iter->second)();
+    auto status = resource_set->AddResource(resource);
+    if (!status.ok()) {
+      LOG(ERROR) << "Unable to add resource to resource set ("
+                 << static_cast<int>(resource_enum) << ")";
+    }
+  }
+  auto *op = new generic::SimpleResourceOperand(resource_set, end,
+                                                resource_delay_line_);
+  return op;
+}
+
+DestinationOperandInterface *RiscV64GZBEncoding::GetDestination(
+    SlotEnum, int, OpcodeEnum opcode, DestOpEnum dest_op, int dest_no,
+    int latency) {
+  int index = static_cast<int>(dest_op);
+  auto iter = dest_op_getters_.find(index);
+  if (iter == dest_op_getters_.end()) {
+    LOG(ERROR) << absl::StrCat("No getter for destination op enum value ",
+                               index, "for instruction ",
+                               kOpcodeNames[static_cast<int>(opcode)]);
+    return nullptr;
+  }
+  return (iter->second)(latency);
+}
+
+SourceOperandInterface *RiscV64GZBEncoding::GetSource(SlotEnum, int,
+                                                      OpcodeEnum opcode,
+                                                      SourceOpEnum source_op,
+                                                      int source_no) {
+  int index = static_cast<int>(source_op);
+  auto iter = source_op_getters_.find(index);
+  if (iter == source_op_getters_.end()) {
+    LOG(ERROR) << absl::StrCat("No getter for source op enum value ", index,
+                               " for instruction ",
+                               kOpcodeNames[static_cast<int>(opcode)]);
+    return nullptr;
+  }
+  return (iter->second)();
+}
+
+}  // namespace mpact::sim::riscv::isa64gzb
diff --git a/riscv/riscv64gzb_encoding.h b/riscv/riscv64gzb_encoding.h
new file mode 100644
index 0000000..63030bb
--- /dev/null
+++ b/riscv/riscv64gzb_encoding.h
@@ -0,0 +1,95 @@
+// Copyright 2024 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
+//
+//     http://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_RISCV64GZB_ENCODING_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV64GZB_ENCODING_H_
+
+#include <cstdint>
+#include <string>
+
+#include "mpact/sim/generic/simple_resource.h"
+#include "mpact/sim/generic/simple_resource_operand.h"
+#include "riscv/riscv64gzb_bin_decoder.h"
+#include "riscv/riscv64gzb_decoder.h"
+#include "riscv/riscv64gzb_enums.h"
+#include "riscv/riscv_encoding_common.h"
+#include "riscv/riscv_getter_helpers.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact::sim::riscv::isa64gzb {
+
+// This class provides the interface between the generated instruction decoder
+// framework (which is agnostic of the actual bit representation of
+// instructions) and the instruction representation. This class provides methods
+// to return the opcode, source operands, and destination operands for
+// instructions according to the operand fields in the encoding.
+class RiscV64GZBEncoding : public RiscV64GZBEncodingBase,
+                           public RiscVEncodingCommon {
+ public:
+  explicit RiscV64GZBEncoding(RiscVState *state);
+  ~RiscV64GZBEncoding() override;
+
+  void ParseInstruction(uint32_t inst_word);
+  OpcodeEnum GetOpcode(SlotEnum, int) { return opcode_; }
+  FormatEnum GetFormat(SlotEnum, int) { return format_; }
+
+  PredicateOperandInterface *GetPredicate(SlotEnum, int, OpcodeEnum,
+                                          PredOpEnum) override {
+    return nullptr;
+  }
+
+  ResourceOperandInterface *GetSimpleResourceOperand(
+      SlotEnum, int, OpcodeEnum, SimpleResourceVector &resource_vec,
+      int end) override;
+
+  ResourceOperandInterface *GetComplexResourceOperand(
+      SlotEnum, int, OpcodeEnum, ComplexResourceEnum resource, int begin,
+      int end);
+
+  SourceOperandInterface *GetSource(SlotEnum, int, OpcodeEnum, SourceOpEnum op,
+                                    int source_no) override;
+
+  DestinationOperandInterface *GetDestination(SlotEnum, int, OpcodeEnum,
+                                              DestOpEnum op, int dest_no,
+                                              int latency) override;
+
+  int GetLatency(SlotEnum, int, OpcodeEnum, DestOpEnum, int) override {
+    return 0;
+  }
+
+  // Methods inherited from RiscVEncodingCommon.
+  RiscVState *state() const override { return state_; }
+  generic::SimpleResourcePool *resource_pool() override {
+    return resource_pool_;
+  }
+  uint32_t inst_word() const override { return inst_word_; }
+
+ private:
+  std::string GetSimpleResourceName(SimpleResourceEnum resource_enum);
+
+  RiscVState *state_;
+  uint32_t inst_word_;
+  OpcodeEnum opcode_;
+  FormatEnum format_;
+  SourceOpGetterMap source_op_getters_;
+  DestOpGetterMap dest_op_getters_;
+  SimpleResourceGetterMap simple_resource_getters_;
+  ComplexResourceGetterMap complex_resource_getters_;
+  generic::SimpleResourceDelayLine *resource_delay_line_ = nullptr;
+  generic::SimpleResourcePool *resource_pool_ = nullptr;
+};
+
+}  // namespace mpact::sim::riscv::isa64gzb
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV64GZB_ENCODING_H_
diff --git a/riscv/riscv64gzb_vec_decoder.cc b/riscv/riscv64gzb_vec_decoder.cc
new file mode 100644
index 0000000..6805732
--- /dev/null
+++ b/riscv/riscv64gzb_vec_decoder.cc
@@ -0,0 +1,104 @@
+// 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.
+
+#include "riscv/riscv64gzb_vec_decoder.h"
+
+#include <cstdint>
+#include <memory>
+#include <new>
+#include <string>
+
+#include "mpact/sim/generic/instruction.h"
+#include "mpact/sim/generic/program_error.h"
+#include "mpact/sim/generic/type_helpers.h"
+#include "mpact/sim/util/memory/memory_interface.h"
+#include "riscv/riscv64gvzb_decoder.h"
+#include "riscv/riscv64gvzb_enums.h"
+#include "riscv/riscv64gzb_vec_encoding.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact {
+namespace sim {
+namespace riscv {
+
+using ::mpact::sim::generic::operator*;  // NOLINT: is used below (clang error).
+
+RiscV64GZBVecDecoder::RiscV64GZBVecDecoder(RiscVState *state,
+                                           util::MemoryInterface *memory)
+    : state_(state),
+      memory_(memory),
+      inst_db_(state_->db_factory()->Allocate<uint32_t>(1)) {
+  // Get a handle to the internal error in the program error controller.
+  decode_error_ = state->program_error_controller()->GetProgramError(
+      generic::ProgramErrorController::kInternalErrorName);
+
+  // Allocate the isa factory class, the top level isa decoder instance, and
+  // the encoding parser.
+  riscv_isa_factory_ = std::make_unique<RV64GVZBIsaFactory>();
+  riscv_isa_ = std::make_unique<isa64gvzb::RiscV64GVZBInstructionSet>(
+      state, riscv_isa_factory_.get());
+  riscv_encoding_ = std::make_unique<isa64gvzb::RiscV64GZBVecEncoding>(state);
+  decode_error_ = state->program_error_controller()->GetProgramError(
+      generic::ProgramErrorController::kInternalErrorName);
+}
+
+RiscV64GZBVecDecoder::~RiscV64GZBVecDecoder() { inst_db_->DecRef(); }
+
+generic::Instruction *RiscV64GZBVecDecoder::DecodeInstruction(
+    uint64_t address) {
+  // First check that the address is aligned properly. If not, create and return
+  // an instruction object that will raise an exception.
+  if (address & 0x1) {
+    auto *inst = new generic::Instruction(address, state_);
+    inst->set_size(1);
+    inst->SetDisassemblyString("Misaligned instruction address");
+    inst->set_opcode(*isa64gvzb::OpcodeEnum::kNone);
+    inst->set_address(address);
+    inst->set_semantic_function([this, address](generic::Instruction *inst) {
+      state_->Trap(/*is_interrupt*/ false, address,
+                   *ExceptionCode::kInstructionAddressMisaligned, address ^ 0x1,
+                   inst);
+    });
+    return inst;
+  }
+
+  // If the address is greater than the max address, return an instruction
+  // object that will raise an exception.
+  if (address > state_->max_physical_address()) {
+    auto *inst = new generic::Instruction(address, state_);
+    inst->set_size(0);
+    inst->SetDisassemblyString("Instruction access fault");
+    inst->set_opcode(*isa64gvzb::OpcodeEnum::kNone);
+    inst->set_address(address);
+    inst->set_semantic_function([this, address](generic::Instruction *inst) {
+      state_->Trap(/*is_interrupt*/ false, address,
+                   *ExceptionCode::kInstructionAccessFault, address, nullptr);
+    });
+    return inst;
+  }
+
+  // Read the instruction word from memory and parse it in the encoding parser.
+  memory_->Load(address, inst_db_, nullptr, nullptr);
+  const uint32_t iword = inst_db_->Get<uint32_t>(0);
+  riscv_encoding_->ParseInstruction(iword);
+
+  // Call the isa decoder to obtain a new instruction object for the instruction
+  // word that was parsed above.
+  auto *instruction = riscv_isa_->Decode(address, riscv_encoding_.get());
+  return instruction;
+}
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
diff --git a/riscv/riscv64gzb_vec_decoder.h b/riscv/riscv64gzb_vec_decoder.h
new file mode 100644
index 0000000..b828271
--- /dev/null
+++ b/riscv/riscv64gzb_vec_decoder.h
@@ -0,0 +1,90 @@
+// 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 MPACT_RISCV_RISCV_RISCV64GZB_VEC_DECODER_H_
+#define MPACT_RISCV_RISCV_RISCV64GZB_VEC_DECODER_H_
+
+#include <cstdint>
+#include <memory>
+
+#include "mpact/sim/generic/data_buffer.h"
+#include "mpact/sim/generic/decoder_interface.h"
+#include "mpact/sim/generic/instruction.h"
+#include "mpact/sim/generic/program_error.h"
+#include "mpact/sim/generic/type_helpers.h"
+#include "mpact/sim/util/memory/memory_interface.h"
+#include "riscv/riscv64gvzb_decoder.h"
+#include "riscv/riscv64gvzb_enums.h"
+#include "riscv/riscv64gzb_vec_encoding.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact {
+namespace sim {
+namespace riscv {
+
+using ::mpact::sim::generic::operator*;  // NOLINT: clang-tidy false positive.
+
+// This is the factory class needed by the generated decoder. It is responsible
+// for creating the decoder for each slot instance. Since the riscv architecture
+// only has a single slot, it's a pretty simple class.
+class RV64GVZBIsaFactory : public isa64gvzb::RiscV64GVZBInstructionSetFactory {
+ public:
+  std::unique_ptr<isa64gvzb::Riscv64gvzbSlot> CreateRiscv64gvzbSlot(
+      ArchState *state) override {
+    return std::make_unique<isa64gvzb::Riscv64gvzbSlot>(state);
+  }
+};
+
+// This class implements the generic DecoderInterface and provides a bridge
+// to the (isa specific) generated decoder classes. It implements a decoder that
+// includes the RV64GZB + vector extensions.
+class RiscV64GZBVecDecoder : public generic::DecoderInterface {
+ public:
+  using SlotEnum = isa64gvzb::SlotEnum;
+  using OpcodeEnum = isa64gvzb::OpcodeEnum;
+
+  RiscV64GZBVecDecoder(RiscVState *state, util::MemoryInterface *memory);
+  RiscV64GZBVecDecoder() = delete;
+  ~RiscV64GZBVecDecoder() override;
+
+  // This will always return a valid instruction that can be executed. In the
+  // case of a decode error, the semantic function in the instruction object
+  // instance will raise an internal simulator error when executed.
+  generic::Instruction *DecodeInstruction(uint64_t address) override;
+  // Return the number of opcodes supported by this decoder.
+  int GetNumOpcodes() const override { return *OpcodeEnum::kPastMaxValue; }
+  // Return the name of the opcode at the given index.
+  const char *GetOpcodeName(int index) const override {
+    return isa64gvzb::kOpcodeNames[index];
+  }
+
+ private:
+  RiscVState *const state_;
+  util::MemoryInterface *const memory_;
+
+  // Buffer used to load instructions from memory. Re-used for each instruction
+  // word.
+  generic::DataBuffer *const inst_db_;
+
+  std::unique_ptr<generic::ProgramError> decode_error_;
+  std::unique_ptr<isa64gvzb::RiscV64GZBVecEncoding> riscv_encoding_;
+  std::unique_ptr<RV64GVZBIsaFactory> riscv_isa_factory_;
+  std::unique_ptr<isa64gvzb::RiscV64GVZBInstructionSet> riscv_isa_;
+};
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
+
+#endif  // MPACT_RISCV_RISCV_RISCV64GZB_VEC_DECODER_H_
diff --git a/riscv/riscv64gzb_vec_encoding.cc b/riscv/riscv64gzb_vec_encoding.cc
new file mode 100644
index 0000000..b0c4c8b
--- /dev/null
+++ b/riscv/riscv64gzb_vec_encoding.cc
@@ -0,0 +1,178 @@
+// Copyright 2024 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
+//
+//     http://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.
+
+#include "riscv/riscv64gzb_vec_encoding.h"
+
+#include <cstdint>
+#include <new>
+
+#include "absl/log/log.h"
+#include "absl/strings/str_cat.h"
+#include "mpact/sim/generic/simple_resource.h"
+#include "mpact/sim/generic/simple_resource_operand.h"
+#include "mpact/sim/generic/type_helpers.h"
+#include "riscv/riscv64gvzb_bin_decoder.h"
+#include "riscv/riscv64gvzb_decoder.h"
+#include "riscv/riscv64gvzb_enums.h"
+#include "riscv/riscv_encoding_common.h"
+#include "riscv/riscv_getters.h"
+#include "riscv/riscv_getters_rv64.h"
+#include "riscv/riscv_getters_vector.h"
+#include "riscv/riscv_getters_zba.h"
+#include "riscv/riscv_getters_zbb64.h"
+#include "riscv/riscv_register.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact::sim::riscv::isa64gvzb {
+
+using ::mpact::sim::generic::operator*;  // NOLINT: clang-tidy false positive.
+
+RiscV64GZBVecEncoding::RiscV64GZBVecEncoding(RiscVState *state)
+    : state_(state),
+      inst_word_(0),
+      opcode_(OpcodeEnum::kNone),
+      format_(FormatEnum::kNone) {
+  resource_pool_ = new generic::SimpleResourcePool("RiscV64GVZB", 128);
+  resource_delay_line_ =
+      state_->CreateAndAddDelayLine<generic::SimpleResourceDelayLine>(8);
+  // Initialize getters.
+  source_op_getters_.emplace(*SourceOpEnum::kNone, []() { return nullptr; });
+  dest_op_getters_.emplace(*DestOpEnum::kNone,
+                           [](int latency) { return nullptr; });
+  simple_resource_getters_.emplace(*SimpleResourceEnum::kNone,
+                                   []() { return nullptr; });
+  complex_resource_getters_.emplace(
+      *ComplexResourceEnum::kNone,
+      [](int latency, int end) { return nullptr; });
+  // Add the operand getters for the base instruction set.
+  AddRiscVSourceGetters<SourceOpEnum, Extractors, RV64Register, RVFpRegister>(
+      source_op_getters_, this);
+  AddRiscVDestGetters<DestOpEnum, Extractors, RV64Register, RVFpRegister>(
+      dest_op_getters_, this);
+  AddRiscVSimpleResourceGetters<SimpleResourceEnum, Extractors>(
+      simple_resource_getters_, this);
+  // Add operand getters for 64 bit version not in the base instruction set.
+  AddRiscV64SourceGetters<SourceOpEnum, Extractors, RV64Register, RVFpRegister>(
+      source_op_getters_, this);
+  // Add the common Zba operand getters.
+  AddRiscVZbaSourceGetters<SourceOpEnum, Extractors, RV64Register,
+                           RVFpRegister>(source_op_getters_, this);
+  // Add operand getters for the 64 bit Zbb instructions.
+  AddRiscVZbb64SourceGetters<SourceOpEnum, Extractors, RV64Register,
+                             RVFpRegister>(source_op_getters_, this);
+  // Add vector operand getters.
+  AddRiscVVectorSourceGetters<SourceOpEnum, Extractors, RVVectorRegister>(
+      source_op_getters_, this);
+  AddRiscVVectorDestGetters<DestOpEnum, Extractors, RVVectorRegister>(
+      dest_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()) {
+      LOG(ERROR) << "No getter for source op enum value " << i;
+    }
+  }
+  for (int i = *DestOpEnum::kNone; i < *DestOpEnum::kPastMaxValue; ++i) {
+    if (dest_op_getters_.find(i) == dest_op_getters_.end()) {
+      LOG(ERROR) << "No getter for destination op enum value " << i;
+    }
+  }
+  for (int i = *SimpleResourceEnum::kNone;
+       i < *SimpleResourceEnum::kPastMaxValue; ++i) {
+    if (simple_resource_getters_.find(i) == simple_resource_getters_.end()) {
+      LOG(ERROR) << "No getter for simple resource enum value " << i;
+    }
+  }
+}
+
+RiscV64GZBVecEncoding::~RiscV64GZBVecEncoding() { delete resource_pool_; }
+
+void RiscV64GZBVecEncoding::ParseInstruction(uint32_t inst_word) {
+  inst_word_ = inst_word;
+  if ((inst_word_ & 0x3) == 3) {
+    auto [opcode, format] = DecodeRiscV64GVZBInst32WithFormat(inst_word_);
+    opcode_ = opcode;
+    format_ = format;
+    return;
+  }
+  auto [opcode, format] =
+      DecodeRiscVCInst16WithFormat(static_cast<uint16_t>(inst_word & 0xffff));
+  opcode_ = opcode;
+  format_ = format;
+}
+
+ResourceOperandInterface *RiscV64GZBVecEncoding::GetComplexResourceOperand(
+    SlotEnum, int, OpcodeEnum, ComplexResourceEnum resource, int begin,
+    int end) {
+  int index = static_cast<int>(resource);
+  auto iter = complex_resource_getters_.find(index);
+  if (iter == complex_resource_getters_.end()) {
+    LOG(WARNING) << "No complex resource getter found for resource: " << index;
+    return nullptr;
+  }
+  return (iter->second)(begin, end);
+}
+
+ResourceOperandInterface *RiscV64GZBVecEncoding::GetSimpleResourceOperand(
+    SlotEnum, int, OpcodeEnum, SimpleResourceVector &resource_vec, int end) {
+  if (resource_vec.empty()) return nullptr;
+  auto *resource_set = resource_pool_->CreateResourceSet();
+  for (auto resource_enum : resource_vec) {
+    int index = static_cast<int>(resource_enum);
+    auto iter = simple_resource_getters_.find(index);
+    if (iter == simple_resource_getters_.end()) {
+      LOG(WARNING) << "No getter for simple resource " << index;
+      continue;
+    }
+    auto *resource = (iter->second)();
+    auto status = resource_set->AddResource(resource);
+    if (!status.ok()) {
+      LOG(ERROR) << "Unable to add resource to resource set ("
+                 << static_cast<int>(resource_enum) << ")";
+    }
+  }
+  auto *op = new generic::SimpleResourceOperand(resource_set, end,
+                                                resource_delay_line_);
+  return op;
+}
+
+DestinationOperandInterface *RiscV64GZBVecEncoding::GetDestination(
+    SlotEnum, int, OpcodeEnum opcode, DestOpEnum dest_op, int dest_no,
+    int latency) {
+  int index = static_cast<int>(dest_op);
+  auto iter = dest_op_getters_.find(index);
+  if (iter == dest_op_getters_.end()) {
+    LOG(ERROR) << absl::StrCat("No getter for destination op enum value ",
+                               index, "for instruction ",
+                               kOpcodeNames[static_cast<int>(opcode)]);
+    return nullptr;
+  }
+  return (iter->second)(latency);
+}
+
+SourceOperandInterface *RiscV64GZBVecEncoding::GetSource(SlotEnum, int,
+                                                         OpcodeEnum opcode,
+                                                         SourceOpEnum source_op,
+                                                         int source_no) {
+  int index = static_cast<int>(source_op);
+  auto iter = source_op_getters_.find(index);
+  if (iter == source_op_getters_.end()) {
+    LOG(ERROR) << absl::StrCat("No getter for source op enum value ", index,
+                               " for instruction ",
+                               kOpcodeNames[static_cast<int>(opcode)]);
+    return nullptr;
+  }
+  return (iter->second)();
+}
+
+}  // namespace mpact::sim::riscv::isa64gvzb
diff --git a/riscv/riscv64gzb_vec_encoding.h b/riscv/riscv64gzb_vec_encoding.h
new file mode 100644
index 0000000..60f106b
--- /dev/null
+++ b/riscv/riscv64gzb_vec_encoding.h
@@ -0,0 +1,95 @@
+// Copyright 2024 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
+//
+//     http://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_RISCV64GZB_VEC_ENCODING_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV64GZB_VEC_ENCODING_H_
+
+#include <cstdint>
+#include <string>
+
+#include "mpact/sim/generic/simple_resource.h"
+#include "mpact/sim/generic/simple_resource_operand.h"
+#include "riscv/riscv64gvzb_bin_decoder.h"
+#include "riscv/riscv64gvzb_decoder.h"
+#include "riscv/riscv64gvzb_enums.h"
+#include "riscv/riscv_encoding_common.h"
+#include "riscv/riscv_getter_helpers.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact::sim::riscv::isa64gvzb {
+
+// This class provides the interface between the generated instruction decoder
+// framework (which is agnostic of the actual bit representation of
+// instructions) and the instruction representation. This class provides methods
+// to return the opcode, source operands, and destination operands for
+// instructions according to the operand fields in the encoding.
+class RiscV64GZBVecEncoding : public RiscV64GVZBEncodingBase,
+                              public RiscVEncodingCommon {
+ public:
+  explicit RiscV64GZBVecEncoding(RiscVState *state);
+  ~RiscV64GZBVecEncoding() override;
+
+  void ParseInstruction(uint32_t inst_word);
+  OpcodeEnum GetOpcode(SlotEnum, int) { return opcode_; }
+  FormatEnum GetFormat(SlotEnum, int) { return format_; }
+
+  PredicateOperandInterface *GetPredicate(SlotEnum, int, OpcodeEnum,
+                                          PredOpEnum) override {
+    return nullptr;
+  }
+
+  ResourceOperandInterface *GetSimpleResourceOperand(
+      SlotEnum, int, OpcodeEnum, SimpleResourceVector &resource_vec,
+      int end) override;
+
+  ResourceOperandInterface *GetComplexResourceOperand(
+      SlotEnum, int, OpcodeEnum, ComplexResourceEnum resource, int begin,
+      int end);
+
+  SourceOperandInterface *GetSource(SlotEnum, int, OpcodeEnum, SourceOpEnum op,
+                                    int source_no) override;
+
+  DestinationOperandInterface *GetDestination(SlotEnum, int, OpcodeEnum,
+                                              DestOpEnum op, int dest_no,
+                                              int latency) override;
+
+  int GetLatency(SlotEnum, int, OpcodeEnum, DestOpEnum, int) override {
+    return 0;
+  }
+
+  // Methods inherited from RiscVEncodingCommon.
+  RiscVState *state() const override { return state_; }
+  generic::SimpleResourcePool *resource_pool() override {
+    return resource_pool_;
+  }
+  uint32_t inst_word() const override { return inst_word_; }
+
+ private:
+  std::string GetSimpleResourceName(SimpleResourceEnum resource_enum);
+
+  RiscVState *state_;
+  uint32_t inst_word_;
+  OpcodeEnum opcode_;
+  FormatEnum format_;
+  SourceOpGetterMap source_op_getters_;
+  DestOpGetterMap dest_op_getters_;
+  SimpleResourceGetterMap simple_resource_getters_;
+  ComplexResourceGetterMap complex_resource_getters_;
+  generic::SimpleResourceDelayLine *resource_delay_line_ = nullptr;
+  generic::SimpleResourcePool *resource_pool_ = nullptr;
+};
+
+}  // namespace mpact::sim::riscv::isa64gvzb
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV64GZB_VEC_ENCODING_H_
diff --git a/riscv/riscv64v.bin_fmt b/riscv/riscv64v.bin_fmt
index 464b69b..9b4df0d 100644
--- a/riscv/riscv64v.bin_fmt
+++ b/riscv/riscv64v.bin_fmt
@@ -25,5 +25,21 @@
   RiscVCInst16;
 };
 
+decoder RiscV64GVZB {
+  namespace mpact::sim::riscv::isa64gvzb;
+  opcode_enum = "isa64gvzb::OpcodeEnum";
+  includes {
+    #include "riscv/riscv64gvzb_decoder.h"
+  }
+  // Group these instruction groups in the same decoder function.
+  RiscV64GVZBInst32 = {RiscVGInst32, RiscVVInst32, RiscVZbaInst32,
+                      RiscVZbaInst64, RiscVZbbInst32, RiscVZbbInst64,
+                      RiscVZbcInst32, RiscVZbsInst32, RiscVZbsImmInst64};
+  // Keep this separate (different base format).
+  RiscVCInst16;
+}
+
+#include "riscv/riscv32zb.bin_fmt"
 #include "riscv/riscv64g.bin_fmt"
+#include "riscv/riscv64zb.bin_fmt"
 #include "riscv/riscv_vector.bin_fmt"
diff --git a/riscv/riscv64v.isa b/riscv/riscv64v.isa
index 44e8ea8..5ed1809 100644
--- a/riscv/riscv64v.isa
+++ b/riscv/riscv64v.isa
@@ -24,12 +24,26 @@
   slots { riscv64gv; }
 }
 
-#include "riscv/riscv64g.isa"
+isa RiscV64GVZB {
+  namespace mpact::sim::riscv::isa64gvzb;
+  slots { riscv64gvzb; }
+}
+
+#include "riscv/riscv64gzb.isa"
 #include "riscv/riscv_vector.isa"
 
+// This adds vector instructions.
 slot riscv64gv : riscv64g, riscv_vector {
   default size = 4;
   default opcode =
     disasm: "Illegal instruction at 0x%(@:08x)",
     semfunc: "&RiscVIllegalInstruction";
-}
\ No newline at end of file
+}
+
+// This adds vector and bit manipulation instructions.
+slot riscv64gvzb : riscv64gzb, riscv_vector {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+}
diff --git a/riscv/riscv64zb.bin_fmt b/riscv/riscv64zb.bin_fmt
new file mode 100644
index 0000000..f1612d7
--- /dev/null
+++ b/riscv/riscv64zb.bin_fmt
@@ -0,0 +1,39 @@
+// Copyright 2024 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.
+
+instruction group RiscVZbaInst64[32] : Inst32Format {
+  add_uw:    RType : func7 == 0b000'0100, func3 == 0b000, opcode == 0b011'1011;
+  sh1add_uw: RType : func7 == 0b001'0000, func3 == 0b010, opcode == 0b011'1011;
+  sh2add_uw: RType : func7 == 0b001'0000, func3 == 0b100, opcode == 0b011'1011;
+  sh3add_uw: RType : func7 == 0b001'0000, func3 == 0b110, opcode == 0b011'1011;
+  slli_uw:   RSType : func6 == 0b000'010, func3 == 0b001, opcode == 0b001'1011;
+}
+
+instruction group RiscVZbbInst64[32] : Inst32Format {
+  clzw  : RType  : func7 == 0b011'0000, rs2 == 0b0'0000, func3 == 0b001, opcode == 0b001'1011;
+  cpopw : RType  : func7 == 0b011'0000, rs2 == 0b0'0010, func3 == 0b001, opcode == 0b001'1011;
+  ctzw  : RType  : func7 == 0b011'0000, rs2 == 0b0'0001, func3 == 0b001, opcode == 0b001'1011;
+  rolw  : RType  : func7 == 0b011'0000, func3 == 0b001, opcode == 0b011'1011;
+  rori  : RSType : func6 == 0b011'000, func3 == 0b101, opcode == 0b001'0011;
+  roriw : RType  : func7 == 0b011'0000, func3 == 0b101, opcode == 0b001'1011;
+  rorw  : RType  : func7 == 0b011'0000, func3 == 0b101, opcode == 0b011'1011;
+  zext_h: RType  : func7 == 0b000'0100, rs2 == 0b0'0000, func3 == 0b100, opcode == 0b011'1011;
+}
+
+instruction group RiscVZbsImmInst64[32] : Inst32Format {
+  bclri : RSType : func6 == 0b010'010, func3 == 0b001, opcode == 0b001'1011;
+  bexti : RSType : func6 == 0b010'010, func3 == 0b101, opcode == 0b001'1011;
+  binvi : RSType : func6 == 0b011'010, func3 == 0b001, opcode == 0b001'1011;
+  bseti : RSType : func6 == 0b001'010, func3 == 0b001, opcode == 0b001'1011;
+}
diff --git a/riscv/riscv64zb.isa b/riscv/riscv64zb.isa
new file mode 100644
index 0000000..edfa18f
--- /dev/null
+++ b/riscv/riscv64zb.isa
@@ -0,0 +1,191 @@
+// Copyright 2024 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.
+
+// This file contains the ISA description for the RiscV32 bitmanipulation
+// extension.
+
+includes {
+  #include "riscv/riscv_bitmanip_instructions.h"
+}
+
+#include "riscv/riscv32zb.isa"
+
+disasm widths = {-18};
+
+slot riscv64_zba : riscv32_zba {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources ThreeOp = { next_pc, rs1, rs2 : rd[..rd]};
+  resources TwoOp = { next_pc, rs1 : rd[..rd]};
+  opcodes {
+    sh1add = override, semfunc: "&RV64::RiscVShAdd";
+    sh2add = override, semfunc: "&RV64::RiscVShAdd";
+    sh3add = override, semfunc: "&RV64::RiscVShAdd";
+    // 64 bit unique instructions.
+    add_uw{: rs1, rs2 : rd},
+      resources: ThreeOp,
+      disasm: "add.uw", "%rd, %rs1, %rs2",
+      semfunc: "&RV64::RiscVAddUw";
+    sh1add_uw{: rs1, rs2, const1 : rd},
+      resources: ThreeOp,
+      disasm: "sh1add.uw", "%rd, %rs1, %rs2",
+      semfunc: "&RV64::RiscVShAddUw";
+    sh2add_uw{: rs1, rs2, const2 : rd},
+      resources: ThreeOp,
+      disasm: "sh2add.uw", "%rd, %rs1, %rs2",
+      semfunc: "&RV64::RiscVShAddUw";
+    sh3add_uw{: rs1, rs2, const3 : rd},
+      resources: ThreeOp,
+      disasm: "sh3add.uw", "%rd, %rs1, %rs2",
+      semfunc: "&RV64::RiscVShAddUw";
+    slli_uw{: rs1, r_uimm6 : rd},
+      resources: TwoOp,
+      disasm: "slli.uw", "%rd, %rs1, %r_uimm6",
+      semfunc: "&RV64::RiscVSlliUw";
+  }
+}
+
+slot riscv64_zbb : riscv32_zbb {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources TwoOp = { next_pc, rs1 : rd[..rd]};
+  resources ThreeOp = { next_pc, rs1, rs2 : rd[..rd]};
+  opcodes {
+    // Logical with negate.
+    andn = override, semfunc: "&RV64::RiscVAndn";
+    orn = override, semfunc: "&RV64::RiscVOrn";
+    xnor = override, semfunc: "&RV64::RiscVXnor";
+    // Counte leading/trailing zero bits.
+    clz = override, semfunc: "&RV64::RiscVClz";
+    ctz = override, semfunc: "&RV64::RiscVCtz";
+    // Count population
+    cpop = override, semfunc: "&RV64::RiscVCpop";
+    // Integer minimum/maximum.
+    max = override, semfunc: "&RV64::RiscVMax";
+    maxu = override, semfunc: "&RV64::RiscVMaxu";
+    min = override, semfunc: "&RV64::RiscVMin";
+    minu = override, semfunc: "&RV64::RiscVMinu";
+    // Sign and zero extension.
+    sext_b = override, semfunc: "&RV64::RiscVSextB";
+    sext_h = override, semfunc: "&RV64::RiscVSextH";
+    zext_h = override, semfunc: "&RV64::RiscVZextH";
+    // Bitwise rotation.
+    rol = override, semfunc: "&RV64::RiscVRol";
+    ror = override, semfunc: "&RV64::RiscVRor";
+    // OR combine.
+    orcb = override, semfunc: "&RV64::RiscVOrcb";
+    // Byte reverse.
+    rev8 = override, semfunc: "&RV64::RiscVRev8";
+    // 64 bit unique instructions.
+    clzw{: rs1 : rd},
+      resources: TwoOp,
+      disasm: "clzw", "%rd, %rs1",
+      semfunc: "&RV64::RiscVClzw";
+    ctzw{: rs1 : rd},
+      resources: TwoOp,
+      disasm: "ctzw", "%rd, %rs1",
+      semfunc: "&RV64::RiscVCtzw";
+    cpopw{: rs1 : rd},
+      resources: TwoOp,
+      disasm: "cpopw", "%rd, %rs1",
+      semfunc: "&RV64::RiscVCpopw";
+    rolw{: rs1, rs2 : rd},
+      resources: ThreeOp,
+      disasm: "rolw", "%rd, %rs1, %rs2",
+      semfunc: "&RV64::RiscVRolw";
+    roriw{: rs1, r_uimm6 : rd},
+      resources: TwoOp,
+      disasm: "roriw", "%rd, %rs1, %r_uimm6",
+      semfunc: "&RV64::RiscVRorw";
+    rorw{: rs1, rs2 : rd},
+      resources: ThreeOp,
+      disasm: "rorw", "%rd, %rs1, %rs2",
+      semfunc: "&RV64::RiscVRorw";
+  }
+}
+
+slot riscv64_zbb_imm {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources TwoOp = { next_pc, rs1 : rd[..rd]};
+  resources ThreeOp = { next_pc, rs1, rs2 : rd[..rd]};
+  opcodes {
+    rori{: rs1, r_uimm6 : rd},
+      resources: TwoOp,
+      disasm: "rori", "%rd, %rs1, %r_uimm6",
+      semfunc: "&RV64::RiscVRor";
+  }
+}
+
+slot riscv64_zbc : riscv32_zbc {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources ThreeOp = { next_pc, rs1, rs2 : rd[..rd]};
+  opcodes {
+    // Carry-less multiplication.
+    clmul = override, semfunc: "&RV64::RiscVClmul";
+    clmulh = override, semfunc: "&RV64::RiscVClmulh";
+    clmulr = override, semfunc: "&RV64::RiscVClmulr";
+  }
+}
+
+slot riscv64_zbs : riscv32_zbs {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources ThreeOp = { next_pc, rs1, rs2 : rd[..rd]};
+  opcodes {
+    // Single-bit instructions.
+    bclr = override, semfunc: "&RV64::RiscVBclr";
+    bext = override, semfunc: "&RV64::RiscVBext";
+    binv = override, semfunc: "&RV64::RiscVBinv";
+    bset = override, semfunc: "&RV64::RiscVBset";
+  }
+}
+
+slot riscv64_zbs_imm {
+  default size = 4;
+  default opcode =
+    disasm: "Illegal instruction at 0x%(@:08x)",
+    semfunc: "&RiscVIllegalInstruction";
+  resources TwoOp = { next_pc, rs1 : rd[..rd]};
+  opcodes {
+    // Single-bit instructions.
+    bclri{: rs1, r_uimm6 : rd},
+      resources: TwoOp,
+      disasm: "bclri", "%rd, %rs1, %r_uimm6",
+      semfunc: "&RV64::RiscVBclr";
+    bexti{: rs1, r_uimm6 : rd},
+      resources: TwoOp,
+      disasm: "bexti", "%rd, %rs1, %r_uimm6",
+      semfunc: "&RV64::RiscVBext";
+    binvi{: rs1, r_uimm6 : rd},
+      resources: TwoOp,
+      disasm: "binvi", "%rd, %rs1, %r_uimm6",
+      semfunc: "&RV64::RiscVBinv";
+    bseti{: rs1, r_uimm6 : rd},
+      resources: TwoOp,
+      disasm: "bseti", "%rd, %rs1, %r_uimm6",
+      semfunc: "&RV64::RiscVBset";
+  }
+}
diff --git a/riscv/riscv_bitmanip_instructions.cc b/riscv/riscv_bitmanip_instructions.cc
index f721266..a217259 100644
--- a/riscv/riscv_bitmanip_instructions.cc
+++ b/riscv/riscv_bitmanip_instructions.cc
@@ -17,6 +17,7 @@
 #include <algorithm>
 #include <cstdint>
 
+#include "absl/base/casts.h"
 #include "absl/numeric/bits.h"
 #include "mpact/sim/generic/instruction.h"
 #include "riscv/riscv_instruction_helpers.h"
@@ -124,17 +125,21 @@
 }
 
 // Rotate left.
-void RiscVrol(const Instruction *instruction) {
+void RiscVRol(const Instruction *instruction) {
   RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
-      instruction,
-      [](UIntReg a, UIntReg b) { return (a << b) | (a >> (32 - b)); });
+      instruction, [](UIntReg a, UIntReg b) {
+        int shamt = b & 0x1f;
+        return (a << shamt) | (a >> (kXlen - shamt));
+      });
 }
 
 // Rotate right.
-void RiscVror(const Instruction *instruction) {
+void RiscVRor(const Instruction *instruction) {
   RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
-      instruction,
-      [](UIntReg a, UIntReg b) { return (a >> b) | (a << (32 - b)); });
+      instruction, [](UIntReg a, UIntReg b) {
+        int shamt = b & 0x1f;
+        return (a >> shamt) | (a << (kXlen - shamt));
+      });
 }
 
 // Or combine (byte wise).
@@ -142,7 +147,7 @@
   RiscVUnaryOp<RegisterType, UIntReg, UIntReg>(instruction, [](UIntReg a) {
     UIntReg mask = 0xff;
     UIntReg result = 0;
-    for (int i = 0; i < 4; i++) {
+    for (int i = 0; i < sizeof(UIntReg); i++) {
       if (a & mask) {
         result |= mask;
       }
@@ -229,4 +234,270 @@
 
 }  // namespace RV32
 
+namespace RV64 {
+
+using RegisterType = RV64Register;
+using UIntReg = uint64_t;
+using IntReg = int64_t;
+constexpr int kXlen = sizeof(UIntReg) * 8;
+
+// 64 + 32 bit unsigned addition.
+void RiscVAddUw(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction,
+      [](UIntReg a, UIntReg b) { return b + (a & 0xffff'ffffULL); });
+}
+
+// Add with shift.
+void RiscVShAdd(const Instruction *instruction) {
+  auto shift = generic::GetInstructionSource<UIntReg>(instruction, 2);
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [shift](UIntReg a, UIntReg b) { return b + (a << shift); });
+}
+
+void RiscVShAddUw(const Instruction *instruction) {
+  auto shift = generic::GetInstructionSource<UIntReg>(instruction, 2);
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [shift](UIntReg a, UIntReg b) {
+        return b + ((a & 0xffff'ffffULL) << shift);
+      });
+}
+
+void RiscVSlliUw(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, uint32_t>(
+      instruction, [](UIntReg a, uint32_t shift) -> UIntReg {
+        return (a & 0xffff'ffffULL) << shift;
+      });
+}
+
+// And not.
+void RiscVAndn(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) { return a & ~b; });
+}
+
+// Or not.
+void RiscVOrn(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) { return a | ~b; });
+}
+
+// Xnor.
+void RiscVXnor(const Instruction *instruction) {  // hmm
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) { return ~(a ^ b); });
+}
+
+// Count leading zeros.
+void RiscVClz(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a) -> UIntReg { return absl::countl_zero(a); });
+}
+
+void RiscVClzw(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, uint32_t>(
+      instruction, [](uint32_t a) -> UIntReg { return absl::countl_zero(a); });
+}
+
+// Count trailing zeros.
+void RiscVCtz(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a) -> UIntReg { return absl::countr_zero(a); });
+}
+
+void RiscVCtzw(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, uint32_t>(
+      instruction, [](uint32_t a) -> UIntReg { return absl::countr_zero(a); });
+}
+
+// Bit population count.
+void RiscVCpop(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a) -> UIntReg { return absl::popcount(a); });
+}
+
+void RiscVCpopw(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, uint32_t, uint32_t>(
+      instruction, [](uint32_t a) -> UIntReg { return absl::popcount(a); });
+}
+
+// Signed max.
+void RiscVMax(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, IntReg, IntReg>(
+      instruction, [](IntReg a, IntReg b) { return std::max(a, b); });
+}
+
+// Unsigned max.
+void RiscVMaxu(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) { return std::max(a, b); });
+}
+
+// Signed min.
+void RiscVMin(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, IntReg, IntReg>(
+      instruction, [](IntReg a, IntReg b) { return std::min(a, b); });
+}
+
+// Unsigned min.
+void RiscVMinu(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) { return std::min(a, b); });
+}
+
+// Sign extend byte.
+void RiscVSextB(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, IntReg, int8_t>(
+      instruction, [](int8_t a) -> IntReg { return static_cast<IntReg>(a); });
+}
+
+// Sign extend half word.
+void RiscVSextH(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, IntReg, int16_t>(
+      instruction, [](int16_t a) -> IntReg { return static_cast<IntReg>(a); });
+}
+
+// Zero extend half word.
+void RiscVZextH(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, uint16_t>(
+      instruction,
+      [](uint16_t a) -> UIntReg { return static_cast<UIntReg>(a); });
+}
+
+// Rotate left.
+void RiscVRol(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) {
+        int shamt = b & 0x3f;
+        return (a << shamt) | (a >> (kXlen - shamt));
+      });
+}
+
+void RiscVRolw(const Instruction *instruction) {  // hmm
+  RiscVBinaryOp<RegisterType, IntReg, uint32_t>(
+      instruction, [](uint32_t a, uint32_t b) {
+        int shamt = b & 0x1f;
+        // Perform rotation.
+        auto c = (a << shamt) | (a >> (32 - shamt));
+        // Sign extend the result.
+        auto d = absl::bit_cast<int32_t>(c);
+        return static_cast<IntReg>(d);
+      });
+}
+
+// Rotate right.
+void RiscVRor(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) {
+        int shamt = b & 0x3f;
+        return (a >> shamt) | (a << (kXlen - shamt));
+      });
+}
+
+void RiscVRorw(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, IntReg, uint32_t>(
+      instruction, [](uint32_t a, uint32_t b) {
+        int shamt = b & 0x1f;
+        // Perform rotation.
+        auto c = (a >> shamt) | (a << (32 - shamt));
+        // Sign extend the result.
+        auto d = absl::bit_cast<int32_t>(c);
+        return static_cast<IntReg>(d);
+      });
+}
+
+// Or combine (byte wise).
+void RiscVOrcb(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, UIntReg>(instruction, [](UIntReg a) {
+    UIntReg mask = 0xffULL;
+    UIntReg result = 0;
+    for (int i = 0; i < sizeof(UIntReg); i++) {
+      if (a & mask) {
+        result |= mask;
+      }
+      mask <<= 8;
+    }
+    return result;
+  });
+}
+
+// Byte reverse.
+void RiscVRev8(const Instruction *instruction) {
+  RiscVUnaryOp<RegisterType, UIntReg, UIntReg>(instruction, [](UIntReg a) {
+    UIntReg result = 0;
+    for (int i = 0; i < sizeof(UIntReg); i++) {
+      result <<= 8;
+      result |= a & 0xff;
+      a >>= 8;
+    }
+    return result;
+  });
+}
+
+// Carry-less multiplication (using xor) - low 32 bits.
+void RiscVClmul(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) {
+        UIntReg result = 0;
+        for (int i = 0; i < kXlen; i++) {
+          result = ((b >> i) & 1) ? result ^ (a << i) : result;
+        }
+        return result;
+      });
+}
+
+// Carry-less multiplication (using xor) - high 32 bits.
+void RiscVClmulh(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) {
+        UIntReg result = 0;
+        for (int i = 1; i < kXlen; i++) {
+          result = ((b >> i) & 1) ? result ^ (a >> (kXlen - i)) : result;
+        }
+        return result;
+      });
+}
+
+// Reverse carry-less multiplication (using xor).
+void RiscVClmulr(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction, [](UIntReg a, UIntReg b) {
+        UIntReg result = 0;
+        for (int i = 0; i < kXlen - 1; i++) {
+          result = ((b >> i) & 1) ? result ^ (a >> (kXlen - i - 1)) : result;
+        }
+        return result;
+      });
+}
+
+// Clear bit.
+void RiscVBclr(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction,
+      [](UIntReg a, UIntReg b) { return a & ~(1ULL << (b & 0x3f)); });
+}
+
+// Extract bit.
+void RiscVBext(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction,
+      [](UIntReg a, UIntReg b) { return (a >> (b & 0x3f)) & 0x1; });
+}
+
+// Invert bit.
+void RiscVBinv(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction,
+      [](UIntReg a, UIntReg b) { return a ^ (1ULL << (b & 0x3f)); });
+}
+
+// Set bit.
+void RiscVBset(const Instruction *instruction) {
+  RiscVBinaryOp<RegisterType, UIntReg, UIntReg>(
+      instruction,
+      [](UIntReg a, UIntReg b) { return a | (1ULL << (b & 0x3f)); });
+}
+
+}  // namespace RV64
+
 }  // namespace mpact::sim::riscv
diff --git a/riscv/riscv_bitmanip_instructions.h b/riscv/riscv_bitmanip_instructions.h
index 83ea8f9..3b346de 100644
--- a/riscv/riscv_bitmanip_instructions.h
+++ b/riscv/riscv_bitmanip_instructions.h
@@ -26,60 +26,39 @@
 
 namespace RV32 {
 
-// This function takes 3 source operands, rs1, rs2, and a shift amount. It takes
-// one destination operand rd.
+// This function takes 3 source operands, rs1, rs2, a shift amount, and one
+// destination operand rd.
 void RiscVShAdd(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
+// These functions take 2 source operands, rs1, rs2, and one destination operand
 // rd.
 void RiscVAndn(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
 void RiscVOrn(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
 void RiscVXnor(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
+// These functions take 1 source operands, rs1, and one destination operand rd.
 void RiscVClz(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
 void RiscVCtz(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
 void RiscVCpop(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
+// These functions take 2 source operands, rs1, rs2, and one destination operand
 // rd.
 void RiscVMax(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
 void RiscVMaxu(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
 void RiscVMin(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
 void RiscVMinu(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
+// These functions take 1 source operands, rs1, and one destination operand rd.
 void RiscVSextB(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
 void RiscVSextH(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
 void RiscVZextH(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
+// These functions take 2 source operands, rs1, rs2, and one destination operand
 // rd.
-void RiscVrol(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
-void RiscVror(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
+void RiscVRol(const Instruction *instruction);
+void RiscVRor(const Instruction *instruction);
+// These functions take 1 source operands, rs1, and one destination operand rd.
 void RiscVOrcb(const Instruction *instruction);
-// This function takes 1 source operands, rs1, and one destination operand rd.
 void RiscVRev8(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
+// These functions take 2 source operands, rs1, rs2, and one destination operand
 // rd.
 void RiscVClmul(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
 void RiscVClmulh(const Instruction *instruction);
-// This function takes 2 source operands, rs1, rs2, and one destination operand
-// rd.
 void RiscVClmulr(const Instruction *instruction);
 // The following functions take 2 source operands, rs1, rs2/imm, and one
 // destination operand rd.
@@ -90,6 +69,58 @@
 
 }  // namespace RV32
 
+namespace RV64 {
+// These functions take 3 source operands, rs1, rs2, a shift amount, and one
+// one destination operand rd.
+void RiscVAddUw(const Instruction *instruction);
+void RiscVShAdd(const Instruction *instruction);
+void RiscVShAddUw(const Instruction *instruction);
+void RiscVSlliUw(const Instruction *instruction);
+// These functions take 2 source operands, rs1, rs2, and one destination
+// operand rd.
+void RiscVAndn(const Instruction *instruction);
+void RiscVOrn(const Instruction *instruction);
+void RiscVXnor(const Instruction *instruction);
+// These functions take 1 source operands, rs1, and one destination operand rd.
+void RiscVClz(const Instruction *instruction);
+void RiscVClzw(const Instruction *instruction);
+void RiscVCtz(const Instruction *instruction);
+void RiscVCtzw(const Instruction *instruction);
+void RiscVCpop(const Instruction *instruction);
+void RiscVCpopw(const Instruction *instruction);
+// These functions take 2 source operands, rs1, rs2, and one destination operand
+// rd.
+void RiscVMax(const Instruction *instruction);
+void RiscVMaxu(const Instruction *instruction);
+void RiscVMin(const Instruction *instruction);
+void RiscVMinu(const Instruction *instruction);
+// These functions take 1 source operands, rs1, and one destination operand rd.
+void RiscVSextB(const Instruction *instruction);
+void RiscVSextH(const Instruction *instruction);
+void RiscVZextH(const Instruction *instruction);
+// These functions take 2 source operands, rs1, rs2, and one destination operand
+// rd.
+void RiscVRol(const Instruction *instruction);
+void RiscVRor(const Instruction *instruction);
+void RiscVRolw(const Instruction *instruction);
+void RiscVRorw(const Instruction *instruction);
+// These functions take 1 source operands, rs1, and one destination operand rd.
+void RiscVOrcb(const Instruction *instruction);
+void RiscVRev8(const Instruction *instruction);
+// These function takes 2 source operands, rs1, rs2, and one destination operand
+// rd.
+void RiscVClmul(const Instruction *instruction);
+void RiscVClmulh(const Instruction *instruction);
+void RiscVClmulr(const Instruction *instruction);
+// These functions take 2 source operands, rs1, rs2/imm, and one destination
+// operand rd.
+void RiscVBclr(const Instruction *instruction);
+void RiscVBext(const Instruction *instruction);
+void RiscVBinv(const Instruction *instruction);
+void RiscVBset(const Instruction *instruction);
+
+}  // namespace RV64
+
 }  // namespace mpact::sim::riscv
 
 #endif  // THIRD_PARTY_MPACT_RISCV_RISCV_BITMANIP_INSTRUCTIONS_H_
diff --git a/riscv/riscv_getter_helpers.h b/riscv/riscv_getter_helpers.h
index 5bb1ed8..e4cb71f 100644
--- a/riscv/riscv_getter_helpers.h
+++ b/riscv/riscv_getter_helpers.h
@@ -1,10 +1,29 @@
+// Copyright 2024 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_GETTER_HELPERS_H_
 #define THIRD_PARTY_MPACT_RISCV_RISCV_GETTER_HELPERS_H_
 
 #include <string>
 
+#include "absl/container/flat_hash_map.h"
+#include "absl/functional/any_invocable.h"
 #include "absl/log/log.h"
+#include "absl/strings/string_view.h"
 #include "mpact/sim/generic/operand_interface.h"
+#include "mpact/sim/generic/resource_operand_interface.h"
+#include "mpact/sim/generic/simple_resource.h"
 #include "riscv/riscv_state.h"
 
 // This file contains helper functions that are used to create commonly used
@@ -15,8 +34,19 @@
 namespace riscv {
 
 using ::mpact::sim::generic::DestinationOperandInterface;
+using ::mpact::sim::generic::ResourceOperandInterface;
 using ::mpact::sim::generic::SourceOperandInterface;
 
+using SourceOpGetterMap =
+    absl::flat_hash_map<int, absl::AnyInvocable<SourceOperandInterface *()>>;
+using DestOpGetterMap =
+    absl::flat_hash_map<int,
+                        absl::AnyInvocable<DestinationOperandInterface *(int)>>;
+using SimpleResourceGetterMap =
+    absl::flat_hash_map<int, absl::AnyInvocable<generic::SimpleResource *()>>;
+using ComplexResourceGetterMap = absl::flat_hash_map<
+    int, absl::AnyInvocable<ResourceOperandInterface *(int, int)>>;
+
 // Helper function to insert and entry into a "getter" map. This is used in
 // the riscv_*_getter.h files.
 template <typename M, typename E, typename G>
@@ -37,7 +67,8 @@
 inline DestinationOperandInterface *GetRegisterDestinationOp(
     RiscVState *state, std::string name, int latency, std::string op_name) {
   auto *reg = state->GetRegister<RegType>(name).first;
-  return reg->CreateDestinationOperand(latency, op_name);
+  auto *op = reg->CreateDestinationOperand(latency, op_name);
+  return op;
 }
 
 template <typename T>
@@ -70,6 +101,27 @@
   return op;
 }
 
+constexpr absl::string_view kXregNames[32] = {
+    "x0",  "x1",  "x2",  "x3",  "x4",  "x5",  "x6",  "x7",  "x8",  "x9",  "x10",
+    "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21",
+    "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31"};
+// ABI names for the integer registers.
+constexpr absl::string_view kXregAbiNames[32] = {
+    "zero", "ra", "sp", "gp", "tp",  "t0",  "t1", "t2", "s0", "s1", "a0",
+    "a1",   "a2", "a3", "a4", "a5",  "a6",  "a7", "s2", "s3", "s4", "s5",
+    "s6",   "s7", "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"};
+// Architectural names for the floating point registers.
+constexpr absl::string_view kFregNames[32] = {
+    "f0",  "f1",  "f2",  "f3",  "f4",  "f5",  "f6",  "f7",  "f8",  "f9",  "f10",
+    "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21",
+    "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"};
+// ABI names for the floating point registers.
+constexpr absl::string_view kFregAbiNames[32] = {
+    "ft0", "ft1", "ft2",  "ft3",  "ft4", "ft5", "ft6",  "ft7",
+    "fs0", "fs1", "fa0",  "fa1",  "fa2", "fa3", "fa4",  "fa5",
+    "fa6", "fa7", "fs2",  "fs3",  "fs4", "fs5", "fs6",  "fs7",
+    "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11"};
+
 }  // namespace riscv
 }  // namespace sim
 }  // namespace mpact
diff --git a/riscv/riscv_getters.h b/riscv/riscv_getters.h
index 5dcfca4..1aaccb6 100644
--- a/riscv/riscv_getters.h
+++ b/riscv/riscv_getters.h
@@ -19,8 +19,6 @@
 #include <new>
 #include <string>
 
-#include "absl/container/flat_hash_map.h"
-#include "absl/functional/any_invocable.h"
 #include "absl/strings/str_cat.h"
 #include "mpact/sim/generic/immediate_operand.h"
 #include "mpact/sim/generic/literal_operand.h"
@@ -48,16 +46,6 @@
 using ::mpact::sim::generic::ResourceOperandInterface;
 using ::mpact::sim::generic::SourceOperandInterface;
 
-using SourceOpGetterMap =
-    absl::flat_hash_map<int, absl::AnyInvocable<SourceOperandInterface *()>>;
-using DestOpGetterMap =
-    absl::flat_hash_map<int,
-                        absl::AnyInvocable<DestinationOperandInterface *(int)>>;
-using SimpleResourceGetterMap =
-    absl::flat_hash_map<int, absl::AnyInvocable<generic::SimpleResource *()>>;
-using ComplexResourceGetterMap = absl::flat_hash_map<
-    int, absl::AnyInvocable<ResourceOperandInterface *(int, int)>>;
-
 // 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
@@ -91,12 +79,6 @@
         common->state(), absl::StrCat(RiscVState::kFregPrefix, num),
         kXRegisterAliases[num]);
   });
-  Insert(getter_map, *Enum::kC3frs2, [common]() {
-    auto num = Extractors::CS::ExtractCsRs2(common->inst_word());
-    return GetRegisterSourceOp<FpRegister>(
-        common->state(), absl::StrCat(RiscVState::kFregPrefix, num),
-        kXRegisterAliases[num]);
-  });
   Insert(getter_map, *Enum::kC3rs1, [common]() {
     auto num = Extractors::CS::ExtractCsRs1(common->inst_word());
     return GetRegisterSourceOp<IntRegister>(
@@ -119,12 +101,6 @@
         common->state(), absl::StrCat(RiscVState::kFregPrefix, num),
         kXRegisterAliases[num]);
   });
-  Insert(getter_map, *Enum::kCfrs2, [common]() {
-    auto num = Extractors::CR::ExtractRs2(common->inst_word());
-    return GetRegisterSourceOp<FpRegister>(
-        common->state(), absl::StrCat(RiscVState::kFregPrefix, num),
-        kXRegisterAliases[num]);
-  });
   Insert(getter_map, *Enum::kCrs1, [common]() {
     auto num = Extractors::CR::ExtractRs1(common->inst_word());
     return GetRegisterSourceOp<IntRegister>(
@@ -326,11 +302,6 @@
     return GetRegisterDestinationOp<IntRegister>(
         common->state(), absl::StrCat(RiscVState::kFregPrefix, num), latency);
   });
-  Insert(getter_map, *Enum::kC3frd, [common](int latency) {
-    int num = Extractors::CL::ExtractClRd(common->inst_word());
-    return GetRegisterDestinationOp<IntRegister>(
-        common->state(), absl::StrCat(RiscVState::kFregPrefix, num), latency);
-  });
   Insert(getter_map, *Enum::kC3rd, [common](int latency) {
     int num = Extractors::CL::ExtractClRd(common->inst_word());
     return GetRegisterDestinationOp<IntRegister>(
@@ -397,7 +368,6 @@
     return GetCSRSetBitsDestinationOp<uint32_t>(common->state(), "fflags",
                                                 latency, "");
   });
-  Insert(getter_map, *Enum::kNone, [](int latency) { return nullptr; });
 }
 
 // This function is used to add the simple resource getters to the given
@@ -408,7 +378,6 @@
 template <typename Enum, typename Extractors>
 void AddRiscVSimpleResourceGetters(SimpleResourceGetterMap &getter_map,
                                    RiscVEncodingCommon *common) {
-  Insert(getter_map, *Enum::kNone, []() { return nullptr; });
   Insert(getter_map, *Enum::kC3drd, [common]() -> generic::SimpleResource * {
     int num = Extractors::CL::ExtractClRd(common->inst_word());
     return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num));
@@ -417,14 +386,6 @@
     int num = Extractors::CS::ExtractCsRs2(common->inst_word());
     return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num));
   });
-  Insert(getter_map, *Enum::kC3frd, [common]() -> generic::SimpleResource * {
-    int num = Extractors::CL::ExtractClRd(common->inst_word());
-    return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num));
-  });
-  Insert(getter_map, *Enum::kC3frs2, [common]() -> generic::SimpleResource * {
-    int num = Extractors::CS::ExtractCsRs2(common->inst_word());
-    return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num));
-  });
   Insert(getter_map, *Enum::kC3rd, [common]() -> generic::SimpleResource * {
     int num = Extractors::CL::ExtractClRd(common->inst_word());
     return common->resource_pool()->GetOrAddResource(absl::StrCat("x", num));
@@ -437,6 +398,18 @@
     int num = Extractors::CS::ExtractCsRs2(common->inst_word());
     return common->resource_pool()->GetOrAddResource(absl::StrCat("x", num));
   });
+  Insert(getter_map, *Enum::kCdrs2, [common]() -> generic::SimpleResource * {
+    auto num = Extractors::CR::ExtractRs2(common->inst_word());
+    return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num));
+  });
+  Insert(getter_map, *Enum::kCrs1, [common]() -> generic::SimpleResource * {
+    auto num = Extractors::CR::ExtractRs1(common->inst_word());
+    return common->resource_pool()->GetOrAddResource(absl::StrCat("x", num));
+  });
+  Insert(getter_map, *Enum::kCrs2, [common]() -> generic::SimpleResource * {
+    auto num = Extractors::CR::ExtractRs2(common->inst_word());
+    return common->resource_pool()->GetOrAddResource(absl::StrCat("x", num));
+  });
   Insert(getter_map, *Enum::kCsr, [common]() -> generic::SimpleResource * {
     return common->resource_pool()->GetOrAddResource("csr");
   });
diff --git a/riscv/riscv_getters_rv32.h b/riscv/riscv_getters_rv32.h
new file mode 100644
index 0000000..fde16f0
--- /dev/null
+++ b/riscv/riscv_getters_rv32.h
@@ -0,0 +1,109 @@
+// Copyright 2024 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_RV32_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_RV32_H_
+
+#include "absl/strings/str_cat.h"
+#include "mpact/sim/generic/immediate_operand.h"
+#include "mpact/sim/generic/literal_operand.h"
+#include "mpact/sim/generic/operand_interface.h"
+#include "mpact/sim/generic/resource_operand_interface.h"
+#include "mpact/sim/generic/simple_resource.h"
+#include "riscv/riscv_encoding_common.h"
+#include "riscv/riscv_getter_helpers.h"
+#include "riscv/riscv_register_aliases.h"
+#include "riscv/riscv_state.h"
+
+// This file contains helper functions that are used to initialize "getter maps"
+// with lambdas that create source, destination, and resource operands for the
+// RiscV32G and RiscV32GZB instruction set decoders. The functions are templated
+// so they can be used with different decoders with different sets of
+// instruction enumerations and register types.
+
+namespace mpact {
+namespace sim {
+namespace riscv {
+
+using ::mpact::sim::generic::DestinationOperandInterface;
+using ::mpact::sim::generic::ImmediateOperand;
+using ::mpact::sim::generic::IntLiteralOperand;
+using ::mpact::sim::generic::ResourceOperandInterface;
+using ::mpact::sim::generic::SourceOperandInterface;
+
+// 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 AddRiscV32SourceGetters(SourceOpGetterMap &getter_map,
+                             RiscVEncodingCommon *common) {
+  // Source operand getters.
+  Insert(getter_map, *Enum::kC3frs2, [common]() {
+    auto num = Extractors::CS::ExtractCsRs2(common->inst_word());
+    return GetRegisterSourceOp<FpRegister>(
+        common->state(), absl::StrCat(RiscVState::kFregPrefix, num),
+        kXRegisterAliases[num]);
+  });
+  Insert(getter_map, *Enum::kCfrs2, [common]() {
+    auto num = Extractors::CR::ExtractRs2(common->inst_word());
+    return GetRegisterSourceOp<FpRegister>(
+        common->state(), absl::StrCat(RiscVState::kFregPrefix, num),
+        kXRegisterAliases[num]);
+  });
+}
+
+// This function is used to add the destination operand getters to the given
+// "getter map". The function is templated on the enum type that defines the
+// destination operand types, the Extractors type that defines the bit
+// extraction functions, and the IntRegister and FpRegister types that are used
+// to construct the register operand.
+template <typename Enum, typename Extractors, typename IntRegister,
+          typename FpRegister>
+void AddRiscV32DestGetters(DestOpGetterMap &getter_map,
+                           RiscVEncodingCommon *common) {
+  // Destination operand getters.
+  Insert(getter_map, *Enum::kC3frd, [common](int latency) {
+    int num = Extractors::CL::ExtractClRd(common->inst_word());
+    return GetRegisterDestinationOp<IntRegister>(
+        common->state(), absl::StrCat(RiscVState::kFregPrefix, num), latency);
+  });
+}
+
+// This function is used to add the simple resource getters to the given
+// "getter map". The function is templated on the enum type that defines the
+// simple resource types, the Extractors type that defines the bit
+// extraction functions, and the IntRegister and FpRegister types that are used
+// to construct the register operand.
+template <typename Enum, typename Extractors>
+void AddRiscV32SimpleResourceGetters(SimpleResourceGetterMap &getter_map,
+                                     RiscVEncodingCommon *common) {
+  Insert(getter_map, *Enum::kC3frd, [common]() -> generic::SimpleResource * {
+    int num = Extractors::CL::ExtractClRd(common->inst_word());
+    return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num));
+  });
+  Insert(getter_map, *Enum::kC3frs2, [common]() -> generic::SimpleResource * {
+    int num = Extractors::CS::ExtractCsRs2(common->inst_word());
+    return common->resource_pool()->GetOrAddResource(absl::StrCat("d", num));
+  });
+}
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_RV32_H_
diff --git a/riscv/riscv_getters_rv64.h b/riscv/riscv_getters_rv64.h
new file mode 100644
index 0000000..7d399d5
--- /dev/null
+++ b/riscv/riscv_getters_rv64.h
@@ -0,0 +1,86 @@
+// Copyright 2024 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_RV64_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_RV64_H_
+
+#include <cstdint>
+#include <new>
+
+#include "mpact/sim/generic/immediate_operand.h"
+#include "mpact/sim/generic/literal_operand.h"
+#include "mpact/sim/generic/operand_interface.h"
+#include "mpact/sim/generic/resource_operand_interface.h"
+#include "riscv/riscv_encoding_common.h"
+#include "riscv/riscv_getter_helpers.h"
+
+// This file contains helper functions that are used to initialize "getter maps"
+// with lambdas that create source, destination, and resource operands for
+// operands only in RiscV64G.
+
+namespace mpact {
+namespace sim {
+namespace riscv {
+
+using ::mpact::sim::generic::DestinationOperandInterface;
+using ::mpact::sim::generic::ImmediateOperand;
+using ::mpact::sim::generic::IntLiteralOperand;
+using ::mpact::sim::generic::ResourceOperandInterface;
+using ::mpact::sim::generic::SourceOperandInterface;
+
+// 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 AddRiscV64SourceGetters(SourceOpGetterMap &getter_map,
+                             RiscVEncodingCommon *common) {
+  // Source operand getters.
+  Insert(getter_map, *Enum::kIUimm6, [common]() {
+    return new ImmediateOperand<uint32_t>(
+        Extractors::Inst32Format::ExtractRUimm6(common->inst_word()));
+  });
+}
+
+// This function is used to add the destination operand getters to the given
+// "getter map". The function is templated on the enum type that defines the
+// destination operand types, the Extractors type that defines the bit
+// extraction functions, and the IntRegister and FpRegister types that are used
+// to construct the register operand.
+template <typename Enum, typename Extractors, typename IntRegister,
+          typename FpRegister>
+void AddRiscV64DestGetters(DestOpGetterMap &getter_map,
+                           RiscVEncodingCommon *common) {
+  // Empty.
+}
+
+// This function is used to add the simple resource getters to the given
+// "getter map". The function is templated on the enum type that defines the
+// simple resource types, the Extractors type that defines the bit
+// extraction functions, and the IntRegister and FpRegister types that are used
+// to construct the register operand.
+template <typename Enum, typename Extractors>
+void AddRiscV64SimpleResourceGetters(SimpleResourceGetterMap &getter_map,
+                                     RiscVEncodingCommon *common) {
+  // Empty.
+}
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_RV64_H_
diff --git a/riscv/riscv_getters_vector.h b/riscv/riscv_getters_vector.h
new file mode 100644
index 0000000..9a41a15
--- /dev/null
+++ b/riscv/riscv_getters_vector.h
@@ -0,0 +1,248 @@
+// Copyright 2024 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_VECTOR_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_VECTOR_H_
+
+#include <cstdint>
+#include <new>
+#include <string>
+#include <vector>
+
+#include "absl/strings/str_cat.h"
+#include "absl/types/span.h"
+#include "mpact/sim/generic/immediate_operand.h"
+#include "mpact/sim/generic/literal_operand.h"
+#include "mpact/sim/generic/operand_interface.h"
+#include "mpact/sim/generic/register.h"
+#include "mpact/sim/generic/resource_operand_interface.h"
+#include "mpact/sim/generic/type_helpers.h"
+#include "riscv/riscv_encoding_common.h"
+#include "riscv/riscv_getter_helpers.h"
+#include "riscv/riscv_register.h"
+#include "riscv/riscv_state.h"
+
+namespace mpact {
+namespace sim {
+namespace riscv {
+
+using ::mpact::sim::generic::DestinationOperandInterface;
+using ::mpact::sim::generic::ImmediateOperand;
+using ::mpact::sim::generic::IntLiteralOperand;
+using ::mpact::sim::generic::ResourceOperandInterface;
+using ::mpact::sim::generic::SourceOperandInterface;
+using ::mpact::sim::generic::operator*;  // NOLINT: is used below.
+
+constexpr int kNumRegTable[8] = {8, 1, 2, 1, 4, 1, 2, 1};
+
+template <typename RegType>
+inline void GetVRegGroup(RiscVState *state, int reg_num,
+                         std::vector<generic::RegisterBase *> *vreg_group) {
+  // The number of registers in a vector register group depends on the register
+  // index: 0, 8, 16, 24 each have 8 registers, 4, 12, 20, 28 each have 4,
+  // 2, 6, 10, 14, 18, 22, 26, 30 each have two, and all odd numbered register
+  // groups have only 1.
+  int num_regs = kNumRegTable[reg_num % 8];
+  for (int i = 0; i < num_regs; i++) {
+    auto vreg_name = absl::StrCat(RiscVState::kVregPrefix, reg_num + i);
+    vreg_group->push_back(state->GetRegister<RegType>(vreg_name).first);
+  }
+}
+template <typename RegType>
+inline SourceOperandInterface *GetVectorRegisterSourceOp(RiscVState *state,
+                                                         int reg_num) {
+  std::vector<generic::RegisterBase *> vreg_group;
+  GetVRegGroup<RegType>(state, reg_num, &vreg_group);
+  auto *v_src_op = new RV32VectorSourceOperand(
+      absl::Span<generic::RegisterBase *>(vreg_group),
+      absl::StrCat(RiscVState::kVregPrefix, reg_num));
+  return v_src_op;
+}
+
+template <typename RegType>
+inline DestinationOperandInterface *GetVectorRegisterDestinationOp(
+    RiscVState *state, int latency, int reg_num) {
+  std::vector<generic::RegisterBase *> vreg_group;
+  GetVRegGroup<RegType>(state, reg_num, &vreg_group);
+  auto *v_dst_op = new RV32VectorDestinationOperand(
+      absl::Span<generic::RegisterBase *>(vreg_group), latency,
+      absl::StrCat(RiscVState::kVregPrefix, reg_num));
+  return v_dst_op;
+}
+
+template <typename RegType>
+inline SourceOperandInterface *GetVectorMaskRegisterSourceOp(RiscVState *state,
+                                                             int reg_num) {
+  // Mask register groups only have a single register.
+  std::vector<generic::RegisterBase *> vreg_group;
+  vreg_group.push_back(
+      state
+          ->GetRegister<RegType>(absl::StrCat(RiscVState::kVregPrefix, reg_num))
+          .first);
+  auto *v_src_op = new RV32VectorSourceOperand(
+      absl::Span<generic::RegisterBase *>(vreg_group),
+      absl::StrCat(RiscVState::kVregPrefix, reg_num));
+  return v_src_op;
+}
+
+template <typename RegType>
+inline DestinationOperandInterface *GetVectorMaskRegisterDestinationOp(
+    RiscVState *state, int latency, int reg_num) {
+  // Mask register groups only have a single register.
+  std::vector<generic::RegisterBase *> vreg_group;
+  vreg_group.push_back(
+      state
+          ->GetRegister<RegType>(absl::StrCat(RiscVState::kVregPrefix, reg_num))
+          .first);
+  auto *v_dst_op = new RV32VectorDestinationOperand(
+      absl::Span<generic::RegisterBase *>(vreg_group), latency,
+      absl::StrCat(RiscVState::kVregPrefix, reg_num));
+  return v_dst_op;
+}
+
+// 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.
+template <typename Enum, typename Extractors, typename VectorRegister>
+void AddRiscVVectorSourceGetters(SourceOpGetterMap &getter_map,
+                                 RiscVEncodingCommon *common) {
+  // Source operand getters.
+  Insert(getter_map, *Enum::kVd, [common]() -> SourceOperandInterface * {
+    auto num = Extractors::VArith::ExtractVd(common->inst_word());
+    return GetVectorRegisterSourceOp<VectorRegister>(common->state(), num);
+  });
+  Insert(getter_map, *Enum::kVmask, [common]() -> SourceOperandInterface * {
+    auto vm = Extractors::VArith::ExtractVm(common->inst_word());
+    if (vm == 1) {
+      // Unmasked, return the True mask.
+      return new RV32VectorTrueOperand(common->state());
+    }
+    // Masked. Return the mask register.
+    return GetVectorMaskRegisterSourceOp<VectorRegister>(common->state(), 0);
+  });
+  Insert(getter_map, *Enum::kVmaskTrue, [common]() -> SourceOperandInterface * {
+    return new RV32VectorTrueOperand(common->state());
+  });
+  Insert(getter_map, *Enum::kVm, [common]() -> SourceOperandInterface * {
+    auto vm = Extractors::VArith::ExtractVm(common->inst_word());
+    return new generic::ImmediateOperand<bool>(
+        vm, absl::StrCat("vm.", vm ? "t" : "f"));
+  });
+  Insert(getter_map, *Enum::kVs1, [common]() -> SourceOperandInterface * {
+    auto num = Extractors::VArith::ExtractVs1(common->inst_word());
+    return GetVectorRegisterSourceOp<VectorRegister>(common->state(), num);
+  });
+  Insert(getter_map, *Enum::kVs2, [common]() -> SourceOperandInterface * {
+    auto num = Extractors::VArith::ExtractVs2(common->inst_word());
+    return GetVectorRegisterSourceOp<VectorRegister>(common->state(), num);
+  });
+  Insert(getter_map, *Enum::kVs3, [common]() -> SourceOperandInterface * {
+    auto num = Extractors::VMem::ExtractVs3(common->inst_word());
+    return GetVectorRegisterSourceOp<VectorRegister>(common->state(), num);
+  });
+
+  Insert(getter_map, *Enum::kSimm5, [common]() -> SourceOperandInterface * {
+    const auto num =
+        Extractors::Inst32Format::ExtractSimm5(common->inst_word());
+    return new generic::ImmediateOperand<int32_t>(num);
+  });
+
+  Insert(getter_map, *Enum::kUimm5, [common]() -> SourceOperandInterface * {
+    const auto num =
+        Extractors::Inst32Format::ExtractUimm5(common->inst_word());
+    return new generic::ImmediateOperand<int32_t>(num);
+  });
+
+  Insert(getter_map, *Enum::kZimm10, [common]() -> SourceOperandInterface * {
+    const auto num =
+        Extractors::Inst32Format::ExtractZimm10(common->inst_word());
+    return new generic::ImmediateOperand<int32_t>(num);
+  });
+
+  Insert(getter_map, *Enum::kZimm11, [common]() -> SourceOperandInterface * {
+    const auto num =
+        Extractors::Inst32Format::ExtractZimm11(common->inst_word());
+    return new generic::ImmediateOperand<int32_t>(num);
+  });
+
+  Insert(getter_map, *Enum::kConst1, []() -> SourceOperandInterface * {
+    return new generic::ImmediateOperand<int32_t>(1);
+  });
+
+  Insert(getter_map, *Enum::kConst2, []() -> SourceOperandInterface * {
+    return new generic::ImmediateOperand<int32_t>(2);
+  });
+
+  Insert(getter_map, *Enum::kConst4, []() -> SourceOperandInterface * {
+    return new generic::ImmediateOperand<int32_t>(4);
+  });
+
+  Insert(getter_map, *Enum::kConst8, []() -> SourceOperandInterface * {
+    return new generic::ImmediateOperand<int32_t>(8);
+  });
+
+  Insert(getter_map, *Enum::kNf, [common]() -> SourceOperandInterface * {
+    auto num_fields = Extractors::VMem::ExtractNf(common->inst_word());
+    return new generic::ImmediateOperand<uint8_t>(num_fields,
+                                                  absl::StrCat(num_fields + 1));
+  });
+  Insert(getter_map, *Enum::kFs1, [common]() -> SourceOperandInterface * {
+    const int num = Extractors::VArith::ExtractRs1(common->inst_word());
+    return GetRegisterSourceOp<RV64Register>(common->state(),
+                                             std::string(kFregNames[num]),
+                                             std::string(kFregAbiNames[num]));
+  });
+}
+
+// This function is used to add the destination operand getters to the given
+// "getter map". The function is templated on the enum type that defines the
+// destination operand types, the Extractors type that defines the bit
+// extraction functions, and the IntRegister and FpRegister types that are used
+// to construct the register operand.
+template <typename Enum, typename Extractors, typename VectorRegister>
+void AddRiscVVectorDestGetters(DestOpGetterMap &getter_map,
+                               RiscVEncodingCommon *common) {
+  // Destination operand getters.
+  Insert(getter_map, *Enum::kVd,
+         [common](int latency) -> DestinationOperandInterface * {
+           auto num = Extractors::VArith::ExtractVd(common->inst_word());
+           return GetVectorRegisterDestinationOp<VectorRegister>(
+               common->state(), latency, num);
+         });
+  Insert(getter_map, *Enum::kFd,
+         [common](int latency) -> DestinationOperandInterface * {
+           const int num = Extractors::VArith::ExtractRd(common->inst_word());
+           return GetRegisterDestinationOp<RV64Register>(
+               common->state(), std::string(kFregNames[num]), latency,
+               std::string(kFregAbiNames[num]));
+         });
+}
+
+// This function is used to add the simple resource getters to the given
+// "getter map". The function is templated on the enum type that defines the
+// simple resource types, the Extractors type that defines the bit
+// extraction functions, and the IntRegister and FpRegister types that are used
+// to construct the register operand.
+template <typename Enum, typename Extractors>
+void AddRiscVVectorSimpleResourceGetters(SimpleResourceGetterMap &getter_map,
+                                         RiscVEncodingCommon *common) {
+  // TODO(torerik): Add resource getters when appropriate.
+}
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_VECTOR_H_
diff --git a/riscv/riscv_getters_zba.h b/riscv/riscv_getters_zba.h
new file mode 100644
index 0000000..6557225
--- /dev/null
+++ b/riscv/riscv_getters_zba.h
@@ -0,0 +1,62 @@
+// 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_ZBA_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_ZBA_H_
+
+#include <new>
+
+#include "mpact/sim/generic/literal_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 AddRiscVZbaSourceGetters(SourceOpGetterMap &getter_map,
+                              RiscVEncodingCommon *common) {
+  // Source operand getters.
+  Insert(getter_map, *Enum::kConst1,
+         [common]() { return new generic::IntLiteralOperand<1>(); });
+  Insert(getter_map, *Enum::kConst2,
+         [common]() { return new generic::IntLiteralOperand<2>(); });
+  Insert(getter_map, *Enum::kConst3,
+         [common]() { return new generic::IntLiteralOperand<3>(); });
+}
+
+template <typename Enum, typename Extractors, typename IntRegister,
+          typename FpRegister>
+void AddRiscVZbaDestGetters(DestOpGetterMap &getter_map,
+                            RiscVEncodingCommon *common) {
+  // Destination operand getters.
+  // Empty.
+}
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_ZBA_H_
diff --git a/riscv/riscv_getters_zbb64.h b/riscv/riscv_getters_zbb64.h
new file mode 100644
index 0000000..5e4317a
--- /dev/null
+++ b/riscv/riscv_getters_zbb64.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_ZBB64_H_
+#define THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_ZBB64_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 AddRiscVZbb64SourceGetters(SourceOpGetterMap &getter_map,
+                                RiscVEncodingCommon *common) {
+  // Source operand getters.
+  Insert(getter_map, *Enum::kRUimm6, [common]() {
+    uint32_t uimm = Extractors::RSType::ExtractRUimm6(common->inst_word());
+    return new generic::ImmediateOperand<uint32_t>(uimm);
+  });
+}
+
+}  // namespace riscv
+}  // namespace sim
+}  // namespace mpact
+
+#endif  // THIRD_PARTY_MPACT_RISCV_RISCV_GETTERS_ZBB64_H_
diff --git a/riscv/riscv_top.cc b/riscv/riscv_top.cc
index fe4c61b..aa76106 100644
--- a/riscv/riscv_top.cc
+++ b/riscv/riscv_top.cc
@@ -19,12 +19,13 @@
 #include <cstring>
 #include <new>
 #include <string>
-#include <thread>  // NOLINT: third_party.
+#include <thread>  // NOLINT: third_party code.
 #include <utility>
 
 #include "absl/functional/any_invocable.h"
 #include "absl/functional/bind_front.h"
 #include "absl/log/check.h"
+#include "absl/log/log.h"
 #include "absl/status/status.h"
 #include "absl/strings/str_cat.h"
 #include "absl/strings/str_format.h"
diff --git a/riscv/riscv_vector.bin_fmt b/riscv/riscv_vector.bin_fmt
index 93548ee..cad9aea 100644
--- a/riscv/riscv_vector.bin_fmt
+++ b/riscv/riscv_vector.bin_fmt
@@ -1,3 +1,17 @@
+// Copyright 2024 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.
+
 // RiscV vector instruction encodings.
 
 format VMem[32] : Inst32Format {
@@ -136,17 +150,17 @@
   // VECTOR STORES
 
   // Unit stride.
-  vse8  : VMem : mew == 0, mop == 0b00, sumop == 0b00000, width == 0b000, opcode == 0b010'0111;
-  vse16 : VMem : mew == 0, mop == 0b00, sumop == 0b00000, width == 0b101, opcode == 0b010'0111;
-  vse32 : VMem : mew == 0, mop == 0b00, sumop == 0b00000, width == 0b110, opcode == 0b010'0111;
-  vse64 : VMem : mew == 0, mop == 0b00, sumop == 0b00000, width == 0b111, opcode == 0b010'0111;
+  vse8  : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b00000, width == 0b000, opcode == 0b010'0111;
+  vse16 : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b00000, width == 0b101, opcode == 0b010'0111;
+  vse32 : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b00000, width == 0b110, opcode == 0b010'0111;
+  vse64 : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b00000, width == 0b111, opcode == 0b010'0111;
   // Mask store.
-  vsm   : VMem : mew == 0, mop == 0b00, sumop == 0b01011, width == 0b000, opcode == 0b010'0111;
+  vsm   : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b01011, width == 0b000, opcode == 0b010'0111;
   // Unit stride, fault first.
-  vse8ff  : VMem : mew == 0, mop == 0b00, sumop == 0b10000, width == 0b000, opcode == 0b010'0111;
-  vse16ff : VMem : mew == 0, mop == 0b00, sumop == 0b10000, width == 0b101, opcode == 0b010'0111;
-  vse32ff : VMem : mew == 0, mop == 0b00, sumop == 0b10000, width == 0b110, opcode == 0b010'0111;
-  vse64ff : VMem : mew == 0, mop == 0b00, sumop == 0b10000, width == 0b111, opcode == 0b010'0111;
+  vse8ff  : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b10000, width == 0b000, opcode == 0b010'0111;
+  vse16ff : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b10000, width == 0b101, opcode == 0b010'0111;
+  vse32ff : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b10000, width == 0b110, opcode == 0b010'0111;
+  vse64ff : VMem : nf == 0, mew == 0, mop == 0b00, sumop == 0b10000, width == 0b111, opcode == 0b010'0111;
   // Unit stride, whole register store.
   vs1re8  : VMem : nf == 0, mop == 0b00, vm == 1, sumop == 0b01000, width == 0b000, opcode == 0b010'0111;
   vs1re16 : VMem : nf == 0, mop == 0b00, vm == 1, sumop == 0b01000, width == 0b101, opcode == 0b010'0111;
@@ -165,20 +179,20 @@
   vs8re32 : VMem : nf == 7, mop == 0b00, vm == 1, sumop == 0b01000, width == 0b110, opcode == 0b010'0111;
   vs8re64 : VMem : nf == 7, mop == 0b00, vm == 1, sumop == 0b01000, width == 0b111, opcode == 0b010'0111;
   // Store strided.
-  vsse8  : VMem : mew == 0, mop == 0b10, width == 0b000, opcode == 0b010'0111;
-  vsse16 : VMem : mew == 0, mop == 0b10, width == 0b101, opcode == 0b010'0111;
-  vsse32 : VMem : mew == 0, mop == 0b10, width == 0b110, opcode == 0b010'0111;
-  vsse64 : VMem : mew == 0, mop == 0b10, width == 0b111, opcode == 0b010'0111;
+  vsse8  : VMem : nf == 0, mew == 0, mop == 0b10, width == 0b000, opcode == 0b010'0111;
+  vsse16 : VMem : nf == 0, mew == 0, mop == 0b10, width == 0b101, opcode == 0b010'0111;
+  vsse32 : VMem : nf == 0, mew == 0, mop == 0b10, width == 0b110, opcode == 0b010'0111;
+  vsse64 : VMem : nf == 0, mew == 0, mop == 0b10, width == 0b111, opcode == 0b010'0111;
   // Store indexed, unordered.
-  vsuxei8 : VMem : mew == 0, mop == 0b01, width == 0b000, opcode == 0b010'0111;
-  vsuxei16: VMem : mew == 0, mop == 0b01, width == 0b101, opcode == 0b010'0111;
-  vsuxei32: VMem : mew == 0, mop == 0b01, width == 0b110, opcode == 0b010'0111;
-  vsuxei64: VMem : mew == 0, mop == 0b01, width == 0b111, opcode == 0b010'0111;
+  vsuxei8 : VMem : nf == 0, mew == 0, mop == 0b01, width == 0b000, opcode == 0b010'0111;
+  vsuxei16: VMem : nf == 0, mew == 0, mop == 0b01, width == 0b101, opcode == 0b010'0111;
+  vsuxei32: VMem : nf == 0, mew == 0, mop == 0b01, width == 0b110, opcode == 0b010'0111;
+  vsuxei64: VMem : nf == 0, mew == 0, mop == 0b01, width == 0b111, opcode == 0b010'0111;
   // Store indexed, ordered.
-  vsoxei8 : VMem : mew == 0, mop == 0b11, width == 0b000, opcode == 0b010'0111;
-  vsoxei16: VMem : mew == 0, mop == 0b11, width == 0b101, opcode == 0b010'0111;
-  vsoxei32: VMem : mew == 0, mop == 0b11, width == 0b110, opcode == 0b010'0111;
-  vsoxei64: VMem : mew == 0, mop == 0b11, width == 0b111, opcode == 0b010'0111;
+  vsoxei8 : VMem : nf == 0, mew == 0, mop == 0b11, width == 0b000, opcode == 0b010'0111;
+  vsoxei16: VMem : nf == 0, mew == 0, mop == 0b11, width == 0b101, opcode == 0b010'0111;
+  vsoxei32: VMem : nf == 0, mew == 0, mop == 0b11, width == 0b110, opcode == 0b010'0111;
+  vsoxei64: VMem : nf == 0, mew == 0, mop == 0b11, width == 0b111, opcode == 0b010'0111;
   // Vector segment store, unit stride.
   vssege8:   VMem : nf != 0, mew == 0, mop == 0b00, sumop == 0b00000, width == 0b000, opcode == 0b010'0111;
   vssege16:  VMem : nf != 0, mew == 0, mop == 0b00, sumop == 0b00000, width == 0b101, opcode == 0b010'0111;
diff --git a/riscv/riscv_vector.isa b/riscv/riscv_vector.isa
index dc429d0..8ded2b5 100644
--- a/riscv/riscv_vector.isa
+++ b/riscv/riscv_vector.isa
@@ -1,3 +1,17 @@
+// Copyright 2024 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.
+
 // This file contains the ISA description of the RiscV V extention instructions.
 
 // First disasm field is 18 char wide and left justified.
@@ -207,19 +221,19 @@
 
     // Vector strided segment load.
     vlssege8{(: rs1, rs2, vmask, nf: ), (: nf : vd)},
-      disasm: "vlssg%nf\\e8.v", "%vd, (%rs1), %rs2, %vmask",
+      disasm: "vlsseg%nf\\e8.v", "%vd, (%rs1), %rs2, %vmask",
       semfunc: "absl::bind_front(&VlSegmentStrided, /*element_width*/ 1)",
                "absl::bind_front(&VlSegmentChild, /*element_width*/ 1)";
     vlssege16{(: rs1, rs2, vmask, nf: ), (: nf : vd)},/*element_width*/ 
-      disasm: "vlssg%nf\\e16.v", "%vd, (%rs1), %rs2, %vmask",
+      disasm: "vlsseg%nf\\e16.v", "%vd, (%rs1), %rs2, %vmask",
       semfunc: "absl::bind_front(&VlSegmentStrided, /*element_width*/ 2)",
                "absl::bind_front(&VlSegmentChild, /*element_width*/ 2)";
     vlssege32{(: rs1, rs2, vmask, nf: ), (: nf : vd)},
-      disasm: "vlssg%nf\\e32.v", "%vd, (%rs1), %rs2, %vmask",
+      disasm: "vlsseg%nf\\e32.v", "%vd, (%rs1), %rs2, %vmask",
       semfunc: "absl::bind_front(&VlSegmentStrided, /*element_width*/ 4)",
                "absl::bind_front(&VlSegmentChild, /*element_width*/ 4)";
     vlssege64{(: rs1, rs2, vmask, nf: ), (: nf : vd)},
-      disasm: "vlssg%nf\\e64.v", "%vd, (%rs1), %rs2, %vmask",
+      disasm: "vlsseg%nf\\e64.v", "%vd, (%rs1), %rs2, %vmask",
       semfunc: "absl::bind_front(&VlSegmentStrided, /*element_width*/ 8)",
                "absl::bind_front(&VlSegmentChild, /*element_width*/ 8)";
 
diff --git a/riscv/riscv_vector_memory_instructions.cc b/riscv/riscv_vector_memory_instructions.cc
index 49aea4a..7591cb3 100644
--- a/riscv/riscv_vector_memory_instructions.cc
+++ b/riscv/riscv_vector_memory_instructions.cc
@@ -16,7 +16,7 @@
 
 #include <algorithm>
 #include <cstdint>
-#include <vector>
+#include <new>
 
 #include "absl/log/log.h"
 #include "absl/status/status.h"
diff --git a/riscv/rv64gv_sim.cc b/riscv/rv64gv_sim.cc
index 70a0316..4ea7313 100644
--- a/riscv/rv64gv_sim.cc
+++ b/riscv/rv64gv_sim.cc
@@ -21,6 +21,7 @@
 #include <ios>
 #include <iostream>
 #include <memory>
+#include <new>
 #include <optional>
 #include <ostream>
 #include <string>
@@ -37,6 +38,7 @@
 #include "absl/time/time.h"
 #include "mpact/sim/generic/core_debug_interface.h"
 #include "mpact/sim/generic/counters.h"
+#include "mpact/sim/generic/decoder_interface.h"
 #include "mpact/sim/generic/instruction.h"
 #include "mpact/sim/proto/component_data.pb.h"
 #include "mpact/sim/util/memory/atomic_memory.h"
@@ -46,20 +48,24 @@
 #include "re2/re2.h"
 #include "riscv/debug_command_shell.h"
 #include "riscv/riscv64g_vec_decoder.h"
+#include "riscv/riscv64gzb_vec_decoder.h"
 #include "riscv/riscv_arm_semihost.h"
 #include "riscv/riscv_fp_state.h"
 #include "riscv/riscv_register.h"
 #include "riscv/riscv_register_aliases.h"
 #include "riscv/riscv_state.h"
 #include "riscv/riscv_top.h"
+#include "riscv/riscv_vector_state.h"
 #include "src/google/protobuf/text_format.h"
 
 using ::mpact::sim::generic::Instruction;
 using ::mpact::sim::proto::ComponentData;
 using ::mpact::sim::riscv::RiscV64GVecDecoder;
+using ::mpact::sim::riscv::RiscV64GZBVecDecoder;
 using ::mpact::sim::riscv::RiscVArmSemihost;
 using ::mpact::sim::riscv::RiscVFPState;
 using ::mpact::sim::riscv::RiscVState;
+using ::mpact::sim::riscv::RiscVVectorState;
 using ::mpact::sim::riscv::RiscVXlen;
 using ::mpact::sim::riscv::RV64Register;
 using ::mpact::sim::riscv::RVFpRegister;
@@ -134,6 +140,9 @@
 // Exit on execution of ecall instruction, default false.
 ABSL_FLAG(bool, exit_on_ecall, false, "Exit on ecall - false by default");
 
+// Enable bit manipulation instructions.
+ABSL_FLAG(bool, bitmanip, false, "Enable bit manipulation instructions");
+
 constexpr char kStackEndSymbolName[] = "__stack_end";
 constexpr char kStackSizeSymbolName[] = "__stack_size";
 
@@ -211,8 +220,16 @@
   // For floating point support add the fp state.
   RiscVFPState rv_fp_state(rv_state.csr_set(), &rv_state);
   rv_state.set_rv_fp(&rv_fp_state);
+  // Set up the vector state.
+  RiscVVectorState rv_vector_state(&rv_state, 64);
+  rv_state.set_rv_vector(&rv_vector_state);
   // Create the instruction decoder.
-  RiscV64GVecDecoder rv_decoder(&rv_state, memory);
+  mpact::sim::generic::DecoderInterface *rv_decoder = nullptr;
+  if (absl::GetFlag(FLAGS_bitmanip)) {
+    rv_decoder = new RiscV64GZBVecDecoder(&rv_state, memory);
+  } else {
+    rv_decoder = new RiscV64GVecDecoder(&rv_state, memory);
+  }
 
   // Make sure the architectural and abi register aliases are added.
   std::string reg_name;
@@ -229,7 +246,7 @@
         reg_name, ::mpact::sim::riscv::kFRegisterAliases[i]);
   }
 
-  RiscVTop riscv_top("RiscV32Sim", &rv_state, &rv_decoder);
+  RiscVTop riscv_top("RiscV32Sim", &rv_state, rv_decoder);
 
   if (absl::GetFlag(FLAGS_exit_on_ecall)) {
     rv_state.set_on_ecall([&riscv_top](const Instruction *inst) -> bool {
@@ -391,4 +408,5 @@
   delete atomic_memory;
   delete memory;
   delete arm_semihost;
+  delete rv_decoder;
 }
diff --git a/riscv/test/BUILD b/riscv/test/BUILD
index f021df3..4feb0d8 100644
--- a/riscv/test/BUILD
+++ b/riscv/test/BUILD
@@ -166,21 +166,6 @@
 )
 
 cc_test(
-    name = "riscv_b_instructions_test",
-    size = "small",
-    srcs = ["riscv_b_instructions_test.cc"],
-    deps = [
-        "//riscv:riscv_g",
-        "//riscv:riscv_state",
-        "@com_google_absl//absl/strings",
-        "@com_google_googletest//:gtest_main",
-        "@com_google_mpact-sim//mpact/sim/generic:core",
-        "@com_google_mpact-sim//mpact/sim/generic:instruction",
-        "@com_google_mpact-sim//mpact/sim/util/memory",
-    ],
-)
-
-cc_test(
     name = "riscv_d_instructions_test",
     size = "small",
     srcs = ["riscv_d_instructions_test.cc"],
@@ -714,9 +699,9 @@
 )
 
 cc_test(
-    name = "riscv_bitmanip_instructions_test",
+    name = "riscv32_bitmanip_instructions_test",
     size = "small",
-    srcs = ["riscv_bitmanip_instructions_test.cc"],
+    srcs = ["riscv32_bitmanip_instructions_test.cc"],
     deps = [
         "//riscv:riscv_bitmanip_instructions",
         "//riscv:riscv_state",
@@ -730,6 +715,23 @@
 )
 
 cc_test(
+    name = "riscv64_bitmanip_instructions_test",
+    size = "small",
+    srcs = ["riscv64_bitmanip_instructions_test.cc"],
+    deps = [
+        "//riscv:riscv_bitmanip_instructions",
+        "//riscv:riscv_state",
+        "@com_google_absl//absl/numeric:int128",
+        "@com_google_absl//absl/random",
+        "@com_google_absl//absl/strings",
+        "@com_google_googletest//:gtest_main",
+        "@com_google_mpact-sim//mpact/sim/generic:core",
+        "@com_google_mpact-sim//mpact/sim/generic:instruction",
+        "@com_google_mpact-sim//mpact/sim/generic:type_helpers",
+    ],
+)
+
+cc_test(
     name = "riscv_counter_csr_test",
     size = "small",
     srcs = ["riscv_counter_csr_test.cc"],
diff --git a/riscv/test/riscv_bitmanip_instructions_test.cc b/riscv/test/riscv32_bitmanip_instructions_test.cc
similarity index 98%
rename from riscv/test/riscv_bitmanip_instructions_test.cc
rename to riscv/test/riscv32_bitmanip_instructions_test.cc
index 0490538..25ccf14 100644
--- a/riscv/test/riscv_bitmanip_instructions_test.cc
+++ b/riscv/test/riscv32_bitmanip_instructions_test.cc
@@ -12,8 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "riscv/riscv_bitmanip_instructions.h"
-
 #include <algorithm>
 #include <cstdint>
 #include <ios>
@@ -29,6 +27,7 @@
 #include "mpact/sim/generic/data_buffer.h"
 #include "mpact/sim/generic/immediate_operand.h"
 #include "mpact/sim/generic/instruction.h"
+#include "riscv/riscv_bitmanip_instructions.h"
 #include "riscv/riscv_register.h"
 #include "riscv/riscv_state.h"
 
@@ -55,8 +54,8 @@
 using ::mpact::sim::riscv::RV32::RiscVOrcb;
 using ::mpact::sim::riscv::RV32::RiscVOrn;
 using ::mpact::sim::riscv::RV32::RiscVRev8;
-using ::mpact::sim::riscv::RV32::RiscVrol;
-using ::mpact::sim::riscv::RV32::RiscVror;
+using ::mpact::sim::riscv::RV32::RiscVRol;
+using ::mpact::sim::riscv::RV32::RiscVRor;
 using ::mpact::sim::riscv::RV32::RiscVSextB;
 using ::mpact::sim::riscv::RV32::RiscVSextH;
 using ::mpact::sim::riscv::RV32::RiscVShAdd;
@@ -351,7 +350,7 @@
 TEST_F(RV32BitmanipInstructionTest, RV32Rol) {
   using T = uint32_t;
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RiscVrol);
+  SetSemanticFunction(&RiscVRol);
   for (int i = 0; i < 100; i++) {
     T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
                            std::numeric_limits<T>::min(),
@@ -367,7 +366,7 @@
 TEST_F(RV32BitmanipInstructionTest, RV32Ror) {
   using T = uint32_t;
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RiscVror);
+  SetSemanticFunction(&RiscVRor);
   for (int i = 0; i < 100; i++) {
     T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
                            std::numeric_limits<T>::min(),
@@ -423,7 +422,6 @@
   }
 }
 
-// TODO(torerik): clmul, clmulh, clmulr
 TEST_F(RV32BitmanipInstructionTest, RV32Clmul) {
   using T = uint32_t;
   AppendRegisterOperands({kX1, kX2}, {kX3});
diff --git a/riscv/test/riscv_b_instructions_test.cc b/riscv/test/riscv64_bitmanip_instructions_test.cc
similarity index 60%
rename from riscv/test/riscv_b_instructions_test.cc
rename to riscv/test/riscv64_bitmanip_instructions_test.cc
index 50ef6c9..e3ecefb 100644
--- a/riscv/test/riscv_b_instructions_test.cc
+++ b/riscv/test/riscv64_bitmanip_instructions_test.cc
@@ -12,45 +12,79 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "riscv/riscv_b_instructions.h"
-
 #include <cstdint>
+#include <limits>
 #include <memory>
 #include <string_view>
 #include <tuple>
 #include <vector>
 
+#include "absl/numeric/int128.h"
+#include "absl/random/random.h"
 #include "absl/strings/string_view.h"
 #include "googlemock/include/gmock/gmock.h"
 #include "mpact/sim/generic/immediate_operand.h"
 #include "mpact/sim/generic/instruction.h"
-#include "mpact/sim/util/memory/flat_demand_memory.h"
+#include "riscv/riscv_bitmanip_instructions.h"
 #include "riscv/riscv_register.h"
 #include "riscv/riscv_state.h"
 
-namespace mpact {
-namespace sim {
-namespace riscv {
 namespace {
+using ::mpact::sim::riscv::RV64::RiscVAddUw;
+using ::mpact::sim::riscv::RV64::RiscVAndn;
+using ::mpact::sim::riscv::RV64::RiscVBclr;
+using ::mpact::sim::riscv::RV64::RiscVBext;
+using ::mpact::sim::riscv::RV64::RiscVBinv;
+using ::mpact::sim::riscv::RV64::RiscVBset;
+using ::mpact::sim::riscv::RV64::RiscVClmul;
+using ::mpact::sim::riscv::RV64::RiscVClmulh;
+using ::mpact::sim::riscv::RV64::RiscVClmulr;
+using ::mpact::sim::riscv::RV64::RiscVClz;
+using ::mpact::sim::riscv::RV64::RiscVClzw;
+using ::mpact::sim::riscv::RV64::RiscVCpop;
+using ::mpact::sim::riscv::RV64::RiscVCpopw;
+using ::mpact::sim::riscv::RV64::RiscVCtz;
+using ::mpact::sim::riscv::RV64::RiscVCtzw;
+using ::mpact::sim::riscv::RV64::RiscVMax;
+using ::mpact::sim::riscv::RV64::RiscVMaxu;
+using ::mpact::sim::riscv::RV64::RiscVMin;
+using ::mpact::sim::riscv::RV64::RiscVMinu;
+using ::mpact::sim::riscv::RV64::RiscVOrcb;
+using ::mpact::sim::riscv::RV64::RiscVOrn;
+using ::mpact::sim::riscv::RV64::RiscVRev8;
+using ::mpact::sim::riscv::RV64::RiscVRol;
+using ::mpact::sim::riscv::RV64::RiscVRolw;
+using ::mpact::sim::riscv::RV64::RiscVRor;
+using ::mpact::sim::riscv::RV64::RiscVRorw;
+using ::mpact::sim::riscv::RV64::RiscVSextB;
+using ::mpact::sim::riscv::RV64::RiscVSextH;
+using ::mpact::sim::riscv::RV64::RiscVShAdd;
+using ::mpact::sim::riscv::RV64::RiscVShAddUw;
+using ::mpact::sim::riscv::RV64::RiscVSlliUw;
+using ::mpact::sim::riscv::RV64::RiscVXnor;
+using ::mpact::sim::riscv::RV64::RiscVZextH;
 
 using ::mpact::sim::generic::ImmediateOperand;
 using ::mpact::sim::generic::Instruction;
-using ::mpact::sim::util::FlatDemandMemory;
+using ::mpact::sim::riscv::RiscVState;
+using ::mpact::sim::riscv::RiscVXlen;
+using ::mpact::sim::riscv::RV64Register;
 
-constexpr uint32_t kInstAddress = 0x2468;
+constexpr uint64_t kInstAddress = 0x2468;
 
 constexpr std::string_view kX1 = "x1";
 constexpr std::string_view kX2 = "x2";
 constexpr std::string_view kX3 = "x3";
+constexpr std::string_view kX4 = "x4";
 
 constexpr uint64_t kUVal1 = 0x1111222233334444ULL;
 constexpr uint64_t kUVal2 = 0x5555666677778888ULL;
 
 // Test class for testing RISCV bit manipulation instructions.
-class RV64BInstructionTest : public testing::Test {
+class RV64BitmanipInstructionTest : public testing::Test {
  public:
-  RV64BInstructionTest() {
-    state_ = std::make_unique<RiscVState>("test", RiscVXlen::RV64, &memory_);
+  RV64BitmanipInstructionTest() {
+    state_ = std::make_unique<RiscVState>("test", RiscVXlen::RV64, nullptr);
     instruction_ = std::make_unique<Instruction>(kInstAddress, state_.get());
     instruction_->set_size(4);
   }
@@ -111,113 +145,115 @@
     return reg->data_buffer()->Get<T>(0);
   }
 
-  FlatDemandMemory memory_;
   std::unique_ptr<RiscVState> state_;
   std::unique_ptr<Instruction> instruction_;
+  absl::BitGen bitgen_;
 };
 
 // The following tests target the Zba instructions. Most have two source
 // register operands and one destination register operand. One replaces a
 // source register operand with an immediate operand.
 
-TEST_F(RV64BInstructionTest, RV64VAddUw) {
+TEST_F(RV64BitmanipInstructionTest, RV64VAddUw) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVAddUw);
+  SetSemanticFunction(&RiscVAddUw);
 
   SetRegisterValues<uint64_t>({{kX1, kUVal1}, {kX2, kUVal2}});
   instruction_->Execute(nullptr);
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), (kUVal1 & 0xffff'ffffLL) + kUVal2);
 }
 
-void VshNaddTestHelper(RV64BInstructionTest &test, int shift) {
-  test.AppendRegisterOperands({kX1, kX2}, {kX3});
+void VshNaddTestHelper(RV64BitmanipInstructionTest &test, int shift) {
+  test.AppendRegisterOperands({kX1, kX2, kX4}, {kX3});
 
-  test.SetRegisterValues<uint64_t>({{kX1, kUVal1}, {kX2, kUVal2}});
+  test.SetRegisterValues<uint64_t>(
+      {{kX1, kUVal1}, {kX2, kUVal2}, {kX4, shift}});
   test.instruction_->Execute(nullptr);
   EXPECT_EQ(test.GetRegisterValue<int64_t>(kX3), (kUVal1 << shift) + kUVal2);
 }
 
-TEST_F(RV64BInstructionTest, RV64VSh1add) {
-  SetSemanticFunction(&RV64::RiscVSh1add);
+TEST_F(RV64BitmanipInstructionTest, RV64VSh1add) {
+  SetSemanticFunction(&RiscVShAdd);
   VshNaddTestHelper(*this, 1);
 }
 
-TEST_F(RV64BInstructionTest, RV64VSh2add) {
-  SetSemanticFunction(&RV64::RiscVSh2add);
+TEST_F(RV64BitmanipInstructionTest, RV64VSh2add) {
+  SetSemanticFunction(&RiscVShAdd);
   VshNaddTestHelper(*this, 2);
 }
 
-TEST_F(RV64BInstructionTest, RV64VSh3add) {
-  SetSemanticFunction(&RV64::RiscVSh3add);
+TEST_F(RV64BitmanipInstructionTest, RV64VSh3add) {
+  SetSemanticFunction(&RiscVShAdd);
   VshNaddTestHelper(*this, 3);
 }
 
-void VshNadduwTestHelper(RV64BInstructionTest &test, int shift) {
-  test.AppendRegisterOperands({kX1, kX2}, {kX3});
+void VshNadduwTestHelper(RV64BitmanipInstructionTest &test, int shift) {
+  test.AppendRegisterOperands({kX1, kX2, kX4}, {kX3});
 
-  test.SetRegisterValues<uint64_t>({{kX1, kUVal1}, {kX2, kUVal2}});
+  test.SetRegisterValues<uint64_t>(
+      {{kX1, kUVal1}, {kX2, kUVal2}, {kX4, shift}});
   test.instruction_->Execute(nullptr);
   EXPECT_EQ(test.GetRegisterValue<int64_t>(kX3),
             ((kUVal1 & 0xffff'ffffULL) << shift) + kUVal2);
 }
 
-TEST_F(RV64BInstructionTest, RV64VSh1adduw) {
-  SetSemanticFunction(&RV64::RiscVSh1adduw);
+TEST_F(RV64BitmanipInstructionTest, RV64VSh1adduw) {
+  SetSemanticFunction(&RiscVShAddUw);
   VshNadduwTestHelper(*this, 1);
 }
 
-TEST_F(RV64BInstructionTest, RV64VSh2adduw) {
-  SetSemanticFunction(&RV64::RiscVSh2adduw);
+TEST_F(RV64BitmanipInstructionTest, RV64VSh2adduw) {
+  SetSemanticFunction(&RiscVShAddUw);
   VshNadduwTestHelper(*this, 2);
 }
 
-TEST_F(RV64BInstructionTest, RV64VSh3adduw) {
-  SetSemanticFunction(&RV64::RiscVSh3adduw);
+TEST_F(RV64BitmanipInstructionTest, RV64VSh3adduw) {
+  SetSemanticFunction(&RiscVShAddUw);
   VshNadduwTestHelper(*this, 3);
 }
 
-TEST_F(RV64BInstructionTest, RV64Slliuw) {
+TEST_F(RV64BitmanipInstructionTest, RV64Slliuw) {
   constexpr int32_t kShiftValue = 3;
   AppendRegisterOperands({kX1}, {kX3});
   AppendImmediateOperands<int32_t>({kShiftValue});
-  SetSemanticFunction(&RV64::RiscVSlliuw);
+  SetSemanticFunction(&RiscVSlliUw);
 
   SetRegisterValues<int64_t>({{kX1, kUVal1}});
   instruction_->Execute(nullptr);
-  EXPECT_EQ(GetRegisterValue<int64_t>(kX3), (kUVal1 & 0xffff'ffffLL)
+  EXPECT_EQ(GetRegisterValue<int64_t>(kX3), (kUVal1 & 0xffff'ffffULL)
                                                 << kShiftValue);
 }
 
-TEST_F(RV64BInstructionTest, RV64Andn) {
+TEST_F(RV64BitmanipInstructionTest, RV64Andn) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVAndn);
+  SetSemanticFunction(&RiscVAndn);
 
   SetRegisterValues<uint64_t>({{kX1, kUVal1}, {kX2, kUVal2}});
   instruction_->Execute(nullptr);
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), kUVal1 & ~kUVal2);
 }
 
-TEST_F(RV64BInstructionTest, RV64Orn) {
+TEST_F(RV64BitmanipInstructionTest, RV64Orn) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVOrn);
+  SetSemanticFunction(&RiscVOrn);
 
   SetRegisterValues<uint64_t>({{kX1, kUVal1}, {kX2, kUVal2}});
   instruction_->Execute(nullptr);
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), kUVal1 | ~kUVal2);
 }
 
-TEST_F(RV64BInstructionTest, RV64Xnor) {
+TEST_F(RV64BitmanipInstructionTest, RV64Xnor) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVXnor);
+  SetSemanticFunction(&RiscVXnor);
 
   SetRegisterValues<uint64_t>({{kX1, kUVal1}, {kX2, kUVal2}});
   instruction_->Execute(nullptr);
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), kUVal1 ^ ~kUVal2);
 }
 
-TEST_F(RV64BInstructionTest, RV64Clz) {
+TEST_F(RV64BitmanipInstructionTest, RV64Clz) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVClz);
+  SetSemanticFunction(&RiscVClz);
 
   SetRegisterValues<uint64_t>({{kX1, 0x0010'0000'0000'0000ULL}});
   instruction_->Execute(nullptr);
@@ -232,9 +268,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 64);
 }
 
-TEST_F(RV64BInstructionTest, RV64Clzw) {
+TEST_F(RV64BitmanipInstructionTest, RV64Clzw) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVClzw);
+  SetSemanticFunction(&RiscVClzw);
 
   SetRegisterValues<uint64_t>({{kX1, 0x8000'0000'0000'0800ULL}});
   instruction_->Execute(nullptr);
@@ -249,9 +285,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 32);
 }
 
-TEST_F(RV64BInstructionTest, RV64Ctz) {
+TEST_F(RV64BitmanipInstructionTest, RV64Ctz) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVCtz);
+  SetSemanticFunction(&RiscVCtz);
 
   SetRegisterValues<uint64_t>({{kX1, 0x0000'0000'0000'0800ULL}});
   instruction_->Execute(nullptr);
@@ -266,9 +302,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 64);
 }
 
-TEST_F(RV64BInstructionTest, RV64Ctzw) {
+TEST_F(RV64BitmanipInstructionTest, RV64Ctzw) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVCtzw);
+  SetSemanticFunction(&RiscVCtzw);
 
   SetRegisterValues<uint64_t>({{kX1, 0x8000'0001'0010'0000ULL}});
   instruction_->Execute(nullptr);
@@ -283,9 +319,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 32);
 }
 
-TEST_F(RV64BInstructionTest, RV64Cpop) {
+TEST_F(RV64BitmanipInstructionTest, RV64Cpop) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVCpop);
+  SetSemanticFunction(&RiscVCpop);
 
   SetRegisterValues<uint64_t>({{kX1, 0x8003'0401'0f00'4002ULL}});
   instruction_->Execute(nullptr);
@@ -300,9 +336,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 64);
 }
 
-TEST_F(RV64BInstructionTest, RV64Cpopw) {
+TEST_F(RV64BitmanipInstructionTest, RV64Cpopw) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVCpopw);
+  SetSemanticFunction(&RiscVCpopw);
 
   SetRegisterValues<uint64_t>({{kX1, 0xffff'ffff'0ff0'f0ffULL}});
   instruction_->Execute(nullptr);
@@ -317,9 +353,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 32);
 }
 
-TEST_F(RV64BInstructionTest, RV64Max) {
+TEST_F(RV64BitmanipInstructionTest, RV64Max) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVMax);
+  SetSemanticFunction(&RiscVMax);
 
   SetRegisterValues<int64_t>({{kX1, 0}, {kX2, 1}});
   instruction_->Execute(nullptr);
@@ -338,9 +374,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0);
 }
 
-TEST_F(RV64BInstructionTest, RV64Maxu) {
+TEST_F(RV64BitmanipInstructionTest, RV64Maxu) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVMaxu);
+  SetSemanticFunction(&RiscVMaxu);
 
   SetRegisterValues<uint64_t>({{kX1, 0}, {kX2, 1}});
   instruction_->Execute(nullptr);
@@ -360,9 +396,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xffff'ffff'ffff'ffff);
 }
 
-TEST_F(RV64BInstructionTest, RV64Min) {
+TEST_F(RV64BitmanipInstructionTest, RV64Min) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVMin);
+  SetSemanticFunction(&RiscVMin);
 
   SetRegisterValues<int64_t>({{kX1, 0}, {kX2, 1}});
   instruction_->Execute(nullptr);
@@ -381,9 +417,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), -1);
 }
 
-TEST_F(RV64BInstructionTest, RV64Minu) {
+TEST_F(RV64BitmanipInstructionTest, RV64Minu) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVMinu);
+  SetSemanticFunction(&RiscVMinu);
 
   SetRegisterValues<uint64_t>({{kX1, 0}, {kX2, 1}});
   instruction_->Execute(nullptr);
@@ -403,9 +439,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0);
 }
 
-TEST_F(RV64BInstructionTest, RV64Sexth) {
+TEST_F(RV64BitmanipInstructionTest, RV64Sexth) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVSexth);
+  SetSemanticFunction(&RiscVSextH);
 
   SetRegisterValues<uint64_t>({{kX1, 0xa5a5'a5a5'a5a5'5678ULL}});
   instruction_->Execute(nullptr);
@@ -416,9 +452,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xffff'ffff'ffff'd678ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Sextb) {
+TEST_F(RV64BitmanipInstructionTest, RV64Sextb) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVSextb);
+  SetSemanticFunction(&RiscVSextB);
 
   SetRegisterValues<uint64_t>({{kX1, 0xa5a5'a5a5'a5a5'a578ULL}});
   instruction_->Execute(nullptr);
@@ -429,9 +465,10 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xffff'ffff'ffff'fff8ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Zextw) {
+/*
+TEST_F(RV64BitmanipInstructionTest, RV64Zextw) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVZextw);
+  SetSemanticFunction(&RiscVZextw);
 
   SetRegisterValues<uint64_t>({{kX1, 0xa5a5'a5a5'1234'5678ULL}});
   instruction_->Execute(nullptr);
@@ -441,10 +478,11 @@
   instruction_->Execute(nullptr);
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0x9234'5678ULL);
 }
+*/
 
-TEST_F(RV64BInstructionTest, RV64Zexth) {
+TEST_F(RV64BitmanipInstructionTest, RV64Zexth) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVZexth);
+  SetSemanticFunction(&RiscVZextH);
 
   SetRegisterValues<uint64_t>({{kX1, 0xa5a5'a5a5'a5a5'5678ULL}});
   instruction_->Execute(nullptr);
@@ -455,9 +493,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xd678ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Rol) {
+TEST_F(RV64BitmanipInstructionTest, RV64Rol) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVRol);
+  SetSemanticFunction(&RiscVRol);
 
   SetRegisterValues<uint64_t>({{kX1, 0x1234'5678'9abc'def0ULL}, {kX2, 16}});
   instruction_->Execute(nullptr);
@@ -468,9 +506,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0x1234'5678'9abc'def0ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Rolw) {
+TEST_F(RV64BitmanipInstructionTest, RV64Rolw) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVRolw);
+  SetSemanticFunction(&RiscVRolw);
 
   SetRegisterValues<uint64_t>({{kX1, 0x1234'5678'9abc'def0ULL}, {kX2, 16}});
   instruction_->Execute(nullptr);
@@ -481,9 +519,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xffff'ffff'9abc'7ef0ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Ror) {
+TEST_F(RV64BitmanipInstructionTest, RV64Ror) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVRor);
+  SetSemanticFunction(&RiscVRor);
 
   SetRegisterValues<uint64_t>({{kX1, 0x1234'5678'9abc'def0ULL}, {kX2, 16}});
   instruction_->Execute(nullptr);
@@ -494,9 +532,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0x1234'5678'9abc'def0ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Rorw) {
+TEST_F(RV64BitmanipInstructionTest, RV64Rorw) {
   AppendRegisterOperands({kX1, kX2}, {kX3});
-  SetSemanticFunction(&RV64::RiscVRorw);
+  SetSemanticFunction(&RiscVRorw);
 
   SetRegisterValues<uint64_t>({{kX1, 0x1234'5678'9abc'7ef0ULL}, {kX2, 16}});
   instruction_->Execute(nullptr);
@@ -507,31 +545,9 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xffff'ffff'9abc'7ef0ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Rori) {
-  constexpr int32_t kShiftValue = 16;
+TEST_F(RV64BitmanipInstructionTest, RV64Orcb) {
   AppendRegisterOperands({kX1}, {kX3});
-  AppendImmediateOperands<int32_t>({kShiftValue});
-  SetSemanticFunction(&RV64::RiscVRori);
-
-  SetRegisterValues<int64_t>({{kX1, 0x1234'5678'9abc'def0ULL}});
-  instruction_->Execute(nullptr);
-  EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xdef0'1234'5678'9abcULL);
-}
-
-TEST_F(RV64BInstructionTest, RV64Roriw) {
-  constexpr int32_t kShiftValue = 16;
-  AppendRegisterOperands({kX1}, {kX3});
-  AppendImmediateOperands<int32_t>({kShiftValue});
-  SetSemanticFunction(&RV64::RiscVRoriw);
-
-  SetRegisterValues<int64_t>({{kX1, 0x1234'5678'9abc'def0ULL}});
-  instruction_->Execute(nullptr);
-  EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0xffff'ffff'def0'9abcULL);
-}
-
-TEST_F(RV64BInstructionTest, RV64Orcb) {
-  AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVOrcb);
+  SetSemanticFunction(&RiscVOrcb);
 
   SetRegisterValues<uint64_t>({{kX1, 0x8003'0401'0f00'4002ULL}});
   instruction_->Execute(nullptr);
@@ -546,16 +562,136 @@
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0x0000'ff00'00ff'0000ULL);
 }
 
-TEST_F(RV64BInstructionTest, RV64Rev8) {
+TEST_F(RV64BitmanipInstructionTest, RV64Rev8) {
   AppendRegisterOperands({kX1}, {kX3});
-  SetSemanticFunction(&RV64::RiscVRev8);
+  SetSemanticFunction(&RiscVRev8);
 
   SetRegisterValues<uint64_t>({{kX1, 0x11'22'33'44'55'66'77'88ULL}});
   instruction_->Execute(nullptr);
   EXPECT_EQ(GetRegisterValue<int64_t>(kX3), 0x8877'6655'4433'2211ULL);
 }
 
+TEST_F(RV64BitmanipInstructionTest, RV64Clmul) {
+  using T = uint64_t;
+  AppendRegisterOperands({kX1, kX2}, {kX3});
+  SetSemanticFunction(&RiscVClmul);
+  for (int i = 0; i < 100; i++) {
+    T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    T val2 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    SetRegisterValues<uint64_t>({{kX1, val1}, {kX2, val2}});
+    instruction_->Execute(nullptr);
+    uint64_t result = 0;
+    for (int i = 0; i < sizeof(T) * 8; ++i) {
+      if (val2 & (1ULL << i)) result ^= static_cast<uint64_t>(val1 << i);
+    }
+    EXPECT_EQ(GetRegisterValue<uint64_t>(kX3), result);
+  }
+}
+
+TEST_F(RV64BitmanipInstructionTest, RV64Clmulh) {
+  using T = uint64_t;
+  AppendRegisterOperands({kX1, kX2}, {kX3});
+  SetSemanticFunction(&RiscVClmulh);
+  for (int i = 0; i < 100; i++) {
+    T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    T val2 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    SetRegisterValues<uint64_t>({{kX1, val1}, {kX2, val2}});
+    instruction_->Execute(nullptr);
+    absl::uint128 result = 0;
+    for (int i = 0; i < sizeof(T) * 8; ++i) {
+      if (val2 & (1ULL << i)) result ^= (absl::MakeUint128(0, val1) << i);
+    }
+    EXPECT_EQ(GetRegisterValue<uint64_t>(kX3), absl::Uint128High64(result));
+  }
+}
+
+TEST_F(RV64BitmanipInstructionTest, RV64Clmulr) {
+  using T = uint64_t;
+  AppendRegisterOperands({kX1, kX2}, {kX3});
+  SetSemanticFunction(&RiscVClmulr);
+  for (int i = 0; i < 100; i++) {
+    T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    T val2 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    SetRegisterValues<uint64_t>({{kX1, val1}, {kX2, val2}});
+    instruction_->Execute(nullptr);
+    uint64_t result = 0;
+    for (int i = 0; i < sizeof(T) * 8 - 1; ++i) {
+      if ((val2 >> i) & 1) result ^= (val1 >> (sizeof(T) * 8 - 1 - i));
+    }
+    EXPECT_EQ(GetRegisterValue<uint64_t>(kX3), result);
+  }
+}
+
+TEST_F(RV64BitmanipInstructionTest, RV64Bclr) {
+  using T = uint64_t;
+  AppendRegisterOperands({kX1, kX2}, {kX3});
+  SetSemanticFunction(&RiscVBclr);
+  for (int i = 0; i < 100; i++) {
+    T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    T val2 = absl::Uniform(absl::IntervalClosed, bitgen_, 0, 63);
+    SetRegisterValues<uint64_t>({{kX1, val1}, {kX2, val2}});
+    instruction_->Execute(nullptr);
+    EXPECT_EQ(GetRegisterValue<uint64_t>(kX3), val1 & ~(1ULL << val2));
+  }
+}
+
+TEST_F(RV64BitmanipInstructionTest, RV64Bext) {
+  using T = uint64_t;
+  AppendRegisterOperands({kX1, kX2}, {kX3});
+  SetSemanticFunction(&RiscVBext);
+  for (int i = 0; i < 100; i++) {
+    T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    T val2 = absl::Uniform(absl::IntervalClosed, bitgen_, 0, 63);
+    SetRegisterValues<uint64_t>({{kX1, val1}, {kX2, val2}});
+    instruction_->Execute(nullptr);
+    EXPECT_EQ(GetRegisterValue<uint64_t>(kX3), (val1 >> val2) & 0x1);
+  }
+}
+
+TEST_F(RV64BitmanipInstructionTest, RV64Binv) {
+  using T = uint64_t;
+  AppendRegisterOperands({kX1, kX2}, {kX3});
+  SetSemanticFunction(&RiscVBinv);
+  for (int i = 0; i < 100; i++) {
+    T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    T val2 = absl::Uniform(absl::IntervalClosed, bitgen_, 0, 63);
+    SetRegisterValues<uint64_t>({{kX1, val1}, {kX2, val2}});
+    instruction_->Execute(nullptr);
+    EXPECT_EQ(GetRegisterValue<uint64_t>(kX3), val1 ^ (1ULL << val2));
+  }
+}
+
+TEST_F(RV64BitmanipInstructionTest, RV64Bset) {
+  using T = uint64_t;
+  AppendRegisterOperands({kX1, kX2}, {kX3});
+  SetSemanticFunction(&RiscVBset);
+  for (int i = 0; i < 100; i++) {
+    T val1 = absl::Uniform(absl::IntervalClosed, bitgen_,
+                           std::numeric_limits<T>::min(),
+                           std::numeric_limits<T>::max());
+    T val2 = absl::Uniform(absl::IntervalClosed, bitgen_, 0, 63);
+    SetRegisterValues<uint64_t>({{kX1, val1}, {kX2, val2}});
+    instruction_->Execute(nullptr);
+    EXPECT_EQ(GetRegisterValue<uint64_t>(kX3), val1 | (1ULL << val2));
+  }
+}
+
 }  // namespace
-}  // namespace riscv
-}  // namespace sim
-}  // namespace mpact