1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
|
// See LICENSE for license details.
package firrtlTests
import firrtl._
import firrtl.ir.Circuit
import firrtl.Parser.IgnoreInfo
import firrtl.passes._
import firrtl.transforms._
class ConstantPropagationSpec extends FirrtlFlatSpec {
val transforms = Seq(
ToWorkingIR,
ResolveKinds,
InferTypes,
ResolveGenders,
InferWidths,
new ConstantPropagation)
protected def exec(input: String) = {
transforms.foldLeft(CircuitState(parse(input), UnknownForm)) {
(c: CircuitState, t: Transform) => t.runTransform(c)
}.circuit.serialize
}
}
class ConstantPropagationMultiModule extends ConstantPropagationSpec {
"ConstProp" should "propagate constant inputs" in {
val input =
"""circuit Top :
module Child :
input in0 : UInt<1>
input in1 : UInt<1>
output out : UInt<1>
out <= and(in0, in1)
module Top :
input x : UInt<1>
output z : UInt<1>
inst c of Child
c.in0 <= x
c.in1 <= UInt<1>(1)
z <= c.out
"""
val check =
"""circuit Top :
module Child :
input in0 : UInt<1>
input in1 : UInt<1>
output out : UInt<1>
out <= in0
module Top :
input x : UInt<1>
output z : UInt<1>
inst c of Child
c.in0 <= x
c.in1 <= UInt<1>(1)
z <= c.out
"""
(parse(exec(input))) should be (parse(check))
}
"ConstProp" should "propagate constant inputs ONLY if ALL instance inputs get the same value" in {
def circuit(allSame: Boolean) =
s"""circuit Top :
module Bottom :
input in : UInt<1>
output out : UInt<1>
out <= in
module Child :
output out : UInt<1>
inst b of Bottom
b.in <= UInt(1)
out <= b.out
module Top :
input x : UInt<1>
output z : UInt<1>
inst c of Child
inst b0 of Bottom
b0.in <= ${if (allSame) "UInt(1)" else "x"}
inst b1 of Bottom
b1.in <= UInt(1)
z <= and(and(b0.out, b1.out), c.out)
"""
val resultFromAllSame =
"""circuit Top :
module Bottom :
input in : UInt<1>
output out : UInt<1>
out <= UInt(1)
module Child :
output out : UInt<1>
inst b of Bottom
b.in <= UInt(1)
out <= UInt(1)
module Top :
input x : UInt<1>
output z : UInt<1>
inst c of Child
inst b0 of Bottom
b0.in <= UInt(1)
inst b1 of Bottom
b1.in <= UInt(1)
z <= UInt(1)
"""
(parse(exec(circuit(false)))) should be (parse(circuit(false)))
(parse(exec(circuit(true)))) should be (parse(resultFromAllSame))
}
// =============================
"ConstProp" should "do nothing on unrelated modules" in {
val input =
"""circuit foo :
module foo :
input dummy : UInt<1>
skip
module bar :
input dummy : UInt<1>
skip
"""
val check = input
(parse(exec(input))) should be (parse(check))
}
// =============================
"ConstProp" should "propagate module chains not connected to the top" in {
val input =
"""circuit foo :
module foo :
input dummy : UInt<1>
skip
module bar1 :
output out : UInt<1>
inst one of baz1
inst zero of baz0
out <= or(one.test, zero.test)
module bar0 :
output out : UInt<1>
inst one of baz1
inst zero of baz0
out <= and(one.test, zero.test)
module baz1 :
output test : UInt<1>
test <= UInt<1>(1)
module baz0 :
output test : UInt<1>
test <= UInt<1>(0)
"""
val check =
"""circuit foo :
module foo :
input dummy : UInt<1>
skip
module bar1 :
output out : UInt<1>
inst one of baz1
inst zero of baz0
out <= UInt<1>(1)
module bar0 :
output out : UInt<1>
inst one of baz1
inst zero of baz0
out <= UInt<1>(0)
module baz1 :
output test : UInt<1>
test <= UInt<1>(1)
module baz0 :
output test : UInt<1>
test <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
}
// Tests the following cases for constant propagation:
// 1) Unsigned integers are always greater than or
// equal to zero
// 2) Values are always smaller than a number greater
// than their maximum value
// 3) Values are always greater than a number smaller
// than their minimum value
class ConstantPropagationSingleModule extends ConstantPropagationSpec {
// =============================
"The rule x >= 0 " should " always be true if x is a UInt" in {
val input =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= geq(x, UInt(0))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= UInt<1>("h1")
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule x < 0 " should " never be true if x is a UInt" in {
val input =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= lt(x, UInt(0))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 0 <= x " should " always be true if x is a UInt" in {
val input =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= leq(UInt(0),x)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= UInt<1>(1)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 0 > x " should " never be true if x is a UInt" in {
val input =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= gt(UInt(0),x)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 1 < 3 " should " always be true" in {
val input =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= lt(UInt(0),UInt(3))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= UInt<1>(1)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule x < 8 " should " always be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= lt(x,UInt(8))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(1)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule x <= 7 " should " always be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= leq(x,UInt(7))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(1)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 8 > x" should " always be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= gt(UInt(8),x)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(1)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 7 >= x" should " always be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= geq(UInt(7),x)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(1)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 10 == 10" should " always be true" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= eq(UInt(10),UInt(10))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(1)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule x == z " should " not be true even if they have the same number of bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
input z : UInt<3>
output y : UInt<1>
y <= eq(x,z)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
input z : UInt<3>
output y : UInt<1>
y <= eq(x,z)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 10 != 10 " should " always be false" in {
val input =
"""circuit Top :
module Top :
output y : UInt<1>
y <= neq(UInt(10),UInt(10))
"""
val check =
"""circuit Top :
module Top :
output y : UInt<1>
y <= UInt(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 1 >= 3 " should " always be false" in {
val input =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= geq(UInt(1),UInt(3))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<5>
output y : UInt<1>
y <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule x >= 8 " should " never be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= geq(x,UInt(8))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule x > 7 " should " never be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= gt(x,UInt(7))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 8 <= x" should " never be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= leq(UInt(8),x)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"The rule 7 < x" should " never be true if x only has 3 bits" in {
val input =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= lt(UInt(7),x)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<3>
output y : UInt<1>
y <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"ConstProp" should "work across wires" in {
val input =
"""circuit Top :
module Top :
input x : UInt<1>
output y : UInt<1>
wire z : UInt<1>
y <= z
z <= mux(x, UInt<1>(0), UInt<1>(0))
"""
val check =
"""circuit Top :
module Top :
input x : UInt<1>
output y : UInt<1>
wire z : UInt<1>
y <= UInt<1>(0)
z <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"ConstProp" should "swap named nodes with temporary nodes that drive them" in {
val input =
"""circuit Top :
module Top :
input x : UInt<1>
input y : UInt<1>
output z : UInt<1>
node _T_1 = and(x, y)
node n = _T_1
z <= n
"""
val check =
"""circuit Top :
module Top :
input x : UInt<1>
input y : UInt<1>
output z : UInt<1>
node n = and(x, y)
node _T_1 = n
z <= n
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"ConstProp" should "swap named nodes with temporary wires that drive them" in {
val input =
"""circuit Top :
module Top :
input x : UInt<1>
input y : UInt<1>
output z : UInt<1>
wire _T_1 : UInt<1>
node n = _T_1
z <= n
_T_1 <= and(x, y)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<1>
input y : UInt<1>
output z : UInt<1>
wire n : UInt<1>
node _T_1 = n
z <= n
n <= and(x, y)
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"ConstProp" should "swap named nodes with temporary registers that drive them" in {
val input =
"""circuit Top :
module Top :
input clock : Clock
input x : UInt<1>
output z : UInt<1>
reg _T_1 : UInt<1>, clock with : (reset => (UInt<1>(0), _T_1))
node n = _T_1
z <= n
_T_1 <= x
"""
val check =
"""circuit Top :
module Top :
input clock : Clock
input x : UInt<1>
output z : UInt<1>
reg n : UInt<1>, clock with : (reset => (UInt<1>(0), n))
node _T_1 = n
z <= n
n <= x
"""
(parse(exec(input))) should be (parse(check))
}
// =============================
"ConstProp" should "only swap a given name with one other name" in {
val input =
"""circuit Top :
module Top :
input x : UInt<1>
input y : UInt<1>
output z : UInt<3>
node _T_1 = add(x, y)
node n = _T_1
node m = _T_1
z <= add(n, m)
"""
val check =
"""circuit Top :
module Top :
input x : UInt<1>
input y : UInt<1>
output z : UInt<3>
node n = add(x, y)
node _T_1 = n
node m = n
z <= add(n, n)
"""
(parse(exec(input))) should be (parse(check))
}
"ConstProp" should "NOT swap wire names with node names" in {
val input =
"""circuit Top :
module Top :
input clock : Clock
input x : UInt<1>
input y : UInt<1>
output z : UInt<1>
wire hit : UInt<1>
node _T_1 = or(x, y)
node _T_2 = eq(_T_1, UInt<1>(1))
hit <= _T_2
z <= hit
"""
val check =
"""circuit Top :
module Top :
input clock : Clock
input x : UInt<1>
input y : UInt<1>
output z : UInt<1>
wire hit : UInt<1>
node _T_1 = or(x, y)
node _T_2 = _T_1
hit <= _T_1
z <= hit
"""
(parse(exec(input))) should be (parse(check))
}
"ConstProp" should "propagate constant outputs" in {
val input =
"""circuit Top :
module Child :
output out : UInt<1>
out <= UInt<1>(0)
module Top :
input x : UInt<1>
output z : UInt<1>
inst c of Child
z <= and(x, c.out)
"""
val check =
"""circuit Top :
module Child :
output out : UInt<1>
out <= UInt<1>(0)
module Top :
input x : UInt<1>
output z : UInt<1>
inst c of Child
z <= UInt<1>(0)
"""
(parse(exec(input))) should be (parse(check))
}
}
// More sophisticated tests of the full compiler
class ConstantPropagationIntegrationSpec extends LowTransformSpec {
def transform = new LowFirrtlOptimization
"ConstProp" should "NOT optimize across dontTouch on nodes" in {
val input =
"""circuit Top :
| module Top :
| input x : UInt<1>
| output y : UInt<1>
| node z = x
| y <= z""".stripMargin
val check = input
execute(input, check, Seq(dontTouch("Top.z")))
}
it should "NOT optimize across dontTouch on wires" in {
val input =
"""circuit Top :
| module Top :
| input x : UInt<1>
| output y : UInt<1>
| wire z : UInt<1>
| y <= z
| z <= x""".stripMargin
val check = input
execute(input, check, Seq(dontTouch("Top.z")))
}
it should "NOT optimize across dontTouch on output ports" in {
val input =
"""circuit Top :
| module Child :
| output out : UInt<1>
| out <= UInt<1>(0)
| module Top :
| input x : UInt<1>
| output z : UInt<1>
| inst c of Child
| z <= and(x, c.out)""".stripMargin
val check = input
execute(input, check, Seq(dontTouch("Child.out")))
}
it should "NOT optimize across dontTouch on input ports" in {
val input =
"""circuit Top :
| module Child :
| input in0 : UInt<1>
| input in1 : UInt<1>
| output out : UInt<1>
| out <= and(in0, in1)
| module Top :
| input x : UInt<1>
| output z : UInt<1>
| inst c of Child
| z <= c.out
| c.in0 <= x
| c.in1 <= UInt<1>(1)""".stripMargin
val check = input
execute(input, check, Seq(dontTouch("Child.in1")))
}
it should "still propagate constants even when there is name swapping" in {
val input =
"""circuit Top :
| module Top :
| input x : UInt<1>
| input y : UInt<1>
| output z : UInt<1>
| node _T_1 = and(and(x, y), UInt<1>(0))
| node n = _T_1
| z <= n""".stripMargin
val check =
"""circuit Top :
| module Top :
| input x : UInt<1>
| input y : UInt<1>
| output z : UInt<1>
| z <= UInt<1>(0)""".stripMargin
execute(input, check, Seq.empty)
}
it should "pad constant connections to wires when propagating" in {
val input =
"""circuit Top :
| module Top :
| output z : UInt<16>
| wire w : { a : UInt<8>, b : UInt<8> }
| w.a <= UInt<2>("h3")
| w.b <= UInt<2>("h3")
| z <= cat(w.a, w.b)""".stripMargin
val check =
"""circuit Top :
| module Top :
| output z : UInt<16>
| z <= UInt<16>("h303")""".stripMargin
execute(input, check, Seq.empty)
}
it should "pad constant connections to registers when propagating" in {
val input =
"""circuit Top :
| module Top :
| input clock : Clock
| output z : UInt<16>
| reg r : { a : UInt<8>, b : UInt<8> }, clock
| r.a <= UInt<2>("h3")
| r.b <= UInt<2>("h3")
| z <= cat(r.a, r.b)""".stripMargin
val check =
"""circuit Top :
| module Top :
| input clock : Clock
| output z : UInt<16>
| z <= UInt<16>("h303")""".stripMargin
execute(input, check, Seq.empty)
}
it should "pad constant connections to outputs when propagating" in {
val input =
"""circuit Top :
| module Child :
| output x : UInt<8>
| x <= UInt<2>("h3")
| module Top :
| output z : UInt<16>
| inst c of Child
| z <= cat(UInt<2>("h3"), c.x)""".stripMargin
val check =
"""circuit Top :
| module Top :
| output z : UInt<16>
| z <= UInt<16>("h303")""".stripMargin
execute(input, check, Seq.empty)
}
it should "pad constant connections to submodule inputs when propagating" in {
val input =
"""circuit Top :
| module Child :
| input x : UInt<8>
| output y : UInt<16>
| y <= cat(UInt<2>("h3"), x)
| module Top :
| output z : UInt<16>
| inst c of Child
| c.x <= UInt<2>("h3")
| z <= c.y""".stripMargin
val check =
"""circuit Top :
| module Top :
| output z : UInt<16>
| z <= UInt<16>("h303")""".stripMargin
execute(input, check, Seq.empty)
}
"Registers with no reset or connections" should "be replaced with constant zero" in {
val input =
"""circuit Top :
| module Top :
| input clock : Clock
| output z : UInt<8>
| reg r : UInt<8>, clock
| z <= r""".stripMargin
val check =
"""circuit Top :
| module Top :
| input clock : Clock
| output z : UInt<8>
| z <= UInt<8>(0)""".stripMargin
execute(input, check, Seq.empty)
}
"Registers with ONLY constant reset" should "be replaced with that constant" in {
val input =
"""circuit Top :
| module Top :
| input clock : Clock
| input reset : UInt<1>
| output z : UInt<8>
| reg r : UInt<8>, clock with : (reset => (reset, UInt<4>("hb")))
| z <= r""".stripMargin
val check =
"""circuit Top :
| module Top :
| input clock : Clock
| input reset : UInt<1>
| output z : UInt<8>
| z <= UInt<8>("hb")""".stripMargin
execute(input, check, Seq.empty)
}
"Registers with ONLY constant connection" should "be replaced with that constant" in {
val input =
"""circuit Top :
| module Top :
| input clock : Clock
| input reset : UInt<1>
| output z : SInt<8>
| reg r : SInt<8>, clock
| r <= SInt<4>(-5)
| z <= r""".stripMargin
val check =
"""circuit Top :
| module Top :
| input clock : Clock
| input reset : UInt<1>
| output z : SInt<8>
| z <= SInt<8>(-5)""".stripMargin
execute(input, check, Seq.empty)
}
"Registers with identical constant reset and connection" should "be replaced with that constant" in {
val input =
"""circuit Top :
| module Top :
| input clock : Clock
| input reset : UInt<1>
| output z : UInt<8>
| reg r : UInt<8>, clock with : (reset => (reset, UInt<4>("hb")))
| r <= UInt<4>("hb")
| z <= r""".stripMargin
val check =
"""circuit Top :
| module Top :
| input clock : Clock
| input reset : UInt<1>
| output z : UInt<8>
| z <= UInt<8>("hb")""".stripMargin
execute(input, check, Seq.empty)
}
}
|