Skip to content

fix: the bug of genlib_reader parser#698

Open
yu-lin-chen wants to merge 1 commit into
lsils:masterfrom
yu-lin-chen:fix/bug-description
Open

fix: the bug of genlib_reader parser#698
yu-lin-chen wants to merge 1 commit into
lsils:masterfrom
yu-lin-chen:fix/bug-description

Conversation

@yu-lin-chen

Copy link
Copy Markdown

Fix Log: genlib_reader constant gate parsing (2026-07-07)

File: include/mockturtle/io/genlib_reader.hpp

Problem:
The genlib_reader incorrectly parses constant gates such as TIEHI (Z=1), TIELO (ZN=0), CONST0, and CONST1. During tokenization, the literal "0" or "1" in the expression is treated as a pin name, producing num_vars=1. When create_from_formula is then called with formula="1" and pin_names={"1"}, the literal collides with the pin name and is interpreted as a variable reference, yielding a 1-variable truth table [0,1] — identical to a buffer. This causes tie-high/tie-low cells to be matched as buffers during technology mapping.

Fix:
After CONST stripping (which converts CONST0/CONST1 to "0"/"1") and after tokenization, check whether the formula is a bare "0" or "1". If so, clear the pin vectors and pin names — these spurious entries were produced by mistaking the constant literal for a variable name. The truth table construction still goes through the standard create_from_formula path, which now correctly receives num_vars=0 and empty pin_names, producing a proper 0-variable constant truth table.

Change: 6 lines added after the CONST stripping block and before num_vars / create_from_formula. No existing code paths altered.
tcbn28hpcplusbwp40p140tt0p9v25c.lib:genlib write by abc
GATE TIEHBWP40P140 0.25 Z=1; PIN * UNKNOWN 1 999 1.00 0.00 1.00 0.00
GATE TIELBWP40P140 0.25 ZN=0; PIN * UNKNOWN 1 999 1.00 0.00 1.00 0.00

Copilot AI review requested due to automatic review settings July 7, 2026 08:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes genlib_reader parsing for constant-output gates whose Boolean expression is a bare literal ("0"/"1"), preventing them from being misinterpreted as 1-input buffers during truth table construction and downstream technology mapping.

Changes:

  • Detects bare constant formulas ("0" / "1") after CONST0/CONST1 stripping.
  • Clears tokenization-derived pin_names (and corresponding pp) for these constant formulas so create_from_formula builds a 0-variable constant truth table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +151 to +155
/* detect constant gates (e.g., Z=1, Z=0, O=CONST0, O=CONST1) and
discard spurious pin names produced by tokenization of "0"/"1" */
if ( formula == "0" || formula == "1" )
{
pp.clear();
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.05%. Comparing base (25beb0e) to head (b35aed0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #698      +/-   ##
==========================================
- Coverage   84.06%   84.05%   -0.01%     
==========================================
  Files         190      190              
  Lines       29468    29471       +3     
==========================================
  Hits        24773    24773              
- Misses       4695     4698       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants