|
1 |
| -// Copyright (C) 2023 Intel Corporation |
| 1 | +// Copyright (C) 2023-2024 Intel Corporation |
2 | 2 | // SPDX-License-Identifier: BSD-3-Clause
|
3 | 3 | //
|
4 | 4 | // logic_array_test.dart
|
@@ -579,6 +579,70 @@ void main() {
|
579 | 579 | });
|
580 | 580 | });
|
581 | 581 |
|
| 582 | + group('access logicarray', () { |
| 583 | + test('slice one bit of 1d array', () async { |
| 584 | + final la = LogicArray([3], 8); |
| 585 | + final slice = la.slice(9, 9); |
| 586 | + expect(slice.width, 1); |
| 587 | + la.elements[1].put(bin('00000010')); |
| 588 | + expect(slice.value.toInt(), 1); |
| 589 | + }); |
| 590 | + |
| 591 | + test('slice 2 bits of one element of 1d array', () async { |
| 592 | + final la = LogicArray([3], 8); |
| 593 | + final slice = la.slice(10, 9); |
| 594 | + expect(slice.width, 2); |
| 595 | + la.elements[1].put(bin('00000110')); |
| 596 | + expect(slice.value.toInt(), bin('11')); |
| 597 | + }); |
| 598 | + |
| 599 | + test('slice 2 bits spanning two elements of 1d array', () async { |
| 600 | + final la = LogicArray([3], 8); |
| 601 | + final slice = la.slice(8, 7); |
| 602 | + expect(slice.width, 2); |
| 603 | + la.elements[1].put(1, fill: true); |
| 604 | + la.elements[0].put(0, fill: true); |
| 605 | + expect(slice.value.toInt(), bin('10')); |
| 606 | + }); |
| 607 | + |
| 608 | + test('slice 2 bits spanning 2 arrays of 2d array', () async { |
| 609 | + final la = LogicArray([3, 2], 8); |
| 610 | + final slice = la.slice(16, 15); |
| 611 | + expect(slice.width, 2); |
| 612 | + la.elements[1].elements[0].put(1, fill: true); |
| 613 | + la.elements[0].elements[1].put(0, fill: true); |
| 614 | + expect(slice.value.toInt(), bin('10')); |
| 615 | + }); |
| 616 | + |
| 617 | + test('slice more than one element of array', () async { |
| 618 | + final la = LogicArray([3], 8); |
| 619 | + final slice = la.slice(19, 4); |
| 620 | + expect(slice.width, 16); |
| 621 | + la.elements[2].put(LogicValue.x); |
| 622 | + la.elements[1].put(0); |
| 623 | + la.elements[0].put(1, fill: true); |
| 624 | + expect(slice.value, LogicValue.of('xxxx000000001111')); |
| 625 | + }); |
| 626 | + |
| 627 | + test('slice more than one element of array at the edges', () async { |
| 628 | + final la = LogicArray([3], 8); |
| 629 | + final slice = la.slice(16, 7); |
| 630 | + expect(slice.width, 10); |
| 631 | + la.elements[2].put(LogicValue.x); |
| 632 | + la.elements[1].put(0); |
| 633 | + la.elements[0].put(1, fill: true); |
| 634 | + expect(slice.value, LogicValue.of('x000000001')); |
| 635 | + }); |
| 636 | + |
| 637 | + test('slice exactly one element of array', () async { |
| 638 | + final la = LogicArray([3], 8); |
| 639 | + final slice = la.slice(15, 8); |
| 640 | + expect(slice.width, 8); |
| 641 | + la.elements[1].put(1, fill: true); |
| 642 | + expect(slice.value, LogicValue.of('11111111')); |
| 643 | + }); |
| 644 | + }); |
| 645 | + |
582 | 646 | group('logicarray passthrough', () {
|
583 | 647 | Future<void> testArrayPassthrough(SimpleLAPassthrough mod,
|
584 | 648 | {bool checkNoSwizzle = true,
|
|
0 commit comments