Skip to content

Commit 44643b5

Browse files
committed
fix state table mbff issue and coverity in this file
Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
1 parent defec0b commit 44643b5

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

liberty/Liberty.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,8 @@ LibertyCell::outputPortSequential(LibertyPort *port)
14891489
bool
14901490
LibertyCell::hasSequentials() const
14911491
{
1492-
return !sequentials_.empty();
1492+
return !sequentials_.empty()
1493+
|| statetable_ != nullptr;
14931494
}
14941495

14951496
void
@@ -2479,7 +2480,7 @@ LibertyPort::less(const LibertyPort *port1,
24792480
{
24802481
if (port1 == nullptr && port2 != nullptr)
24812482
return true;
2482-
if (port1 != nullptr && port2 == nullptr)
2483+
if (port1 == nullptr || port2 == nullptr)
24832484
return false;
24842485
const std::string &name1 = port1->name();
24852486
const std::string &name2 = port2->name();

liberty/Liberty.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ ensure_voltage_waveforms()
303303
}
304304

305305
LibertyCell *test_cell() { return self->testCell(); }
306+
bool has_sequentials() { return self->hasSequentials(); }
306307

307308
} // LibertyCell methods
308309

liberty/test/cpp/TestLibertyStaCallbacks.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,4 +4308,52 @@ library(test_r11_ccs) {
43084308
}() ));
43094309
}
43104310

4311+
// Regression: hasSequentials must return true for cells that define
4312+
// sequential behavior via a statetable group (no ff/latch).
4313+
// Multi-bit flip-flops (MBFFs) and clock-gated cells commonly use
4314+
// statetable instead of ff/latch groups. Without the statetable_
4315+
// check in hasSequentials(), these cells are misclassified as
4316+
// combinational — breaking power categorization, resizer guards,
4317+
// and dbSta cell-type mapping.
4318+
TEST_F(StaLibertyTest, HasSequentialsStatetableMBFF) {
4319+
const char *content = R"(
4320+
library(test_mbff_statetable) {
4321+
delay_model : table_lookup ;
4322+
time_unit : "1ns" ;
4323+
voltage_unit : "1V" ;
4324+
current_unit : "1mA" ;
4325+
capacitive_load_unit(1, ff) ;
4326+
cell(MBFF2) {
4327+
area : 6.0 ;
4328+
pin(D0) { direction : input ; capacitance : 0.01 ; }
4329+
pin(D1) { direction : input ; capacitance : 0.01 ; }
4330+
pin(CLK) { direction : input ; capacitance : 0.01 ; clock : true ; }
4331+
pin(Q0) { direction : output ; function : "IQ0" ; }
4332+
pin(Q1) { direction : output ; function : "IQ1" ; }
4333+
statetable("D0 D1 CLK", "IQ0 IQ1") {
4334+
table : "- - ~R : - - : N N ,\
4335+
H - R : - - : H N ,\
4336+
L - R : - - : L N ,\
4337+
- H R : - - : N H ,\
4338+
- L R : - - : N L" ;
4339+
}
4340+
}
4341+
}
4342+
)";
4343+
LibertyLibrary *lib = writeAndReadLibReturn(sta_, content);
4344+
ASSERT_NE(lib, nullptr);
4345+
LibertyCell *mbff = lib->findLibertyCell("MBFF2");
4346+
ASSERT_NE(mbff, nullptr);
4347+
4348+
// The cell has no ff/latch group, so sequentials_ is empty.
4349+
EXPECT_TRUE(mbff->sequentials().empty());
4350+
// But it has a statetable, so it IS sequential.
4351+
EXPECT_NE(mbff->statetable(), nullptr);
4352+
// hasSequentials() must return true for statetable-only cells.
4353+
EXPECT_TRUE(mbff->hasSequentials())
4354+
<< "MBFF2 uses statetable (no ff/latch) but hasSequentials() "
4355+
"returned false — statetable cells are misclassified as "
4356+
"combinational";
4357+
}
4358+
43114359
} // namespace sta

0 commit comments

Comments
 (0)