43 uint64_t value, reset_value;
44 mutable bool read, write;
45 mutable bool disabled_;
47 ubits_base() : value(0), reset_value(0), read(
false), write(
false), disabled_(
false) {}
48 explicit ubits_base(uint64_t v)
49 : value(v), reset_value(v), read(
false), write(
false), disabled_(
false) {}
50 operator uint64_t()
const {
54 bool modified()
const {
return write; }
55 void set_modified(
bool v =
true) { write = v; }
56 bool disabled()
const {
return disabled_; }
57 bool disable_if_unmodified() {
return write ? false : (disabled_ =
true); }
58 bool disable_if_zero()
const {
return value == 0 && !write; }
59 bool disable_if_reset_value() {
return value == reset_value ? (disabled_ =
true) :
false; }
60 bool disable()
const {
62 LOG1(
"ERROR: Disabling modified register in " <<
this);
68 void enable()
const { disabled_ =
false; }
69 void rewrite() { write =
false; }
70 virtual uint64_t operator=(uint64_t v) = 0;
71 virtual const ubits_base &operator|=(uint64_t v) = 0;
72 virtual unsigned size() = 0;
73 void log(
const char *op, uint64_t v)
const;
82struct ubits : ubits_base {
83 ubits() : ubits_base() {}
84 const ubits &check(std::true_type) {
85 if (value >= (uint64_t(1) << N)) {
86 LOG1(
"ERROR: out of range for " << N <<
" bits in " <<
this);
87 value &= (uint64_t(1) << N) - 1;
91 const ubits &check(std::false_type) {
return *
this; }
92 const ubits &check() {
93 return check(std::integral_constant<
bool, (N !=
sizeof(uint64_t) * CHAR_BIT)>{});
95 explicit ubits(uint64_t v) : ubits_base(v) { check(); }
96 ubits(
const ubits &) =
delete;
97 ubits(ubits &&) =
default;
98 uint64_t operator=(uint64_t v)
override {
99 if (disabled_) LOG1(
"ERROR: Writing disabled register value in " <<
this);
101 LOG1((value != v ?
"ERROR:" :
"WARNING:")
102 <<
" Overwriting " << value <<
" with " << v <<
" in " <<
this);
109 const ubits &operator=(
const ubits &v) {
114 const ubits_base &operator=(
const ubits_base &v) {
119 unsigned size()
override {
return N; }
120 const ubits &operator|=(uint64_t v)
override {
121 if (disabled_) LOG1(
"ERROR: Writing disabled register value in " <<
this);
122 if (write && (v & value) != 0)
123 LOG1(
"WARNING: Overwriting " << value <<
" with " << (v | value) <<
" in " <<
this);
129 const ubits &operator|=(
bitvec v) {
130 if (disabled_) LOG1(
"ERROR: Writing disabled register value in " <<
this);
132 LOG1(
"ERROR: bitvec 0x" << v <<
" out of range for " << N <<
" bits in " <<
this);
133 uint64_t val = v.getrange(0, N);
134 if (write && (val & value) != 0)
135 LOG1(
"WARNING: Overwriting " << value <<
" with " << (val | value) <<
" in " <<
this);
141 const ubits &operator+=(uint64_t v) {
142 if (disabled_) LOG1(
"ERROR: Overwriting disabled register value in " <<
this);
148 const ubits &operator^=(uint64_t v) {
149 if (disabled_) LOG1(
"ERROR: Overwriting disabled register value in " <<
this);
155 const ubits &set_subfield(uint64_t v,
unsigned bit,
unsigned size) {
156 if (disabled_) LOG1(
"ERROR: Overwriting disabled register value in " <<
this);
157 uint64_t mask = (1ULL << size) - 1;
158 uint64_t oldv = (value >> bit) & mask;
159 if (bit + size > N) {
160 LOG1(
"ERROR: subfield " << bit <<
".." << (bit + size - 1) <<
" out of range in "
162 }
else if (write && oldv) {
163 LOG1((v != oldv ?
"ERROR" :
"WARNING")
164 <<
": Overwriting subfield(" << bit <<
".." << (bit + size - 1) <<
") value "
165 << oldv <<
" with " << v <<
" in " <<
this);
168 LOG1(
"ERROR: Subfield value " << v <<
" too large for " << size <<
" bits in " <<
this);
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24