-
Notifications
You must be signed in to change notification settings - Fork 77
Issue #377: assign a logic subset to logic (array) #456
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
Merged
Merged
Changes from 11 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 9180cb4
refactor selectFrom
RPG-coder-intc fcfcf7e
Add tests for selectFrom and selectIndex
RPG-coder-intc ad325fc
add documentations and test for defaultValue
RPG-coder-intc 304a7a9
remove extra line doc
RPG-coder-intc 0f634ce
ROHD: code review fix
RPG-coder-intc 3069cae
fix import
RPG-coder-intc 2bdd4d0
Merge branch 'intel:main' into fix-issue-116
RPG-coder-intc b76c0ea
Merge branch 'fix-issue-116' of https://github.com/RPG-coder-intc/roh…
RPG-coder-intc afa5337
ROHD naming mergable
RPG-coder-intc edfcb2e
assign subset to logic array
RPG-coder-intc e15b9b6
Merge branch 'intel:main' into fix-issue-377
RPG-coder-intc f680a0b
add test and doc
RPG-coder-intc b654d5f
add tests
RPG-coder-intc 97a9577
fix tests
RPG-coder-intc 1034071
Merge branch 'intel:main' into fix-issue-377
RPG-coder-intc 980829d
use SignalWidthMismatchException
RPG-coder-intc 29695c9
Merge branch 'intel:main' into fix-issue-377
RPG-coder-intc 9fb7761
use SignalWidthMismatchException
RPG-coder-intc efda064
fix tests
RPG-coder-intc 9933cf4
fix test
RPG-coder-intc edec601
ignore broken link
RPG-coder-intc 9e1b467
fix review
RPG-coder-intc e55eb3a
ignore stackoverflow links
RPG-coder-intc 8762cb4
fix deprecated analysis_option
RPG-coder-intc c60c14e
fix review
RPG-coder-intc b299416
fix code quality
RPG-coder-intc 692cfbb
Merge branch 'main' into fix-issue-377
RPG-coder-intc 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// selection.dart | ||
// Definition for selecting a Logic from List<Logic> by a given index. | ||
// | ||
// 2023 November 14 | ||
// Author: Rahul Gautham Putcha <[email protected]> | ||
|
||
import 'package:rohd/rohd.dart'; | ||
|
||
/// Allows a lists of [Logic]s to have its elemets picked | ||
/// by a [Logic] index value. | ||
extension IndexedLogic on List<Logic> { | ||
/// Performs a [index] based selection on an [List] of [Logic]. | ||
/// | ||
/// Given a [List] of [Logic] say `logicList` on which we apply [selectIndex] | ||
/// and an element [index] as argument , we can select any valid element | ||
/// of type [Logic] within the `logicList` using the [index] of [Logic] type. | ||
/// | ||
/// Alternatively we can approach this with `index.selectFrom(logicList)` | ||
/// | ||
/// Example: | ||
/// ``` | ||
/// // ordering matches closer to array indexing with `0` index-based. | ||
/// List<Logic> logicList = [/* Add your Logic elements here */]; | ||
/// selected <= logicList.selectIndex(index); | ||
/// ``` | ||
/// | ||
Logic selectIndex(Logic index, {Logic? defaultValue}) => | ||
index.selectFrom(this, defaultValue: defaultValue); | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
// simulator, as well as basic operations on them | ||
// | ||
// 2021 August 2 | ||
// Author: Max Korbel <[email protected]> | ||
// Author: Max Korbel <[email protected]>, | ||
// Rahul Gautham Putcha <[email protected]> | ||
|
||
part of 'signals.dart'; | ||
|
||
|
@@ -712,4 +713,42 @@ class Logic { | |
} | ||
return isLogicIn; | ||
} | ||
|
||
/// Performs a [Logic] `index` based selection on an [List] of [Logic] | ||
/// named [busList]. | ||
/// | ||
/// Using the [Logic] `index` on which [selectFrom] is performed on and | ||
/// a [List] of [Logic] named [busList] for `index` based selection, we can | ||
/// select any valid element of type [Logic] within the `logicList` using | ||
/// the `index` of [Logic] type. | ||
/// | ||
/// Alternatively we can approach this with `busList.selectIndex(index)` | ||
/// | ||
/// Example: | ||
/// ``` | ||
/// // ordering matches closer to array indexing with `0` index-based. | ||
/// selected <= index.selectFrom(busList); | ||
/// ``` | ||
/// | ||
Logic selectFrom(List<Logic> busList, {Logic? defaultValue}) { | ||
final selected = Logic( | ||
name: 'selectFrom', | ||
width: busList.first.width, | ||
naming: Naming.mergeable); | ||
|
||
Combinational( | ||
[ | ||
Case( | ||
this, | ||
[ | ||
for (var i = 0; i < busList.length; i++) | ||
CaseItem(Const(i, width: width), [selected < busList[i]]) | ||
], | ||
conditionalType: ConditionalType.unique, | ||
defaultItem: [selected < (defaultValue ?? 0)]) | ||
], | ||
); | ||
|
||
return selected; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,10 +7,61 @@ | |
// 2021 May 7 | ||
// Author: Max Korbel <[email protected]> | ||
|
||
import 'dart:math'; | ||
|
||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd/src/utilities/simcompare.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
class SelectTestModule extends Module { | ||
Logic get selectIndexValue => output('selectIndexValue'); | ||
Logic get selectFromValue => output('selectFromValue'); | ||
|
||
SelectTestModule(Logic a1, Logic a2, Logic a3, Logic b, {Logic? defaultValue}) | ||
: super(name: 'selecttestmodule') { | ||
a1 = addInput('a1', a1, width: a1.width); | ||
a2 = addInput('a2', a2, width: a2.width); | ||
a3 = addInput('a3', a3, width: a3.width); | ||
b = addInput('b', b, width: b.width); | ||
|
||
if (defaultValue != null) { | ||
defaultValue = | ||
addInput('defaultValue', defaultValue, width: defaultValue.width); | ||
selectWithDefaultValue(a1, a2, a3, b, defaultValue); | ||
} else { | ||
selectWithoutDefaultValue(a1, a2, a3, b); | ||
} | ||
} | ||
|
||
void selectWithoutDefaultValue(Logic a1, Logic a2, Logic a3, Logic b) { | ||
final selectIndexValue = addOutput('selectIndexValue', width: a1.width); | ||
final selectFromValue = addOutput('selectFromValue', width: a1.width); | ||
|
||
if (a1.width != a2.width || a1.width != a3.width) { | ||
throw Exception('a1, a2 and a3 must be same width.'); | ||
} | ||
|
||
final logicList = <Logic>[a1, a2, a3]; | ||
|
||
selectIndexValue <= logicList.selectIndex(b); | ||
selectFromValue <= b.selectFrom(logicList); | ||
} | ||
|
||
void selectWithDefaultValue( | ||
Logic a1, Logic a2, Logic a3, Logic b, Logic defaultValue) { | ||
final selectFromValue = addOutput('selectFromValue', width: a1.width); | ||
final selectIndexValue = addOutput('selectIndexValue', width: a1.width); | ||
|
||
if (a1.width != a2.width || a1.width != a3.width) { | ||
throw Exception('a1, a2 and a3 must be same width.'); | ||
} | ||
|
||
final logicList = <Logic>[a1, a2, a3]; | ||
selectFromValue <= b.selectFrom(logicList, defaultValue: defaultValue); | ||
selectIndexValue <= logicList.selectIndex(b, defaultValue: defaultValue); | ||
} | ||
} | ||
|
||
class BusTestModule extends Module { | ||
// --- Getters --- | ||
Logic get aBar => output('a_bar'); | ||
|
@@ -561,5 +612,36 @@ void main() { | |
await SimCompare.checkFunctionalVector(gtm, vectors); | ||
SimCompare.checkIverilogVector(gtm, vectors); | ||
}); | ||
|
||
test('selectFrom and selectIndex', () async { | ||
final gtm = SelectTestModule(Logic(width: 8), Logic(width: 8), | ||
Logic(width: 8), Logic(width: (log(8) / log(2)).ceil())); | ||
await gtm.build(); | ||
final vectors = [ | ||
Vector({'a1': 1, 'a2': 2, 'a3': 3, 'b': 1}, | ||
{'selectIndexValue': 2, 'selectFromValue': 2}), | ||
Vector({'a1': 1, 'a2': 2, 'a3': 3, 'b': 0}, | ||
{'selectIndexValue': 1, 'selectFromValue': 1}), | ||
Vector({'a1': 1, 'a2': 2, 'a3': 3, 'b': 2}, | ||
{'selectIndexValue': 3, 'selectFromValue': 3}) | ||
]; | ||
await SimCompare.checkFunctionalVector(gtm, vectors); | ||
final simResult = SimCompare.iverilogVector(gtm, vectors); | ||
expect(simResult, equals(true)); | ||
}); | ||
|
||
test('selectFrom with default Value', () async { | ||
final gtm = SelectTestModule(Logic(width: 8), Logic(width: 8), | ||
Logic(width: 8), Logic(width: (log(8) / log(2)).ceil()), | ||
defaultValue: Logic(width: 8)); | ||
await gtm.build(); | ||
final vectors = [ | ||
Vector({'a1': 1, 'a2': 2, 'a3': 3, 'b': 4, 'defaultValue': 5}, | ||
{'selectFromValue': 5, 'selectIndexValue': 5}), | ||
]; | ||
await SimCompare.checkFunctionalVector(gtm, vectors); | ||
final simResult = SimCompare.iverilogVector(gtm, vectors); | ||
expect(simResult, equals(true)); | ||
}); | ||
}); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.