From 2a106b551dd24779e9902b6e5efc281bfe76d5fd Mon Sep 17 00:00:00 2001 From: dsengupta0628 Date: Tue, 27 Oct 2026 14:07:17 +0000 Subject: [PATCH 1/7] keep annotated powers appropriately accross network edits, delete only when pin deleted Signed-off-by: dsengupta0628 --- src/sta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sta b/src/sta index bc7af6f0267..013a0dc97e9 160000 --- a/src/sta +++ b/src/sta @@ -1 +1 @@ -Subproject commit bc7af6f02679074eaf43657488ca117c05f98eed +Subproject commit 013a0dc97e9f3c9bdeae2555b91fdc5f40a46ff3 From ed14ba78eb5eea1dfba9512c3ef8ca8a215a6daa Mon Sep 17 00:00:00 2001 From: dsengupta0628 Date: Tue, 27 Oct 2026 20:43:11 +0000 Subject: [PATCH 2/7] dbSta, dft, gpl: keep power activity annotations on replaced pins scan_replace and cluster_flops replace cells by creating new instances and deleting the old ones. Since OpenSTA drops the activity annotation of a deleted pin, the user/SAIF/VCD activity on the replaced flop pins was lost and their power fell back to the propagated estimate, even though the new pins carry the same signals on the same nets. After cluster_flops the original instance names no longer exist, so re-reading the SAIF cannot recover it. Add dbSta::copyUserActivity(from, to) and call it before the old cell is destroyed: - dft utils::ReplaceCell (scan_replace and its rollback): copy each old pin to the new pin given by the port mapping. ReplaceCell now takes the dbSta. - gpl MBFF::ModifyPinConnections (cluster_flops): copy each flop's D and Q/QN pin to the tray pin it is reconnected to. New pins without a counterpart (scan in/enable) and shared tray pins (clock, scan enable, preset, clear) keep the default activity. Add dft scan_replace_activity_sky130 and gpl mbff_activity. Signed-off-by: dsengupta0628 --- src/dbSta/include/db_sta/dbSta.hh | 4 ++ src/dbSta/src/dbSta.cc | 13 ++++++ src/dft/src/replace/ScanReplace.cpp | 5 ++- src/dft/src/utils/Utils.cpp | 12 ++++++ src/dft/src/utils/Utils.hh | 2 + src/dft/test/BUILD | 4 ++ src/dft/test/scan_replace_activity_sky130.ok | 24 +++++++++++ src/dft/test/scan_replace_activity_sky130.tcl | 16 ++++++++ src/gpl/src/mbff.cpp | 3 ++ src/gpl/test/BUILD | 1 + src/gpl/test/mbff_activity.ok | 37 +++++++++++++++++ src/gpl/test/mbff_activity.tcl | 41 +++++++++++++++++++ 12 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/dft/test/scan_replace_activity_sky130.ok create mode 100644 src/dft/test/scan_replace_activity_sky130.tcl create mode 100644 src/gpl/test/mbff_activity.ok create mode 100644 src/gpl/test/mbff_activity.tcl 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 504f1d518f0..29ac906ead7 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 03bf63528eb..11f37f1c752 100644 --- a/src/dft/src/replace/ScanReplace.cpp +++ b/src/dft/src/replace/ScanReplace.cpp @@ -426,7 +426,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); @@ -469,7 +469,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 53685a65557..989fbb7492b 100644 --- a/src/dft/test/BUILD +++ b/src/dft/test/BUILD @@ -18,6 +18,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", @@ -53,6 +54,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..90c01228872 --- /dev/null +++ b/src/dft/test/scan_replace_activity_sky130.ok @@ -0,0 +1,24 @@ +[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__sdfsbp_1 + Library: sky130_fd_sc_hd_merged + Path cells: sky130_fd_sc_hd__sdfsbp_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 + Q_N output (unconnected) +input 1 +unannotated 10 +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 3a7c44f9ac6..afe74728cd8 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 48fe16b7122..2205e8ddaef 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]" +} From 868d3a0cf59f2cdf7e76b04a44c00a97b961e281 Mon Sep 17 00:00:00 2001 From: dsengupta0628 Date: Tue, 27 Oct 2026 20:56:05 +0000 Subject: [PATCH 3/7] dbSta: copy activity annotations only with the OpenSTA fork dbSta::copyUserActivity uses Power::hasUserActivity()/userActivity(), which are public only in the OpenROAD fork of OpenSTA. Guard it with STA_OPENROAD_FORK so OpenROAD still builds with stock OpenSTA, where the annotation is not copied. CMake now defines STA_OPENROAD_FORK for dbSta_lib in C++ as well as swig; Bazel gets it from opensta_lib. Bump src/sta for the opensta_lib define. Signed-off-by: dsengupta0628 --- src/dbSta/src/CMakeLists.txt | 1 + src/dbSta/src/dbSta.cc | 4 ++++ src/sta | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dbSta/src/CMakeLists.txt b/src/dbSta/src/CMakeLists.txt index 21678dc3e91..79bb4eeaee1 100644 --- a/src/dbSta/src/CMakeLists.txt +++ b/src/dbSta/src/CMakeLists.txt @@ -35,6 +35,7 @@ target_link_libraries(dbSta_lib # submodule provides them, so stock (parallaxsw) OpenSTA still builds. if(EXISTS ${OPENSTA_HOME}/search/AnalysisCorner.i) list(APPEND CMAKE_SWIG_FLAGS -DSTA_OPENROAD_FORK) + target_compile_definitions(dbSta_lib PRIVATE STA_OPENROAD_FORK) set(STA_ANALYSIS_CORNER_TCL ${OPENSTA_HOME}/tcl/AnalysisCorner.tcl) else() set(STA_ANALYSIS_CORNER_TCL "") diff --git a/src/dbSta/src/dbSta.cc b/src/dbSta/src/dbSta.cc index 29ac906ead7..70e5e14da67 100644 --- a/src/dbSta/src/dbSta.cc +++ b/src/dbSta/src/dbSta.cc @@ -503,6 +503,9 @@ float dbSta::slack(const odb::dbNet* db_net, const MinMax* min_max) void dbSta::copyUserActivity(odb::dbITerm* from, odb::dbITerm* to) { +// Power::hasUserActivity/userActivity are public only in the OpenROAD +// fork of OpenSTA; with stock OpenSTA the annotation is not copied. +#ifdef STA_OPENROAD_FORK const Pin* from_pin = db_network_->dbToSta(from); if (power()->hasUserActivity(from_pin)) { const PwrActivity& activity = power()->userActivity(from_pin); @@ -511,6 +514,7 @@ void dbSta::copyUserActivity(odb::dbITerm* from, odb::dbITerm* to) activity.duty(), activity.origin()); } +#endif } odb::PtrSet dbSta::findClkNets() diff --git a/src/sta b/src/sta index 03844fc7581..5ccfdb16035 160000 --- a/src/sta +++ b/src/sta @@ -1 +1 @@ -Subproject commit 03844fc7581340a5f67c276a438b345f3097b090 +Subproject commit 5ccfdb16035d66896fbd54de96a15e6a7edc4d4f From 313082d3c5e14236cb9b38bfda2a9445abd7e580 Mon Sep 17 00:00:00 2001 From: dsengupta0628 Date: Tue, 27 Oct 2026 21:04:29 +0000 Subject: [PATCH 4/7] ci: retrigger Signed-off-by: dsengupta0628 From 0943e7ebd908c5cc016b10358ba32244435a3f43 Mon Sep 17 00:00:00 2001 From: dsengupta0628 Date: Wed, 28 Oct 2026 22:08:17 +0000 Subject: [PATCH 5/7] use sta master now as it has the necessary bugfixes to retain annotations correctly Signed-off-by: dsengupta0628 --- src/sta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sta b/src/sta index 5ccfdb16035..a50641666c6 160000 --- a/src/sta +++ b/src/sta @@ -1 +1 @@ -Subproject commit 5ccfdb16035d66896fbd54de96a15e6a7edc4d4f +Subproject commit a50641666c6e2fd19ff0226f9b6300d876bf8613 From 9496d5d4afa1dd708539e63459230ee6641a90c1 Mon Sep 17 00:00:00 2001 From: dsengupta0628 Date: Mon, 2 Nov 2026 17:59:15 +0000 Subject: [PATCH 6/7] dbSta: drop the STA_OPENROAD_FORK guard in copyUserActivity Power::hasUserActivity()/userActivity() are public in upstream OpenSTA now, so the copy no longer needs the fork-only guard. Bazel does not define STA_OPENROAD_FORK for C++, so the guard turned copyUserActivity into a no-op. Signed-off-by: dsengupta0628 --- src/dbSta/src/dbSta.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/dbSta/src/dbSta.cc b/src/dbSta/src/dbSta.cc index 30844c26737..3b7b4025485 100644 --- a/src/dbSta/src/dbSta.cc +++ b/src/dbSta/src/dbSta.cc @@ -503,9 +503,6 @@ float dbSta::slack(const odb::dbNet* db_net, const MinMax* min_max) void dbSta::copyUserActivity(odb::dbITerm* from, odb::dbITerm* to) { -// Power::hasUserActivity/userActivity are public only in the OpenROAD -// fork of OpenSTA; with stock OpenSTA the annotation is not copied. -#ifdef STA_OPENROAD_FORK const Pin* from_pin = db_network_->dbToSta(from); if (power()->hasUserActivity(from_pin)) { const PwrActivity& activity = power()->userActivity(from_pin); @@ -514,7 +511,6 @@ void dbSta::copyUserActivity(odb::dbITerm* from, odb::dbITerm* to) activity.duty(), activity.origin()); } -#endif } odb::PtrSet dbSta::findClkNets() From 6ae9da0df3f325d511abfbca64896f94367b3cc6 Mon Sep 17 00:00:00 2001 From: dsengupta0628 Date: Mon, 2 Nov 2026 18:02:08 +0000 Subject: [PATCH 7/7] dft: regolden scan_replace_activity_sky130 for the new scan cell ranking Master now picks sdfstp_1 instead of sdfsbp_1 for this design, as in one_cell_sky130. The activity lines are unchanged. Signed-off-by: dsengupta0628 --- src/dft/test/scan_replace_activity_sky130.ok | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dft/test/scan_replace_activity_sky130.ok b/src/dft/test/scan_replace_activity_sky130.ok index 90c01228872..bfbcdc67b78 100644 --- a/src/dft/test/scan_replace_activity_sky130.ok +++ b/src/dft/test/scan_replace_activity_sky130.ok @@ -5,9 +5,9 @@ [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__sdfsbp_1 + Cell: sky130_fd_sc_hd__sdfstp_1 Library: sky130_fd_sc_hd_merged - Path cells: sky130_fd_sc_hd__sdfsbp_1 + Path cells: sky130_fd_sc_hd__sdfstp_1 Input pins: D input port1 SCD input (unconnected) @@ -16,9 +16,8 @@ Instance ff1 CLK input clock Output pins: Q output output1 - Q_N output (unconnected) input 1 -unannotated 10 +unannotated 9 Annotated pins: user ff1/Q ff1/Q 2.50000e+07 0.500 user