Skip to content

Conversation

@izzianyramli
Copy link
Contributor

Description & Motivation

Similar to the Count bit occurrence, but instead, find an entire multi-bit pattern

Related Issue(s)

Count pattern occurrence #170

Testing

Test are defined in test/count_pattern_test.dart with multiple cases

Backwards-compatibility

Is this a breaking change that will not be backwards-compatible? If yes, how so?

No

Documentation

Does the change require any updates to documentation? If so, where? Are they included?

Yes, documentation on how to use it, and some examples are added in doc/components/count_pattern.md

@mkorbel1 mkorbel1 linked an issue Aug 12, 2025 that may be closed by this pull request
Copy link
Contributor

@mkorbel1 mkorbel1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! Some comments :)

///
/// Takes in [bus] of type [Logic].
/// [pattern] is the pattern to be counted in the bus.
/// If [fromStart] is `true`, the count starts from the beginning of the bus.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the meaning of counting from the start or the end? Shouldn't the resulting count be the same?


if (generateError) {
// If pattern is not found (count equals to 0), return error
addOutput('error');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it an error if count is 0?

count += valCheck.zeroExtend(count.width);
}

_output = addOutput('count', width: count.width);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of the internal _output vairable? Why not just assign this.count <= count or something?

/// Count the number of occurence of a fixed-width pattern in a bus.
///
/// Takes in [bus] of type [Logic].
/// [pattern] is the pattern to be counted in the bus.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be worth explicitly stating that if the pattern width is greater than the width of the bus, the count will always be 0

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.

Count pattern occurrence

4 participants