diff --git a/src/dbSta/include/db_sta/dbSta.hh b/src/dbSta/include/db_sta/dbSta.hh index 006c69a79c9..c66018ab59a 100644 --- a/src/dbSta/include/db_sta/dbSta.hh +++ b/src/dbSta/include/db_sta/dbSta.hh @@ -162,6 +162,10 @@ class dbSta : public Sta, public odb::dbDatabaseObserver float slack(const odb::dbNet* net, const MinMax* min_max); + // Copy the user/SAIF/VCD activity annotated on from to to, for netlist + // edits that replace a pin with an equivalent one. + void copyUserActivity(odb::dbITerm* from, odb::dbITerm* to); + // From ord::OpenRoad::Observer void postReadLef(odb::dbTech* tech, odb::dbLib* library) override; void postReadDef(odb::dbBlock* block) override; diff --git a/src/dbSta/src/dbSta.cc b/src/dbSta/src/dbSta.cc index 19341955a47..3b7b4025485 100644 --- a/src/dbSta/src/dbSta.cc +++ b/src/dbSta/src/dbSta.cc @@ -39,6 +39,7 @@ #include "odb/dbBlockCallBackObj.h" #include "odb/dbObject.h" #include "odb/dbTypes.h" +#include "power/Power.hh" #include "sta/ArcDelayCalc.hh" #include "sta/Clock.hh" #include "sta/Delay.hh" @@ -500,6 +501,18 @@ float dbSta::slack(const odb::dbNet* db_net, const MinMax* min_max) return slack(net, min_max); } +void dbSta::copyUserActivity(odb::dbITerm* from, odb::dbITerm* to) +{ + const Pin* from_pin = db_network_->dbToSta(from); + if (power()->hasUserActivity(from_pin)) { + const PwrActivity& activity = power()->userActivity(from_pin); + power()->setUserActivity(db_network_->dbToSta(to), + activity.density(), + activity.duty(), + activity.origin()); + } +} + odb::PtrSet dbSta::findClkNets() { return findClkNets(cmdMode()); diff --git a/src/dft/src/replace/ScanReplace.cpp b/src/dft/src/replace/ScanReplace.cpp index 97737e9a1d9..3582eb9e5d1 100644 --- a/src/dft/src/replace/ScanReplace.cpp +++ b/src/dft/src/replace/ScanReplace.cpp @@ -594,7 +594,7 @@ void ScanReplace::scanReplace(odb::dbBlock* block) odb::dbMaster* master_scan_cell = db_network_->staToDb(scan_cell); odb::dbInst* new_cell = utils::ReplaceCell( - block, inst, master_scan_cell, scan_candidate->getPortMapping()); + sta_, block, inst, master_scan_cell, scan_candidate->getPortMapping()); already_replaced.insert(new_cell); addCellForRollback(master, master_scan_cell, scan_candidate); @@ -637,7 +637,8 @@ void ScanReplace::rollbackScanReplace(odb::dbBlock* block) } RollbackCandidate& rollback_candidate = *found->second; - utils::ReplaceCell(block, + utils::ReplaceCell(sta_, + block, inst, rollback_candidate.getMaster(), rollback_candidate.getPortMapping()); diff --git a/src/dft/src/utils/Utils.cpp b/src/dft/src/utils/Utils.cpp index 27d8da263b1..79028b530d0 100644 --- a/src/dft/src/utils/Utils.cpp +++ b/src/dft/src/utils/Utils.cpp @@ -58,6 +58,7 @@ bool IsSequentialCell(sta::dbNetwork* db_network, odb::dbInst* instance) } odb::dbInst* ReplaceCell( + sta::dbSta* sta, odb::dbBlock* top_block, odb::dbInst* old_instance, odb::dbMaster* new_master, @@ -120,6 +121,17 @@ odb::dbInst* ReplaceCell( } } + // Keep the activity annotations of the old pins on the new pins + for (odb::dbITerm* old_iterm : old_instance->getITerms()) { + auto mapped = port_mapping.find(old_iterm->getMTerm()->getName()); + if (mapped != port_mapping.end()) { + odb::dbITerm* new_iterm = new_instance->findITerm(mapped->second.c_str()); + if (new_iterm) { + sta->copyUserActivity(old_iterm, new_iterm); + } + } + } + // Delete the old cell odb::dbInst::destroy(old_instance); diff --git a/src/dft/src/utils/Utils.hh b/src/dft/src/utils/Utils.hh index e0caf103115..ae70a3f1523 100644 --- a/src/dft/src/utils/Utils.hh +++ b/src/dft/src/utils/Utils.hh @@ -20,7 +20,9 @@ namespace dft::utils { // cell will be preserved by using the given port mapping from // . Returns the new instance and deletes the old // one. The name of the new instance is going to be the same as the old one. +// User/SAIF/VCD activity of the old pins is copied to the mapped new pins. odb::dbInst* ReplaceCell( + sta::dbSta* sta, odb::dbBlock* top_block, odb::dbInst* old_instance, odb::dbMaster* new_master, diff --git a/src/dft/test/BUILD b/src/dft/test/BUILD index 0e30e9d57a3..b43a4e94626 100644 --- a/src/dft/test/BUILD +++ b/src/dft/test/BUILD @@ -14,6 +14,7 @@ COMPULSORY_TESTS = [ "scan_architect_clock_mix_sky130", "scan_architect_no_mix_sky130", "scan_architect_register_bank_no_clock_mix_sky130", + "scan_replace_activity_sky130", "scan_replace_dont_use_sky130", "scandef_core_sky130", "scandef_sky130", @@ -51,6 +52,9 @@ filegroup( "scan_architect_register_bank_no_clock_mix_sky130": [ "register_bank_top.v", ], + "scan_replace_activity_sky130": [ + "one_cell_sky130.def", + ], "scan_replace_dont_use_sky130": [ "one_cell_sky130.def", ], diff --git a/src/dft/test/scan_replace_activity_sky130.ok b/src/dft/test/scan_replace_activity_sky130.ok new file mode 100644 index 00000000000..bfbcdc67b78 --- /dev/null +++ b/src/dft/test/scan_replace_activity_sky130.ok @@ -0,0 +1,23 @@ +[INFO ODB-0227] LEF file: sky130hd/sky130hd.tlef, created 13 layers, 25 vias +[INFO ODB-0227] LEF file: sky130hd/sky130_fd_sc_hd_merged.lef, created 437 library cells +[INFO ODB-0128] Design: one_cell +[INFO ODB-0130] Created 4 pins. +[INFO ODB-0131] Created 1 components and 6 component-terminals. +[INFO ODB-0133] Created 4 nets and 4 connections. +Instance ff1 + Cell: sky130_fd_sc_hd__sdfstp_1 + Library: sky130_fd_sc_hd_merged + Path cells: sky130_fd_sc_hd__sdfstp_1 + Input pins: + D input port1 + SCD input (unconnected) + SCE input (unconnected) + SET_B input set_b + CLK input clock + Output pins: + Q output output1 +input 1 +unannotated 9 +Annotated pins: + user ff1/Q +ff1/Q 2.50000e+07 0.500 user diff --git a/src/dft/test/scan_replace_activity_sky130.tcl b/src/dft/test/scan_replace_activity_sky130.tcl new file mode 100644 index 00000000000..50b0f30f991 --- /dev/null +++ b/src/dft/test/scan_replace_activity_sky130.tcl @@ -0,0 +1,16 @@ +# scan_replace keeps the activity annotation of the replaced flop's pins +source "helpers.tcl" + +read_lef sky130hd/sky130hd.tlef +read_lef sky130hd/sky130_fd_sc_hd_merged.lef +read_liberty sky130hd/sky130_fd_sc_hd__tt_025C_1v80.lib + +read_def one_cell_sky130.def + +create_clock -name main_clock -period 2.0000 -waveform {0.0000 1.0000} [get_ports {clock}] + +set_power_activity -pins [get_pins ff1/Q] -activity 0.05 +scan_replace +report_instance ff1 +report_activity_annotation -report_annotated +puts "ff1/Q [get_property [get_pins ff1/Q] activity]" diff --git a/src/gpl/src/mbff.cpp b/src/gpl/src/mbff.cpp index 02e18f874b9..b6b2f39a5c6 100644 --- a/src/gpl/src/mbff.cpp +++ b/src/gpl/src/mbff.cpp @@ -513,6 +513,9 @@ void MBFF::ModifyPinConnections(const std::vector& flops, } } if (tray_iterm) { + // Keep the activity annotation of the flop pin on the tray pin. + sta_->copyUserActivity(iterm, tray_iterm); + const std::string val = orig_inst_name + "/" + orig_port_name; odb::dbStringProperty* prop = odb::dbStringProperty::find(tray_iterm, kOrigNameProp); diff --git a/src/gpl/test/BUILD b/src/gpl/test/BUILD index d356b95e029..63f8ad5114d 100644 --- a/src/gpl/test/BUILD +++ b/src/gpl/test/BUILD @@ -19,6 +19,7 @@ TESTS = [ "diverge01", "error01", "incremental01", + "mbff_activity", "mbff_hier", "mbff_orig_name", "mbff_clock_power_off", diff --git a/src/gpl/test/mbff_activity.ok b/src/gpl/test/mbff_activity.ok new file mode 100644 index 00000000000..6092fb0d4d6 --- /dev/null +++ b/src/gpl/test/mbff_activity.ok @@ -0,0 +1,37 @@ +[INFO ODB-0227] LEF file: ./asap7/asap7_tech_1x_201209.lef, created 30 layers, 9 vias +[INFO ODB-0227] LEF file: ./SingleBit/asap7sc7p5t_28_L_1x_220121a.lef, created 212 library cells +[INFO ODB-0227] LEF file: ./4BitTrayH4/asap7sc7p5t_DFFHQNV4X.lef, created 9 library cells +[WARNING IFP-0028] Core area lower left (1.000, 1.000) snapped to (1.026, 1.080). +[INFO IFP-0001] Added 29 rows of 147 site asap7sc7p5t. +[INFO IFP-0100] Die BBox: ( 0.000 0.000 ) ( 10.000 10.000 ) um +[INFO IFP-0101] Core BBox: ( 1.026 1.080 ) ( 8.964 8.910 ) um +[INFO IFP-0102] Core area: 62.155 um^2 +[INFO IFP-0103] Total instances area: 1.166 um^2 +[INFO IFP-0104] Effective utilization: 0.019 +[INFO IFP-0105] Number of instances: 4 +Alpha = 40.0, Beta = 1.0, #paths = 0, max size = -1 +Total ILP Cost: 112.644 +Total Timing Critical Path Displacement: 0.0 +Average slot-to-flop displacement: 1.730 +Final Objective Value: 112.644 +Sizes used + 4-bit: 1 +input 8 +unannotated 10 +Annotated pins: + user _tray_size4_7/D0 + user _tray_size4_7/D1 + user _tray_size4_7/D2 + user _tray_size4_7/D3 + user _tray_size4_7/QN0 + user _tray_size4_7/QN1 + user _tray_size4_7/QN2 + user _tray_size4_7/QN3 +_tray_size4_7/D0 8.00000e+07 0.500 user +_tray_size4_7/D1 7.00000e+07 0.500 user +_tray_size4_7/D2 5.00000e+07 0.500 user +_tray_size4_7/D3 6.00000e+07 0.500 user +_tray_size4_7/QN0 4.00000e+07 0.500 user +_tray_size4_7/QN1 3.00000e+07 0.500 user +_tray_size4_7/QN2 1.00000e+07 0.500 user +_tray_size4_7/QN3 2.00000e+07 0.500 user diff --git a/src/gpl/test/mbff_activity.tcl b/src/gpl/test/mbff_activity.tcl new file mode 100644 index 00000000000..d635397f63b --- /dev/null +++ b/src/gpl/test/mbff_activity.tcl @@ -0,0 +1,41 @@ +# cluster_flops keeps the activity annotation of each flop pin on its tray pin +source helpers.tcl + +read_lef ./asap7/asap7_tech_1x_201209.lef +read_lef ./SingleBit/asap7sc7p5t_28_L_1x_220121a.lef +read_liberty ./SingleBit/asap7sc7p5t_SEQ_LVT_TT_nldm_220123.lib +read_lef ./4BitTrayH4/asap7sc7p5t_DFFHQNV4X.lef +read_liberty ./4BitTrayH4/asap7sc7p5t_DFFHQNV4X_LVT_TT_nldm_FAKE.lib + +read_verilog ./mbff_orig_name.v +link_design tray_test + +initialize_floorplan -die_area "0 0 10 10" \ + -core_area "1 1 9 9" \ + -site asap7sc7p5t + +place_inst -name ff1 -origin {6 6} -status PLACED +place_inst -name ff2 -origin {4 6} -status PLACED +place_inst -name ff3 -origin {4 4} -status PLACED +place_inst -name ff4 -origin {6 4} -status PLACED + +create_clock -name clk -period 1000 [get_ports clk1] + +set_power_activity -pins [get_pins ff1/QN] -activity 0.01 +set_power_activity -pins [get_pins ff2/QN] -activity 0.02 +set_power_activity -pins [get_pins ff3/QN] -activity 0.03 +set_power_activity -pins [get_pins ff4/QN] -activity 0.04 +set_power_activity -pins [get_pins ff1/D] -activity 0.05 +set_power_activity -pins [get_pins ff2/D] -activity 0.06 +set_power_activity -pins [get_pins ff3/D] -activity 0.07 +set_power_activity -pins [get_pins ff4/D] -activity 0.08 + +cluster_flops -tray_weight 40.0 \ + -timing_weight 1.0 \ + -max_split_size -1 \ + -num_paths 0 + +report_activity_annotation -report_annotated +foreach pin [get_pins {_tray_size4_*/D* _tray_size4_*/QN*}] { + puts "[get_full_name $pin] [get_property $pin activity]" +}