-
Notifications
You must be signed in to change notification settings - Fork 4
Bugfix for dumping xz values incorrectly #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnjohnlin
wants to merge
2
commits into
gtkwave:main
Choose a base branch
from
johnjohnlin:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -533,8 +533,8 @@ class VariableInfoScalarInt { | |
| // clang-format off | ||
| case 0: delta_time_index = (delta_time_index<<2) | (0<<1) | 0; break; // '0' | ||
| case 1: delta_time_index = (delta_time_index<<2) | (1<<1) | 0; break; // '1' | ||
| case 2: delta_time_index = (delta_time_index<<4) | (1<<1) | 1; break; // 'Z' | ||
| case 3: delta_time_index = (delta_time_index<<4) | (0<<1) | 1; break; // 'X' | ||
| case 2: delta_time_index = (delta_time_index<<4) | (0<<1) | 1; break; // 'X' | ||
| case 3: delta_time_index = (delta_time_index<<4) | (1<<1) | 1; break; // 'Z' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the zxhu mapping results in 0123 -> 0110 mapping, which is not very reasonable. With xzhu, it becomes 0101 |
||
| // Not supporting VHDL now | ||
| // LCOV_EXCL_START | ||
| case 4: delta_time_index = (delta_time_index<<4) | (2<<1) | 1; break; // 'H' | ||
|
|
@@ -603,20 +603,11 @@ class VariableInfoLongInt { | |
| VariableInfoLongInt(VariableInfo &info_) : info(info_) {} | ||
|
|
||
| public: | ||
| size_t computeBytesNeededNoHeader(EncodingType encoding) const { | ||
| switch (encoding) { | ||
| case EncodingType::BINARY: | ||
| return num_words() * sizeof(uint64_t); | ||
| case EncodingType::VERILOG: | ||
| return num_words32() * sizeof(uint32_t) * 2; | ||
| [[unlikely]] case EncodingType::VHDL: | ||
| FST_FAIL_STRING("VHDL format is unsupported with wide values"); | ||
| } | ||
| FST_UNREACHABLE; | ||
| } | ||
|
|
||
| size_t computeBytesNeeded(EncodingType encoding) const { | ||
| return kEmitTimeIndexAndEncodingSize + computeBytesNeededNoHeader(encoding); | ||
| return ( | ||
| kEmitTimeIndexAndEncodingSize + | ||
| num_words() * sizeof(uint64_t) * bitPerEncodedBit(encoding) | ||
| ); | ||
| } | ||
|
|
||
| EmitWriterHelper emitValueChangeCommonPart(uint64_t current_time_index, EncodingType encoding) { | ||
|
|
@@ -634,12 +625,13 @@ class VariableInfoLongInt { | |
|
|
||
| public: | ||
| void construct() { | ||
| const size_t nw = num_words32(); | ||
| const size_t nw = num_words(); | ||
| info.resize(computeBytesNeeded(EncodingType::VERILOG)); | ||
| EmitWriterHelper wh(info.data_ptr()); | ||
| wh // | ||
| .writeTimeIndexAndEncoding(0, EncodingType::VERILOG) | ||
| .fill(static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) << 32, nw); | ||
| .fill(uint64_t(0), nw) | ||
| .fill(uint64_t(-1), nw); | ||
| } | ||
|
|
||
| void emitValueChange(uint64_t current_time_index, const uint64_t val) { | ||
|
|
@@ -650,11 +642,11 @@ class VariableInfoLongInt { | |
|
|
||
| void emitValueChange(uint64_t current_time_index, const uint32_t *val, EncodingType encoding) { | ||
| const unsigned nw32 = num_words32(); | ||
| const unsigned bpb = bitPerEncodedBit(encoding); | ||
|
|
||
| auto wh = emitValueChangeCommonPart(current_time_index, encoding); | ||
|
|
||
| switch (encoding) { | ||
| case EncodingType::BINARY: { | ||
| for (unsigned i = 0; i < bpb; ++i) { | ||
| for (unsigned j = 0; j < nw32 / 2; ++j) { | ||
| uint64_t v = val[1]; // high bits | ||
| v <<= 32; | ||
|
|
@@ -667,25 +659,13 @@ class VariableInfoLongInt { | |
| wh.write(v); | ||
| val += 1; | ||
| } | ||
| } break; | ||
| case EncodingType::VERILOG: { | ||
| for (unsigned j = 0; j < nw32; ++j) { | ||
| uint64_t v = val[1]; // high bits | ||
| v <<= 32; | ||
| v |= val[0]; // low bits | ||
| wh.write(v); | ||
| val += 2; | ||
| } | ||
| } break; | ||
| [[unlikely]] case EncodingType::VHDL: | ||
| FST_FAIL_STRING("VHDL format is unsupported with wide values"); | ||
| } | ||
| } | ||
|
|
||
| void emitValueChange(uint64_t current_time_index, const uint64_t *val, EncodingType encoding) { | ||
| const unsigned nw_encoded = num_words() * bitPerEncodedBit(encoding); | ||
| auto wh = emitValueChangeCommonPart(current_time_index, encoding); | ||
| FST_CHECK(encoding == EncodingType::BINARY); | ||
| wh.write(val, num_words()); | ||
| wh.write(val, nw_encoded); | ||
| } | ||
|
|
||
| void dumpInitialBits(std::vector<uint8_t> &buf) const { | ||
|
|
@@ -708,16 +688,15 @@ class VariableInfoLongInt { | |
| break; | ||
| } | ||
| case EncodingType::VERILOG: { | ||
| for (unsigned word_index = num_words32(); word_index-- > 0;) { | ||
| const uint64_t val = rh.peek<uint64_t>(word_index); | ||
| const uint32_t aval = static_cast<uint32_t>(val); | ||
| const uint32_t bval = static_cast<uint32_t>(val >> 32); | ||
| for (unsigned word_index = nw; word_index-- > 0;) { | ||
| const uint64_t v0 = rh.peek<uint64_t>(nw * 0 + word_index); | ||
| const uint64_t v1 = rh.peek<uint64_t>(nw * 1 + word_index); | ||
| const unsigned num_bit = | ||
| (word_index * 32 + 32 > info.bitwidth()) ? (info.bitwidth() % 32) : 32; | ||
| (word_index * 64 + 64 > info.bitwidth()) ? (info.bitwidth() % 64) : 64; | ||
| for (unsigned bit_index = num_bit; bit_index-- > 0;) { | ||
| const bool a = ((aval >> bit_index) & 1); | ||
| const bool b = ((bval >> bit_index) & 1); | ||
| const char c = kEncodedBitToCharTable[(b << 1) | a]; | ||
| const bool b0 = ((v0 >> bit_index) & uint64_t(1)); | ||
| const bool b1 = ((v1 >> bit_index) & uint64_t(1)); | ||
| const char c = kEncodedBitToCharTable[(b1 << 1) | b0]; | ||
| buf.push_back(c); | ||
| } | ||
| } | ||
|
|
@@ -763,7 +742,8 @@ class VariableInfoLongInt { | |
| FST_DCHECK_GT(tail, rh.ptr); | ||
| const auto time_index = rh.read<uint64_t>(); | ||
| const auto enc = rh.read<EncodingType>(); | ||
| const auto num_byte = computeBytesNeededNoHeader(enc); | ||
| const auto num_element = bitPerEncodedBit(enc); | ||
| const auto num_byte = num_element * nw * sizeof(uint64_t); | ||
| if (first) { | ||
| // Note: [0] is initial value, which is already dumped in dumpInitialBits() | ||
| first = false; | ||
|
|
@@ -793,22 +773,16 @@ class VariableInfoLongInt { | |
| } break; | ||
| case EncodingType::VERILOG: { | ||
| h.writeLEB128((delta_time_index << 1) | 1); | ||
| const int fullWords = (bitwidth / 32); | ||
| if (int j = bitwidth % 32) { | ||
| const uint64_t val = rh.peek<uint64_t>(fullWords); | ||
| while (j > 0) { | ||
| --j; | ||
| const uint64_t v = val >> j; | ||
| h.writeUIntBE(kEncodedBitToCharTable[((v >> 31) & 2) | (v & 1)]); | ||
| } | ||
| } | ||
| for (size_t i = fullWords; i > 0;) { | ||
| --i; | ||
| const uint64_t val = rh.peek<uint64_t>(i); | ||
| for (int j = 32; j > 0;) { | ||
| --j; | ||
| const uint64_t v = val >> j; | ||
| h.writeUIntBE(kEncodedBitToCharTable[((v >> 31) & 2) | (v & 1)]); | ||
| for (unsigned word_index = nw; word_index-- > 0;) { | ||
| const uint64_t v0 = rh.peek<uint64_t>(nw * 0 + word_index); | ||
| const uint64_t v1 = rh.peek<uint64_t>(nw * 1 + word_index); | ||
| const unsigned num_bit = | ||
| (word_index * 64 + 64 > bitwidth) ? (bitwidth % 64) : 64; | ||
| for (unsigned bit_index = num_bit; bit_index-- > 0;) { | ||
| const bool b0 = ((v0 >> bit_index) & uint64_t(1)); | ||
| const bool b1 = ((v1 >> bit_index) & uint64_t(1)); | ||
| const char c = kEncodedBitToCharTable[(b1 << 1) | b0]; | ||
| h.write(c); | ||
| } | ||
| } | ||
| } break; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think xz is more reasonable than zx (see the case encoding below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was intentionally changed in #11 to match the encoding defined in the VPI standard to match the internal encoding used by the new 4 state support in Verilator.