Skip to content
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

Issue #377: assign a logic subset to logic (array) #456

Merged
merged 28 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4a1db9e
ROHD adding way to get a Logic via a index of a Logic Array
RPG-coder-intc Nov 16, 2023
9180cb4
refactor selectFrom
RPG-coder-intc Nov 16, 2023
fcfcf7e
Add tests for selectFrom and selectIndex
RPG-coder-intc Nov 30, 2023
ad325fc
add documentations and test for defaultValue
RPG-coder-intc Dec 7, 2023
304a7a9
remove extra line doc
RPG-coder-intc Dec 7, 2023
0f634ce
ROHD: code review fix
RPG-coder-intc Dec 14, 2023
3069cae
fix import
RPG-coder-intc Dec 14, 2023
2bdd4d0
Merge branch 'intel:main' into fix-issue-116
RPG-coder-intc Dec 14, 2023
b76c0ea
Merge branch 'fix-issue-116' of https://github.com/RPG-coder-intc/roh…
RPG-coder-intc Dec 14, 2023
afa5337
ROHD naming mergable
RPG-coder-intc Dec 14, 2023
edfcb2e
assign subset to logic array
RPG-coder-intc Jan 4, 2024
e15b9b6
Merge branch 'intel:main' into fix-issue-377
RPG-coder-intc Jan 11, 2024
f680a0b
add test and doc
RPG-coder-intc Jan 11, 2024
b654d5f
add tests
RPG-coder-intc Jan 18, 2024
97a9577
fix tests
RPG-coder-intc Feb 1, 2024
1034071
Merge branch 'intel:main' into fix-issue-377
RPG-coder-intc Feb 1, 2024
980829d
use SignalWidthMismatchException
RPG-coder-intc Feb 15, 2024
29695c9
Merge branch 'intel:main' into fix-issue-377
RPG-coder-intc Feb 15, 2024
9fb7761
use SignalWidthMismatchException
RPG-coder-intc Feb 15, 2024
efda064
fix tests
RPG-coder-intc Feb 22, 2024
9933cf4
fix test
RPG-coder-intc Feb 22, 2024
edec601
ignore broken link
RPG-coder-intc Feb 22, 2024
9e1b467
fix review
RPG-coder-intc Feb 22, 2024
e55eb3a
ignore stackoverflow links
RPG-coder-intc Feb 22, 2024
8762cb4
fix deprecated analysis_option
RPG-coder-intc Feb 22, 2024
c60c14e
fix review
RPG-coder-intc Feb 22, 2024
b299416
fix code quality
RPG-coder-intc Feb 22, 2024
692cfbb
Merge branch 'main' into fix-issue-377
RPG-coder-intc Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/src/signals/logic_array.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,32 @@ class LogicArray extends LogicStructure {
return LogicArray(dimensions, elementWidth,
numUnpackedDimensions: numUnpackedDimensions, name: name);
}

/// Perform Assign operation on a Logic subset or slice
///
/// Assigns part of this LogicArray with a given [updatedSubset] of type
/// [List<Logic>]. The update is performed from a given [start] position
/// to the length of the [updatedSubset].
///
/// Example:
/// ```
/// LogicArray sampleLogic;
/// // Note: updatedSubset.length < (sampleLogic.length - start)
/// List<Logic> updatedSubset;
/// // Assign part of sampleLogic as [updatedSubset]
/// sampleLogic.assignSubset(updatedSubset); // start = 0 by default
/// // assign updated subset to sampleLogic[10:10+updatedSubset.length]
/// sampleLogic.assignSubset(updatedSubset, 10);
/// ```
///
void assignSubset(List<Logic> updatedSubset, {int start = 0}) {
if (updatedSubset.length > elements.length - start) {
throw LogicConstructionException('${updatedSubset.length}');
RPG-coder-intc marked this conversation as resolved.
Show resolved Hide resolved
mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved
}

// Assign Logic array from `start` index to `start+updatedSubset.length`
for (var i = 0; i < updatedSubset.length; i++) {
elements[start + i] <= updatedSubset[i];
}
}
}
55 changes: 55 additions & 0 deletions test/logic_array_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,21 @@ class IndexBitOfArrayModule extends Module {
}
}

class AssignSubsetModule extends Module {
AssignSubsetModule(LogicArray updatedSubset, {int? start}) {
updatedSubset = addInputArray('inputLogicArray', updatedSubset,
dimensions: [5], elementWidth: 3);

final o =
addOutputArray('outputLogicArray', dimensions: [10], elementWidth: 3);
if (start != null) {
o.assignSubset(updatedSubset.elements, start: start);
} else {
o.assignSubset(updatedSubset.elements);
}
}
}

void main() {
tearDown(() async {
await Simulator.reset();
Expand Down Expand Up @@ -938,5 +953,45 @@ void main() {
await SimCompare.checkFunctionalVector(mod, vectors);
SimCompare.checkIverilogVector(mod, vectors);
});

mkorbel1 marked this conversation as resolved.
Show resolved Hide resolved
test('assign subset of logic array without mentioning start', () async {
final updatedSubset = LogicArray([5], 3, name: 'updatedSubset');
final mod = AssignSubsetModule(updatedSubset);
await mod.build();

final vectors = [
Vector({'inputLogicArray': 0},
{'outputLogicArray': LogicValue.ofString(('z' * 15) + ('0' * 15))}),
Vector({'inputLogicArray': bin('101' * 5)},
{'outputLogicArray': LogicValue.ofString(('z' * 15) + ('101' * 5))})
];

await SimCompare.checkFunctionalVector(mod, vectors);
SimCompare.checkIverilogVector(mod, vectors);
});

test('assign subset of logic array with mentioning start', () async {
final updatedSubset = LogicArray([5], 3, name: 'updatedSubset');
final mod = AssignSubsetModule(updatedSubset, start: 3);
await mod.build();

final vectors = [
Vector({
'inputLogicArray': 0
}, {
'outputLogicArray':
LogicValue.ofString(('z' * 3 * 2) + ('0' * 3 * 5) + ('z' * 3 * 3))
}),
Vector({
'inputLogicArray': bin('101' * 5)
}, {
'outputLogicArray':
LogicValue.ofString(('z' * 3 * 2) + ('101' * 5) + ('z' * 3 * 3))
})
];

await SimCompare.checkFunctionalVector(mod, vectors);
SimCompare.checkIverilogVector(mod, vectors);
});
});
}
Loading