2024-03-18 07:12:59 +00:00
|
|
|
#!/usr/bin/env -S yosys -c
|
|
|
|
yosys -import
|
|
|
|
|
2024-04-04 23:08:40 +00:00
|
|
|
## Check arguments
|
|
|
|
if { $argc != 1 && $argc != 2 } {
|
2024-03-18 07:12:59 +00:00
|
|
|
puts "USAGE: $argv0 -- <VERILOG FILE>"
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2024-04-04 06:33:47 +00:00
|
|
|
set fbasename [file rootname [file tail [lindex $argv 0]]]
|
|
|
|
puts $fbasename
|
|
|
|
|
2024-03-18 07:12:59 +00:00
|
|
|
exec rm -rf output
|
|
|
|
exec mkdir output
|
|
|
|
|
2024-04-04 23:08:40 +00:00
|
|
|
## Set target chip (default to GAL16V8)
|
|
|
|
set target [expr {$argc == 2 ? [lindex $argv 1] : "GAL16V8"}]
|
|
|
|
if {$target == "GAL16V8"} {
|
|
|
|
set num_max_products 7
|
|
|
|
} elseif {$target == "GAL22V10"} {
|
|
|
|
set num_max_products 11
|
|
|
|
} else {
|
|
|
|
puts "Invalid target chip: GAL16V8 and GAL22V10 available"
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2024-04-04 06:33:47 +00:00
|
|
|
## Read Verilog/Liberty file
|
2024-03-18 07:12:59 +00:00
|
|
|
read_verilog [lindex $argv 0]
|
|
|
|
hierarchy -auto-top
|
2024-04-04 06:33:47 +00:00
|
|
|
read_verilog -lib cells_sim.v
|
|
|
|
read_liberty -lib techmaps/gal_dff.lib
|
2024-03-18 07:12:59 +00:00
|
|
|
|
|
|
|
## First pass synthesis
|
2024-04-04 06:33:47 +00:00
|
|
|
tribuf
|
2024-03-18 07:12:59 +00:00
|
|
|
synth
|
|
|
|
design -save preop
|
|
|
|
|
2024-04-04 06:33:47 +00:00
|
|
|
# Map IO pins (and undo port removal for the output)
|
|
|
|
iopadmap -bits -inpad GAL_INPUT Y:A -toutpad GAL_OUTPUT E:A:Y -outpad GAL_OUTPUT A
|
|
|
|
expose */t:GAL_OUTPUT "%x:+\[A\]" */t:GAL_OUTPUT %d
|
|
|
|
|
2024-03-18 07:12:59 +00:00
|
|
|
## DFF/SOP mapping
|
|
|
|
dfflibmap -liberty techmaps/gal_dff.lib
|
|
|
|
|
2024-04-04 06:33:47 +00:00
|
|
|
# Get count of non-clock inputs and registers
|
|
|
|
set num_inputs [regexp -inline {\d+} [tee -s result.string select -count t:GAL_INPUT]]
|
|
|
|
set num_regs [regexp -inline {\d+} [tee -s result.string select -count t:DFF_P]]
|
|
|
|
set num_inputs_regs [expr $num_inputs + $num_regs]
|
|
|
|
if {$num_regs > 0} { set num_inputs_regs [expr $num_inputs_regs - 1] }
|
|
|
|
|
|
|
|
#abc -script "+strash;,dretime;,collapse;,write_pla,test.pla" -sop
|
|
|
|
# Force one-level SOP
|
2024-04-04 18:54:11 +00:00
|
|
|
#abc -script "abc.script" -sop
|
2024-04-04 06:33:47 +00:00
|
|
|
|
|
|
|
# Resynth all too big SOPs together in multi-level SOP
|
|
|
|
#select "t:\$sop" r:DEPTH>8 %i
|
|
|
|
#techmap -autoproc -map sop.v
|
|
|
|
#yosys proc
|
|
|
|
#techmap
|
|
|
|
#select *
|
2024-04-04 22:16:02 +00:00
|
|
|
|
|
|
|
abc -sop -I $num_inputs_regs -P $num_max_products
|
2024-03-18 07:12:59 +00:00
|
|
|
|
|
|
|
opt
|
|
|
|
clean -purge
|
|
|
|
|
|
|
|
## Tech mapping
|
2024-04-04 18:54:11 +00:00
|
|
|
# PLAs
|
2024-04-04 22:16:02 +00:00
|
|
|
techmap -map techmaps/pla.v -D PLA_MAX_PRODUCTS=$num_max_products
|
|
|
|
techmap -max_iter 1 -map techmaps/trivial_sop.v
|
2024-04-04 06:33:47 +00:00
|
|
|
|
|
|
|
# Sequential OLMC
|
2024-04-04 18:54:11 +00:00
|
|
|
extract -constports -map extractions/ndff.v
|
2024-04-04 06:33:47 +00:00
|
|
|
extract -constports -map extractions/olmc.v
|
2024-04-04 17:02:51 +00:00
|
|
|
techmap -map techmaps/olmc_seq.v
|
2024-04-04 06:33:47 +00:00
|
|
|
|
2024-04-04 22:16:02 +00:00
|
|
|
# Add OLMC for internal GAL_SOPs
|
|
|
|
#techmap -max_iter 1 -map techmaps/pla_olmc_int.v */t:GAL_OLMC %ci2 */t:GAL_SOP %i */t:GAL_SOP %D
|
|
|
|
techmap -max_iter 1 -map techmaps/pla_olmc_int.v */t:GAL_SOP %co1 */w:* %i */t:GAL_SOP %ci1 */w:* %i %i %c %ci1 %D
|
|
|
|
|
2024-04-04 06:33:47 +00:00
|
|
|
# Combinational OLMC
|
|
|
|
iopadmap -bits -outpad GAL_COMB_OUTPUT_P A:Y */t:GAL_SOP "%x:+\[Y\]" */t:GAL_SOP %d o:* %i
|
2024-04-04 22:16:02 +00:00
|
|
|
techmap -map techmaps/olmc_comb.v
|
2024-04-04 18:54:11 +00:00
|
|
|
|
2024-03-18 07:12:59 +00:00
|
|
|
clean -purge
|
|
|
|
|
2024-04-04 23:08:40 +00:00
|
|
|
## Write output files
|
2024-04-04 06:33:47 +00:00
|
|
|
write_verilog "output/synth_${fbasename}.v"
|
|
|
|
write_json "output/synth_${fbasename}.json"
|
2024-03-18 07:12:59 +00:00
|
|
|
|
|
|
|
## Verify equivalence
|
|
|
|
# Backup and make gold and gate modules
|
|
|
|
design -stash postop
|
|
|
|
design -copy-from preop -as gold A:top
|
|
|
|
design -copy-from postop -as gate A:top
|
|
|
|
|
2024-04-04 06:33:47 +00:00
|
|
|
# Inverse tech map into primatives
|
2024-04-04 23:08:40 +00:00
|
|
|
techmap -autoproc -map cells_sim.v
|
2024-04-04 06:33:47 +00:00
|
|
|
clean -purge
|
2024-03-18 07:12:59 +00:00
|
|
|
|
|
|
|
# Verify
|
|
|
|
equiv_make gold gate equiv
|
2024-04-04 06:33:47 +00:00
|
|
|
tribuf -formal equiv
|
2024-03-18 07:12:59 +00:00
|
|
|
equiv_induct equiv
|
2024-04-04 06:33:47 +00:00
|
|
|
equiv_status -assert equiv
|
|
|
|
|
|
|
|
# Get LTP from inverse tech map so FF cells are recognized
|
|
|
|
ltp -noff
|
2024-03-18 07:12:59 +00:00
|
|
|
|
|
|
|
# Restore backup
|
|
|
|
design -load postop
|
|
|
|
|
2024-04-04 23:08:40 +00:00
|
|
|
## Print final stats and show graph
|
2024-04-04 06:33:47 +00:00
|
|
|
show -width -signed -enum
|
2024-03-18 07:12:59 +00:00
|
|
|
stat
|
|
|
|
|
|
|
|
shell
|