1
- // Copyright (C) 2023 Intel Corporation
1
+ // Copyright (C) 2023-2025 Intel Corporation
2
2
// SPDX-License-Identifier: BSD-3-Clause
3
3
//
4
4
// ssa_test.dart
@@ -21,6 +21,90 @@ abstract class SsaTestModule extends Module {
21
21
int model (int a);
22
22
}
23
23
24
+ class SimpleStruct extends LogicStructure {
25
+ SimpleStruct ()
26
+ : super ([Logic (width: 4 ), Logic (width: 4 )], name: 'simple_struct' );
27
+ }
28
+
29
+ class StructOpRepack extends Module {
30
+ late final SimpleStruct x = SimpleStruct ()..gets (output ('x' ));
31
+
32
+ StructOpRepack (SimpleStruct a) {
33
+ a = SimpleStruct ()..gets (addInput ('a' , a, width: 8 ));
34
+ final x_ = SimpleStruct ();
35
+
36
+ x_.elements[0 ] <= a.elements[0 ] + 1 ;
37
+ x_.elements[1 ] <= a.elements[1 ] + 2 ;
38
+
39
+ addOutput ('x' , width: 8 ) <= x_;
40
+ }
41
+ }
42
+
43
+ class SsaModWithStructElements extends SsaTestModule {
44
+ SsaModWithStructElements (Logic a) : super (name: 'struct_elements' ) {
45
+ a = addInput ('a' , a, width: 8 );
46
+ final x = addOutput ('x' , width: 8 );
47
+
48
+ final s1 = SimpleStruct ();
49
+
50
+ final sx = SimpleStruct ();
51
+
52
+ Combinational .ssa ((s) => [
53
+ s (s1) < a,
54
+ s (sx) < StructOpRepack (SimpleStruct ()..gets (s (s1))).x,
55
+ ]);
56
+
57
+ x <= sx;
58
+ }
59
+
60
+ @override
61
+ int model (int a) {
62
+ final orig = LogicValue .ofInt (a, 8 );
63
+ return [
64
+ orig.getRange (0 , 4 ) + 1 ,
65
+ orig.getRange (4 , 8 ) + 2 ,
66
+ ].rswizzle ().toInt ();
67
+ }
68
+ }
69
+
70
+ class StructOpSplit extends Module {
71
+ Logic get x0 => output ('x0' );
72
+ Logic get x1 => output ('x1' );
73
+
74
+ StructOpSplit (SimpleStruct a) {
75
+ a = SimpleStruct ()..gets (addInput ('a' , a, width: 8 ));
76
+ final x0 = addOutput ('x0' , width: 4 );
77
+ final x1 = addOutput ('x1' , width: 4 );
78
+
79
+ x0 <= a.elements[0 ] + 1 ;
80
+ x1 <= a.elements[1 ] + 2 ;
81
+ }
82
+ }
83
+
84
+ class SsaModWithStructSplit extends SsaTestModule {
85
+ SsaModWithStructSplit (Logic a) : super (name: 'struct_split' ) {
86
+ a = addInput ('a' , a, width: 8 );
87
+ final x = addOutput ('x' , width: 8 );
88
+
89
+ final s1 = SimpleStruct ();
90
+
91
+ Combinational .ssa ((s) => [
92
+ s (s1) < a,
93
+ s (x) <
94
+ () {
95
+ final splitMod = StructOpSplit (SimpleStruct ()..gets (s (s1)));
96
+ return (splitMod.x0 + splitMod.x1).zeroExtend (8 );
97
+ }(),
98
+ ]);
99
+ }
100
+
101
+ @override
102
+ int model (int a) {
103
+ final orig = LogicValue .ofInt (a, 8 );
104
+ return (orig.getRange (0 , 4 ) + 1 + orig.getRange (4 , 8 ) + 2 ).toInt ();
105
+ }
106
+ }
107
+
24
108
class SsaModAssignsOnly extends SsaTestModule {
25
109
SsaModAssignsOnly (Logic a) : super (name: 'assigns_only' ) {
26
110
a = addInput ('a' , a, width: 8 );
@@ -338,6 +422,8 @@ void main() {
338
422
SsaMix (aInput),
339
423
SsaNested (aInput),
340
424
SsaMultiDep (aInput),
425
+ SsaModWithStructElements (aInput),
426
+ SsaModWithStructSplit (aInput),
341
427
];
342
428
343
429
for (final mod in mods) {
0 commit comments