-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocs.tcl
1308 lines (1199 loc) · 43.4 KB
/
procs.tcl
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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2017 Björn Gottschall <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Checks if a design is opened, like elaborated, synthesized or implemented
# design. Outputs Error if not and can be used in if statements.
#
# @return 1 if design is open, 0 else
proc design_open {} {
if { [llength [current_design -quiet]] eq 0 } {
puts stderr "ERROR: \[Common 17-53\] User Exception: No open design. Please open an elaborated, synthesized or implemented design before executing this command."
return 0
}
return 1
}
# Gets the primitive starting cells of a net or a list of nets
#
# @param of_nets list of nets
# @return list of start cells
proc get_nets_start_cells { of_nets } {
if { ! [design_open] } {
return ""
}
set of_nets [get_nets $of_nets]
set cells [list]
#need to iterate over possible list, we only take one elemnt for each call
foreach net $of_nets {
lappend cells [get_cells -of_objects [lindex [get_nets -segments $net] 0] -filter {IS_PRIMITIVE}]
}
return [get_cells $cells]
}
# Gets the primitive ending cells of a net or a list of nets
#
# @param of_nets list of nets
# @return list of end cells
proc get_nets_end_cells { of_nets } {
if { ! [design_open] } {
return ""
}
set of_nets [get_nets $of_nets]
set cells [list]
#need to iterate over possible list, we only take one elemnt for each call
foreach net $of_nets {
lappend cells [get_cells -of_objects [lindex [get_nets -segments $net] end] -filter {IS_PRIMITIVE}]
}
return [get_cells $cells]
}
# Get all Interconnect Tiles of Sites or Tiles like SLICE_X0Y0 or
#
# @param of_nets list of nets
# @return list of end cells
proc get_interconnects { from } {
if { ! [design_open] } {
return ""
}
set target [get_sites -quiet $from]
if { [string length $target] eq 0 } {
#Could be a tile, check it
set target [get_tiles -quiet $from]
if { [string length $target] eq 0 } {
#unknown what ever, empty response
puts stderr "WARNING: Not a valid object for retrieving interconnects"
return ""
}
} {
#List of Sites were given, parse all tiles from:
set target [get_tiles -of_objects $target]
}
return [filter_tiles [get_tiles -of_objects $target] "INT_\[RL\]"]
}
# Unfixes and unroutes given nets, routes them and fixes them again
# Useful in relocation process for nets which fails on routing
#
# @param of_nets list of nets
# @return nothing
proc refix_routes {of_nets} {
if { ! [design_open] } {
return ""
}
set of_nets [get_nets $of_nets]
fix_lut_pins $of_nets 0
fix_routes $of_nets 0
route_design -unroute -nets $of_nets
route_design -nets $of_nets
fix_lut_pins $of_nets 1
fix_routes $of_nets 1
}
# (Un)fixes the routes of the given nets. Does basically the same as the GUI
# but for any number of nets. Aliases will be transformed to real nets.
#
# @param of_nets list of nets
# @param state 1 for fix (default), 0 for unfix
# @return nothing
proc fix_routes {of_nets {state 1}} {
if { ! [design_open] } {
return ""
}
set index 0
set of_nets [get_nets $of_nets]
if { $state eq 1 } {
puts "Fix #[llength $of_nets] routes..."
} {
puts "Unfix #[llength $of_nets] routes..."
set state 0
}
foreach net $of_nets {
set parent [get_property PARENT $net]
if { $parent ne $net } {
puts "Net #$index: Parent $parent found!"
set net [get_nets $parent]
}
set start [get_nets_start_cells $net]
set end [get_nets_end_cells $net]
puts "Net #$index: $net starts at $start and goes to $end"
startgroup
set_property is_route_fixed $state $net
set_property is_bel_fixed $state [get_cells $start]
set_property is_loc_fixed $state [get_cells $start]
set_property is_bel_fixed $state [get_cells $end]
set_property is_loc_fixed $state [get_cells $end]
endgroup
incr index
}
}
# (Un)sets the LOCK_PINS constraint of a placed and routed LUT Cell. This
# constraint is a fixed definition which Input Pins and Output Pin of the LUT
# Cell is used from the routes. Fixing a Route without this constraint is not
# possible! Basically an improved version from Xilinx which does ignore non
# LUT Cells.
#
# @param of_nets list of nets
# @param state 1 for fix (default), 0 for unfix
# @return nothing
proc fix_lut_pins {of_nets {state 1}} {
if { ! [design_open] } {
return ""
}
set of_nets [get_nets $of_nets]
foreach net $of_nets {
puts "Processing net $net"
set loadpins [get_pins -leaf -of [get_nets $net] -filter direction=~in]
foreach loadpin $loadpins {
set pin [lindex [split $loadpin /] end]
set belpin [lindex [split [get_bel_pins -of [get_pins $loadpin]] /] end]
set index [expr [string last "/" $loadpin] - 1]
set lut [string range $loadpin 0 $index]
set beltype [get_bel_pins -of [get_pins $loadpin]]
set type [get_property PRIMITIVE_GROUP [get_cells $lut]]
if { $type eq "LUT" } {
# Create hash table of LUT names and pin assignments, appending when needed
if {[regexp (LUT) $beltype]} {
if { [info exists lut_array($lut)] } {
set lut_array($lut) "$lut_array($lut) $pin:$belpin"
} else {
set lut_array($lut) "$pin:$belpin"
}
}
} else {
puts "Primitive Cell is $type and not LUT! Skipping..."
}
}
}
foreach lut_name [array names lut_array] {
if { $state eq 1 } {
puts "Creating LOCK_PINS constraint $lut_array($lut_name) for LUT $lut_name."
set_property LOCK_PINS "$lut_array($lut_name)" [get_cells $lut_name]
} else {
puts "Reset LOCK_PINS constraint for LUT $lut_name."
reset_property LOCK_PINS [get_cells $lut_name]
}
}
}
# Sets the HD.PARTPIN_LOCS constraint for the given pins to the nearest.
# interconnect. A Pin has a direction (IN or OUT) and a related net. Depending
# on the direction the interconnect tile from the start or end cells is used.
#
# @param of_pins list of pins
# @param state 1 for fix (default), 0 for unfix
# @return nothing
proc fix_plocs { of_pins {state 1}} {
if { ! [design_open] } {
return ""
}
set of_pins [get_pins $of_pins]
foreach pin $of_pins {
if { $state eq 0 } {
reset_property -quiet HD.PARTPIN_LOCS $pin
puts "$pin resetted"
} {
set dir [get_property DIRECTION $pin]
set net [get_nets -of_objects $pin]
set parent [get_property PARENT $net]
set parentNet [get_nets $parent]
#Get only one target Cell
if { $dir eq "OUT" } {
set targetCell [lindex [get_nets_start_cells $parentNet] 0]
} {
set targetCell [lindex [get_nets_end_cells $parentNet] 0]
}
set loc [get_property LOC $targetCell]
if { [string length $loc] eq 0 } {
puts "Pin $pin is not correctly fixed! Pin ignored!"
} {
set intc [get_interconnects $loc]
if { [string length $intc] eq 0 } {
puts "No Interconnect found for LOC $loc! Pin ignored!"
} {
reset_property -quiet HD.PARTPIN_LOCS $pin
set_property HD.PARTPIN_LOCS $intc $pin
puts "$pin will be placed on $intc"
}
}
}
}
}
# Helper Procedure for saving constraints in a more comfortable way. Can save
# constraints to a new constraints set (existing one gets overwritten) and can
# also change target file while saving. The saved constraint set will be the
# target set.
#
# @param name optionally a new name of the constraint (current set is default)
# @param target_file name of the target file to save the constraints
# @return nothing
proc save_constraints_force {{name ""} {target_file ""}} {
if { ! [design_open] } {
return ""
}
set path [get_property DIRECTORY [current_project]]/[current_project].srcs
set old_target_file [file tail [get_property TARGET_CONSTRS_FILE [current_fileset -constrset]]]
if { [string length $name] eq 0 } {
#NO OBJECT HERE! Deleting fileset will turn $name empty if it is an object
set name [lindex [current_fileset -constrset] 0]
}
if { [string length $target_file] eq 0} {
set target_file $old_target_file
}
if { [string length $target_file] ne 0 && [file extension $target_file] ne ".xdc" } {
set target_file [file tail [file rootname $target_file]].xdc
}
if { [current_fileset -constrset] eq $name } {
#Switch to another name, save_constraints doesn't support changing target file
save_constraints_as SAVE_CONSTRAINTS_FORCE_TEMP -target_constrs_file $target_file
set_property constrset SAVE_CONSTRAINTS_FORCE_TEMP [current_run -synthesis]
set_property constrset SAVE_CONSTRAINTS_FORCE_TEMP [current_run -implementation]
delete_fileset -quiet $name
file delete -force $path/$name
save_constraints_as $name -target_constrs_file $target_file
set_property constrset $name [current_run -synthesis]
set_property constrset $name [current_run -implementation]
delete_fileset -quiet SAVE_CONSTRAINTS_FORCE_TEMP
file delete -force $path/SAVE_CONSTRAINTS_FORCE_TEMP
} else {
if { [file exists $path/$name] eq 1 || [string length [get_filesets -quiet -filter {FILESET_TYPE==Constrs} $name]] ne 0 } {
delete_fileset -quiet $name
file delete -force $path/$name
}
save_constraints_as $name -target_constrs_file $target_file
set_property constrset $name [current_run -synthesis]
set_property constrset $name [current_run -implementation]
}
}
# Gets the resource ranges from a pblock. Can filter a specific resource type
# out of the ranges list (SLICES, RAM ...)
#
# @param pblock pblock to get the ranges from
# @param type optional filter for a range type
# @return nothing
proc get_range_from_pblock {pblock {type ""}} {
if { ! [design_open] } {
return ""
}
set pblock [ get_pblocks $pblock ]
if { [llength $pblock] ne 1 } {
puts stderr "ERROR: no pblock or multiple pblocks found"
return ""
}
set ranges [get_property DERIVED_RANGES [get_pblock $pblock]]
if { [string length $type] ne 0 } {
set gridtypes [list]
foreach gridtype $ranges {
if { [regexp ^${type}_X[0-9]+Y[0-9]+ $gridtype] eq 1 } {
lappend gridtypes $gridtype
}
}
return $gridtypes
} else {
return $ranges
}
}
# Filters a list of tiles or sites. Useful for filtering specific tiles, rows
# or columns.
#
# @param tiles list to process
# @param regex_tile regex filter for tile (default any)
# @param regex_col regex filter for column (default any)
# @param regex_row regex filter for row (default any)
# @return filtered list
proc filter_tiles {tiles {regex_tile "[A-Z0-9_]+"} {regex_col "[0-9]+"} {regex_row "[0-9]+"}} {
set result [list]
foreach tile $tiles {
if { [regexp ^${regex_tile}_X${regex_col}Y${regex_row}\$ $tile] eq 1 } {
lappend result $tile
}
}
return $result
}
# Extracts the types from a tile list.
# E.g. SLICE_X1Y1 INT_L_X0Y0 -> SLICE INT_L
#
# @param tiles list to process
# @return list of types
proc get_types { tiles } {
set types [list]
foreach tile $tiles {
set matched [regexp {^([A-Z0-9_]+)_X([0-9]+)Y([0-9]+)} $tile -> tile x y]
if { $matched ne 0 } {
if { [lsearch $types $tile] eq -1 } {
lappend types $tile
}
}
}
return $types
}
# Extracts the rows from a tile list.
# E.g. SLICE_X1Y1 SLICEX0Y0 -> 0 1
#
# @param tiles list to process
# @return list of rows in ascending order
proc get_rows {tiles} {
set result [list]
foreach tile $tiles {
set matched [regexp {^[A-Z0-9_]+_X([0-9]+)Y([0-9]+)$} $tile -> x y]
if {$matched eq 0} {
puts stderr "$tile: invalid tile"
} else {
if { [lsearch $result $y] eq -1 } {
lappend result $y
}
}
}
return [lsort -integer $result]
}
# Extracts the columns from a tile list.
# E.g. SLICE_X1Y0 SLICEX0Y0 -> 0 1
#
# @param tiles list to process
# @return list of cols in ascending order
proc get_cols {tiles} {
set result [list]
foreach tile $tiles {
set matched [regexp {^[A-Z0-9_]+_X([0-9]+)Y([0-9]+)$} $tile -> x y]
if {$matched eq 0} {
puts stderr "$tile: invalid tile"
} else {
if { [lsearch $result $x] eq -1 } {
lappend result $x
}
}
}
return [lsort -integer $result]
}
# Transforms a range statement to a list. Respects the changing bahviour of
# interconnect tiles (R and L).
# E.g. SLICE_X0Y0:SLICE_X2Y0 -> SLICE_X0Y0 SLICE_X1Y0 SLICEX2Y0
#
# @param ranges range list to process
# @return list of tiles (no objects)
proc get_list_from_range {ranges} {
set result [list]
foreach range $ranges {
set matched [regexp {^([A-Z0-9_]+)_X([0-9]+)Y([0-9]+):([A-Z0-9_]+)_X([0-9]+)Y([0-9]+)} $range -> tile1 x1 y1 tile2 x2 y2]
if {$matched eq 0} {
puts stderr "$range: invalid tile range"
}
if { $tile1 eq "INT_L" || $tile1 eq "INT_R" } {
set tile1 "INT"
}
if { $tile2 eq "INT_L" || $tile2 eq "INT_R" } {
set tile2 "INT"
}
if { $tile1 ne $tile2 } {
puts stderr "$range: invalid tile range"
set matched 0
}
if { $matched ne 0 } {
set tile $tile1
set startx [expr min($x1,$x2)]
set endx [expr max($x1,$x2)]
set starty [expr min($y1,$y2)]
set endy [expr max($y1,$y2)]
for {set i $startx} {$i <= $endx} {incr i} {
if { $tile1 eq "INT" } {
set tile [if {[expr {$i%2}]} {list "INT_R"} {list "INT_L"}]
}
for {set z $starty} {$z <= $endy} {incr z} {
lappend result "${tile}_X${i}Y${z}"
}
}
}
}
return $result
}
# Evenly distributes the given pins on the given interconnects with respect of
# the list orders.
#
# @param ranges range list to process
# @return list of tiles (no objects)
proc distribute_pins { pins intc } {
if { ! [design_open] } {
return ""
}
set pins [get_pins $pins]
set intc [get_tiles $intc]
set pinsPerIntc [expr ceil(double([llength $pins])/double([llength $intc]))]
set pinIndex 0
for {set i 0} {$i < [llength $intc]} {incr i} {
for {set z 0} {$z < $pinsPerIntc && $pinIndex < [llength $pins]} {incr z; incr pinIndex} {
put "Pin [lindex $pins $pinIndex] will be on [lindex $intc $i]"
reset_property HD.PARTPIN_LOCS [lindex $pins $pinIndex]
set_property HD.PARTPIN_LOCS [lindex $intc $i] [lindex $pins $pinIndex]
}
}
}
# Returns all nets which failed on routing. Does a simple text processing of
# report_route_status and parsing the nets to objects.
#
# @return list of nets with routing errors
proc get_failed_nets {} {
if { ! [design_open] } {
return ""
}
set nets [list]
set status [report_route_status -return_string -show_all]
set matched [regexp {^.*Nets with Routing Errors:(.*)$} $status -> nets_status]
if { $matched eq 0 } {
return $nets
}
while { $matched eq 1 } {
set matched [regexp {\n ([^\n]+)\n(.*)$} $nets_status -> net nets_status]
if { $matched eq 1 } {
lappend nets $net
}
}
return [get_nets $nets]
}
# Helper function for sort_properties. Constraints need a fixed order in the
# files which are not always correctly saved by Vivado.
#
# @param x item to compare
# @param y item to compare
# @return 0 if no sorting is neede, -1 if y < x, 1 if y > x
proc sort_properties_compare { x y } {
set order [list BEL LOC LOCK_PINS FIXED_ROUTE]
foreach item $order {
set pos1 [string first "set_property $item" $x]
set pos2 [string first "set_property $item" $y]
if { $pos1 > $pos2 } {
return -1
} elseif { $pos1 < $pos2 } {
return 1
}
}
return 0
}
# Sorts a constraint file to assure correct order of constraints. Vivado
# does sometimes strange stuff.
# BEL < LOC < LOCK_PINS < FIXED_ROUTE
#
# @param file file to sort
# @return nothing
proc sort_properties { file } {
set file [get_files -of_objects [current_fileset -constrset] $file]
if { [file exists $file] eq 0 } {
puts stderr "ERROR: $file doesn't exist!"
return ""
}
set f [open $file "r"]
set sortdata [split [read $f] "\n"]
close $f
set sorted [lsort -command sort_properties_compare $sortdata]
set f [open $file "w"]
puts $f [join $sorted "\n"]
close $f
}
# Starts and waits for the given run
#
# @param run run to start
# @return 0 on error and 1 on success
proc start_run { run } {
launch_runs $run
wait_on_run $run
if { [get_property PROGRESS $run] != "100%" } {
puts stderr "ERROR: $run failed"
return 0
}
return 1
}
# Start the synthesize run
#
# @param run name of the synth run
# @param force force the run even if not necessary
# @return 0 on error and 1 on success
proc synthesize {{run "synth_1"} {force ""}} {
set run [get_runs $run]
set refresh [get_property NEEDS_REFRESH $run]
set progress [get_property PROGRESS $run]
if { $force ne "force" && $refresh eq 0 && $progress eq "100%" } {
puts stderr "WARNING: Synthesized Design is up to date! Will not synthesize again!"
return 1
}
reset_run $run
return [start_run $run]
}
# Start the implementation run. does always start on synthesize
#
# @param run name of the impl run
# @param force force the run even if not necessary
# @return 0 on error and 1 on success
proc implement {{run "impl_1"} {force ""}} {
set run [get_runs $run]
set refresh [get_property NEEDS_REFRESH $run]
set progress [get_property PROGRESS $run]
if { $force ne "force" && $refresh eq 0 && $progress eq "100%" } {
puts stderr "WARNING: Implemented Design is up to date! Will not synthesize again!"
return 1
}
set parent [get_runs [get_property PARENT $run]]
reset_run $run
reset_run $parent
return [start_run $run]
}
# Opens the synthesized design
#
# @param run optional name of the synthesize run
# @return nothing
proc open_synth { {run "synth_1"} } {
set run [get_runs $run]
open_run $run
}
# Opens the implemented design
#
# @param run optional name of the implementation run
# @return nothing
proc open_impl { {run "impl_1"} } {
set run [get_runs $run]
open_run $run
}
# Get all LUT6 resources of the given BELs
#
# @param of_objects list of BELs to retrieve the LUTs
# @return list of LUTs
proc get_bels_lut6 { of_objects } {
set luts [list]
set luts [concat $luts [get_bels -of_objects $of_objects -filter {TYPE=~LUT*6}]]
return $luts
}
# Get all REG resources of the given BELs
#
# @param of_objects list of BELs to retrieve the REGs
# @return list of REGs
proc get_bels_ff { of_objects } {
set of_objects [get_sites $of_objects]
set ffs [list]
set ffs [concat $ffs [get_bels -of_objects $of_objects -filter {TYPE==FF_INIT}]]
set ffs [lsort [concat $ffs [get_bels -of_objects $of_objects -filter {TYPE==REG_INIT}]]]
return $ffs
}
# Placed the given cells on the given BELs with respect to the list orders.
#
# @param cells list of cells
# @param bels list of bells
# @return nothing
proc place_cells {cells bels} {
if {[llength $bels] < [llength $cells]} {
puts stderr "Cannot place [llength $cells] cells on [llength $bels] BELs!"
return ""
}
set index 0
foreach cell $cells {
puts "Place $cell to [lindex $bels $index]"
place_cell $cell [lindex $bels $index]
incr index
}
}
# Gets the top cell in hirachie foreach given cell.
#
# @param cells list of cells
# @return root cells
proc get_cells_root { cells } {
set cells [get_cells $cells]
set result [list]
foreach cell $cells {
set parent $cell
set prev_parent [get_property PARENT $parent]
set timeout 0
while { [string length $prev_parent] ne 0 && $timeout ne 100} {
set parent $prev_parent
set prev_parent [get_property PARENT $parent]
incr timeout
}
if { $timeout ne 100 } {
lappend result $parent
} else {
puts stderr "TIMEOUT: get_cells_root $cell"
}
}
return $result
}
# Get the root from a path.
# E.g. pr_0/pr_0_input/reg[0] -> pr_0
#
# @param values list of paths
# @return root element of the paths
proc get_roots { values } {
set result [list]
foreach value $values {
set matched [regexp {^([a-zA-Z0-9\[\]_\.]+)/?.*$} $value -> name]
if { $matched ne 0 } {
lappend result $name
}
}
if { [llength $result] eq 1 } {
set result [lindex $result 0]
}
return $result
}
# Get name from a path.
# E.g. pr_0/pr_0_input/reg[0] -> reg[0]
#
# @param values list of paths
# @return name from the paths
proc get_names { values } {
set result [list]
foreach value $values {
set matched [regexp {^.*/([a-zA-Z0-9\[\]_\.]+)$} $value -> name]
if { $matched ne 0 } {
lappend result $name
}
}
if { [llength $result] eq 1 } {
set result [lindex $result 0]
}
return $result
}
# Get all boundary nets from a cell. That means all nets of a cell from which
# the start or end cell is not inside the cell itself.
#
# @param of_cells list of cells
# @return boundary nets
proc get_boundary_nets { of_cells } {
set of_cells [get_cells $of_cells]
set result [list]
foreach cell $of_cells {
set nets [get_nets $cell/*]
foreach net $nets {
set boundary false
set starts [get_cells_root [get_nets_start_cells $net]]
set ends [get_cells_root [get_nets_end_cells $net]]
foreach start $starts {
if { [lsearch $ends $start] eq -1 } {
set boundary true
break
}
}
if { $boundary eq true } {
lappend result $net
}
}
}
return $result
}
# Outputs a list to the console. Child elements get indented.
#
# @param output_list list to output on the console
# @param level indent level used for childs
# @return nothing
proc puts_list { output_list {level 1} } {
if { [string length $output_list] eq 0 } {
return
}
for {set i 1} { $i < $level } {incr i} {
puts -nonewline "\t"
}
puts "{"
foreach ele $output_list {
if { [llength $ele] > 1 } {
puts_list $ele [expr $level + 1]
} else {
for {set i 0} { $i < $level } {incr i} {
puts -nonewline "\t"
}
puts $ele
}
}
for {set i 1} { $i < $level } {incr i} {
puts -nonewline "\t"
}
puts "}"
}
# get_nets wrapper for filtering clock nets
#
# @param nets nets to process
# @return nets without clock nets
proc get_nets_no_clk { nets } {
get_nets -filter {TYPE!~*CLOCK*} $nets
}
# get_pins wrapper for filtering clock pins. Sadly only detecting clock pins
# only from the name of the pins.
#
# @param pins pins to process
# @return pins without clock pins
proc get_pins_no_clk { nets } {
get_pins -filter {NAME!~*CLOCK* && NAME!~*clk*} $nets
}
# Compares two lists
#
# @param a list
# @param b list
# @return 0 if not equal, 1 if equal
proc lequal {a b} {
if { [llength $a] ne [llength $b] } {
return 0
}
foreach i $a {
if {[lsearch -exact $b $i] == -1} {
return 0
}
}
return 1
}
# Checkes the existance of elements in a list
#
# @param a list to search in
# @param b list of elements to search in a
# @return 0 if b is not in a, 1 if b is in a
proc lcontains {a b} {
foreach i $b {
if {[lsearch -exact $a $i] eq -1 } {
return 0
}
}
return 1
}
# Relocates the given tiles with a column and row offset
# E.g. SLICE_X5Y0 5 10 -> SLICE_X10Y10
#
# @param tiles list of tiles
# @param offset_x column offset
# @param offset_y row offset
# @return list of relocated tiles
proc get_tiles_relocated { tiles { offset_x 0 } { offset_y 0 }} {
set result [list]
foreach tile $tiles {
set matched [regexp {^([A-Z0-9_]+)_X([0-9]+)Y([0-9]+)$} $tile -> tile x y]
if { $matched ne 0 } {
lappend result "${tile}_X[expr $x + ${offset_x}]Y[expr $y + ${offset_y}]"
}
}
return $result
}
# Normalizes a list of tile to column 0 and row 0
# E.g. SLICE_X5Y6 SLICE_X7Y7 -> SLICE_X0Y0 SLICE_X2Y1
#
# @param tiles list of tiles
# @return list of normalized tiles
proc get_tiles_normalized { tiles } {
return [get_tiles_relocated $tiles -[get_tiles_offset_x $tiles] -[get_tiles_offset_y $tiles]]
}
# Returns the column offset of the tile list, which is the smallest column
# number
# E.g. SLICE_X5Y6 SLICE_X7Y7 -> 5
#
# @param tiles list of tiles
# @return column offset
proc get_tiles_offset_x { tiles } {
return [lindex [get_cols $tiles] 0]
}
# Returns the row offset of the tile list, which is the smallest row
# number
# E.g. SLICE_X5Y6 SLICE_X7Y7 -> 6
#
# @param tiles list of tiles
# @return row offset
proc get_tiles_offset_y { tiles } {
return [lindex [get_rows $tiles] 0]
}
# Compares given pblocks if they are relocatable. Does not compare the
# arrangement of resources over different resource types. Checkes wrong
# hirachie and nested Cell count and the amount and arrangement of resources of
# the same type
#
# @param pblocks list of pblocks
# @return 1 on success, 0 on error
proc verify_relocateable_pblocks { pblocks } {
set verify_pblocks [get_pblocks $pblocks]
if { [lequal $verify_pblocks $pblocks] eq 0 } {
puts stderr "Verify Error: Invalid pblocks!"
return 0
}
if {[llength $verify_pblocks] eq 1 } {
puts stderr "Verify Error: need more than one pblock!"
return 0
}
set reloc 1
set base_pblock ""
set base_types [list]
set base_sites [list]
foreach pblock $verify_pblocks {
if { [get_property CELL_COUNT $pblock] ne 1 } {
puts stderr "Verify Error: Pblock $pblock needs exactly one cell!"
set reloc 0
}
if { [get_property PARENT $pblock] ne "ROOT" } {
puts stderr "Verify Error: Pblock $pblock is nested!"
set reloc 0
}
set comp_types [list]
set comp_sites [list]
puts "Verify pblock $pblock:"
set comp_types [lsort [get_types [get_range_from_pblock $pblock]]]
foreach type $comp_types {
set sites [lsort [get_tiles_normalized [get_list_from_range [get_range_from_pblock $pblock $type]]]]
puts "\t - [llength $sites] $type sites"
lappend comp_sites $sites
}
if { [llength $base_types] eq 0 } {
set base_types $comp_types
set base_sites $comp_sites
set base_pblock $pblock
} else {
if { [lequal $base_sites $comp_sites] eq 0 } {
puts stderr "Verify Error: pblock $pblock doesn't match with $base_pblock!"
set reloc 0
}
}
}
if { $reloc eq 1 } {
return 1
} else {
puts stderr "Verify Error: pblocks are not suitable for relocation!"
return 0
}
}
# Sets cells as isolated for the Isolated Design Flow
#
# @param cells list of cells
# @return nothing
proc set_isolated { cells } {
set cells [get_cells $cells]
foreach cell $cells {
set_property HD.RECONFIGURABLE false $cell
#set_property DONT_TOUCH false $cell
set_property HD.ISOLATED true $cell
}
}
# Sets cells as reconfigurable
#
# @param cells list of cells
# @return nothing
proc set_reconfigurable { cells } {
set cells [get_cells $cells]
foreach cell $cells {
set_property HD.ISOLATED false $cell
#set_property DONT_TOUCH true $cell
set_property HD.RECONFIGURABLE true $cell
}
}
# Escapes all special TCL characters in a value
#
# @param value
# @return escaped valued
proc escape { value } {
return [string map [list \[ {\[} \] {\]} \* {\*} \? {\?} \\ {\\}] $value]
}
# Escapes all special regex characters in a value
#
# @param value
# @return escaped valued
proc escape_regex { value } {
return [string map [list \[ {\[} \] {\]} \* {\*} \? {\?} \\ {\\} - {\-} ( {\(} ) {\)} + {\+} . {\.} , {\,} / {\/}] $value]
}
# Sorts the second lsit to match the first one. Also Strips off path elements
# for comparison. Useful to match cells or nets from different parent cells.
# E.g [X/T[0] X/T[1]] [Y/T[1] Y/T[0]] -> [X/T[0] X/T[1]] [Y/T[0] Y/T[1]]
#
# @param list1 list to compare against
# @param pList2 name of list to sort and compare to list one
# @param strip_filter regex filter to strip of path elements for comparison (default first path element)
# @return 0 on error, 1 on success
proc match_lists { list1 pList2 { strip_filter "[a-zA-Z0-9_\\.\\[\\]]+/?" } } {
upvar 1 $pList2 list2
set assoc_list [list]
set result 1
for {set i 0} { $i < [llength $list1] } { incr i } {
set entry [lindex $list1 $i]
set matching_entry ""
set matched [regex ^${strip_filter}(.*)$ $entry -> value]
if { $matched ne 0 } {
set value [escape_regex $value]
set index [lsearch -regex $list2 ^.*${value}$]
if { $index ne -1 } {
set matching_entry [lindex $list2 $index]
} else {
puts stderr "Associate Error: no matching element found for $value"
set result 0