Skip to content

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 28 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
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 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
1 change: 1 addition & 0 deletions lib/rohd.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export 'src/finite_state_machine.dart';
export 'src/interfaces/interfaces.dart';
export 'src/module.dart';
export 'src/modules/modules.dart';
export 'src/selection.dart';
export 'src/signals/signals.dart';
export 'src/simulator.dart';
export 'src/swizzle.dart';
Expand Down
32 changes: 32 additions & 0 deletions lib/src/selection.dart
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);
}
41 changes: 40 additions & 1 deletion lib/src/signals/logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions lib/src/signals/logic_array.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,14 @@ class LogicArray extends LogicStructure {
return LogicArray(dimensions, elementWidth,
numUnpackedDimensions: numUnpackedDimensions, name: name);
}

/// add doc later
void assignSubset(List<Logic> updatedSubset, int start) {
// TO-DO: optimize with dart: zip, reduce,

// get the end from start+updatedSubset.addr to updatedSubset.length ...
for (var i = 0; i < updatedSubset.length; i++) {
elements[start + i] <= updatedSubset[i];
}
}
}
4 changes: 4 additions & 0 deletions lib/src/signals/logic_structure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,8 @@ class LogicStructure implements Logic {
void _updateWire(_Wire newWire) {
throw UnsupportedError('Delegated to elements');
}

@override
Logic selectFrom(List<Logic> busList, {Logic? defaultValue}) =>
packed.selectFrom(busList, defaultValue: defaultValue);
}
82 changes: 82 additions & 0 deletions test/bus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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));
});
});
}