Skip to content

Fix the documented bit order of waveform groups, and paint large groups MSB-first - #707

Merged
joern274 merged 2 commits into
masterfrom
fix/waveform-group-bit-order
Dec 2, 2026
Merged

joern274 merged 2 commits into
masterfrom
fix/waveform-group-bit-order

Conversation

@RenWal

@RenWal RenWal commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Problem

The docstring of add_waveform_group(name, nets) says the first net is the least significant bit. In the code it is the most significant bit:

  • WaveDataGroup::recalcData() puts list element i at mask 1 << (n-i-1).
  • WaveDataGroup::intValue() and WaveDataProviderGroup use the same order.

A script that follows the docstring gets every group value bit-mirrored. Example: a group built as [KEY(0), …, KEY(15)], with KEY(0) carrying bit 0 of 0xABCD, shows B3D5. Built as [KEY(15), …, KEY(0)], it shows ABCD.

Groups built in the GUI are not affected: a net dropped onto a group goes in at the top, and the top row is the MSB.

There is one place that uses the opposite order. WaveFormPainted::generateGroup composes the group value with the first child as the LSB. The viewer uses it for groups whose waves exceed the loadable size. Such a group is drawn bit-mirrored relative to its member waves and to get_value_at(). This applies to every group above the limit, whether a script, the GUI or load_waveform_groups() created it.

Groups from pin groups

The pin-group overloads, and through them the groups that load_waveform_groups() creates automatically, take the nets in get_pins() order. get_pins() honors the group's direction:

  • ascending groups come back lowest index first;
  • descending groups come back highest index first.

So the pin at the start index is the MSB: the highest index for a descending group, index 0 for an ascending one. The value of these groups was consistent with that before this PR and is unchanged. Only their documentation was missing.

Changes

  1. Docs (C++ header and Python bindings):
    • add_waveform_group(name, nets): the first net is the most significant bit.
    • The pin-group overloads take the pins in pin-group order, so the pin at the start index is the MSB: the lowest index for an ascending group, the highest for a descending one.
    • The gate pin-group overload skips inout pins and pins without a net.
    • The NetGroup overload refers to the pin-group order.
  2. generateGroup: the first child is now the MSB, as everywhere else.

I fixed the documentation rather than the value computation. Changing the computation would flip every existing group, including those restored from saved waveform_viewer.json files.

Testing

  • I ran a headless test on a 16-bit design. get_value_at() and get_events() on groups built from net lists in both orders now match the documented order.

  • Module pin groups match it as well:

    • ascending with start index 0: index 0 is the MSB;
    • descending with start index 15: index 15 is the MSB.
  • generateGroup, in the viewer: I reproduced the bug on master via the GUI. A group above the limit shows the mirror of its member bits.

    Steps:

    1. Set "Max events to load into memory" below the event count of the group's member waves (the limit applies per wave).
    2. Load the data, create the group, and expand it so every member row is on screen.
    3. Compare the group's value with its member bits.

    Don't compare it with the cursor value: for such a group the cursor value is read from the same painted values, so the two always agree.

Not changed

WaveDataGroup(WaveDataList*, const WaveData*) splits a multi-bit wave into child waves LSB-first, so it would produce mirrored groups. It has no callers, so I left it alone. It could be fixed or removed.

🤖 Generated with Claude Code

RenWal and others added 2 commits December 2, 2026 16:20
The group value treats the first net in the list as the most significant
bit (WaveDataGroup::recalcData, intValue, WaveDataProviderGroup), but the
docstring of add_waveform_group said it is the least significant one.
Scripts that followed the docstring got every group value bit-mirrored.

Fix the docstring in the header and the Python binding, and state the
order of the pin group overloads: they take the pins in pin group order,
so the pin at the start index is the most significant bit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WaveFormPainted::generateGroup composed the group value with the first
child as the least significant bit, while WaveDataGroup::recalcData(),
intValue() and WaveDataProviderGroup use it as the most significant one.
The viewer uses generateGroup for groups whose waves exceed the loadable
size, so such a group was drawn bit-mirrored relative to its cursor value
and to get_value_at().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RenWal
RenWal requested a review from joern274 December 2, 2026 16:43
@joern274
joern274 merged commit d7fdf7b into master Dec 2, 2026
5 checks passed
@joern274
joern274 deleted the fix/waveform-group-bit-order branch December 2, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants