fix: the bug of genlib_reader parser#698
Open
yu-lin-chen wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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") afterCONST0/CONST1stripping. - Clears tokenization-derived
pin_names(and correspondingpp) for these constant formulas socreate_from_formulabuilds 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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