diff options
author | Andrew Waterman <andrew@sifive.com> | 2022-03-15 17:47:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-15 17:47:01 -0700 |
commit | 2528ad66c11bc44309135c9ab0896e2907847105 (patch) | |
tree | 0eb047e02e81fec2dc30d421c4177d84104166c9 /riscv/csrs.h | |
parent | b1fcb02bb1c97c8080b0dcb8133d78de443d1ffe (diff) | |
download | spike-2528ad66c11bc44309135c9ab0896e2907847105.zip spike-2528ad66c11bc44309135c9ab0896e2907847105.tar.gz spike-2528ad66c11bc44309135c9ab0896e2907847105.tar.bz2 |
Fix perf regression from CSR refactoring (#949)
Since many instructions are only conditionally legal, their
implementations need to query misa (or isa). Since reading
misa is therefore on the critical path, make sure it's inlined.
Making misa_csr_t a final class sidesteps the need for a vtable
lookup when calling read().
Diffstat (limited to 'riscv/csrs.h')
-rw-r--r-- | riscv/csrs.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/riscv/csrs.h b/riscv/csrs.h index e3cbdd7..688ad6b 100644 --- a/riscv/csrs.h +++ b/riscv/csrs.h @@ -8,6 +8,7 @@ #include <memory> // For access_type: #include "memtracer.h" +#include <cassert> class processor_t; struct state_t; @@ -61,7 +62,11 @@ typedef std::shared_ptr<csr_t> csr_t_p; class basic_csr_t: public csr_t { public: basic_csr_t(processor_t* const proc, const reg_t addr, const reg_t init); - virtual reg_t read() const noexcept override; + + virtual reg_t read() const noexcept override { + return val; + } + protected: virtual bool unlogged_write(const reg_t val) noexcept override; private: @@ -263,10 +268,15 @@ class sstatus_csr_t: public virtualized_csr_t { typedef std::shared_ptr<sstatus_csr_t> sstatus_csr_t_p; -class misa_csr_t: public basic_csr_t { +class misa_csr_t final: public basic_csr_t { public: misa_csr_t(processor_t* const proc, const reg_t addr, const reg_t max_isa); - bool extension_enabled(unsigned char ext) const noexcept; + + bool extension_enabled(unsigned char ext) const noexcept { + assert(ext >= 'A' && ext <= 'Z'); + return (read() >> (ext - 'A')) & 1; + } + bool extension_enabled_const(unsigned char ext) const noexcept; protected: virtual bool unlogged_write(const reg_t val) noexcept override; |