From d0a24ca79f3bfd5d5e3bc1d01bfd6b4699874747 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 19 Oct 2018 09:35:12 +0100 Subject: [PATCH] bring in new version of sv_reg.h --- riscv/sv_reg.h | 130 +++++-------------------------------------------- 1 file changed, 13 insertions(+), 117 deletions(-) diff --git a/riscv/sv_reg.h b/riscv/sv_reg.h index 6a69f28..a1a6dbf 100644 --- a/riscv/sv_reg.h +++ b/riscv/sv_reg.h @@ -1,132 +1,28 @@ #ifndef SV_REG_H #define SV_REG_H -#include -#include "decode.h" - -#define DECL_1OP( op ) \ - bool operator op () const { \ - return op (this->as_uint64()); } - -#define DECL_BOP( op ) \ - bool operator op (const sv_reg_t& rhs) const { \ - return this->as_uint64() op rhs.as_uint64(); } \ - bool operator op (reg_t rhs) const { \ - return this->as_uint64() op rhs; } - -#define DECL_BOPE( op ) \ - bool operator op (int rhs) const { \ - return this->as_uint64() op ((unsigned int)rhs); } \ - bool operator op (long int rhs) const { \ - return this->as_uint64() op ((unsigned long int)rhs); } - -#define DECL_OP( type, op ) \ - sv_reg_t operator op (const sv_reg_t& rhs) const { \ - return make_##type( (this->as_uint64() op rhs.as_uint64()) ); } \ - sv_reg_t operator op (const reg_t& rhs) const { \ - return make_##type( (this->as_uint64() op rhs) ); } \ - sv_reg_t operator op (const sreg_t& rhs) const { \ - return make_##type( (this->as_uint64() op rhs) ); } \ - sv_reg_t operator op (int rhs) const { \ - return make_##type( (this->as_uint64() op rhs) ); } \ - sv_reg_t operator op (uint32_t rhs) const { \ - return make_##type( (this->as_uint64() op rhs) ); } - -#define op_bneg ~ -#define op_xor ^ -#define op_or | -#define op_and & -#define op_plus + -#define op_minus - -#define op_div / -#define op_rem % -#define op_mul * -#define op_gt > -#define op_ge >= -#define op_lt < -#define op_le <= -#define op_eq == -#define op_ne != -#define op_sl << -#define op_sr >> - -class sv_uint64_t; -class sv_sreg_t; - class sv_reg_t { public: - virtual ~sv_reg_t() {} - // using a type which accommodates all values - virtual uint64_t as_uint64() const = 0; + sv_reg_t(uint64_t _reg) : reg(_reg), elwidth(0) {} // default elwidth + sv_reg_t(uint64_t _reg, uint8_t _elwidth) : reg(_reg), elwidth(_elwidth) {} + uint64_t reg; + uint8_t elwidth; public: - DECL_BOP( op_ge ) - DECL_BOP( op_gt ) - DECL_BOP( op_eq ) - DECL_BOPE( op_eq ) - DECL_BOP( op_ne ) - DECL_BOPE( op_ne ) - DECL_BOP( op_le ) - DECL_BOP( op_lt ) - DECL_1OP( op_bneg ) - DECL_OP( sv_uint64_t, op_or ) - DECL_OP( sv_uint64_t, op_xor ) - DECL_OP( sv_uint64_t, op_and ) - DECL_OP( sv_uint64_t, op_plus ) - DECL_OP( sv_uint64_t, op_minus ) - DECL_OP( sv_uint64_t, op_div ) - DECL_OP( sv_uint64_t, op_rem ) - DECL_OP( sv_uint64_t, op_mul ) - DECL_OP( sv_uint64_t, op_sl ) - DECL_OP( sv_uint64_t, op_sr ) - - operator uint8_t (); - operator char (); - operator uint32_t (); - operator int32_t (); - operator uint16_t (); - operator sv_sreg_t () ; - operator sreg_t () ; - operator reg_t () ; - //operator uint_fast64_t () const - // { return make_sv_uint64_t( (reg_t) (as_uint64()) ); } - //operator int_fast64_t () const - //{ return make_sv_int64_t( (sreg_t) (as_uint64()) ); } - // ... -public: - uint64_t get_data() { return as_uint64(); } - sv_reg_t make_sv_uint64_t (uint64_t v) const; - sv_reg_t make_sv_int64_t (int64_t v) const; -}; - -class sv_sreg_t : public sv_reg_t { -public: - sv_sreg_t(int64_t v) : data(v) {} -// ... -private: - virtual uint64_t as_uint64() const { return this->data; } -private: - int64_t data; + uint64_t get_data() { return reg; } + uint8_t get_width() { return elwidth; } }; -class sv_uint64_t : public sv_reg_t { +class sv_sreg_t { public: - sv_uint64_t(uint64_t v) : data(v) {} -// ... -private: - virtual uint64_t as_uint64() const { return this->data; } -private: - uint64_t data; -}; + sv_sreg_t(int64_t _reg) : reg(_reg), elwidth(0) {} // default elwidth + sv_sreg_t(int64_t _reg, uint8_t _elwidth) : reg(_reg), elwidth(_elwidth) {} -class sv_uint16_t : public sv_reg_t { -// ... + int64_t reg; + uint8_t elwidth; public: - sv_uint16_t(uint16_t v) : data(v) {} -private: - virtual uint64_t as_uint64() const { return this->data; } -private: - uint16_t data; + int64_t get_data() { return reg; } + uint8_t get_width() { return elwidth; } }; -- 2.30.2