I am working on a simulator for a microprocessor, written in C++.
I am looking for a way to model state elements in the hardware that have just been powered up and have not yet been reset in any way. A real state element would have an unknown value that is either 0 or 1, but in software models this is commonly modeled as an X
, meaning unknown.
I am looking for a library in C++ that can model these X
values, including their propagation. That is, it would have to know how to handle logical and arithmetical operations with X
es:
1 AND X = X
0 AND X = 0
1 + X = X
etc...
Is there any such library that is both stable and fast?
Edit:
I neglected to mention that my current code works with bitvectors. More accurately, I use the standard uint_*t
data types, and these are the ones I want to replace. Whatever library I use, it must support arithmetic, shifts and logical operators for it to be useful.
Try Boost.Tribool.
The
tribool
class acts like the built-inbool
type, but for 3-state boolean logic. The three states aretrue
,false
, andindeterminate
, where the first two states are equivalent to those of the C++bool
type and the last state represents an unknown boolean value (that may betrue
orfalse
, we don't know).
You can see the test suit and the header documentation for the rules this class supports.
Boost libraries are pretty high quality and well maintained, so you don't need to worry about its stability. And "fast"... well it's hard to be slow for simple classes like this :). The operations are implemented with 2 to 3 integer comparison with 1 or 2 if
clauses so it should be efficient enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With