[NFC][HW] Add container class for n-valued logic constants #5793
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds RLELogic, a run-length encoding container class for arbitrary sequences of n-valued logic digits within the set of
0,1,X,Z,U,W,L,H,-
. It is a prerequisite for integrating thehw.logic
type of #5622. As it is not currently used anywhere it should not cause any functional changes, yet.The motivation behind RLELogic is to provide a somewhat efficient representation for non-integer constants in hardware designs, which generally will be of
logic
orstd_logic
type for SystemVerilog and VHDL respectively. These can usually be assumed to be short and/or contain long runs of the same digit repeatedly. Thus, RLELogic uses run-length encoding to reduce their size in memory.Each byte of the encoded buffer represents one of the nine possible digits in its lower nibble, while encoding a run-length from one to sixteen in the upper nibble. The run-length of the most significant encoded digit is implicitly assumed to be infinite. Thus, all values which are just one specific digit repeated over and over share the same encoding independent of their 'actual' length. Since an RLELogic value will generally be associated with a known width instance of the
hw.logic
type class, storing the width in RLELogic would be redundant. However, it contains a bit mask indicating all the digits contained in its value at least once. This allows to quickly check, e.g., whether the encoded value contains an 'unknown' digit or represents an integer.In general RLELogic should not be used to store integers. In fact, it should be avoided to encode an integer value as RLELogic whenever possible and APInt should be used instead. This is a major departure from my previous attempts of creating an unified APLogic container for both integer and non-integer values. While APLogic technically worked, its integration did not pan out as I had hoped, and it would not have been particularly efficient. Also, its implementation became way too complex to be worthwhile. RLELogic should be a much cleaner solution, and likely more efficient in real-world scenarios.
There is currently only a limited number of operations implemented on RLELogic. I intend to add more when the general type infrastructure for
hw.logic
is in place.